summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-05-17 15:36:45 (GMT)
committerThomas Haller <thaller@redhat.com>2024-05-17 15:54:05 (GMT)
commitd44505ede1ebec0d2e7b038d4e41006a99f657ec (patch)
treef5f4bf53f729a4dbd4d5dd94971bc210169c0b3e
parent774863b4738a7e9af7bb82ca23011937e36538eb (diff)
downloadlibnl-d44505ede1ebec0d2e7b038d4e41006a99f657ec.zip
libnl-d44505ede1ebec0d2e7b038d4e41006a99f657ec.tar.gz
libnl-d44505ede1ebec0d2e7b038d4e41006a99f657ec.tar.bz2
tests: add helper to detect availablility of iproute2
-rw-r--r--tests/nl-test-util.c22
-rw-r--r--tests/nl-test-util.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/nl-test-util.c b/tests/nl-test-util.c
index 4bab90b..4e5caec 100644
--- a/tests/nl-test-util.c
+++ b/tests/nl-test-util.c
@@ -675,3 +675,25 @@ void _nltst_assert_link_exists_full(const char *ifname, bool exists)
/* FIXME: we would expect that the cloned object is identical. It is not. */
/* _nltst_object_identical(link, link_clone); */
}
+
+/*****************************************************************************/
+
+bool _nltst_has_iproute2(void)
+{
+ static int has = -1;
+
+ if (has == -1)
+ has = (system("ip link &>/dev/null") == 0);
+
+ return has;
+}
+
+bool _nltst_skip_no_iproute2(const char *msg)
+{
+ if (_nltst_has_iproute2())
+ return false;
+
+ printf("skip test due to missing iproute2%s%s%s\n", msg ? " (" : "",
+ msg ?: "", msg ? ")" : "");
+ return true;
+}
diff --git a/tests/nl-test-util.h b/tests/nl-test-util.h
index 028a0df..b64d830 100644
--- a/tests/nl-test-util.h
+++ b/tests/nl-test-util.h
@@ -410,6 +410,9 @@ void nltst_netns_leave(struct nltst_netns *nsdata);
#define _nltst_system(command) _nltst_assert_retcode(system(command))
+bool _nltst_has_iproute2(void);
+bool _nltst_skip_no_iproute2(const char *msg);
+
/*****************************************************************************/
void _nltst_object_identical(const void *a, const void *b);