Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions lib/ts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ library_includedir=$(includedir)/ts
library_include_HEADERS = apidefs.h

noinst_PROGRAMS = mkdfa CompileParseRules
check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_List test_Map test_Regex test_PriorityQueue test_Vec test_X509HostnameValidator test_Ptr
check_PROGRAMS = test_tsutil test_arena test_atomic test_freelist test_geometry test_List test_Map test_Vec test_X509HostnameValidator

TESTS = $(check_PROGRAMS)

Expand Down Expand Up @@ -216,14 +216,6 @@ test_Map_SOURCES = test_Map.cc
test_Map_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_Map_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@

test_Regex_SOURCES = test_Regex.cc
test_Regex_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_Regex_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@

test_PriorityQueue_SOURCES = test_PriorityQueue.cc
test_PriorityQueue_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_PriorityQueue_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@

test_Vec_SOURCES = test_Vec.cc
test_Vec_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_Vec_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
Expand All @@ -236,16 +228,15 @@ test_X509HostnameValidator_SOURCES = test_X509HostnameValidator.cc
test_X509HostnameValidator_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@ @OPENSSL_LIBS@
test_X509HostnameValidator_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@

test_Ptr_SOURCES = test_Ptr.cc
test_Ptr_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_Ptr_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
test_tsutil_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_tsutil_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
test_tsutil_SOURCES = \
test_PriorityQueue.cc \
test_Ptr.cc \
test_Regex.cc \
tests.cc

CompileParseRules_SOURCES = CompileParseRules.cc

test:: $(TESTS)
for f in $(TESTS) ; do $$f ; done

#$(foreach F, $(TESTS), $(shell $F))

clean-local:
rm -f ParseRulesCType ParseRulesCTypeToLower ParseRulesCTypeToUpper
65 changes: 53 additions & 12 deletions lib/ts/Regression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,27 @@

****************************************************************************/

#include "ts/Regression.h"
#include "ts/I_Version.h"
#include "ts/ink_platform.h"
#include "ts/ink_assert.h"
#include "ts/Regression.h"
#include "ts/ink_args.h"

static RegressionTest *test = NULL;
static RegressionTest *exclusive_test = NULL;

RegressionTest *RegressionTest::current = 0;
int RegressionTest::ran_tests = 0;
DFA RegressionTest::dfa;
int regression_level = 0;
int RegressionTest::final_status = REGRESSION_TEST_PASSED;

static const char *
progname(const char *path)
{
const char *slash = strrchr(path, '/');
return slash ? slash + 1 : path;
}

char *
regression_status_string(int status)
{
Expand All @@ -65,7 +73,7 @@ RegressionTest::RegressionTest(const char *_n, const SourceLocation &_l, TestFun
}

static inline int
start_test(RegressionTest *t)
start_test(RegressionTest *t, int regression_level)
{
ink_assert(t->status == REGRESSION_TEST_NOT_RUN);
t->status = REGRESSION_TEST_INPROGRESS;
Expand All @@ -81,23 +89,25 @@ start_test(RegressionTest *t)
}

int
RegressionTest::run(const char *atest)
RegressionTest::run(const char *atest, int regression_level)
{
if (atest)
dfa.compile(atest);
else
dfa.compile(".*");

fprintf(stderr, "REGRESSION_TEST initialization begun\n");
// start the non exclusive tests
for (RegressionTest *t = test; t; t = t->next) {
if ((dfa.match(t->name) >= 0)) {
int res = start_test(t);
int res = start_test(t, regression_level);
if (res == REGRESSION_TEST_FAILED)
final_status = REGRESSION_TEST_FAILED;
}
}

current = exclusive_test;
return run_some();
return run_some(regression_level);
}

void
Expand All @@ -121,12 +131,14 @@ RegressionTest::list()
}

