mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-07 18:05:21 +02:00
selftests/bpf: Fix arg parsing in veristat, test_progs
[ Upstream commit03bfcda1fb
] Current code parses arguments with strtok_r() using a construct like char *state = NULL; while ((next = strtok_r(state ? NULL : input, ",", &state))) { ... } where logic assumes the 'state' var can distinguish between first and subsequent strtok_r() calls, and adjusts parameters accordingly. However, 'state' is strictly internal context for strtok_r() and no such assumptions are supported in the man page. Moreover, the exact behaviour of 'state' depends on the libc implementation, making the above code fragile. Indeed, invoking "./test_progs -t <test_name>" on mips64el/musl will hang, with the above code in an infinite loop. Similarly, we see strange behaviour running 'veristat' on mips64el/musl: $ ./veristat -e file,prog,verdict,insns -C two-ok add-failure Can't specify more than 9 stats Rewrite code using a counter to distinguish between strtok_r() calls. Fixes:61ddff373f
("selftests/bpf: Improve by-name subtest selection logic in prog_tests") Fixes:394169b079
("selftests/bpf: add comparison mode to veristat") Fixes:c8bc5e0509
("selftests/bpf: Add veristat tool for mass-verifying BPF object files") Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/392d8bf5559f85fa37926c1494e62312ef252c3d.1722244708.git.tony.ambardar@gmail.com Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
d57f8de839
commit
564d1abf50
|
@ -220,13 +220,13 @@ int parse_test_list(const char *s,
|
||||||
bool is_glob_pattern)
|
bool is_glob_pattern)
|
||||||
{
|
{
|
||||||
char *input, *state = NULL, *test_spec;
|
char *input, *state = NULL, *test_spec;
|
||||||
int err = 0;
|
int err = 0, cnt = 0;
|
||||||
|
|
||||||
input = strdup(s);
|
input = strdup(s);
|
||||||
if (!input)
|
if (!input)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
while ((test_spec = strtok_r(state ? NULL : input, ",", &state))) {
|
while ((test_spec = strtok_r(cnt++ ? NULL : input, ",", &state))) {
|
||||||
err = insert_test(set, test_spec, is_glob_pattern);
|
err = insert_test(set, test_spec, is_glob_pattern);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -753,13 +753,13 @@ static int parse_stat(const char *stat_name, struct stat_specs *specs)
|
||||||
static int parse_stats(const char *stats_str, struct stat_specs *specs)
|
static int parse_stats(const char *stats_str, struct stat_specs *specs)
|
||||||
{
|
{
|
||||||
char *input, *state = NULL, *next;
|
char *input, *state = NULL, *next;
|
||||||
int err;
|
int err, cnt = 0;
|
||||||
|
|
||||||
input = strdup(stats_str);
|
input = strdup(stats_str);
|
||||||
if (!input)
|
if (!input)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
while ((next = strtok_r(state ? NULL : input, ",", &state))) {
|
while ((next = strtok_r(cnt++ ? NULL : input, ",", &state))) {
|
||||||
err = parse_stat(next, specs);
|
err = parse_stat(next, specs);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -1444,7 +1444,7 @@ static int parse_stats_csv(const char *filename, struct stat_specs *specs,
|
||||||
while (fgets(line, sizeof(line), f)) {
|
while (fgets(line, sizeof(line), f)) {
|
||||||
char *input = line, *state = NULL, *next;
|
char *input = line, *state = NULL, *next;
|
||||||
struct verif_stats *st = NULL;
|
struct verif_stats *st = NULL;
|
||||||
int col = 0;
|
int col = 0, cnt = 0;
|
||||||
|
|
||||||
if (!header) {
|
if (!header) {
|
||||||
void *tmp;
|
void *tmp;
|
||||||
|
@ -1462,7 +1462,7 @@ static int parse_stats_csv(const char *filename, struct stat_specs *specs,
|
||||||
*stat_cntp += 1;
|
*stat_cntp += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((next = strtok_r(state ? NULL : input, ",\n", &state))) {
|
while ((next = strtok_r(cnt++ ? NULL : input, ",\n", &state))) {
|
||||||
if (header) {
|
if (header) {
|
||||||
/* for the first line, set up spec stats */
|
/* for the first line, set up spec stats */
|
||||||
err = parse_stat(next, specs);
|
err = parse_stat(next, specs);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user