]> granicus.if.org Git - strace/commitdiff
tests: add skip_if_unavailable function to libtests
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 19 Apr 2017 02:16:31 +0000 (02:16 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 19 Apr 2017 02:16:31 +0000 (02:16 +0000)
* tests/skip_unavailable.c: New file.
* tests/tests.h (skip_if_unavailable): New prototype.
* tests/Makefile.am (libtests_a_SOURCES): Add skip_unavailable.c.

tests/Makefile.am
tests/skip_unavailable.c [new file with mode: 0644]
tests/tests.h

index c935cc70cd511171b25e7ad3c63dd374fc631778..0ed8694c3ce1982851e0360b02338f4c27b6e012 100644 (file)
@@ -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 (file)
index 0000000..074fc3a
--- /dev/null
@@ -0,0 +1,13 @@
+#include "tests.h"
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+void
+skip_if_unavailable(const char *const path)
+{
+       struct stat st;
+
+       if (stat(path, &st))
+               perror_msg_and_skip("stat: %s", path);
+}
index d077c5c8a6bb4710b776c6d0b601e1260b12e4aa..d7bbff452ec4d4d68583c2919fbd873f849458ee 100644 (file)
@@ -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