[asterisk-commits] mnicholson: branch mnicholson/asttest r247753 - in /team/mnicholson/asttest/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 18 15:20:09 CST 2010


Author: mnicholson
Date: Thu Feb 18 15:20:05 2010
New Revision: 247753

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247753
Log:
Added the ability to asttest to run a single test using the -s option.

Modified:
    team/mnicholson/asttest/asttest/asttest.c
    team/mnicholson/asttest/asttest/include/asttest/asttest.h
    team/mnicholson/asttest/asttest/include/asttest/testsuite.h
    team/mnicholson/asttest/asttest/include/asttest/testutils.h
    team/mnicholson/asttest/asttest/lib/testsuite.c
    team/mnicholson/asttest/asttest/lib/testutils.c

Modified: team/mnicholson/asttest/asttest/asttest.c
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/asttest.c?view=diff&rev=247753&r1=247752&r2=247753
==============================================================================
--- team/mnicholson/asttest/asttest/asttest.c (original)
+++ team/mnicholson/asttest/asttest/asttest.c Thu Feb 18 15:20:05 2010
@@ -29,7 +29,7 @@
 void usage(const char *prog_name) {
 	fprintf(stderr,
 		"Usage:\n"
-		"  %s [-wh] [-l <filename>] [-a <directory>] <test_dir> [test_dir...]\n"
+		"  %s [-whs] [-l <filename>] [-a <directory>] <test_dir> [test_dir...]\n"
 		"\n"
 		"Options:\n"
 		"  -l <filename>  Specify the name of the log file.  One log file will be\n"
@@ -44,8 +44,13 @@
 		"  -w             warn if tests were skipped because of errors.  This\n"
 		"                 option will cause a warning to print instead of an\n"
 		"                 error being generated if any tests fail because of\n"
-		"                 errors.\n" 
+		"                 errors.  This is ignored in single test mode.\n"
 		"  -h             print this help message\n"
+		"  -s <directory> Run in single test mode.  The given directory should contain a\n"
+		"                 test.lua test script.  Single test mode will also cause test\n"
+		"                 output to be sent to stdout instead of a log file and will cause\n"
+		"                 the program to exit with a non zero return code in if the test\n"
+		"                 fails.\n"
 		"\n"
 		, prog_name);
 }
@@ -73,7 +78,7 @@
 	opts->asterisk_path = "asterisk";
 
 	/* parse options */	
