Commit a7238f7c authored by John Fastabend's avatar John Fastabend Committed by Daniel Borkmann

bpf: Selftests, add blacklist to test_sockmap

This adds a blacklist to test_sockmap. For example, now we can run
all apply and cork tests except those with timeouts by doing,

 $ ./test_sockmap --whitelist "apply,cork" --blacklist "hang"
Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/158939734350.15176.6643981099665208826.stgit@john-Precision-5820-Tower
parent 065a74cb
...@@ -108,6 +108,7 @@ static const struct option long_options[] = { ...@@ -108,6 +108,7 @@ static const struct option long_options[] = {
{"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' }, {"whitelist", required_argument, NULL, 'n' },
{"blacklist", required_argument, NULL, 'b' },
{0, 0, NULL, 0 } {0, 0, NULL, 0 }
}; };
...@@ -389,6 +390,7 @@ struct sockmap_options { ...@@ -389,6 +390,7 @@ struct sockmap_options {
int rate; int rate;
char *map; char *map;
char *whitelist; char *whitelist;
char *blacklist;
}; };
static int msg_loop_sendpage(int fd, int iov_length, int cnt, static int msg_loop_sendpage(int fd, int iov_length, int cnt,
...@@ -1641,6 +1643,24 @@ static int check_whitelist(struct _test *t, struct sockmap_options *opt) ...@@ -1641,6 +1643,24 @@ static int check_whitelist(struct _test *t, struct sockmap_options *opt)
return -EINVAL; return -EINVAL;
} }
static int check_blacklist(struct _test *t, struct sockmap_options *opt)
{
char *entry, *ptr;
if (!opt->blacklist)
return -EINVAL;
ptr = strdup(opt->blacklist);
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;
...@@ -1655,7 +1675,9 @@ static int __test_selftests(int cg_fd, struct sockmap_options *opt) ...@@ -1655,7 +1675,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) if (check_whitelist(&t, opt) != 0)
continue;
if (check_blacklist(&t, opt) == 0)
continue; continue;
test_start_subtest(t.title, opt->map); test_start_subtest(t.title, opt->map);
...@@ -1696,7 +1718,7 @@ int main(int argc, char **argv) ...@@ -1696,7 +1718,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:n:", while ((opt = getopt_long(argc, argv, ":dhv:c:r:i:l:t:p:q:n:b:",
long_options, &longindex)) != -1) { long_options, &longindex)) != -1) {
switch (opt) { switch (opt) {
case 's': case 's':
...@@ -1769,6 +1791,11 @@ int main(int argc, char **argv) ...@@ -1769,6 +1791,11 @@ int main(int argc, char **argv)
options.whitelist = strdup(optarg); options.whitelist = strdup(optarg);
if (!options.whitelist) if (!options.whitelist)
return -ENOMEM; return -ENOMEM;
break;
case 'b':
options.blacklist = strdup(optarg);
if (!options.blacklist)
return -ENOMEM;
case 0: case 0:
break; break;
case 'h': case 'h':
...@@ -1823,6 +1850,8 @@ int main(int argc, char **argv) ...@@ -1823,6 +1850,8 @@ int main(int argc, char **argv)
out: out:
if (options.whitelist) if (options.whitelist)
free(options.whitelist); free(options.whitelist);
if (options.blacklist)
free(options.blacklist);
if (cg_created) if (cg_created)
cleanup_cgroup_environment(); cleanup_cgroup_environment();
close(cg_fd); close(cg_fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment