]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-bpf-token: use test macros and functions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Jul 2025 23:49:52 +0000 (08:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 18 Jul 2025 11:25:42 +0000 (20:25 +0900)
No functional change, just refactoring.

src/test/test-bpf-token.c

index 23dd14308213a8ce347ed77cce929ad876b02341..3d6127182ec40ee43a788923c7693a114c00153c 100644 (file)
@@ -4,25 +4,22 @@
 #include <fcntl.h>
 
 #include "fd-util.h"
-#include "main-func.h"
 #include "tests.h"
 
-static int run(int argc, char *argv[]) {
+static int intro(void) {
 #if __LIBBPF_CURRENT_VERSION_GEQ(1, 5)
-        _cleanup_close_ int bpffs_fd = -EBADF, token_fd = -EBADF;
-
-        bpffs_fd = open("/sys/fs/bpf", O_RDONLY);
+        _cleanup_close_ int bpffs_fd = open("/sys/fs/bpf", O_RDONLY);
         if (bpffs_fd < 0)
-                return -errno;
+                return log_error_errno(errno, "Failed to open '/sys/fs/bpf': %m");
 
-        token_fd = bpf_token_create(bpffs_fd, /* opts = */ NULL);
+        _cleanup_close_ int token_fd = bpf_token_create(bpffs_fd, /* opts = */ NULL);
         if (token_fd < 0)
-                return -errno;
+                return log_error_errno(errno, "Failed to create bpf token: %m");
 
-        return 0;
+        return EXIT_SUCCESS;
 #else
-        exit(77);
+        return log_tests_skipped("libbpf is older than v1.5");
 #endif
 }
 
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro);