1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2021 Facebook */ 3 #include <test_progs.h> 4 #include "timer.skel.h" 5 6 static int timer(struct timer *timer_skel) 7 { 8 int err, prog_fd; 9 LIBBPF_OPTS(bpf_test_run_opts, topts); 10 11 err = timer__attach(timer_skel); 12 if (!ASSERT_OK(err, "timer_attach")) 13 return err; 14 15 ASSERT_EQ(timer_skel->data->callback_check, 52, "callback_check1"); 16 ASSERT_EQ(timer_skel->data->callback2_check, 52, "callback2_check1"); 17 18 prog_fd = bpf_program__fd(timer_skel->progs.test1); 19 err = bpf_prog_test_run_opts(prog_fd, &topts); 20 ASSERT_OK(err, "test_run"); 21 ASSERT_EQ(topts.retval, 0, "test_run"); 22 timer__detach(timer_skel); 23 24 usleep(50); /* 10 usecs should be enough, but give it extra */ 25 /* check that timer_cb1() was executed 10+10 times */ 26 ASSERT_EQ(timer_skel->data->callback_check, 42, "callback_check2"); 27 ASSERT_EQ(timer_skel->data->callback2_check, 42, "callback2_check2"); 28 29 /* check that timer_cb2() was executed twice */ 30 ASSERT_EQ(timer_skel->bss->bss_data, 10, "bss_data"); 31 32 /* check that timer_cb3() was executed twice */ 33 ASSERT_EQ(timer_skel->bss->abs_data, 12, "abs_data"); 34 35 /* check that there were no errors in timer execution */ 36 ASSERT_EQ(timer_skel->bss->err, 0, "err"); 37 38 /* check that code paths completed */ 39 ASSERT_EQ(timer_skel->bss->ok, 1 | 2 | 4, "ok"); 40 41 return 0; 42 } 43 44 /* TODO: use pid filtering */ 45 void serial_test_timer(void) 46 { 47 struct timer *timer_skel = NULL; 48 int err; 49 50 timer_skel = timer__open_and_load(); 51 if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load")) 52 goto cleanup; 53 54 err = timer(timer_skel); 55 ASSERT_OK(err, "timer"); 56 cleanup: 57 timer__destroy(timer_skel); 58 } 59