1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2019 Facebook */ 3 4 #include <test_progs.h> 5 6 struct s { 7 int a; 8 long long b; 9 } __attribute__((packed)); 10 11 #include "test_skeleton.skel.h" 12 13 void test_skeleton(void) 14 { 15 int duration = 0, err; 16 struct test_skeleton* skel; 17 struct test_skeleton__bss *bss; 18 struct test_skeleton__kconfig *kcfg; 19 20 skel = test_skeleton__open(); 21 if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) 22 return; 23 24 if (CHECK(skel->kconfig, "skel_kconfig", "kconfig is mmaped()!\n")) 25 goto cleanup; 26 27 err = test_skeleton__load(skel); 28 if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err)) 29 goto cleanup; 30 31 bss = skel->bss; 32 bss->in1 = 1; 33 bss->in2 = 2; 34 bss->in3 = 3; 35 bss->in4 = 4; 36 bss->in5.a = 5; 37 bss->in5.b = 6; 38 kcfg = skel->kconfig; 39 40 err = test_skeleton__attach(skel); 41 if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) 42 goto cleanup; 43 44 /* trigger tracepoint */ 45 usleep(1); 46 47 CHECK(bss->out1 != 1, "res1", "got %d != exp %d\n", bss->out1, 1); 48 CHECK(bss->out2 != 2, "res2", "got %lld != exp %d\n", bss->out2, 2); 49 CHECK(bss->out3 != 3, "res3", "got %d != exp %d\n", (int)bss->out3, 3); 50 CHECK(bss->out4 != 4, "res4", "got %lld != exp %d\n", bss->out4, 4); 51 CHECK(bss->handler_out5.a != 5, "res5", "got %d != exp %d\n", 52 bss->handler_out5.a, 5); 53 CHECK(bss->handler_out5.b != 6, "res6", "got %lld != exp %d\n", 54 bss->handler_out5.b, 6); 55 56 CHECK(bss->bpf_syscall != kcfg->CONFIG_BPF_SYSCALL, "ext1", 57 "got %d != exp %d\n", bss->bpf_syscall, kcfg->CONFIG_BPF_SYSCALL); 58 CHECK(bss->kern_ver != kcfg->LINUX_KERNEL_VERSION, "ext2", 59 "got %d != exp %d\n", bss->kern_ver, kcfg->LINUX_KERNEL_VERSION); 60 61 cleanup: 62 test_skeleton__destroy(skel); 63 } 64