1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
3 
4 #include <test_progs.h>
5 #include <sys/syscall.h>
6 #include "linked_vars.skel.h"
7 
test_linked_vars(void)8 void test_linked_vars(void)
9 {
10 	int err;
11 	struct linked_vars *skel;
12 
13 	skel = linked_vars__open();
14 	if (!ASSERT_OK_PTR(skel, "skel_open"))
15 		return;
16 
17 	skel->bss->input_bss1 = 1000;
18 	skel->bss->input_bss2 = 2000;
19 	skel->bss->input_bss_weak = 3000;
20 
21 	err = linked_vars__load(skel);
22 	if (!ASSERT_OK(err, "skel_load"))
23 		goto cleanup;
24 
25 	err = linked_vars__attach(skel);
26 	if (!ASSERT_OK(err, "skel_attach"))
27 		goto cleanup;
28 
29 	/* trigger */
30 	syscall(SYS_getpgid);
31 
32 	ASSERT_EQ(skel->bss->output_bss1, 1000 + 2000 + 3000, "output_bss1");
33 	ASSERT_EQ(skel->bss->output_bss2, 1000 + 2000 + 3000, "output_bss2");
34 	/* 10 comes from "winner" input_data_weak in first obj file */
35 	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_bss1");
36 	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_bss2");
37 	/* 100 comes from "winner" input_rodata_weak in first obj file */
38 	ASSERT_EQ(skel->bss->output_rodata1, 11 + 22 + 100, "output_weak1");
39 	ASSERT_EQ(skel->bss->output_rodata2, 11 + 22 + 100, "output_weak2");
40 
41 cleanup:
42 	linked_vars__destroy(skel);
43 }
44