From: Dmitry V. Levin Date: Wed, 19 Apr 2017 02:16:31 +0000 (+0000) Subject: tests: add skip_if_unavailable function to libtests X-Git-Tag: v4.17~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f93fd094f645941097fa0618ca4c2a723c13f2d;p=strace tests: add skip_if_unavailable function to libtests * tests/skip_unavailable.c: New file. * tests/tests.h (skip_if_unavailable): New prototype. * tests/Makefile.am (libtests_a_SOURCES): Add skip_unavailable.c. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index c935cc70..0ed8694c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -58,6 +58,7 @@ libtests_a_SOURCES = \ printflags.c \ printxval.c \ signal2name.c \ + skip_unavailable.c \ sprintrc.c \ tail_alloc.c \ tests.h \ diff --git a/tests/skip_unavailable.c b/tests/skip_unavailable.c new file mode 100644 index 00000000..074fc3a2 --- /dev/null +++ b/tests/skip_unavailable.c @@ -0,0 +1,13 @@ +#include "tests.h" + +#include +#include + +void +skip_if_unavailable(const char *const path) +{ + struct stat st; + + if (stat(path, &st)) + perror_msg_and_skip("stat: %s", path); +} diff --git a/tests/tests.h b/tests/tests.h index d077c5c8..d7bbff45 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -60,6 +60,9 @@ void error_msg_and_skip(const char *, ...) void perror_msg_and_skip(const char *, ...) ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN; +/* Stat the specified file and skip the test if the stat call failed. */ +void skip_if_unavailable(const char *); + /* * Allocate memory that ends on the page boundary. * Pages allocated by this call are preceeded by an unmapped page