All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] test-runner: allow all unit tests to be run in VM
@ 2019-10-09 16:57 James Prestwood
  2019-10-09 19:33 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: James Prestwood @ 2019-10-09 16:57 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2758 bytes --]

The -U parameter only allowed for a list of unit tests to be run.
Most of the time for sanity checking you want to run all the unit
tests so this has been changed to take an optional argument.

Now, the -U flag (by itself) will run all unit tests. Running a
single or list of unit tests can still be achieved by:

--unit-tests=test-eapol,test-crypto
---
 tools/test-runner.c | 48 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 11 deletions(-)

diff --git a/tools/test-runner.c b/tools/test-runner.c
index 88cc16a8..b3e509c2 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -2364,28 +2364,54 @@ exit:
 
 static void run_unit_tests(void)
 {
-	size_t i;
+	DIR *d;
+	struct dirent *dirent;
 	char *argv[2];
-	char *unit_test_abs_path;
-	char **unit_tests = l_strsplit(test_action_params, ',');
+	char *unit_test_abs_path = NULL;
+	char **unit_tests = NULL;
 
-	if (!unit_tests || !unit_tests[0])
-		goto exit;
+	if (strcmp(test_action_params, "")) {
+		unit_tests = l_strsplit(test_action_params, ',');
+
+		if (!unit_tests || !unit_tests[0])
+			goto exit;
+	}
 
 	if (chdir(top_level_path) < 0)
 		goto exit;
 
-	for (i = 0; unit_tests[i]; i++) {
-		unit_test_abs_path =
-			l_strdup_printf("%s%s%s", top_level_path, "/unit/",
-								unit_tests[i]);
+	d = opendir("unit/");
+	if (!d)
+		goto exit;
+
+	while ((dirent = readdir(d)) != NULL) {
+		struct stat st;
+
+		if (dirent->d_type != DT_REG)
+			continue;
+
+		unit_test_abs_path = l_strdup_printf("%s%s%s", top_level_path,
+						"/unit/", dirent->d_name);
+
+		if (stat(unit_test_abs_path, &st) < 0)
+			goto next;
+
+		if (!(st.st_mode & S_IEXEC))
+			goto next;
+
+		if (unit_tests) {
+			if (!l_strv_contains(unit_tests, dirent->d_name))
+				goto next;
+		}
 
 		argv[0] = unit_test_abs_path;
 		argv[1] = NULL;
 
+		l_info("\n---------- Unit %s ----------", dirent->d_name);
 		execute_program(argv, environ, true,
 					check_verbosity("unit"), false);
 
+next:
 		l_free(unit_test_abs_path);
 	}
 
@@ -2850,7 +2876,7 @@ static void usage(void)
 
 static const struct option main_options[] = {
 	{ "auto-tests",	required_argument, NULL, 'A' },
-	{ "unit-tests",	required_argument, NULL, 'U' },
+	{ "unit-tests",	optional_argument, NULL, 'U' },
 	{ "qemu",	required_argument, NULL, 'q' },
 	{ "kernel",	required_argument, NULL, 'k' },
 	{ "verbose",	required_argument, NULL, 'v' },
@@ -2887,7 +2913,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "A:U:q:k:v:g:Vdh", main_options,
+		opt = getopt_long(argc, argv, "A:q:k:v:g:UVdh", main_options,
 									NULL);
 		if (opt < 0)
 			break;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] test-runner: allow all unit tests to be run in VM
  2019-10-09 16:57 [PATCH] test-runner: allow all unit tests to be run in VM James Prestwood
@ 2019-10-09 19:33 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2019-10-09 19:33 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

Hi James,

On 10/9/19 11:57 AM, James Prestwood wrote:
> The -U parameter only allowed for a list of unit tests to be run.
> Most of the time for sanity checking you want to run all the unit
> tests so this has been changed to take an optional argument.
> 
> Now, the -U flag (by itself) will run all unit tests. Running a
> single or list of unit tests can still be achieved by:
> 
> --unit-tests=test-eapol,test-crypto
> ---
>   tools/test-runner.c | 48 ++++++++++++++++++++++++++++++++++-----------
>   1 file changed, 37 insertions(+), 11 deletions(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-09 19:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 16:57 [PATCH] test-runner: allow all unit tests to be run in VM James Prestwood
2019-10-09 19:33 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.