Skip to content

Commit 4db10a8

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
selftests/bpf: verifier/value_ptr_arith converted to inline assembly
Test verifier/value_ptr_arith automatically converted to use inline assembly. Test cases "sanitation: alu with different scalars 2" and "sanitation: alu with different scalars 3" are updated to avoid -ENOENT as return value, as __retval() annotation only supports numeric literals. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent efe25a3 commit 4db10a8

File tree

3 files changed

+1451
-1146
lines changed

3 files changed

+1451
-1146
lines changed

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "verifier_value.skel.h"
6363
#include "verifier_value_illegal_alu.skel.h"
6464
#include "verifier_value_or_null.skel.h"
65+
#include "verifier_value_ptr_arith.skel.h"
6566
#include "verifier_var_off.skel.h"
6667
#include "verifier_xadd.skel.h"
6768
#include "verifier_xdp.skel.h"
@@ -164,29 +165,50 @@ void test_verifier_xadd(void) { RUN(verifier_xadd); }
164165
void test_verifier_xdp(void) { RUN(verifier_xdp); }
165166
void test_verifier_xdp_direct_packet_access(void) { RUN(verifier_xdp_direct_packet_access); }
166167

167-
static int init_array_access_maps(struct bpf_object *obj)
168+
static int init_test_val_map(struct bpf_object *obj, char *map_name)
168169
{
169-
struct bpf_map *array_ro;
170170
struct test_val value = {
171171
.index = (6 + 1) * sizeof(int),
172172
.foo[6] = 0xabcdef12,
173173
};
174+
struct bpf_map *map;
174175
int err, key = 0;
175176

176-
array_ro = bpf_object__find_map_by_name(obj, "map_array_ro");
177-
if (!ASSERT_OK_PTR(array_ro, "lookup map_array_ro"))
177+
map = bpf_object__find_map_by_name(obj, map_name);
178+
if (!map) {
179+
PRINT_FAIL("Can't find map '%s'\n", map_name);
178180
return -EINVAL;
181+
}
179182

180-
err = bpf_map_update_elem(bpf_map__fd(array_ro), &key, &value, 0);
181-
if (!ASSERT_OK(err, "map_array_ro update"))
183+
err = bpf_map_update_elem(bpf_map__fd(map), &key, &value, 0);
184+
if (err) {
185+
PRINT_FAIL("Error while updating map '%s': %d\n", map_name, err);
182186
return err;
187+
}
183188

184189
return 0;
185190
}
186191

192+
static int init_array_access_maps(struct bpf_object *obj)
193+
{
194+
return init_test_val_map(obj, "map_array_ro");
195+
}
196+
187197
void test_verifier_array_access(void)
188198
{
189199
run_tests_aux("verifier_array_access",
190200
verifier_array_access__elf_bytes,
191201
init_array_access_maps);
192202
}
203+
204+
static int init_value_ptr_arith_maps(struct bpf_object *obj)
205+
{
206+
return init_test_val_map(obj, "map_array_48b");
207+
}
208+
209+
void test_verifier_value_ptr_arith(void)
210+
{
211+
run_tests_aux("verifier_value_ptr_arith",
212+
verifier_value_ptr_arith__elf_bytes,
213+
init_value_ptr_arith_maps);
214+
}

0 commit comments

Comments
 (0)