[PATCHv1][ptest-runner 2/2] Add support to specify multiple folder for ptest-runner


Anibal Limon
 

Enables multiple folders in -d option the current use case is to be able
specify multilib folders in the same run.

The -d option allows directories without whitespaces inside, example to
run after compile:

$ ./ptest-runner -d "test/data tests/data2/"

[YOCTO #12604]

Signed-off-by: Aníbal Limón <anibal.limon@...>
---
main.c | 91 ++++++++++++++++++++++-----------
ptest_list.c | 17 ++++++
ptest_list.h | 1 +
tests/data2/go/ptest/run-ptest | 3 ++
tests/data2/lua/ptest/run-ptest | 3 ++
utils.h | 4 +-
6 files changed, 87 insertions(+), 32 deletions(-)
create mode 100755 tests/data2/go/ptest/run-ptest
create mode 100755 tests/data2/lua/ptest/run-ptest

diff --git a/main.c b/main.c
index 01d60f7..e3a1b69 100644
--- a/main.c
+++ b/main.c
@@ -47,10 +47,43 @@
static inline void
print_usage(FILE *stream, char *progname)
{
- fprintf(stream, "Usage: %s [-d directory] [-e exclude] [-l list] [-t timeout]"
+ fprintf(stream, "Usage: %s [-d directory directory2 ...] [-e exclude] [-l list] [-t timeout]"
" [-x xml-filename] [-h] [ptest1 ptest2 ...]\n", progname);
}

+static char **
+str2array(char *str, const char *delim, int *num)
+{
+ char *c, *tok;
+ char **array;
+ int i;
+
+ c = str;
+ *num = 1;
+ while (*c) {
+ if (isspace(*c))
+ (*num)++;
+ c++;
+ }
+
+
+ array = malloc((size_t)*num * sizeof(char**));
+ CHECK_ALLOCATION(array, 1, 1);
+
+ i = 0;
+ tok = strtok_r(str, delim, &c);
+ array[i] = strdup(tok);
+ CHECK_ALLOCATION(array[i], 1, 1);
+ i++;
+ while ((tok = strtok_r(NULL, " ", &c)) != NULL) {
+ array[i] = strdup(tok);
+ CHECK_ALLOCATION(array[i], 1, 1);
+ i++;
+ }
+
+ return array;
+}
+
int
main(int argc, char *argv[])
{
@@ -59,7 +92,6 @@ main(int argc, char *argv[])
int i;
int rc;
int ptest_exclude_num = 0;
- char *c, *tok;

#ifdef MEMCHECK
mtrace();
@@ -68,7 +100,11 @@ main(int argc, char *argv[])
struct ptest_list *head, *run;
struct ptest_options opts;

- opts.directory = strdup(DEFAULT_DIRECTORY);
+ opts.dirs = malloc(sizeof(char **) * 1);
+ CHECK_ALLOCATION(opts.dirs, 1, 1);
+ opts.dirs[0] = strdup(DEFAULT_DIRECTORY);
+ CHECK_ALLOCATION(opts.dirs[0], 1, 1);
+ opts.dirs_no = 1;
opts.exclude = NULL;
opts.list = 0;
opts.timeout = DEFAULT_TIMEOUT;
@@ -78,34 +114,12 @@ main(int argc, char *argv[])
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);
+ free(opts.dirs[0]);
+ free(opts.dirs);
+ opts.dirs = str2array(optarg, " ", &(opts.dirs_no));
break;
case 'e':
- c = optarg;
- ptest_exclude_num = 1;
-
- while (*c) {
- if (isspace(*c))
- ptest_exclude_num++;
- c++;
- }
-
-
- opts.exclude = malloc((size_t)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++;
- }
+ opts.exclude = str2array(optarg, " ", &ptest_exclude_num);
break;
case 'l':
opts.list = 1;
@@ -140,10 +154,25 @@ main(int argc, char *argv[])
}
}

- head = get_available_ptests(opts.directory);
+ head = NULL;
+ for (i = 0; i < opts.dirs_no; i ++) {
+ struct ptest_list *tmp;
+
+ tmp = get_available_ptests(opts.dirs[i]);
+ if (tmp == NULL) {
+ fprintf(stderr, PRINT_PTESTS_NOT_FOUND_DIR, opts.dirs[i]);
+ continue;
+ }
+
+
+ if (head == NULL)
+ head = tmp;
+ else
+ head = ptest_list_extend(head, tmp);
+ }
if (head == NULL || ptest_list_length(head) == 0) {
fprintf(stderr, PRINT_PTESTS_NOT_FOUND);
- return 1;
+ return 1;
}

if (opts.list) {
diff --git a/ptest_list.c b/ptest_list.c
index a5632f8..917ef4f 100644
--- a/ptest_list.c
+++ b/ptest_list.c
@@ -216,3 +216,20 @@ ptest_list_remove(struct ptest_list *head, char *ptest, int free)

return p;
}
+
+struct ptest_list *
+ptest_list_extend(struct ptest_list *head, struct ptest_list *extend)
+{
+ struct ptest_list *p, *q;
+
+ VALIDATE_PTR_RNULL(head);
+ VALIDATE_PTR_RNULL(extend);
+
+ for (p = head; p->next != NULL; p = p->next);
+ q = extend->next;
+ p->next = q;
+
+ free(extend);
+
+ return head;
+}
diff --git a/ptest_list.h b/ptest_list.h
index e1caffc..02a64bb 100644
--- a/ptest_list.h
+++ b/ptest_list.h
@@ -64,5 +64,6 @@ extern struct ptest_list *ptest_list_search(struct ptest_list *, char *);
extern struct ptest_list *ptest_list_search_by_file(struct ptest_list *, char *, struct stat);
extern struct ptest_list *ptest_list_add(struct ptest_list *, char *, char *);
extern struct ptest_list *ptest_list_remove(struct ptest_list *, char *, int);
+extern struct ptest_list *ptest_list_extend(struct ptest_list *, struct ptest_list *);

#endif // PTEST_RUNNER_LIST_H
diff --git a/tests/data2/go/ptest/run-ptest b/tests/data2/go/ptest/run-ptest
new file mode 100755
index 0000000..d8a9ca2
--- /dev/null
+++ b/tests/data2/go/ptest/run-ptest
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo "go"
diff --git a/tests/data2/lua/ptest/run-ptest b/tests/data2/lua/ptest/run-ptest
new file mode 100755
index 0000000..07a7713
--- /dev/null
+++ b/tests/data2/lua/ptest/run-ptest
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo "lua"
diff --git a/utils.h b/utils.h
index aa53707..39832e6 100644
--- a/utils.h
+++ b/utils.h
@@ -27,13 +27,15 @@
#include "ptest_list.h"

#define PRINT_PTESTS_NOT_FOUND "No ptests found.\n"
+#define PRINT_PTESTS_NOT_FOUND_DIR "Warning: ptests not found in, %s.\n"
#define PRINT_PTESTS_AVAILABLE "Available ptests:\n"

#define CHECK_ALLOCATION(p, size, exit_on_null) \
check_allocation1(p, size, __FILE__, __LINE__, exit_on_null)

struct ptest_options {
- char *directory;
+ char **dirs;
+ int dirs_no;
char **exclude;
int list;
int timeout;
--
2.26.0

Join yocto@lists.yoctoproject.org to automatically receive all group messages.