[asterisk-commits] dvossel: branch dvossel/test_api r234453 - /team/dvossel/test_api/main/test.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 11 17:38:39 CST 2009


Author: dvossel
Date: Fri Dec 11 17:38:35 2009
New Revision: 234453

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234453
Log:
xml and txt result generation update

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

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=234453&r1=234452&r2=234453
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Fri Dec 11 17:38:35 2009
@@ -36,7 +36,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
-
+#include "asterisk/version.h"
 
 #define DEFAULT_XML_PATH "asterisk_test_result.xml"
 #define DEFAULT_TXT_PATH "asterisk_test_result.txt"
@@ -70,9 +70,13 @@
 };
 
 static struct ast_test_execute_results {
-	int count; /* number of tests run */
-	int passed; /* number of tests passed */
-	int failed; /* number of tests failed */
+	int total_tests;  /* total number of tests, reguardless if they have been executed or not */
+	int total_passed; /* number of tests passed */
+	int total_failed; /* number of tests failed */
+	int total_time;   /* total time of all executed tests */
+	int last_passed;  /* number of tests passed during last execution */
+	int last_failed;  /* number of tests filed during last execution */
+	int last_time;    /* total time of the last test execution */
 } last_results = { 0 };
 
 /*! List of registered test definitions */
@@ -174,7 +178,7 @@
 	int execute = 0;
 
 	/* clear previous execution results */
-	last_results.count = last_results.passed = last_results.failed = 0;
+	memset(&last_results, 0, sizeof(last_results));
 
 	if (!ast_strlen_zero(catagory) && ast_strlen_zero(name)) {
 		mode = 1;
@@ -198,11 +202,13 @@
 			}
 
 			__test_execute(test);
-			last_results.count++;
+
+			/* update execution specific counts here */
+			last_results.last_time += test->result.time;
 			if (test->result.state == AST_TEST_PASS) {
-				last_results.passed++;
+				last_results.last_passed++;
 			} else {
-				last_results.failed++;
+				last_results.last_failed++;
 			}
 
 			if (a) {
@@ -211,11 +217,22 @@
 			}
 
 		}
+
+		/* update total counts as well during this iteration */
+		last_results.total_time += test->result.time;
+		last_results.total_tests++;
+		if (test->result.state != AST_TEST_NOT_RUN) {
+			if (test->result.state == AST_TEST_PASS) {
+				last_results.total_passed++;
+			} else {
+				last_results.total_failed++;
+			}
+		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 	AST_LIST_UNLOCK(&tests);
 
-	return last_results.count;
+	return last_results.last_passed + last_results.last_failed;
 }
 
 int ast_test_generate_results(const char *name, const char *catagory, const char *xml_path, const char *txt_path)
@@ -255,20 +272,29 @@
 		}
 	}
 
-	/* todohere xml and txt headers */
+	/* xml header information */
 	if (f_xml) {
 		fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
 		fprintf(f_xml, "\n<results>\n");
-	//	fprintf(f_xml, "<version>%s</version>\n"); //todohere version!?
-	//	fprintf(f_xml, "<version>%s</version>\n");
-
-		fprintf(f_xml, "\n</results>\n");
-	}
-
+		fprintf(f_xml, "<version>%s</version>\n", ASTERISK_VERSION);
+		fprintf(f_xml, "<versionnum>%d</versionnum>\n", ASTERISK_VERSION_NUM);
+		fprintf(f_xml, "<numtests>%d</numtests>\n", (last_results.total_tests));
+		fprintf(f_xml, "<executedtests>%d</executedtests>\n", (last_results.total_passed + last_results.total_failed));
+		fprintf(f_xml, "<passedtests>%d</passedtests>\n", last_results.total_passed);
+		fprintf(f_xml, "<failedtests>%d</failedtests>\n", last_results.total_failed);
+		fprintf(f_xml, "<totaltime>%d</totaltime>\n", last_results.total_time);
+		fprintf(f_xml, "</results>\n");
+	}
+
+	/* txt header information */
 	if (f_txt) {
-
-//todohere txt header info
-
+		fprintf(f_txt, "Asterisk Version:         %s\n", ASTERISK_VERSION);
+		fprintf(f_txt, "Asterisk Version Number:  %d\n", ASTERISK_VERSION_NUM);
+		fprintf(f_txt, "Number of Tests:          %d\n", last_results.total_tests);
+		fprintf(f_txt, "Number of Tests Executed: %d\n", (last_results.total_passed + last_results.total_failed));
+		fprintf(f_txt, "Passed Tests:             %d\n", last_results.total_passed);
+		fprintf(f_txt, "Failed Tests:             %d\n", last_results.total_failed);
+		fprintf(f_txt, "Total Execution Time:     %d\n", last_results.total_time);
 	}
 
 	/* export each individual test */
@@ -496,10 +522,13 @@
 			return CLI_SHOWUSAGE;
 		}
 
-		if (!last_results.count) {
+		if (!(last_results.last_passed + last_results.last_failed)) {
 			ast_cli(a->fd, "--- No Tests Found! ---\n");
 		}
-		ast_cli(a->fd, "\n%d Test(s) Executed  %d Passed  %d Failed\n", last_results.count, last_results.passed, last_results.failed);
+		ast_cli(a->fd, "\n%d Test(s) Executed  %d Passed  %d Failed\n",
+			(last_results.last_passed + last_results.last_failed),
+			last_results.last_passed,
+			last_results.last_failed);
 	default:
 		return NULL;
 	}
@@ -636,9 +665,6 @@
 	AST_TEST_REGISTER("sample_test_1", "main/test", "this is sample test 1", "for example purposes", sample_test1);
 	AST_TEST_REGISTER("sample_test_2", "main/test", "this is sample test 2", "for example purposes", sample_test2);
 
-	/* Unregister Sample Tests */
-	//AST_TEST_UNREGISTER(sample_test1);
-
 	return 0;
 }
 #endif




More information about the asterisk-commits mailing list