-	while ((c = getopt(argc, argv, "l:a:wh")) != -1) {
+	while ((c = getopt(argc, argv, "l:a:s:wh")) != -1) {
 		switch (c) {
 		case 'l':
 			opts->log_filename = optarg;
@@ -83,6 +88,9 @@
 			break;
 		case 'a':
 			opts->asterisk_path = optarg;
+			break;
+		case 's':
+			opts->single_test_mode = optarg;
 			break;
 		case 'h':
 			return 1;
@@ -109,16 +117,20 @@
 			return 1;
 	}
 
-	if (optind == argc) {
-		fprintf(stderr, "%s: missing arguments -- specify at least one test directory\n", argv[0]);
-		usage(argv[0]);
-		return 1;
-	}
+	if (opts.single_test_mode) {
+		return process_single_test(&opts);
+	} else {
+		if (optind == argc) {
+			fprintf(stderr, "%s: missing arguments -- specify at least one test directory\n", argv[0]);
+			usage(argv[0]);
+			return 1;
+		}
 
-	for (i = optind; i < argc; i++) {
-		if (process_test_dir(argv[i], &opts)) {
-			fprintf(stderr, "test suite failed, exiting...\n");
-			return 1;
+		for (i = optind; i < argc; i++) {
+			if (process_test_dir(argv[i], &opts)) {
+				fprintf(stderr, "test suite failed, exiting...\n");
+				return 1;
+			}
 		}
 	}
 

Modified: team/mnicholson/asttest/asttest/include/asttest/asttest.h
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/include/asttest/asttest.h?view=diff&rev=247753&r1=247752&r2=247753
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/asttest.h (original)
+++ team/mnicholson/asttest/asttest/include/asttest/asttest.h Thu Feb 18 15:20:05 2010
@@ -25,6 +25,7 @@
 	unsigned int warn_on_error:1;
 	const char *log_filename;
 	const char *asterisk_path;
+	const char *single_test_mode;
 };
 
 extern const char *default_log_filename;

Modified: team/mnicholson/asttest/asttest/include/asttest/testsuite.h
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/include/asttest/testsuite.h?view=diff&rev=247753&r1=247752&r2=247753
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/testsuite.h (original)
+++ team/mnicholson/asttest/asttest/include/asttest/testsuite.h Thu Feb 18 15:20:05 2010
@@ -31,6 +31,7 @@
 	unsigned int total;
 	FILE *log;
 	char asterisk_path[PATH_MAX];
+	unsigned int single_test_mode:1;
 };
 
 enum ts_result {
@@ -43,6 +44,7 @@
 };
 
 int ts_init(struct testsuite *ts, const char *path, struct asttest_opts *opts);
+int ts_init_single(struct testsuite *ts, struct asttest_opts *opts);
 void ts_cleanup(struct testsuite *ts);
 
 void ts_print(struct testsuite *ts);

Modified: team/mnicholson/asttest/asttest/include/asttest/testutils.h
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/include/asttest/testutils.h?view=diff&rev=247753&r1=247752&r2=247753
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/testutils.h (original)
+++ team/mnicholson/asttest/asttest/include/asttest/testutils.h Thu Feb 18 15:20:05 2010
@@ -21,6 +21,7 @@
 
 #include "asttest/asttest.h"
 
+int process_single_test(struct asttest_opts *opts);
 int process_test_dir(const char *path, struct asttest_opts *opts);
 
 #endif

Modified: team/mnicholson/asttest/asttest/lib/testsuite.c
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/lib/testsuite.c?view=diff&rev=247753&r1=247752&r2=247753
==============================================================================
--- team/mnicholson/asttest/asttest/lib/testsuite.c (original)
+++ team/mnicholson/asttest/asttest/lib/testsuite.c Thu Feb 18 15:20:05 2010
@@ -61,8 +61,35 @@
 	return 1;
 }
 
+int ts_init_single(struct testsuite *ts, struct asttest_opts *opts) {
+	char cwd[PATH_MAX];
+
+	memset(ts, 0, sizeof(struct testsuite));
+
+	ts->log = stdout;
+	ts->single_test_mode = 1;
+
+	/* make asterisk_path absolute */
+	if (opts->asterisk_path[0] == '/') {
+		/* path starts with '/' we will assume it is absolute */
+		snprintf(ts->asterisk_path, sizeof(ts->asterisk_path), "%s", opts->asterisk_path);
+	} else {
+		if (!getcwd(cwd, sizeof(cwd))) {
+			printf("Error determining the current working directory\n");
+			goto e_return;
+		}
+
+		snprintf(ts->asterisk_path, sizeof(ts->asterisk_path), "%s/%s", cwd, opts->asterisk_path);
+	}
+
+	return 0;
+
+e_return:
+	return 1;
+}
+
 void ts_cleanup(struct testsuite *ts) {
-	if (ts->log) {
+	if (ts->log && ts->log != stdout) {
 		fclose(ts->log);
 	}
 }
@@ -80,8 +107,12 @@
 }
 
 int ts_log_va(struct testsuite *ts, const char *test_name, const char *fmt, va_list ap) {
-	int res;
-	res = fprintf(ts->log, "%s: ", test_name);
+	int res = 0;
+
+	if (!ts->single_test_mode) {
+		res = fprintf(ts->log, "%s: ", test_name);
+	}
+
 	res += vfprintf(ts->log, fmt, ap);
 	fflush(ts->log);
 	return res;

Modified: team/mnicholson/asttest/asttest/lib/testutils.c
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/lib/testutils.c?view=diff&rev=247753&r1=247752&r2=247753
==============================================================================
--- team/mnicholson/asttest/asttest/lib/testutils.c (original)
+++ team/mnicholson/asttest/asttest/lib/testutils.c Thu Feb 18 15:20:05 2010
@@ -248,6 +248,25 @@
 	return res;
 }
 
+int process_single_test(struct asttest_opts *opts) {
+	struct testsuite ts;
+	int res = 0;
+
+	if (ts_init_single(&ts, opts)) {
+		printf("Error running test\n");
+		return 1;
+	}
+
+	run_test(&ts, opts->single_test_mode, opts->single_test_mode);
+	if (ts.fail || ts.xpass || ts.error) {
+		res = 1;
+	}
+
+	ts_cleanup(&ts);
+
+	return res;
+}
+
 int process_test_dir(const char *path, struct asttest_opts *opts) {
 	DIR *main_dir = opendir(path);
 	char full_path[PATH_MAX];




More information about the asterisk-commits mailing list