Skip to contentSkip to conversation

main.c: Use realpath to get the actual directory of ptests

PATCH New Aníbal Limón 1 participant 2 messages Apr 25, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 main.c: Use realpath to get the actual directory of ptests

Fix usage of relative paths in -d argument.

$ ./ptest-runner -d ./tests/data
---
 main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
main.c +2 -1
index 505829c..593aff1 100644
@@ -19,6 +19,7 @@
  * 	Aníbal Limón <[email protected]>
  */
 
+#include <limits.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -70,7 +71,7 @@ main(int argc, char *argv[])
 		switch (opt) {
 			case 'd':
 				free(opts.directory);
-				opts.directory = strdup(optarg);
+				opts.directory = realpath(optarg, NULL);
 				CHECK_ALLOCATION(opts.directory, 1, 1);
 			break;
 			case 'l':
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 main.c: Add option (-e) to exclude certain tests for execution

You can specify a set of ptests to be excluded, it will not fail if some ptest excluded isn't found in the list of execution.

$ ./ptest-runner -e "hang glibc" -d tests/data
---
 main.c  | 38 +++++++++++++++++++++++++++++++++++---
 utils.h |  1 +
 2 files changed, 36 insertions(+), 3 deletions(-)
main.c +35 -3
index 593aff1..83600b7 100644
@@ -19,6 +19,7 @@
  * 	Aníbal Limón <[email protected]>
  */
 
+#include <ctype.h>
 #include <limits.h>
 #include <unistd.h>
 #include <string.h>
@@ -42,8 +43,8 @@
 static inline void
 print_usage(FILE *stream, char *progname)
 {
-	fprintf(stream, "Usage: %s [-d directory] [-l list] [-t timeout] [-x xml-filename]"
-			" [-h] [ptest1 ptest2 ...]\n", progname);
+	fprintf(stream, "Usage: %s [-d directory] [-e exclude] [-l list] [-t timeout]"
+			" [-x xml-filename] [-h] [ptest1 ptest2 ...]\n", progname);
 }
 
 int
@@ -53,6 +54,8 @@ main(int argc, char *argv[])
 	int ptest_num = 0;
 	int i;
 	int rc;
+	int ptest_exclude_num = 0;
+	char *c, *tok;
 
 #ifdef MEMCHECK
 	mtrace();
@@ -62,18 +65,44 @@ main(int argc, char *argv[])
 	struct ptest_options opts;
 
 	opts.directory = strdup(DEFAULT_DIRECTORY);
+	opts.exclude = NULL;
 	opts.list = 0;
 	opts.timeout = DEFAULT_TIMEOUT;
 	opts.ptests = NULL;
 	opts.xml_filename = NULL;
 
-	while ((opt = getopt(argc, argv, "d:lt:x:h")) != -1) {
+	while ((opt = getopt(argc, argv, "d:e:lt:x:h")) != -1) {
 		switch (opt) {
 			case 'd':
 				free(opts.directory);
 				opts.directory = realpath(optarg, NULL);
 				CHECK_ALLOCATION(opts.directory, 1, 1);
 			break;
+			case 'e':
+				c = optarg;
+				ptest_exclude_num = 1;
+
+				while (*c) {
+					if (isspace(*c))
+						ptest_exclude_num++;
+					c++;
+				}
+
+
+				opts.exclude = malloc(ptest_exclude_num * sizeof(char));
+				CHECK_ALLOCATION(opts.exclude, 1, 1);
+
+				i = 0;
+				tok = strtok_r(optarg, " ", &c);
+				opts.exclude[i] = strdup(tok);
+				CHECK_ALLOCATION(opts.exclude[i], 1, 1);
+				i++;
+				while ((tok = strtok_r(NULL, " ", &c)) != NULL) {
+					opts.exclude[i] = strdup(tok);
+					CHECK_ALLOCATION(opts.exclude[i], 1, 1);
+					i++;
+				}
+			break;
 			case 'l':
 				opts.list = 1;
 			break;
@@ -134,6 +163,9 @@ main(int argc, char *argv[])
 		ptest_list_free_all(head);
 	}
 
+	for (i = 0; i < ptest_exclude_num; i++)
+		ptest_list_remove(run, opts.exclude[i], 1);
+
 	rc = run_ptests(run, opts, argv[0], stdout, stderr);
 
 	ptest_list_free_all(run);
utils.h +1 -0
index 8fa20a8..ee85163 100644
@@ -32,6 +32,7 @@
 
 struct ptest_options {
 	char *directory;
+	char **exclude;
 	int list;
 	int timeout;
 	char **ptests;
Signature · 1 line
2.11.0