1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2023. Huawei Technologies Co., Ltd */
3 #define _GNU_SOURCE
4 #include <sched.h>
5 #include <pthread.h>
6 #include <stdbool.h>
7 #include <bpf/btf.h>
8 #include <test_progs.h>
9 
10 #include "test_bpf_ma.skel.h"
11 
test_test_bpf_ma(void)12 void test_test_bpf_ma(void)
13 {
14 	struct test_bpf_ma *skel;
15 	struct btf *btf;
16 	int i, err;
17 
18 	skel = test_bpf_ma__open();
19 	if (!ASSERT_OK_PTR(skel, "open"))
20 		return;
21 
22 	btf = bpf_object__btf(skel->obj);
23 	if (!ASSERT_OK_PTR(btf, "btf"))
24 		goto out;
25 
26 	for (i = 0; i < ARRAY_SIZE(skel->rodata->data_sizes); i++) {
27 		char name[32];
28 		int id;
29 
30 		snprintf(name, sizeof(name), "bin_data_%u", skel->rodata->data_sizes[i]);
31 		id = btf__find_by_name_kind(btf, name, BTF_KIND_STRUCT);
32 		if (!ASSERT_GT(id, 0, "bin_data"))
33 			goto out;
34 		skel->rodata->data_btf_ids[i] = id;
35 	}
36 
37 	err = test_bpf_ma__load(skel);
38 	if (!ASSERT_OK(err, "load"))
39 		goto out;
40 
41 	err = test_bpf_ma__attach(skel);
42 	if (!ASSERT_OK(err, "attach"))
43 		goto out;
44 
45 	skel->bss->pid = getpid();
46 	usleep(1);
47 	ASSERT_OK(skel->bss->err, "test error");
48 out:
49 	test_bpf_ma__destroy(skel);
50 }
51