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
Unified · Split
| @@ -7,12 +7,14 @@ · 6 unmodified lines | ||
| 7 | 7 | #include "find_vma_fail1.skel.h" |
| 8 | 8 | #include "find_vma_fail2.skel.h" |
| 9 | 9 | |
| 10 | −static void test_and_reset_skel(struct find_vma *skel, int expected_find_zero_ret) | |
| 10 | +static 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"); | |
| 13 | − ASSERT_EQ(skel->data->find_addr_ret, 0, "find_addr_ret"); | |
| 14 | − ASSERT_EQ(skel->data->find_zero_ret, expected_find_zero_ret, "find_zero_ret"); | |
| 15 | − ASSERT_OK_PTR(strstr(skel->bss->d_iname, "test_progs"), "find_test_progs"); | |
| 12 | + if (need_test) { | |
| 13 | + ASSERT_EQ(skel->bss->found_vm_exec, 1, "found_vm_exec"); | |
| 14 | + ASSERT_EQ(skel->data->find_addr_ret, 0, "find_addr_ret"); | |
| 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 | 19 | skel->bss->found_vm_exec = 0; |
| 18 | 20 | skel->data->find_addr_ret = -1; |
| @@ -36,11 +38,20 @@ static int open_pe(void) · 17 unmodified lines | ||
| 36 | 38 | return pfd >= 0 ? pfd : -errno; |
| 37 | 39 | } |
| 38 | 40 | |
| 41 | +static 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 | + | |
| 39 | 49 | static void test_find_vma_pe(struct find_vma *skel) |
| 40 | 50 | { |
| 41 | 51 | struct bpf_link *link = NULL; |
| 42 | 52 | volatile int j = 0; |
| 43 | 53 | int pfd, i; |
| 54 | + const int one_bn = 1000000000; | |
| 44 | 55 | |
| 45 | 56 | pfd = open_pe(); |
| 46 | 57 | if (pfd < 0) { |
| @@ -57,10 +68,10 @@ static void test_find_vma_pe(struct find_vma *skel) · 10 unmodified lines | ||
| 57 | 68 | if (!ASSERT_OK_PTR(link, "attach_perf_event")) |
| 58 | 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 | 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); | |
| 64 | 75 | cleanup: |
| 65 | 76 | bpf_link__destroy(link); |
| 66 | 77 | close(pfd); |
| @@ -75,7 +86,7 @@ static void test_find_vma_kprobe(struct find_vma *skel) · 8 unmodified lines | ||
| 75 | 86 | return; |
| 76 | 87 | |
| 77 | 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 | |
| 81 | 92 | static void test_illegal_write_vma(void) |
| @@ -108,7 +119,6 @@ void serial_test_find_vma(void) · 26 unmodified lines | ||
| 108 | 119 | skel->bss->addr = (__u64)(uintptr_t)test_find_vma_pe; |
| 109 | 120 | |
| 110 | 121 | test_find_vma_pe(skel); |
| 111 | − usleep(100000); /* allow the irq_work to finish */ | |
| 112 | 122 | test_find_vma_kprobe(skel); |
| 113 | 123 | |
| 114 | 124 | find_vma__destroy(skel); |