[asterisk-commits] dvossel: branch dvossel/test_api r235384 - in /team/dvossel/test_api: include...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 16 19:14:51 CST 2009


Author: dvossel
Date: Wed Dec 16 19:14:50 2009
New Revision: 235384

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235384
Log:
test define information is not stored within the callback function

Modified:
    team/dvossel/test_api/include/asterisk/test.h
    team/dvossel/test_api/main/test.c
    team/dvossel/test_api/tests/test_heap.c

Modified: team/dvossel/test_api/include/asterisk/test.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/include/asterisk/test.h?view=diff&rev=235384&r1=235383&r2=235384
==============================================================================
--- team/dvossel/test_api/include/asterisk/test.h (original)
+++ team/dvossel/test_api/include/asterisk/test.h Wed Dec 16 19:14:50 2009
@@ -35,14 +35,35 @@
 1. DEFINE TEST: Create a callback function for the test
    using the AST_TEST_DEFINE macro.
 
+   Each defined test has three arguments avaliable to it's test code.
+       \param struct ast_test_info *info
+       \param enum ast_test_command cmd
+       \param struct ast_test_args *args
+
+   While these arguments are not visible they are passed to every test function
+   defined using the AST_TEST_DEFINE macro.
+
+   Below is an example of how to define and write a test function.
+
    AST_TEST_DEFINE(sample_test_cb, \\The first argument is the name of the callback function
    {                               \\The second argument is the function's body *
-       \test code
+       switch (cmd) {
+       case TEST_INIT:
+           info->name = "sample_test";
+           info->category = "main/test/";
+           info->summary = "sample test for example purpose";
+           info->description = "This demonstrates how to initialize a test function";
+
+           return AST_TEST_NOT_RUN;
+       case TEST_EXECUTE:
+           break;
+       }
+	   \test code
         .
         .
         .
         if (fail) {                 \\ the following is just some example logic
-            ast_str_set(ast_test_error_str, 0 , "an error occured because...");
+            ast_str_set(&args->ast_test_error_str, 0 , "an error occured because...");
             res = AST_RESULT_FAIL;
         } else {
             res = AST_RESULT_PASS
@@ -50,9 +71,9 @@
         return res;                 \\ result must be of type enum ast_test_result_state
     })
 
-    Every callback function is passed a string buffer which allows
-    the function to provide an optional short description of
-    what went wrong if the test failed.
+    Every callback function is passed ast_test_args object which contains
+	a ast_str allowing the function to provide an optional short description of
+    what went wrong if the test failed. args->ast_test_error_str
 
     *NOTE: It is possible for a ',' within the code body to mess up the macro
     depending on how it is used.  If this happens (it will be obvious because
@@ -64,15 +85,15 @@
 
 2. REGISTER TEST: Register the test using the AST_TEST_REGISTER macro.
 
-    AST_TEST_REGISTER("sample_test",         \\ Test's Name
-                      "main/test",           \\ Test's Catagory
-                      "this is sample test", \\ Brief summary of test
-                      "Sample test designed for test purposes", \\ Verbose discription of test
-                       sample_test_cb);      \\ Test callback function defined by AST_TEST_DEFINE
+	AST_TEST_REGISTER uses the callback function to retrieve all the information
+	pertaining to a test, so the callback function is the only argument required
+	to register a test.
+
+    AST_TEST_REGISTER(sample_test_cb);    \\ Test callback function defined by AST_TEST_DEFINE
 
     Tests are unregestered by using the AST_TEST_UNREGISTER macro.
 
-    AST_TEST_UNREGISTER(sample_test_cb); \\ Remove a registered test by callback function
+    AST_TEST_UNREGISTER(sample_test_cb);  \\ Remove a registered test by callback function
 
 3. EXECUTE: Execute and generate test results via CLI commands
 
@@ -86,16 +107,44 @@
 
 /*! Macros used for defining and registering a test */
 #ifdef TEST_FRAMEWORK
-#define AST_TEST_DEFINE(hdr, body) enum ast_test_result_state hdr(struct ast_str **ast_test_error_str); enum ast_test_result_state hdr(struct ast_str **ast_test_error_str) body
-#define AST_TEST_REGISTER(name, cat, sum, des, cb) ast_test_register(name, cat, sum, des, cb)
+#define AST_TEST_DEFINE(hdr, body) static enum ast_test_result_state hdr(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test_args *args) body
+#define AST_TEST_REGISTER(cb) ast_test_register(cb)
 #define AST_TEST_UNREGISTER(cb) ast_test_unregister(cb)
 #else /* else no-op */
 #define AST_TEST_DEFINE(hdr, body)
-#define AST_TEST_REGISTER(name, cat, sum, des, cb)
+#define AST_TEST_REGISTER(cb)
 #define AST_TEST_UNREGISTER(cb)
 #endif
 
 #ifdef TEST_FRAMEWORK
+enum ast_test_result_state {
+	AST_TEST_NOT_RUN = 0,
+	AST_TEST_PASS = 1,
+	AST_TEST_FAIL = 2,
+};
+
+enum ast_test_command {
+	TEST_INIT = 0,
+	TEST_EXECUTE = 1,
+};
+
+/*!
+ * tools made available to the callback function during test execution
+ */
+struct ast_test_args {
+	struct ast_str *ast_test_error_str;  /*! optional error str to describe error result */
+};
+
+/*!
+ * Contains all the initilization information required to store a new test definition
+ */
+struct ast_test_info {
+	const char *name;          /*! name of test, unique to category */
+	const char *category;      /*! test category */
+	const char *summary;       /*! optional short summary of test */
+	const char *description;   /*! optional brief detailed description of test */
+};
+
 /*!
  * \brief Generic test callback function
  *
@@ -103,13 +152,7 @@
  *
  * \return AST_TEST_PASS for pass, AST_TEST_FAIL for failure
  */
-typedef enum ast_test_result_state (ast_test_cb_t)(struct ast_str **ast_test_error_str);
-
-enum ast_test_result_state {
-	AST_TEST_NOT_RUN = 0,
-	AST_TEST_PASS = 1,
-	AST_TEST_FAIL = 2,
-};
+typedef enum ast_test_result_state (ast_test_cb_t)(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test_args *args);
 
 /*!
  * \brief unregisters a test with the test framework
@@ -124,16 +167,12 @@
 /*!
  * \brief registers a test with the test framework
  *
- * \param name of test (required)
- * \param test category (required)
- * \param test summary (optional)
- * \param test description (optional)
  * \param test callback function (required)
  *
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_test_register(const char *name, const char *category, const char *summary, const char *description, ast_test_cb_t *cb);
+int ast_test_register(ast_test_cb_t *cb);
 
 #endif /* TEST_FRAMEWORK */
 #endif /* _AST_TEST_H */

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=235384&r1=235383&r2=235384
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Wed Dec 16 19:14:50 2009
@@ -40,7 +40,7 @@
 #define DEFAULT_XML_PATH "asterisk_test_result.xml"
 #define DEFAULT_TXT_PATH "asterisk_test_result.txt"
 
-/*! This array corrisponds to the values defined in the ast_test_result_state enum */
+/*! This array corrisponds to the values defined in the ast_test_state enum */
 static const char *test_result2str[] = {
 	[AST_TEST_NOT_RUN] = "NOT RUN",
 	[AST_TEST_PASS] = "PASS",
@@ -49,19 +49,15 @@
 
 /*! represents all the test result data for a single ast_test object */
 struct ast_test_result {
-	enum ast_test_result_state state; /*! current test result state */
-	struct ast_str *error;            /*! optional error str to describe error result */
-	unsigned int time;                         /*! time in ms test took */
 };
 
 /*! holds all the information pertaining to a single defined test */
 struct ast_test {
-	char *name;          /*! name of test, unique to category */
-	char *category;      /*! test category */
-	char *summary;       /*! optional short summary of test */
-	char *description;   /*! optional brief detailed description of test */
-	struct ast_test_result result;  /*! stores the latest execution results */
-	ast_test_cb_t *cb;   /*! test callback function */
+	struct ast_test_info info;       /*! holds test callback information */
+	struct ast_test_args args;       /*! function callback arguments */
+	enum ast_test_result_state state;       /*! current test state */
+	unsigned int time;               /*! time in ms test took */
+	ast_test_cb_t *cb;               /*! test callback function */
 	AST_LIST_ENTRY(ast_test) entry;
 };
 
@@ -86,25 +82,24 @@
 static AST_LIST_HEAD_STATIC(tests, ast_test);
 
 /*! static function prototypes */
-static struct ast_test *test_alloc(const char *name, const char *category, const char *summary, const char *description, ast_test_cb_t *cb);
+static struct ast_test *test_alloc(ast_test_cb_t *cb);
 static struct ast_test *test_free(struct ast_test *test);
 static int test_insert(struct ast_test *test);
 static struct ast_test *test_remove(ast_test_cb_t *cb);
 static int test_cat_cmp(const char *cat1, const char *cat2);
 
-int ast_test_register(const char *name, const char *category, const char *summary, const char *description, ast_test_cb_t *cb)
+int ast_test_register(ast_test_cb_t *cb)
 {
 	struct ast_test *test;
 
 	/* verify data.*/
-	if (ast_strlen_zero(name) || ast_strlen_zero(category) ||
-			ast_strlen_zero(description) || ast_strlen_zero(summary) || !cb) {
+	if (!cb) {
 		ast_log(LOG_WARNING, "Attempted to register test without all required information\n");
 		return -1;
 	}
 
 	/* create test object */
-	if (!(test = test_alloc(name, category, summary, description, cb))) {
+	if (!(test = test_alloc(cb))) {
 		return -1;
 	}
 
@@ -144,13 +139,13 @@
 	struct timeval begin;
 
 	/* clear any previous error results before starting */
-	ast_str_reset(test->result.error);
+	ast_str_reset(test->args.ast_test_error_str);
 	/* get start time */
 	begin = ast_tvnow();
 	/* the callback gets the pointer to the pointer of the error buf */
-	test->result.state = test->cb(&test->result.error);
+	test->state = test->cb(&test->info, TEST_EXECUTE, &test->args);
 	/* record the total time the test took */
-	test->result.time = ast_tvdiff_ms(ast_tvnow(), begin);
+	test->time = ast_tvdiff_ms(ast_tvnow(), begin);
 }
 
 static void test_xml_entry(struct ast_test *test, FILE *f)
@@ -160,17 +155,17 @@
 	}
 
 	fprintf(f, "\n<test>\n");
-	fprintf(f, "<name>%s</name>\n", test->name);
-	fprintf(f, "<category>%s</category>\n", test->category);
-	fprintf(f, "<summary>%s</summary>\n", test->summary);
-	fprintf(f, "<description>%s</description>\n", test->description);
-
-	fprintf(f, "<result>\n%s\n", test_result2str[test->result.state]);
-	if (test->result.state == AST_TEST_FAIL) {
-		fprintf(f, "\t<error>\n\t\t%s\n\t</error>\n", S_OR(ast_str_buffer(test->result.error), "NA"));
-	}
-	if (test->result.state != AST_TEST_NOT_RUN) {
-		fprintf(f, "\t<time>\n\t\t%d\n\t</time>\n", test->result.time);
+	fprintf(f, "<name>%s</name>\n", test->info.name);
+	fprintf(f, "<category>%s</category>\n", test->info.category);
+	fprintf(f, "<summary>%s</summary>\n", test->info.summary);
+	fprintf(f, "<description>\n%s\n</description>\n", test->info.description);
+
+	fprintf(f, "<result>\n\t%s\n", test_result2str[test->state]);
+	if (test->state == AST_TEST_FAIL) {
+		fprintf(f, "\t<error>\n\t\t%s\n\t</error>\n", S_OR(ast_str_buffer(test->args.ast_test_error_str), "NA"));
+	}
+	if (test->state != AST_TEST_NOT_RUN) {
+		fprintf(f, "\t<time>\n\t\t%d\n\t</time>\n", test->time);
 	}
 	fprintf(f, "</result>\n");
 
@@ -183,20 +178,21 @@
 		return;
 	}
 
-	fprintf(f, "\nName:              %s\n", test->name);
-	fprintf(f,   "Catagory:          %s\n", test->category);
-	fprintf(f,   "Summary:           %s\n", test->summary);
-	fprintf(f,   "Description:       %s\n", test->description);
-	fprintf(f,   "Result:            %s\n", test_result2str[test->result.state]);
-	if (test->result.state == AST_TEST_FAIL) {
-		fprintf(f,   "Error Description: %s\n", S_OR(ast_str_buffer(test->result.error), "NA"));
-	}
-	if (test->result.state != AST_TEST_NOT_RUN) {
-		fprintf(f,   "Time:              %d\n", test->result.time);
+	fprintf(f, "\nName:              %s\n", test->info.name);
+	fprintf(f,   "Catagory:          %s\n", test->info.category);
+	fprintf(f,   "Summary:           %s\n", test->info.summary);
+	fprintf(f,   "Description:       %s\n", test->info.description);
+	fprintf(f,   "Result:            %s\n", test_result2str[test->state]);
+	if (test->state == AST_TEST_FAIL) {
+		fprintf(f,   "Error Description: %s\n", S_OR(ast_str_buffer(test->args.ast_test_error_str), "NA"));
+	}
+	if (test->state != AST_TEST_NOT_RUN) {
+		fprintf(f,   "Time:              %d\n", test->time);
 	}
 }
 
 /*!
+ * \internal
  * \brief Executes registered unit tests
  *
  * \param name of test to run (optional)
@@ -234,12 +230,12 @@
 		execute = 0;
 		switch (mode) {
 		case TEST_CATEGORY:
-			if (!test_cat_cmp(test->category, category)) {
+			if (!test_cat_cmp(test->info.category, category)) {
 				execute = 1;
 			}
 			break;
 		case TEST_NAME_CATEGORY:
-			if (!(strcmp(test->category, category)) && !(strcmp(test->name, name))) {
+			if (!(strcmp(test->info.category, category)) && !(strcmp(test->info.name, name))) {
 				execute = 1;
 			}
 			break;
@@ -249,15 +245,15 @@
 
 		if (execute) {
 			if (fd) {
-				ast_cli(fd, "START  %s/%s \n", test->category, test->name);
+				ast_cli(fd, "START  %s/%s \n", test->info.category, test->info.name);
 			}
 
 			/* execute the test and save results */
 			test_execute(test);
 
 			/* update execution specific counts here */
-			last_results.last_time += test->result.time;
-			if (test->result.state == AST_TEST_PASS) {
+			last_results.last_time += test->time;
+			if (test->state == AST_TEST_PASS) {
 				last_results.last_passed++;
 			} else {
 				last_results.last_failed++;
@@ -265,25 +261,25 @@
 
 			if (fd) {
 				term_color(result_buf,
-					test_result2str[test->result.state],
-					(test->result.state == AST_TEST_FAIL) ? COLOR_RED : COLOR_GREEN,
+					test_result2str[test->state],
+					(test->state == AST_TEST_FAIL) ? COLOR_RED : COLOR_GREEN,
 					0,
 					sizeof(result_buf));
 				ast_cli(fd, "END    %s/%s Time: %dms Result: %s %s\n",
-					test->category,
-					test->name,
-					test->result.time,
+					test->info.category,
+					test->info.name,
+					test->time,
 					result_buf,
-					ast_str_buffer(test->result.error));
+					ast_str_buffer(test->args.ast_test_error_str));
 			}
 		}
 
 		/* update total counts as well during this iteration
 		 * even if the current test did not execute this time */
-		last_results.total_time += test->result.time;
+		last_results.total_time += test->time;
 		last_results.total_tests++;
-		if (test->result.state != AST_TEST_NOT_RUN) {
-			if (test->result.state == AST_TEST_PASS) {
+		if (test->state != AST_TEST_NOT_RUN) {
+			if (test->state == AST_TEST_PASS) {
 				last_results.total_passed++;
 			} else {
 				last_results.total_failed++;
@@ -418,12 +414,12 @@
 	 * comparisons on every item within the list to insert in sorted order. */
 	AST_LIST_LOCK(&tests);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, cur, entry) {
-		if ((i = strcmp(test->category, cur->category)) < 0) {
+		if ((i = strcmp(test->info.category, cur->info.category)) < 0) {
 			AST_LIST_INSERT_BEFORE_CURRENT(test, entry);
 			inserted = 1;
 			break;
 		} else if (!i) {  /* same category, now insert by name within that category*/
-			if ((i = strcmp(test->name, cur->name)) < 0) {
+			if ((i = strcmp(test->info.name, cur->info.name)) < 0) {
 				AST_LIST_INSERT_BEFORE_CURRENT(test, entry);
 				inserted = 1;
 				break;
@@ -470,6 +466,32 @@
 }
 
 /*!
+ * \brief compares two test catagories to determine if cat1 resides in cat2
+ * \internal
+ *
+ * \return 0 if true
+ */
+
+static int test_cat_cmp(const char *cat1, const char *cat2)
+{
+	int len1 = 0;
+	int len2 = 0;
+
+	if (!cat1 || !cat2) {
+		return -1;
+	}
+
+	len1 = strlen(cat1);
+	len2 = strlen(cat2);
+
+	if (len2 > len1) {
+		return -1;
+	}
+
+	return strncmp(cat1, cat2, len2) ? 1 : 0;
+}
+
+/*!
  * \brief frees a ast_test object and all it's data members
  * \internal
  */
@@ -479,64 +501,36 @@
 		return NULL;
 	}
 
-	ast_free(test->name);
-	ast_free(test->category);
-	ast_free(test->summary);
-	ast_free(test->description);
-	ast_free(test->result.error);
+	ast_free(test->args.ast_test_error_str);
 	ast_free(test);
 
 	return NULL;
-}
-
-/*!
- * \brief compares two test catagories to determine if cat1 resides in cat2
- * \internal
- *
- * \return 0 if true
- */
-
-static int test_cat_cmp(const char *cat1, const char *cat2)
-{
-	int len1 = 0;
-	int len2 = 0;
-
-	if (!cat1 || !cat2) {
-		return -1;
-	}
-
-	len1 = strlen(cat1);
-	len2 = strlen(cat2);
-
-	if (len2 > len1) {
-		return -1;
-	}
-
-	return strncmp(cat1, cat2, len2) ? 1 : 0;
 }
 
 /*!
  * \internal
  * \brief allocates an ast_test object.
  */
-static struct ast_test *test_alloc(const char *name, const char *category, const char *summary, const char *description, ast_test_cb_t *cb)
+static struct ast_test *test_alloc(ast_test_cb_t *cb)
 {
 	struct ast_test *test;
 
-	if (!(test = ast_calloc(1, sizeof(*test)))) {
-		return NULL;
-	}
-
-	if (!(test->name = ast_strdup(name)) ||
-		 !(test->category = ast_strdup(category)) ||
-		 !(test->summary = ast_strdup(summary)) ||
-		 !(test->description = ast_strdup(description)) ||
-		 !(test->result.error = ast_str_create(128))) {
+	if (!cb || !(test = ast_calloc(1, sizeof(*test)))) {
+		return NULL;
+	}
+
+	test->cb = cb;
+
+	test->cb(&test->info, TEST_INIT, &test->args);
+
+	if (ast_strlen_zero(test->info.name) ||
+		ast_strlen_zero(test->info.category) ||
+		ast_strlen_zero(test->info.summary) ||
+		ast_strlen_zero(test->info.description) ||
+		!(test->args.ast_test_error_str = ast_str_create(128))) {
 
 		return test_free(test);
 	}
-
-	test->cb = cb;
 
 	return test;
 }
@@ -579,10 +573,10 @@
 		AST_LIST_LOCK(&tests);
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
 			if ((a->argc == 4) ||
-				 ((a->argc == 5) && !test_cat_cmp(test->category, a->argv[4])) ||
-				 ((a->argc == 7) && !strcmp(test->category, a->argv[4]) && !strcmp(test->name, a->argv[6]))) {
-
-				ast_cli(a->fd, FORMAT, test->name, test->category, test->summary, test_result2str[test->result.state]);
+				 ((a->argc == 5) && !test_cat_cmp(test->info.category, a->argv[4])) ||
+				 ((a->argc == 7) && !strcmp(test->info.category, a->argv[4]) && !strcmp(test->info.name, a->argv[6]))) {
+
+				ast_cli(a->fd, FORMAT, test->info.name, test->info.category, test->info.summary, test_result2str[test->state]);
 				count ++;
 			}
 		}
@@ -696,22 +690,22 @@
 		ast_cli(a->fd, FORMAT_RES_ALL, "Result", "", "Name", "Catagory", "Error Description");
 		AST_LIST_LOCK(&tests);
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
-			if (test->result.state == AST_TEST_NOT_RUN) {
+			if (test->state == AST_TEST_NOT_RUN) {
 				continue;
 			}
-			test->result.state == AST_TEST_FAIL ? failed++ : passed++;
-			if (!mode || ((mode == 1) && (test->result.state == AST_TEST_FAIL)) || ((mode == 2) && (test->result.state == AST_TEST_PASS))) {
+			test->state == AST_TEST_FAIL ? failed++ : passed++;
+			if (!mode || ((mode == 1) && (test->state == AST_TEST_FAIL)) || ((mode == 2) && (test->state == AST_TEST_PASS))) {
 				/* give our results pretty colors */
-				term_color(result_buf, test_result2str[test->result.state],
-					(test->result.state == AST_TEST_FAIL) ? COLOR_RED : COLOR_GREEN,
+				term_color(result_buf, test_result2str[test->state],
+					(test->state == AST_TEST_FAIL) ? COLOR_RED : COLOR_GREEN,
 					0, sizeof(result_buf));
 
 				ast_cli(a->fd, FORMAT_RES_ALL,
 					result_buf,
 					"  ",
-					test->name,
-					test->category,
-					(test->result.state == AST_TEST_FAIL) ? S_OR(ast_str_buffer(test->result.error), "Not Avaliable") : "");
+					test->info.name,
+					test->info.category,
+					(test->state == AST_TEST_FAIL) ? S_OR(ast_str_buffer(test->args.ast_test_error_str), "Not Avaliable") : "");
 			}
 		}
 		AST_LIST_TRAVERSE_SAFE_END;

Modified: team/dvossel/test_api/tests/test_heap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/tests/test_heap.c?view=diff&rev=235384&r1=235383&r2=235384
==============================================================================
--- team/dvossel/test_api/tests/test_heap.c (original)
+++ team/dvossel/test_api/tests/test_heap.c Wed Dec 16 19:14:50 2009
@@ -63,12 +63,23 @@
 	struct node *obj;
 	struct node nodes[3];
 
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "heap_test_1";
+		info->category = "main/heap/";
+		info->summary = "push and pop elements";
+		info->description = "Push a few elements onto a heap and make sure that they come back off in the right order.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
 	nodes[0].val = nodes[0].index = 1;
 	nodes[1].val = nodes[1].index = 2;
 	nodes[2].val = nodes[2].index = 3;
 
 	if (!(h = ast_heap_create(8, node_cmp, offsetof(struct node, index)))) {
-		return -1;
+		return AST_TEST_FAIL;
 	}
 
 	/* Pushing 1 2 3, and then popping 3 elements */
@@ -102,8 +113,7 @@
 	h = ast_heap_destroy(h);
 
 	return AST_TEST_PASS;
-}
-)
+})
 
 AST_TEST_DEFINE(heap_test_2,
 {
@@ -116,6 +126,17 @@
 	long cur;
 	int res = AST_TEST_PASS;
 
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "heap_test_2";
+		info->category = "main/heap/";
+		info->summary = "load test";
+		info->description = "Push a million random elements on to a heap,verify that the heap has been properly constructed, and then ensure that the elements are come back off in the proper order";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
 	if (!(nodes = ast_malloc(one_million * sizeof(*node)))) {
 		res = AST_TEST_FAIL;
 		goto return_cleanup;
@@ -140,7 +161,7 @@
 	while ((node = ast_heap_pop(h))) {
 		cur = node->val;
 		if (cur > last) {
-			ast_str_set(ast_test_error_str, 0, "i: %u, cur: %ld, last: %ld\n", i, cur, last);
+			ast_str_set(&args->ast_test_error_str, 0, "i: %u, cur: %ld, last: %ld\n", i, cur, last);
 			res = AST_TEST_FAIL;
 			goto return_cleanup;
 		}
@@ -149,7 +170,7 @@
 	}
 
 	if (i != one_million) {
-		ast_str_set(ast_test_error_str, 0, "Stopped popping off after only getting %u nodes\n", i);
+		ast_str_set(&args->ast_test_error_str, 0, "Stopped popping off after only getting %u nodes\n", i);
 		res = AST_TEST_FAIL;
 		goto return_cleanup;
 	}
@@ -176,17 +197,9 @@
 static int load_module(void)
 {
 
-	AST_TEST_REGISTER("heap_test_1",
-		"main/heap",
-		"push and pop elements",
-		"Push a few elements onto a heap and make sure that they come back off in the right order.",
-		heap_test_1);
-
-	AST_TEST_REGISTER("heap_test_2",
-		"main/heap",
-		"load test",
-		"Push a million random elements on to a heap,verify that the heap has been properly constructed, and then ensure that the elements are come back off in the proper order",
-		heap_test_2);
+	AST_TEST_REGISTER(heap_test_1);
+
+	AST_TEST_REGISTER(heap_test_2);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }




More information about the asterisk-commits mailing list