[asterisk-commits] dvossel: branch dvossel/test_api r234254 - /team/dvossel/test_api/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 10 14:44:22 CST 2009


Author: dvossel
Date: Thu Dec 10 14:44:18 2009
New Revision: 234254

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234254
Log:
adds additional options to cli commands, fixes bug in ast_test_execute where wrong mode was picked

Modified:
    team/dvossel/test_api/main/asterisk.c
    team/dvossel/test_api/main/test.c

Modified: team/dvossel/test_api/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/asterisk.c?view=diff&rev=234254&r1=234253&r2=234254
==============================================================================
--- team/dvossel/test_api/main/asterisk.c (original)
+++ team/dvossel/test_api/main/asterisk.c Thu Dec 10 14:44:18 2009
@@ -3550,10 +3550,12 @@
 		exit(1);
 	}
 
+#ifdef AST_TEST_FRAMEWORK
 	if (ast_test_init()) {
 		printf("%s", term_quit());
 		exit(1);
 	}
+#endif
 
 	ast_makesocket();
 	sigemptyset(&sigs);

Modified: team/dvossel/test_api/main/test.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/test.c?view=diff&rev=234254&r1=234253&r2=234254
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Thu Dec 10 14:44:18 2009
@@ -18,22 +18,24 @@
 
 /*! \file
  *
- * \brief Internal test framework
+ * \brief Internal Test Framework
  *
  * \author David Vossel <dvossel at digium.com>
  */
 
+
 #include "asterisk.h"
 
 #include "asterisk/_private.h"
 
 #include "asterisk/test.h"
+
+#ifdef AST_TEST_FRAMEWORK
 #include "asterisk/logger.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/utils.h"
 #include "asterisk/cli.h"
 
-#ifdef AST_TEST_FRAMEWORK
 enum ast_test_result_state {
 	AST_TEST_NOT_RUN = 0,
 	AST_TEST_PASS = 1,
@@ -73,7 +75,6 @@
 
 /*! List of registered test definitions */
 static AST_LIST_HEAD_STATIC(tests, ast_test);
-#endif
 
 
 /*! static function prototypes */
@@ -86,52 +87,87 @@
 static char *test_cli_show_registered(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 #define FORMAT "%-15s %-20s %-30s %-10s\n"
-	struct ast_test *cur = NULL;
+	struct ast_test *test = NULL;
 	int count = 0;
-
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "test show registered";
 		e->usage =
-			"Usage: test show registered\n"
-			"       Shows current registered tests\n";
+			"Usage: test show registered [test catagory] [test name] \n"
+			"       Shows registered tests. Has three modes.\n"
+			"       1. If no arguments are provided, all registered tests will be shown\n"
+			"       2. If [test catagory] is provided only tests which fall within that\n"
+			"          catagory will be shown.\n"
+			"       3. If both [test catagory] and [test name] is provided, only the test\n"
+			"          within [test catagory] matching [test name] will be shown \n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	case CLI_HANDLER:
+		if (a->argc < 3 || a->argc > 5) {
+			return CLI_SHOWUSAGE;
+		}
 		ast_cli(a->fd, FORMAT, "Name", "Catagory", "Summary", "Test Result");
 		AST_LIST_LOCK(&tests);
-		AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, cur, entry) {
-			ast_cli(a->fd, FORMAT, cur->name, cur->catagory, cur->summary, test_result2str[cur->result.state]);
-			count ++;
+		AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
+			if ((a->argc == 3) ||
+				 ((a->argc == 4) && !strcmp(test->catagory, a->argv[3])) ||
+				 ((a->argc == 5) && !strcmp(test->catagory, a->argv[3]) && !strcmp(test->name, a->argv[4]))) {
+
+				ast_cli(a->fd, FORMAT, test->name, test->catagory, test->summary, test_result2str[test->result.state]);
+				count ++;
+			}
 		}
 		AST_LIST_TRAVERSE_SAFE_END;
 		AST_LIST_UNLOCK(&tests);
-		ast_cli(a->fd, "%d Test(s) Registered\n", count);
-
+		ast_cli(a->fd, "%d Registered Tests Matched\n", count);
 	default:
 		return NULL;
 	}
+
+	return CLI_SUCCESS;
 }
 
 static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-//todohere add additional options for tests 
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "test execute";
 		e->usage =
-			"Usage: test execute\n"
-			"       Executes registered tests\n";
+			"Usage: test execute [test catagory] [test name]\n"
+			"       Executes registered tests. Has three modes.\n"
+			"       1. If no arguments are provided, all registered tests will execute\n"
+			"       2. If [test catagory] is provided only tests which fall within that\n"
+			"          catagory will be executed.\n"
+			"       3. If both [test catagory] and [test name] is provided, only the test\n"
+			"          within [test catagory] matching [test name] will execute \n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	case CLI_HANDLER:
-		ast_test_execute(NULL, NULL);
+
+		if (a->argc == 2) { /* run all registered tests */
+			ast_cli(a->fd, "Running all available tests...\n");
+			ast_test_execute(NULL, NULL);
+		} else if (a->argc == 3) { /* run only tests within a catagory */
+			ast_cli(a->fd, "Running all available tests matching catagory %s\n", a->argv[2]);
+			ast_test_execute(NULL, a->argv[2]);
+		} else if (a->argc == 4) { /* run only a single test matching the catagory and name */
+			ast_cli(a->fd, "Running all available tests matching catagory %s and name %s\n", a->argv[2], a->argv[3]);
+			ast_test_execute(a->argv[3], a->argv[2]);
+		} else {
+			return CLI_SHOWUSAGE;
+		}
+
+		if (!last_results.count) {
+			ast_cli(a->fd, "--- No Tests Found! ---\n");
+		}
 		ast_cli(a->fd, "%d Test(s) Executed  %d Passed  %d Failed\n", last_results.count, last_results.passed, last_results.failed);
 	default:
 		return NULL;
 	}
+
+	return CLI_SUCCESS;
 }
 
 
@@ -153,7 +189,7 @@
 	ast_cli_register_multiple(test_cli, ARRAY_LEN(test_cli));
 
 	/* Register Sample Tests */
-	AST_TEST_REGISTER("sample test 1", "main/test", "this is sample test 1", "for example purposes", sample_test1);
+	AST_TEST_REGISTER("sample_test_1", "main/test", "this is sample test 1", "for example purposes", sample_test1);
 
 	/* Unregister Sample Tests */
 	//AST_TEST_UNREGISTER(sample_test1);
@@ -205,11 +241,12 @@
 	int mode = 0; /* 3 modes, 0 = run all, 1 = only by catagory, 2 = only by name and catagory */
 	int execute = 0;
 
+	/* clear previous execution results */
 	last_results.count = last_results.passed = last_results.failed = 0;
 
-	if (!ast_strlen_zero(catagory) && !ast_strlen_zero(name)) {
+	if (!ast_strlen_zero(catagory) && ast_strlen_zero(name)) {
 		mode = 1;
-	} else if (!ast_strlen_zero(catagory)) {
+	} else if (!ast_strlen_zero(catagory) && !ast_strlen_zero(name)) {
 		mode = 2;
 	}
 
@@ -244,7 +281,6 @@
 	//todohere
 	return 0;
 }
-
 
 /*!
  * \brief adds test to container sorted first by catagory then by name
@@ -355,3 +391,4 @@
 
 	return test;
 }
+#endif




More information about the asterisk-commits mailing list