This is an automated email from the ASF dual-hosted git repository. jpeach pushed a commit to branch master in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit e5dd21f26b653d1fc9cebadb224587c8d88e4f92 Author: James Peach <[email protected]> AuthorDate: Wed Apr 20 22:28:43 2016 -0700 TS-4370: Add a traffic_server option to list tests. Add the -l option to traffic_server option to list the available tests. This is helpful when you want to run specific tests but need to know what they are. This closes #597. --- doc/appendices/command-line/traffic_server.en.rst | 7 ++++- lib/ts/Regression.cc | 31 +++++++++++++++++------ lib/ts/Regression.h | 22 ++++++++++------ proxy/Main.cc | 12 ++++++++- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/doc/appendices/command-line/traffic_server.en.rst b/doc/appendices/command-line/traffic_server.en.rst index 4c0c905..43c0c3c 100644 --- a/doc/appendices/command-line/traffic_server.en.rst +++ b/doc/appendices/command-line/traffic_server.en.rst @@ -57,7 +57,12 @@ environments or where the working set is highly variable. .. option:: -R LEVEL, --regression LEVEL -.. option:: -r TEST, --regression_rest TEST +.. option:: -r TEST, --regression_test TEST + +.. option:: -l, --regression_list + +If Traffic Server was built with tests enabled, this option lists +the available tests. .. option:: -T TAGS, --debug_tags TAGS diff --git a/lib/ts/Regression.cc b/lib/ts/Regression.cc index 878197c..4639285 100644 --- a/lib/ts/Regression.cc +++ b/lib/ts/Regression.cc @@ -50,14 +50,9 @@ regression_status_string(int status) (status == REGRESSION_TEST_PASSED ? "PASSED" : (status == REGRESSION_TEST_INPROGRESS ? "INPROGRESS" : "FAILED"))); } -RegressionTest::RegressionTest(const char *name_arg, TestFunction *function_arg, int aopt) +RegressionTest::RegressionTest(const char *_n, const SourceLocation &_l, TestFunction *_f, int _o) + : name(_n), location(_l), function(_f), next(0), status(REGRESSION_TEST_NOT_RUN), printed(false), opt(_o) { - name = name_arg; - function = function_arg; - status = REGRESSION_TEST_NOT_RUN; - printed = 0; - opt = aopt; - if (opt == REGRESSION_OPT_EXCLUSIVE) { if (exclusive_test) this->next = exclusive_test; @@ -80,7 +75,7 @@ start_test(RegressionTest *t) if (tresult != REGRESSION_TEST_INPROGRESS) { fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", t->name, 40 - (int)strlen(t->name), " ", regression_status_string(tresult)); - t->printed = 1; + t->printed = true; } return tresult; } @@ -105,6 +100,26 @@ RegressionTest::run(const char *atest) return run_some(); } +void +RegressionTest::list() +{ + char buf[128]; + const char *bold = "\x1b[1m"; + const char *unbold = "\x1b[0m"; + + if (!isatty(fileno(stdout))) { + bold = unbold = ""; + } + + for (RegressionTest *t = test; t; t = t->next) { + fprintf(stdout, "%s%s%s %s\n", bold, t->name, unbold, t->location.str(buf, sizeof(buf))); + } + + for (RegressionTest *t = exclusive_test; t; t = t->next) { + fprintf(stdout, "%s%s%s %s\n", bold, t->name, unbold, t->location.str(buf, sizeof(buf))); + } +} + int RegressionTest::run_some() { diff --git a/lib/ts/Regression.h b/lib/ts/Regression.h index cec9255..d22d9c4 100644 --- a/lib/ts/Regression.h +++ b/lib/ts/Regression.h @@ -26,6 +26,7 @@ #include "ts/ink_platform.h" #include "ts/Regex.h" +#include "ts/Diags.h" // Each module should provide one or more regression tests // @@ -60,37 +61,42 @@ // regression options #define REGRESSION_OPT_EXCLUSIVE (1 << 0) +#define RegressionMakeLocation(f) SourceLocation(__FILE__, f, __LINE__) + struct RegressionTest; typedef void TestFunction(RegressionTest *t, int type, int *status); struct RegressionTest { const char *name; + const SourceLocation location; TestFunction *function; RegressionTest *next; int status; - int printed; + bool printed; int opt; - RegressionTest(const char *name_arg, TestFunction *function_arg, int aopt); + RegressionTest(const char *name_arg, const SourceLocation &loc, TestFunction *function_arg, int aopt); static int final_status; static int ran_tests; static DFA dfa; static RegressionTest *current; static int run(const char *name = NULL); + static void list(); static int run_some(); static int check_status(); }; -#define REGRESSION_TEST(_f) \ - void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ - RegressionTest regressionTest_##_f(#_f, &RegressionTest_##_f, 0); \ +#define REGRESSION_TEST(_f) \ + void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ + RegressionTest regressionTest_##_f(#_f, RegressionMakeLocation("RegressionTest_" #_f), &RegressionTest_##_f, 0); \ void RegressionTest_##_f -#define EXCLUSIVE_REGRESSION_TEST(_f) \ - void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ - RegressionTest regressionTest_##_f(#_f, &RegressionTest_##_f, REGRESSION_OPT_EXCLUSIVE); \ +#define EXCLUSIVE_REGRESSION_TEST(_f) \ + void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ + RegressionTest regressionTest_##_f(#_f, RegressionMakeLocation("RegressionTest_" #_f), &RegressionTest_##_f, \ + REGRESSION_OPT_EXCLUSIVE); \ void RegressionTest_##_f int rprintf(RegressionTest *t, const char *format, ...); diff --git a/proxy/Main.cc b/proxy/Main.cc index 089e06a..eec06d9 100644 --- a/proxy/Main.cc +++ b/proxy/Main.cc @@ -143,6 +143,7 @@ bool command_valid = false; static char const *CMD_VERIFY_CONFIG = "verify_config"; #if TS_HAS_TESTS static char regression_test[1024] = ""; +static int regression_list = 0; #endif int auto_clear_hostdb_flag = 0; extern int fds_limit; @@ -192,6 +193,7 @@ static const ArgumentDescription argument_descriptions[] = { #if TS_HAS_TESTS {"regression", 'R', "Regression Level (quick:1..long:3)", "I", ®ression_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", ®ression_list, "PROXY_REGRESSION_LIST", NULL}, #endif // TS_HAS_TESTS #if TS_USE_DIAGS @@ -211,7 +213,7 @@ static const ArgumentDescription argument_descriptions[] = { {"read_core", 'c', "Read Core file", "S255", &core_file, NULL, NULL}, #endif - {"accept_mss", ' ', "MSS for client connections", "I", &accept_mss, NULL, NULL}, + {"accept_mss", '-', "MSS for client connections", "I", &accept_mss, NULL, NULL}, {"poll_timeout", 't', "poll timeout in milliseconds", "I", &poll_timeout, NULL, NULL}, HELP_ARGUMENT_DESCRIPTION(), VERSION_ARGUMENT_DESCRIPTION()}; @@ -1495,6 +1497,14 @@ main(int /* argc ATS_UNUSED */, const char **argv) if (cmd_disable_freelist) { ink_freelist_init_ops(ink_freelist_malloc_ops()); } + +#if TS_HAS_TESTS + if (regression_list) { + RegressionTest::list(); + ::exit(0); + } +#endif + // Specific validity checks. if (*conf_dir && command_index != find_cmd_index(CMD_VERIFY_CONFIG)) { fprintf(stderr, "-D option can only be used with the %s command\n", CMD_VERIFY_CONFIG); -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
