Skip to content

Commit 1890887

Browse files
committed
refactor code test02_should_fail
Introduce helper to make is easier to test two struct variations with the same invalid btf_id struct location. Signed-off-by: Jesper Dangaard Brouer <[email protected]>
1 parent 1e4e033 commit 1890887

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

AF_XDP-interaction/btf_unit_test.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,12 @@ int test01_normal()
144144
return EXIT_OK;
145145
}
146146

147-
int test02_should_fail()
147+
int helper_expect_invalid_btf_id(struct btf *btf,
148+
const char *xdp_hint_name)
148149
{
149-
struct bpf_object *bpf_obj;
150150
struct xsk_btf_info *xbi;
151-
struct btf *btf;
152-
int errval = 0;
153151
int ret = EXIT_OK;
154-
const char *xdp_hint_name = "xdp_hints_fail001";
155-
156-
bpf_obj = load_bpf_object("btf_unit_test_bpf.o");
157-
if (!bpf_obj)
158-
return EXIT_FAIL_BPF;
159-
160-
btf = bpf_object__btf(bpf_obj);
152+
int errval = 0;
161153

162154
xbi = setup_btf_info(btf, xdp_hint_name, &errval);
163155
if (xbi) {
@@ -179,6 +171,32 @@ int test02_should_fail()
179171
xdp_hint_name);
180172
}
181173

174+
out:
175+
return ret;
176+
}
177+
178+
int test02_should_fail()
179+
{
180+
const char *xdp_hint01 = "xdp_hints_fail001";
181+
const char *xdp_hint02 = "xdp_hints_fail002";
182+
struct bpf_object *bpf_obj;
183+
int ret = EXIT_OK;
184+
struct btf *btf;
185+
186+
bpf_obj = load_bpf_object("btf_unit_test_bpf.o");
187+
if (!bpf_obj)
188+
return EXIT_FAIL_BPF;
189+
190+
btf = bpf_object__btf(bpf_obj);
191+
192+
ret = helper_expect_invalid_btf_id(btf, xdp_hint01);
193+
if (ret)
194+
goto out;
195+
196+
ret = helper_expect_invalid_btf_id(btf, xdp_hint02);
197+
if (ret)
198+
goto out;
199+
182200
out:
183201
bpf_object__close(bpf_obj);
184202
return ret;

0 commit comments

Comments
 (0)