[yocto] [ptest-runner][PATCHv2 1/2] utils, main: pass opts struct to run_ptests
Pascal Bach
pascal.bach at siemens.com
Wed Feb 1 07:42:40 PST 2017
This allows to easily add additional parameters
Signed-off-by: Pascal Bach <pascal.bach at siemens.com>
---
main.c | 10 ++--------
tests/utils.c | 14 ++++++++++----
utils.c | 4 ++--
utils.h | 9 ++++++++-
4 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/main.c b/main.c
index 31bf3b5..765d688 100644
--- a/main.c
+++ b/main.c
@@ -45,13 +45,6 @@ print_usage(FILE *stream, char *progname)
"[-h] [ptest1 ptest2 ...]\n", progname);
}
-static struct {
- char *directory;
- int list;
- int timeout;
- char **ptests;
-} opts;
-
int
main(int argc, char *argv[])
{
@@ -66,6 +59,7 @@ main(int argc, char *argv[])
struct ptest_list *head, *run;
+ struct options opts;
opts.directory = strdup(DEFAULT_DIRECTORY);
opts.list = 0;
opts.timeout = DEFAULT_TIMEOUT;
@@ -133,7 +127,7 @@ main(int argc, char *argv[])
ptest_list_free_all(head);
}
- rc = run_ptests(run, opts.timeout, argv[0], stdout, stderr);
+ rc = run_ptests(run, opts, argv[0], stdout, stderr);
ptest_list_free_all(run);
diff --git a/tests/utils.c b/tests/utils.c
index 1332798..6b70c2e 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -51,6 +51,8 @@ static char *ptests_not_found[] = {
NULL,
};
+static struct options EmptyOpts;
+
static inline void
find_word(int *found, const char *line, const char *word)
{
@@ -153,8 +155,9 @@ START_TEST(test_filter_ptests)
END_TEST
START_TEST(test_run_ptests)
- struct ptest_list *head;
- int timeout = 1;
+ struct ptest_list *head;
+ struct options opts = EmptyOpts;
+ opts.timeout = 1;
int rc;
char *buf_stdout;
@@ -173,7 +176,7 @@ START_TEST(test_run_ptests)
ptest_list_remove(head, "hang", 1);
ptest_list_remove(head, "fail", 1);
- rc = run_ptests(head, timeout, "test_run_ptests", fp_stdout, fp_stderr);
+ rc = run_ptests(head, opts, "test_run_ptests", fp_stdout, fp_stderr);
ck_assert(rc == 0);
ptest_list_free_all(head);
@@ -275,8 +278,11 @@ test_ptest_expected_failure(struct ptest_list *head, const int timeout, char *pr
struct ptest_list *filtered = filter_ptests(head, &progname, 1);
ck_assert(ptest_list_length(filtered) == 1);
+ struct options opts = EmptyOpts;
+ opts.timeout = timeout;
+
h_analizer(
- run_ptests(filtered, timeout, progname, fp_stdout, fp_stderr),
+ run_ptests(filtered, opts, progname, fp_stdout, fp_stderr),
fp_stdout, fp_stderr
);
diff --git a/utils.c b/utils.c
index 77427e0..48c1990 100644
--- a/utils.c
+++ b/utils.c
@@ -302,7 +302,7 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid,
}
int
-run_ptests(struct ptest_list *head, int timeout, const char *progname,
+run_ptests(struct ptest_list *head, const struct options opts, const char *progname,
FILE *fp, FILE *fp_stderr)
{
int rc = 0;
@@ -350,7 +350,7 @@ run_ptests(struct ptest_list *head, int timeout, const char *progname,
fprintf(fp, "BEGIN: %s\n", ptest_dir);
status = wait_child(ptest_dir, p->run_ptest, child,
- timeout, fds, fps);
+ opts.timeout, fds, fps);
if (status) {
fprintf(fp, "ERROR: Exit status is %d\n", status);
rc += 1;
diff --git a/utils.h b/utils.h
index 4dc23ef..d7f5268 100644
--- a/utils.h
+++ b/utils.h
@@ -30,10 +30,17 @@
#define CHECK_ALLOCATION(p, size, exit_on_null) \
check_allocation1(p, size, __FILE__, __LINE__, exit_on_null)
+struct options {
+ char *directory;
+ int list;
+ int timeout;
+ char **ptests;
+};
+
extern void check_allocation1(void *, size_t, char *, int, int);
extern struct ptest_list *get_available_ptests(const char *);
extern int print_ptests(struct ptest_list *, FILE *);
extern struct ptest_list *filter_ptests(struct ptest_list *, char **, int);
-extern int run_ptests(struct ptest_list *, int, const char *progname, FILE *, FILE *);
+extern int run_ptests(struct ptest_list *, const struct options, const char *progname, FILE *, FILE *);
#endif
--
2.1.4
More information about the yocto
mailing list