diff mbox series

[v2,bpf-next,5/6] selftests/bpf: extend linked_vars selftests with static variables

Message ID 20210423185357.1992756-6-andrii@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series BPF static linker: support static vars and maps | expand

Checks

Context Check Description
netdev/apply fail Patch does not apply to bpf-next
netdev/tree_selection success Clearly marked for bpf-next

Commit Message

Andrii Nakryiko April 23, 2021, 6:53 p.m. UTC
Now that BPF static linker supports static variable renames and thus
non-unique static variables in BPF skeleton, add tests validating static
variables are resolved properly during multi-file static linking.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/prog_tests/linked_vars.c | 12 ++++++++----
 tools/testing/selftests/bpf/progs/linked_vars1.c     |  4 +++-
 tools/testing/selftests/bpf/progs/linked_vars2.c     |  4 +++-
 3 files changed, 14 insertions(+), 6 deletions(-)

Comments

Yonghong Song April 23, 2021, 11:03 p.m. UTC | #1
On 4/23/21 11:53 AM, Andrii Nakryiko wrote:
> Now that BPF static linker supports static variable renames and thus
> non-unique static variables in BPF skeleton, add tests validating static
> variables are resolved properly during multi-file static linking.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>   tools/testing/selftests/bpf/prog_tests/linked_vars.c | 12 ++++++++----
>   tools/testing/selftests/bpf/progs/linked_vars1.c     |  4 +++-
>   tools/testing/selftests/bpf/progs/linked_vars2.c     |  4 +++-
>   3 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/linked_vars.c b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
> index 267166abe4c1..75dcce539ff1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/linked_vars.c
> +++ b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
> @@ -14,8 +14,12 @@ void test_linked_vars(void)
>   	if (!ASSERT_OK_PTR(skel, "skel_open"))
>   		return;
>   
> +	skel->bss->linked_vars1__input_bss_static = 100;
>   	skel->bss->input_bss1 = 1000;
> +
> +	skel->bss->linked_vars2__input_bss_static = 200;
>   	skel->bss->input_bss2 = 2000;
> +
>   	skel->bss->input_bss_weak = 3000;
>   
>   	err = linked_vars__load(skel);
> @@ -29,11 +33,11 @@ void test_linked_vars(void)
>   	/* trigger */
>   	syscall(SYS_getpgid);
>   
> -	ASSERT_EQ(skel->bss->output_bss1, 1000 + 2000 + 3000, "output_bss1");
> -	ASSERT_EQ(skel->bss->output_bss2, 1000 + 2000 + 3000, "output_bss2");
> +	ASSERT_EQ(skel->bss->output_bss1, 100 + 1000 + 2000 + 3000, "output_bss1");
> +	ASSERT_EQ(skel->bss->output_bss2, 200 + 1000 + 2000 + 3000, "output_bss2");
>   	/* 10 comes from "winner" input_data_weak in first obj file */
> -	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_bss1");
> -	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_bss2");
> +	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_data1");
> +	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_data2");
>   	/* 100 comes from "winner" input_rodata_weak in first obj file */
>   	ASSERT_EQ(skel->bss->output_rodata1, 11 + 22 + 100, "output_weak1");
>   	ASSERT_EQ(skel->bss->output_rodata2, 11 + 22 + 100, "output_weak2");
> diff --git a/tools/testing/selftests/bpf/progs/linked_vars1.c b/tools/testing/selftests/bpf/progs/linked_vars1.c
> index ef9e9d0bb0ca..7d5152c066d9 100644
> --- a/tools/testing/selftests/bpf/progs/linked_vars1.c
> +++ b/tools/testing/selftests/bpf/progs/linked_vars1.c
> @@ -10,6 +10,8 @@ extern int LINUX_KERNEL_VERSION __kconfig;
>   extern bool CONFIG_BPF_SYSCALL __kconfig __weak;
>   extern const void bpf_link_fops __ksym __weak;
>   
> +static volatile int input_bss_static;
> +
>   int input_bss1;
>   int input_data1 = 1;
>   const volatile int input_rodata1 = 11;
> @@ -32,7 +34,7 @@ long output_sink1;
>   static __noinline int get_bss_res(void)
>   {
>   	/* just make sure all the relocations work against .text as well */
> -	return input_bss1 + input_bss2 + input_bss_weak;
> +	return input_bss_static + input_bss1 + input_bss2 + input_bss_weak;
>   }
>   
>   SEC("raw_tp/sys_enter")
> diff --git a/tools/testing/selftests/bpf/progs/linked_vars2.c b/tools/testing/selftests/bpf/progs/linked_vars2.c
> index e4f5bd388a3c..fdc347a609d9 100644
> --- a/tools/testing/selftests/bpf/progs/linked_vars2.c
> +++ b/tools/testing/selftests/bpf/progs/linked_vars2.c
> @@ -10,6 +10,8 @@ extern int LINUX_KERNEL_VERSION __kconfig;
>   extern bool CONFIG_BPF_SYSCALL __kconfig;
>   extern const void __start_BTF __ksym;
>   
> +static volatile int input_bss_static;
> +
>   int input_bss2;
>   int input_data2 = 2;
>   const volatile int input_rodata2 = 22;
> @@ -38,7 +40,7 @@ static __noinline int get_data_res(void)
>   SEC("raw_tp/sys_enter")
>   int BPF_PROG(handler2)
>   {
> -	output_bss2 = input_bss1 + input_bss2 + input_bss_weak;
> +	output_bss2 = input_bss_static + input_bss1 + input_bss2 + input_bss_weak;
>   	output_data2 = get_data_res();
>   	output_rodata2 = input_rodata1 + input_rodata2 + input_rodata_weak;
>   
>
Yonghong Song April 23, 2021, 11:03 p.m. UTC | #2
On 4/23/21 11:53 AM, Andrii Nakryiko wrote:
> Now that BPF static linker supports static variable renames and thus
> non-unique static variables in BPF skeleton, add tests validating static
> variables are resolved properly during multi-file static linking.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Acked-by: Yonghong Song <yhs@fb.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/linked_vars.c b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
index 267166abe4c1..75dcce539ff1 100644
--- a/tools/testing/selftests/bpf/prog_tests/linked_vars.c
+++ b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
@@ -14,8 +14,12 @@  void test_linked_vars(void)
 	if (!ASSERT_OK_PTR(skel, "skel_open"))
 		return;
 
+	skel->bss->linked_vars1__input_bss_static = 100;
 	skel->bss->input_bss1 = 1000;
+
+	skel->bss->linked_vars2__input_bss_static = 200;
 	skel->bss->input_bss2 = 2000;
+
 	skel->bss->input_bss_weak = 3000;
 
 	err = linked_vars__load(skel);
@@ -29,11 +33,11 @@  void test_linked_vars(void)
 	/* trigger */
 	syscall(SYS_getpgid);
 
-	ASSERT_EQ(skel->bss->output_bss1, 1000 + 2000 + 3000, "output_bss1");
-	ASSERT_EQ(skel->bss->output_bss2, 1000 + 2000 + 3000, "output_bss2");
+	ASSERT_EQ(skel->bss->output_bss1, 100 + 1000 + 2000 + 3000, "output_bss1");
+	ASSERT_EQ(skel->bss->output_bss2, 200 + 1000 + 2000 + 3000, "output_bss2");
 	/* 10 comes from "winner" input_data_weak in first obj file */
-	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_bss1");
-	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_bss2");
+	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_data1");
+	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_data2");
 	/* 100 comes from "winner" input_rodata_weak in first obj file */
 	ASSERT_EQ(skel->bss->output_rodata1, 11 + 22 + 100, "output_weak1");
 	ASSERT_EQ(skel->bss->output_rodata2, 11 + 22 + 100, "output_weak2");
diff --git a/tools/testing/selftests/bpf/progs/linked_vars1.c b/tools/testing/selftests/bpf/progs/linked_vars1.c
index ef9e9d0bb0ca..7d5152c066d9 100644
--- a/tools/testing/selftests/bpf/progs/linked_vars1.c
+++ b/tools/testing/selftests/bpf/progs/linked_vars1.c
@@ -10,6 +10,8 @@  extern int LINUX_KERNEL_VERSION __kconfig;
 extern bool CONFIG_BPF_SYSCALL __kconfig __weak;
 extern const void bpf_link_fops __ksym __weak;
 
+static volatile int input_bss_static;
+
 int input_bss1;
 int input_data1 = 1;
 const volatile int input_rodata1 = 11;
@@ -32,7 +34,7 @@  long output_sink1;
 static __noinline int get_bss_res(void)
 {
 	/* just make sure all the relocations work against .text as well */
-	return input_bss1 + input_bss2 + input_bss_weak;
+	return input_bss_static + input_bss1 + input_bss2 + input_bss_weak;
 }
 
 SEC("raw_tp/sys_enter")
diff --git a/tools/testing/selftests/bpf/progs/linked_vars2.c b/tools/testing/selftests/bpf/progs/linked_vars2.c
index e4f5bd388a3c..fdc347a609d9 100644
--- a/tools/testing/selftests/bpf/progs/linked_vars2.c
+++ b/tools/testing/selftests/bpf/progs/linked_vars2.c
@@ -10,6 +10,8 @@  extern int LINUX_KERNEL_VERSION __kconfig;
 extern bool CONFIG_BPF_SYSCALL __kconfig;
 extern const void __start_BTF __ksym;
 
+static volatile int input_bss_static;
+
 int input_bss2;
 int input_data2 = 2;
 const volatile int input_rodata2 = 22;
@@ -38,7 +40,7 @@  static __noinline int get_data_res(void)
 SEC("raw_tp/sys_enter")
 int BPF_PROG(handler2)
 {
-	output_bss2 = input_bss1 + input_bss2 + input_bss_weak;
+	output_bss2 = input_bss_static + input_bss1 + input_bss2 + input_bss_weak;
 	output_data2 = get_data_res();
 	output_rodata2 = input_rodata1 + input_rodata2 + input_rodata_weak;