test-bpf-token: use test macros and functions

No functional change, just refactoring.
This commit is contained in:
Yu Watanabe
2025-07-16 08:49:52 +09:00
parent 0e8e655c52
commit f1eed4e592

View 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);