Message ID | 20200327213924.18816-2-pvorel@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | C API: .needs_cmds and SAFE_RUN_CMD() | expand |
On Sat, Mar 28, 2020 at 5:39 AM Petr Vorel <pvorel@suse.cz> wrote: > Signed-off-by: Petr Vorel <pvorel@suse.cz> > --- > New commit. > > doc/test-writing-guidelines.txt | 15 +++++++++++++++ > include/tst_test.h | 3 +++ > lib/tst_test.c | 11 +++++++++++ > 3 files changed, 29 insertions(+) > > diff --git a/doc/test-writing-guidelines.txt > b/doc/test-writing-guidelines.txt > index 32c9e87df..f7206f1bf 100644 > --- a/doc/test-writing-guidelines.txt > +++ b/doc/test-writing-guidelines.txt > @@ -2023,6 +2023,21 @@ struct tst_test test = { > }; > > ------------------------------------------------------------------------------- > > +2.2.35 Checking for required binaries > +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > Maybe better to talk commands but not binaries, since not all of the commands are binary, there is possible python, perl or shell executable file need check too. Isn't it?
Hi Li, thanks for your review. > > +2.2.35 Checking for required binaries > > +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > Maybe better to talk commands but not binaries, since not all of the > commands are binary, there is possible python, perl or shell executable > file need check too. Isn't it? +1 Kind regards, Petr
Hi! > > > +2.2.35 Checking for required binaries > > > +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > Maybe better to talk commands but not binaries, since not all of the > > commands are binary, there is possible python, perl or shell executable > > file need check too. Isn't it? > +1 Acked with this change.
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 32c9e87df..f7206f1bf 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -2023,6 +2023,21 @@ struct tst_test test = { }; ------------------------------------------------------------------------------- +2.2.35 Checking for required binaries +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Required binaries can be checked with '.needs_cmds', which points to a 'NULL' +terminated array of strings such as: + +[source,c] +------------------------------------------------------------------------------- +.needs_cmds = (const char *const []) { + "useradd", + "userdel", + NULL +}, +------------------------------------------------------------------------------- + 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/tst_test.h b/include/tst_test.h index 84b6a940f..592097084 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -239,6 +239,9 @@ struct tst_test { * {NULL, NULL} terminated array of tags. */ const struct tst_tag *tags; + + /* NULL terminated array of required binaries */ + const char *const *needs_cmds; }; /* diff --git a/lib/tst_test.c b/lib/tst_test.c index 220d7fdfc..dae3fa1b5 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -3,6 +3,7 @@ * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz> */ +#include <limits.h> #include <stdio.h> #include <stdarg.h> #include <unistd.h> @@ -880,6 +881,16 @@ static void do_setup(int argc, char *argv[]) if (tst_test->min_kver) check_kver(); + if (tst_test->needs_cmds) { + const char *cmd; + char path[PATH_MAX]; + int i; + + for (i = 0; (cmd = tst_test->needs_cmds[i]); ++i) + if (tst_get_path(cmd, path, sizeof(path))) + tst_brk(TCONF, "Couldn't find '%s' in $PATH", cmd); + } + if (tst_test->needs_drivers) { const char *name; int i;
Signed-off-by: Petr Vorel <pvorel@suse.cz> --- New commit. doc/test-writing-guidelines.txt | 15 +++++++++++++++ include/tst_test.h | 3 +++ lib/tst_test.c | 11 +++++++++++ 3 files changed, 29 insertions(+)