[PATCH bpf-next 5/5] selftests/bpf: Improve readability in iter test for percpu data

Leon Hwang <[email protected]>
Newsgroups org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest
Message-ID <[email protected]>
The original 'offsetof()' + offset is equal to the new 'offsetof()'. Use
the new 'offsetof()' instead.

Rename two variables btw:

* offsetof_num -> num_off
* percpu_data_sum -> sum

Signed-off-by: Leon Hwang <[email protected]>
---
 tools/testing/selftests/bpf/prog_tests/global_data_init.c   | 6 +++---
 tools/testing/selftests/bpf/progs/test_global_percpu_data.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 2f0dbeb88934..c6d055b9457d 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -348,8 +348,8 @@ static void test_global_percpu_data_iter(void)
 		return;
 
 	skel->rodata->num_cpus = num_cpus;
-	skel->rodata->offsetof_num = offsetof(struct test_global_percpu_data__percpu, struct_data);
-	skel->rodata->offsetof_num += sizeof(skel->percpu->struct_data) - sizeof(int);
+	skel->rodata->num_off = offsetof(struct test_global_percpu_data__percpu,
+					 struct_data.nums[6]);
 	skel->rodata->elem_sz = roundup(sizeof(struct test_global_percpu_data__percpu), 8);
 	skel->percpu->struct_data.nums[6] = 0xc0de;
 
@@ -372,7 +372,7 @@ static void test_global_percpu_data_iter(void)
 		do { } while (0);
 	ASSERT_EQ(len, 0, "read iter");
 	ASSERT_TRUE(skel->bss->run_iter, "run_iter");
-	ASSERT_EQ(skel->bss->percpu_data_sum, 0xc0de * num_cpus, "percpu_data_sum");
+	ASSERT_EQ(skel->bss->sum, 0xc0de * num_cpus, "sum");
 
 	close(fd);
 out:
diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
index 12556590b647..175c44000753 100644
--- a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
+++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
@@ -64,9 +64,9 @@ int verifier_snprintf(void *ctx)
 }
 
 volatile const __u32 num_cpus = 0;
-volatile const int offsetof_num;
+volatile const int num_off;
 volatile const int elem_sz;
-__u32 percpu_data_sum = 0;
+__u32 sum = 0;
 bool run_iter = false;
 
 SEC("iter/bpf_map_elem")
@@ -82,7 +82,7 @@ int dump_percpu_data(struct bpf_iter__bpf_map_elem *ctx)
 	run_iter = true;
 
 	for (i = 0; i < num_cpus; i++) {
-		percpu_data_sum += *(int *) (pptr + offsetof_num);
+		sum += *(int *) (pptr + num_off);
 		pptr += elem_sz;
 	}
 	return 0;
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.