History

Improve stability of find_vma BPF test

Remove unneeded spleep and increase length of dummy CPU intensive computation to guarantee test process execution. Also, complete aforemention computation as soon as test success criteria is met

Mykola Lysenko committed 4 years ago

Commit ba83af01 parent 1fd49861 file · +19 −9Browse files

Unified · Split

tools/testing/selftests/bpf/prog_tests/find_vma.c+19−9
@@ -7,12 +7,14 @@ · 6 unmodified lines
7#include "find_vma_fail1.skel.h"7#include "find_vma_fail1.skel.h"
8#include "find_vma_fail2.skel.h"8#include "find_vma_fail2.skel.h"
9 9
10static void test_and_reset_skel(struct find_vma *skel, int expected_find_zero_ret)10static void test_and_reset_skel(struct find_vma *skel, int expected_find_zero_ret, bool need_test)
11{11{
12 ASSERT_EQ(skel->bss->found_vm_exec, 1, "found_vm_exec");12 if (need_test) {
13 ASSERT_EQ(skel->data->find_addr_ret, 0, "find_addr_ret");13 ASSERT_EQ(skel->bss->found_vm_exec, 1, "found_vm_exec");
14 ASSERT_EQ(skel->data->find_zero_ret, expected_find_zero_ret, "find_zero_ret");14 ASSERT_EQ(skel->data->find_addr_ret, 0, "find_addr_ret");
15 ASSERT_OK_PTR(strstr(skel->bss->d_iname, "test_progs"), "find_test_progs");15 ASSERT_EQ(skel->data->find_zero_ret, expected_find_zero_ret, "find_zero_ret");
16 ASSERT_OK_PTR(strstr(skel->bss->d_iname, "test_progs"), "find_test_progs");
17 }
16 18
17 skel->bss->found_vm_exec = 0;19 skel->bss->found_vm_exec = 0;
18 skel->data->find_addr_ret = -1;20 skel->data->find_addr_ret = -1;
@@ -36,11 +38,20 @@ static int open_pe(void) · 17 unmodified lines
36 return pfd >= 0 ? pfd : -errno;38 return pfd >= 0 ? pfd : -errno;
37}39}
38 40
41static bool find_vma_pe_condition(struct find_vma *skel)
42{
43 return skel->bss->found_vm_exec == 0 ||
44 skel->data->find_addr_ret != 0 ||
45 skel->data->find_zero_ret == -1 ||
46 strcmp(skel->bss->d_iname, "test_progs") != 0;
47}
48
39static void test_find_vma_pe(struct find_vma *skel)49static void test_find_vma_pe(struct find_vma *skel)
40{50{
41 struct bpf_link *link = NULL;51 struct bpf_link *link = NULL;
42 volatile int j = 0;52 volatile int j = 0;
43 int pfd, i;53 int pfd, i;
54 const int one_bn = 1000000000;
44 55
45 pfd = open_pe();56 pfd = open_pe();
46 if (pfd < 0) {57 if (pfd < 0) {
@@ -57,10 +68,10 @@ static void test_find_vma_pe(struct find_vma *skel) · 10 unmodified lines
57 if (!ASSERT_OK_PTR(link, "attach_perf_event"))68 if (!ASSERT_OK_PTR(link, "attach_perf_event"))
58 goto cleanup;69 goto cleanup;
59 70
60 for (i = 0; i < 1000000; ++i)71 for (i = 0; i < one_bn && find_vma_pe_condition(skel); ++i)
61 ++j;72 ++j;
62 73
63 test_and_reset_skel(skel, -EBUSY /* in nmi, irq_work is busy */);74 test_and_reset_skel(skel, -EBUSY /* in nmi, irq_work is busy */, i == one_bn);
64cleanup:75cleanup:
65 bpf_link__destroy(link);76 bpf_link__destroy(link);
66 close(pfd);77 close(pfd);
@@ -75,7 +86,7 @@ static void test_find_vma_kprobe(struct find_vma *skel) · 8 unmodified lines
75 return;86 return;
76 87
77 getpgid(skel->bss->target_pid);88 getpgid(skel->bss->target_pid);
78 test_and_reset_skel(skel, -ENOENT /* could not find vma for ptr 0 */);89 test_and_reset_skel(skel, -ENOENT /* could not find vma for ptr 0 */, true);
79}90}
80 91
81static void test_illegal_write_vma(void)92static void test_illegal_write_vma(void)
@@ -108,7 +119,6 @@ void serial_test_find_vma(void) · 26 unmodified lines
108 skel->bss->addr = (__u64)(uintptr_t)test_find_vma_pe;119 skel->bss->addr = (__u64)(uintptr_t)test_find_vma_pe;
109 120
110 test_find_vma_pe(skel);121 test_find_vma_pe(skel);
111 usleep(100000); /* allow the irq_work to finish */
112 test_find_vma_kprobe(skel);122 test_find_vma_kprobe(skel);
113 123
114 find_vma__destroy(skel);124 find_vma__destroy(skel);