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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 14 11:59:30 CST 2009


Author: dvossel
Date: Mon Dec 14 11:59:29 2009
New Revision: 234672

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234672
Log:
protect latest test results with lock

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=234672&r1=234671&r2=234672
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Mon Dec 14 11:59:29 2009
@@ -180,17 +180,16 @@
 	struct ast_test *test = NULL;
 	int mode = 0; /* 3 modes, 0 = run all, 1 = only by catagory, 2 = only by name and catagory */
 	int execute = 0;
-
+	int res = 0;
+
+	AST_LIST_LOCK(&tests);
 	/* clear previous execution results */
 	memset(&last_results, 0, sizeof(last_results));
-
 	if (!ast_strlen_zero(catagory) && ast_strlen_zero(name)) {
 		mode = 1;
 	} else if (!ast_strlen_zero(catagory) && !ast_strlen_zero(name)) {
 		mode = 2;
 	}
-
-	AST_LIST_LOCK(&tests);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
 		execute = 0;
 		if ((!mode) ||
@@ -233,9 +232,10 @@
 		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
+	res = last_results.last_passed + last_results.last_failed;
 	AST_LIST_UNLOCK(&tests);
 
-	return last_results.last_passed + last_results.last_failed;
+	return res;
 }
 
 int ast_test_generate_results(const char *name, const char *catagory, const char *xml_path, const char *txt_path)
@@ -275,6 +275,7 @@
 		}
 	}
 
+	AST_LIST_LOCK(&tests);
 	/* xml header information */
 	if (f_xml) {
 		fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
@@ -301,7 +302,6 @@
 	}
 
 	/* export each individual test */
-	AST_LIST_LOCK(&tests);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, test, entry) {
 		__test_xml_entry(test, f_xml);
 		__test_txt_entry(test, f_txt);
@@ -527,6 +527,7 @@
 			return CLI_SHOWUSAGE;
 		}
 
+		AST_LIST_LOCK(&tests);
 		if (!(last_results.last_passed + last_results.last_failed)) {
 			ast_cli(a->fd, "--- No Tests Found! ---\n");
 		}
@@ -534,6 +535,7 @@
 			(last_results.last_passed + last_results.last_failed),
 			last_results.last_passed,
 			last_results.last_failed);
+		AST_LIST_UNLOCK(&tests);
 	default:
 		return NULL;
 	}




More information about the asterisk-commits mailing list