Skip to content

Commit e2fc818

Browse files
HoyeonRheeKernel Patches Daemon
authored andcommitted
selftests/bpf: refactor snprintf_btf test to use bpf_strncmp
The netif_receive_skb BPF program used in snprintf_btf test still uses a custom __strncmp. This is unnecessary as the bpf_strncmp helper is available and provides the same functionality. This commit refactors the test to use the bpf_strncmp helper, removing the redundant custom implementation. Signed-off-by: Hoyeon Lee <[email protected]> Acked-by: Eduard Zingerman <[email protected]>
1 parent c95b89c commit e2fc818

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

tools/testing/selftests/bpf/progs/netif_receive_skb.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ struct {
3131
__type(value, char[STRSIZE]);
3232
} strdata SEC(".maps");
3333

34-
static int __strncmp(const void *m1, const void *m2, size_t len)
35-
{
36-
const unsigned char *s1 = m1;
37-
const unsigned char *s2 = m2;
38-
int i, delta = 0;
39-
40-
for (i = 0; i < len; i++) {
41-
delta = s1[i] - s2[i];
42-
if (delta || s1[i] == 0 || s2[i] == 0)
43-
break;
44-
}
45-
return delta;
46-
}
4734

4835
#if __has_builtin(__builtin_btf_type_id)
4936
#define TEST_BTF(_str, _type, _flags, _expected, ...) \
@@ -69,7 +56,7 @@ static int __strncmp(const void *m1, const void *m2, size_t len)
6956
&_ptr, sizeof(_ptr), _hflags); \
7057
if (ret) \
7158
break; \
72-
_cmp = __strncmp(_str, _expectedval, EXPECTED_STRSIZE); \
59+
_cmp = bpf_strncmp(_str, EXPECTED_STRSIZE, _expectedval); \
7360
if (_cmp != 0) { \
7461
bpf_printk("(%d) got %s", _cmp, _str); \
7562
bpf_printk("(%d) expected %s", _cmp, \

0 commit comments

Comments
 (0)