Skip to content

Commit 8082575

Browse files
anakryikogregkh
authored andcommitted
selftests/bpf: Fix core_reloc test runner
[ Upstream commit bede0eb ] Fix failed tests checks in core_reloc test runner, which allowed failing tests to pass quietly. Also add extra check to make sure that expected to fail test cases with invalid names are caught as test failure anyway, as this is not an expected failure mode. Also fix mislabeled probed vs direct bitfield test cases. Fixes: 124a892 ("selftests/bpf: Test TYPE_EXISTS and TYPE_SIZE CO-RE relocations") Reported-by: Lorenz Bauer <lmb@cloudflare.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Lorenz Bauer <lmb@cloudflare.com> Link: https://lore.kernel.org/bpf/20210426192949.416837-6-andrii@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 79fe74b commit 8082575

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎tools/testing/selftests/bpf/prog_tests/core_reloc.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ static int duration = 0;
217217

218218
#define BITFIELDS_CASE(name, ...) { \
219219
BITFIELDS_CASE_COMMON("test_core_reloc_bitfields_probed.o", \
220-
"direct:", name), \
220+
"probed:", name), \
221221
.input = STRUCT_TO_CHAR_PTR(core_reloc_##name) __VA_ARGS__, \
222222
.input_len = sizeof(struct core_reloc_##name), \
223223
.output = STRUCT_TO_CHAR_PTR(core_reloc_bitfields_output) \
224224
__VA_ARGS__, \
225225
.output_len = sizeof(struct core_reloc_bitfields_output), \
226226
}, { \
227227
BITFIELDS_CASE_COMMON("test_core_reloc_bitfields_direct.o", \
228-
"probed:", name), \
228+
"direct:", name), \
229229
.input = STRUCT_TO_CHAR_PTR(core_reloc_##name) __VA_ARGS__, \
230230
.input_len = sizeof(struct core_reloc_##name), \
231231
.output = STRUCT_TO_CHAR_PTR(core_reloc_bitfields_output) \
@@ -545,8 +545,7 @@ static struct core_reloc_test_case test_cases[] = {
545545
ARRAYS_ERR_CASE(arrays___err_too_small),
546546
ARRAYS_ERR_CASE(arrays___err_too_shallow),
547547
ARRAYS_ERR_CASE(arrays___err_non_array),
548-
ARRAYS_ERR_CASE(arrays___err_wrong_val_type1),
549-
ARRAYS_ERR_CASE(arrays___err_wrong_val_type2),
548+
ARRAYS_ERR_CASE(arrays___err_wrong_val_type),
550549
ARRAYS_ERR_CASE(arrays___err_bad_zero_sz_arr),
551550

552551
/* enum/ptr/int handling scenarios */
@@ -864,13 +863,20 @@ void test_core_reloc(void)
864863
"prog '%s' not found\n", probe_name))
865864
goto cleanup;
866865

866+
867+
if (test_case->btf_src_file) {
868+
err = access(test_case->btf_src_file, R_OK);
869+
if (!ASSERT_OK(err, "btf_src_file"))
870+
goto cleanup;
871+
}
872+
867873
load_attr.obj = obj;
868874
load_attr.log_level = 0;
869875
load_attr.target_btf_path = test_case->btf_src_file;
870876
err = bpf_object__load_xattr(&load_attr);
871877
if (err) {
872878
if (!test_case->fails)
873-
CHECK(false, "obj_load", "failed to load prog '%s': %d\n", probe_name, err);
879+
ASSERT_OK(err, "obj_load");
874880
goto cleanup;
875881
}
876882

@@ -909,10 +915,8 @@ void test_core_reloc(void)
909915
goto cleanup;
910916
}
911917

912-
if (test_case->fails) {
913-
CHECK(false, "obj_load_fail", "should fail to load prog '%s'\n", probe_name);
918+
if (!ASSERT_FALSE(test_case->fails, "obj_load_should_fail"))
914919
goto cleanup;
915-
}
916920

917921
equal = memcmp(data->out, test_case->output,
918922
test_case->output_len) == 0;

0 commit comments

Comments
 (0)