xref: /linux/tools/testing/selftests/bpf/prog_tests/timer_crash.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*a7e75016SKumar Kartikeya Dwivedi // SPDX-License-Identifier: GPL-2.0
2*a7e75016SKumar Kartikeya Dwivedi #include <test_progs.h>
3*a7e75016SKumar Kartikeya Dwivedi #include "timer_crash.skel.h"
4*a7e75016SKumar Kartikeya Dwivedi 
5*a7e75016SKumar Kartikeya Dwivedi enum {
6*a7e75016SKumar Kartikeya Dwivedi 	MODE_ARRAY,
7*a7e75016SKumar Kartikeya Dwivedi 	MODE_HASH,
8*a7e75016SKumar Kartikeya Dwivedi };
9*a7e75016SKumar Kartikeya Dwivedi 
test_timer_crash_mode(int mode)10*a7e75016SKumar Kartikeya Dwivedi static void test_timer_crash_mode(int mode)
11*a7e75016SKumar Kartikeya Dwivedi {
12*a7e75016SKumar Kartikeya Dwivedi 	struct timer_crash *skel;
13*a7e75016SKumar Kartikeya Dwivedi 
14*a7e75016SKumar Kartikeya Dwivedi 	skel = timer_crash__open_and_load();
15*a7e75016SKumar Kartikeya Dwivedi 	if (!ASSERT_OK_PTR(skel, "timer_crash__open_and_load"))
16*a7e75016SKumar Kartikeya Dwivedi 		return;
17*a7e75016SKumar Kartikeya Dwivedi 	skel->bss->pid = getpid();
18*a7e75016SKumar Kartikeya Dwivedi 	skel->bss->crash_map = mode;
19*a7e75016SKumar Kartikeya Dwivedi 	if (!ASSERT_OK(timer_crash__attach(skel), "timer_crash__attach"))
20*a7e75016SKumar Kartikeya Dwivedi 		goto end;
21*a7e75016SKumar Kartikeya Dwivedi 	usleep(1);
22*a7e75016SKumar Kartikeya Dwivedi end:
23*a7e75016SKumar Kartikeya Dwivedi 	timer_crash__destroy(skel);
24*a7e75016SKumar Kartikeya Dwivedi }
25*a7e75016SKumar Kartikeya Dwivedi 
test_timer_crash(void)26*a7e75016SKumar Kartikeya Dwivedi void test_timer_crash(void)
27*a7e75016SKumar Kartikeya Dwivedi {
28*a7e75016SKumar Kartikeya Dwivedi 	if (test__start_subtest("array"))
29*a7e75016SKumar Kartikeya Dwivedi 		test_timer_crash_mode(MODE_ARRAY);
30*a7e75016SKumar Kartikeya Dwivedi 	if (test__start_subtest("hash"))
31*a7e75016SKumar Kartikeya Dwivedi 		test_timer_crash_mode(MODE_HASH);
32*a7e75016SKumar Kartikeya Dwivedi }
33