mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
bpf: Selftests, add whitelist option to test_sockmap
Allow running specific tests with a comma deliminated whitelist. For example to run all apply and cork tests. $ ./test_sockmap --whitelist="cork,apply" Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com> Link: https://lore.kernel.org/bpf/158939732464.15176.1959113294944564542.stgit@john-Precision-5820-Tower
This commit is contained in:
parent
b98ca90c56
commit
065a74cbd0
1 changed files with 30 additions and 1 deletions
|
@ -107,6 +107,7 @@ static const struct option long_options[] = {
|
||||||
{"txmsg_skb", no_argument, &txmsg_skb, 1 },
|
{"txmsg_skb", no_argument, &txmsg_skb, 1 },
|
||||||
{"ktls", no_argument, &ktls, 1 },
|
{"ktls", no_argument, &ktls, 1 },
|
||||||
{"peek", no_argument, &peek_flag, 1 },
|
{"peek", no_argument, &peek_flag, 1 },
|
||||||
|
{"whitelist", required_argument, NULL, 'n' },
|
||||||
{0, 0, NULL, 0 }
|
{0, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -387,6 +388,7 @@ struct sockmap_options {
|
||||||
int iov_length;
|
int iov_length;
|
||||||
int rate;
|
int rate;
|
||||||
char *map;
|
char *map;
|
||||||
|
char *whitelist;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int msg_loop_sendpage(int fd, int iov_length, int cnt,
|
static int msg_loop_sendpage(int fd, int iov_length, int cnt,
|
||||||
|
@ -1621,6 +1623,24 @@ struct _test test[] = {
|
||||||
{"txmsg test push/pop data", test_txmsg_push_pop},
|
{"txmsg test push/pop data", test_txmsg_push_pop},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int check_whitelist(struct _test *t, struct sockmap_options *opt)
|
||||||
|
{
|
||||||
|
char *entry, *ptr;
|
||||||
|
|
||||||
|
if (!opt->whitelist)
|
||||||
|
return 0;
|
||||||
|
ptr = strdup(opt->whitelist);
|
||||||
|
if (!ptr)
|
||||||
|
return -ENOMEM;
|
||||||
|
entry = strtok(ptr, ",");
|
||||||
|
while (entry) {
|
||||||
|
if (strstr(opt->map, entry) != 0 || strstr(t->title, entry) != 0)
|
||||||
|
return 0;
|
||||||
|
entry = strtok(NULL, ",");
|
||||||
|
}
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
static int __test_selftests(int cg_fd, struct sockmap_options *opt)
|
static int __test_selftests(int cg_fd, struct sockmap_options *opt)
|
||||||
{
|
{
|
||||||
int i, err;
|
int i, err;
|
||||||
|
@ -1635,6 +1655,9 @@ static int __test_selftests(int cg_fd, struct sockmap_options *opt)
|
||||||
for (i = 0; i < sizeof(test)/sizeof(struct _test); i++) {
|
for (i = 0; i < sizeof(test)/sizeof(struct _test); i++) {
|
||||||
struct _test t = test[i];
|
struct _test t = test[i];
|
||||||
|
|
||||||
|
if (check_whitelist(&t, opt) < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
test_start_subtest(t.title, opt->map);
|
test_start_subtest(t.title, opt->map);
|
||||||
t.tester(cg_fd, opt);
|
t.tester(cg_fd, opt);
|
||||||
test_end_subtest();
|
test_end_subtest();
|
||||||
|
@ -1673,7 +1696,7 @@ int main(int argc, char **argv)
|
||||||
int test = SELFTESTS;
|
int test = SELFTESTS;
|
||||||
bool cg_created = 0;
|
bool cg_created = 0;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, ":dhv:c:r:i:l:t:p:q:",
|
while ((opt = getopt_long(argc, argv, ":dhv:c:r:i:l:t:p:q:n:",
|
||||||
long_options, &longindex)) != -1) {
|
long_options, &longindex)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -1742,6 +1765,10 @@ int main(int argc, char **argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
options.whitelist = strdup(optarg);
|
||||||
|
if (!options.whitelist)
|
||||||
|
return -ENOMEM;
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -1794,6 +1821,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
err = run_options(&options, cg_fd, test);
|
err = run_options(&options, cg_fd, test);
|
||||||
out:
|
out:
|
||||||
|
if (options.whitelist)
|
||||||
|
free(options.whitelist);
|
||||||
if (cg_created)
|
if (cg_created)
|
||||||
cleanup_cgroup_environment();
|
cleanup_cgroup_environment();
|
||||||
close(cg_fd);
|
close(cg_fd);
|
||||||
|
|
Loading…
Add table
Reference in a new issue