int
RegressionTest::run_some()
RegressionTest::run_some(int regression_level)
{
if (current) {
if (current->status == REGRESSION_TEST_INPROGRESS)
if (current->status == REGRESSION_TEST_INPROGRESS) {
return REGRESSION_TEST_INPROGRESS;
else if (current->status != REGRESSION_TEST_NOT_RUN) {
}

if (current->status != REGRESSION_TEST_NOT_RUN) {
if (!current->printed) {
current->printed = true;
fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", current->name, 40 - (int)strlen(current->name), " ",
Expand All @@ -138,7 +150,7 @@ RegressionTest::run_some()

for (; current; current = current->next) {
if ((dfa.match(current->name) >= 0)) {
int res = start_test(current);
int res = start_test(current, regression_level);
if (res == REGRESSION_TEST_INPROGRESS)
return res;
if (res == REGRESSION_TEST_FAILED)
Expand All @@ -149,14 +161,15 @@ RegressionTest::run_some()
}

int
RegressionTest::check_status()
RegressionTest::check_status(int regression_level)
{
int status = REGRESSION_TEST_PASSED;
if (current) {
status = run_some();
status = run_some(regression_level);
if (!current)
return status;
}

RegressionTest *t = test;
int exclusive = 0;

Expand Down Expand Up @@ -190,6 +203,34 @@ RegressionTest::check_status()
return (status == REGRESSION_TEST_INPROGRESS) ? REGRESSION_TEST_INPROGRESS : final_status;
}

int
RegressionTest::main(int /* argc */, const char **argv)
{
static char regression_test[1024] = "";
static int regression_list = 0;
static int regression_level = 1;

static const ArgumentDescription argument_descriptions[] = {
{"regression", 'R', "Regression Level (quick:1..long:3)", "I", &regression_level, "PROXY_REGRESSION", NULL},
{"regression_test", 'r', "Run Specific Regression Test", "S512", regression_test, "PROXY_REGRESSION_TEST", NULL},
{"regression_list", 'l', "List Regression Tests", "T", &regression_list, "PROXY_REGRESSION_LIST", NULL},
};

AppVersionInfo version;

version.setup(PACKAGE_NAME, progname(argv[0]), PACKAGE_VERSION, __DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");

process_args(&version, argument_descriptions, countof(argument_descriptions), argv);

if (regression_list) {
RegressionTest::list();
} else {
RegressionTest::run(*regression_test == '\0' ? NULL : regression_test, regression_level);
}

return RegressionTest::final_status == REGRESSION_TEST_PASSED ? 0 : 1;
}

int
rprintf(RegressionTest *t, const char *format, ...)
{
Expand Down
10 changes: 5 additions & 5 deletions lib/ts/Regression.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ struct RegressionTest {
static int ran_tests;
static DFA dfa;
static RegressionTest *current;
static int run(const char *name = NULL);
static int run(const char *name = NULL, int regression_level = 1);
static void list();
static int run_some();
static int check_status();
static int run_some(int regression_level = 1);
static int check_status(int regression_level = 1);

static int main(int argc, const char **argv);
};

#define REGRESSION_TEST(_f) \
Expand All @@ -103,6 +105,4 @@ int rprintf(RegressionTest *t, const char *format, ...);
int rperf(RegressionTest *t, const char *tag, double val);
char *regression_status_string(int status);

extern int regression_level;

#endif /* _Regression_h */
9 changes: 0 additions & 9 deletions lib/ts/test_PriorityQueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,3 @@ REGRESSION_TEST(PriorityQueue_5)(RegressionTest *t, int /* atype ATS_UNUSED */,

box.check(pq->top() == NULL, "top should be NULL");
}

int
main(int /* argc ATS_UNUSED */, const char ** /* argv ATS_UNUSED */)
{
const char *name = "PriorityQueue";
RegressionTest::run(name);

return RegressionTest::final_status == REGRESSION_TEST_PASSED ? 0 : 1;
}
7 changes: 0 additions & 7 deletions lib/ts/test_Ptr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,3 @@ REGRESSION_TEST(Ptr_bool)(RegressionTest *t, int /* atype ATS_UNUSED */, int *ps
box.check(!none, "Empty Ptr<T> is false");
box.check(some, "Non-empty Ptr<T> is true");
}

int
main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */)
{
RegressionTest::run();
return RegressionTest::final_status == REGRESSION_TEST_PASSED ? 0 : 1;
}
20 changes: 8 additions & 12 deletions lib/ts/test_Regex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ts/ink_assert.h"
#include "ts/ink_defs.h"
#include "ts/Regex.h"
#include "ts/TestBox.h"

typedef struct {
char subject[100];
Expand All @@ -38,24 +39,19 @@ static const test_t test_data[] = {
{"foo$", {{"foo", true}, {"bar", false}, {"foobar", false}, {"foobarbaz", false}}},
};

static void
test_basic()
REGRESSION_TEST(Regex_basic)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
{
TestBox box(t, pstatus, REGRESSION_TEST_PASSED);

for (unsigned int i = 0; i < countof(test_data); i++) {
Regex r;

printf("Regex: %s\n", test_data[i].regex);
rprintf(t, "Regex: %s\n", test_data[i].regex);
r.compile(test_data[i].regex);

for (unsigned int j = 0; j < countof(test_data[i].tests); j++) {
printf("Subject: %s Result: %s\n", test_data[i].tests[j].subject, test_data[i].tests[j].match ? "true" : "false");
ink_assert(r.exec(test_data[i].tests[j].subject) == test_data[i].tests[j].match);
box.check(r.exec(test_data[i].tests[j].subject) == test_data[i].tests[j].match, "Subject: %s Result: %s\n",
test_data[i].tests[j].subject, test_data[i].tests[j].match ? "true" : "false");
}
}
}

int
main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */)
{
test_basic();
printf("test_Regex PASSED\n");
}
Loading