Skip to content

Commit 128cd76

Browse files
eddyz87anakryiko
authored andcommitted
veristat: @files-list.txt notation for object files list
Allow reading object file list from file. E.g. the following command: ./veristat @list.txt Is equivalent to the following invocation: ./veristat line-1 line-2 ... line-N Where line-i corresponds to lines from list.txt. Lines starting with '#' are ignored. Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Mykyta Yatsenko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent d38ad24 commit 128cd76

File tree

1 file changed

+53
-9
lines changed

1 file changed

+53
-9
lines changed

tools/testing/selftests/bpf/veristat.c

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,11 @@ static int append_filter(struct filter **filters, int *cnt, const char *str);
268268
static int append_filter_file(const char *path);
269269
static int append_var_preset(struct var_preset **presets, int *cnt, const char *expr);
270270
static int append_var_preset_file(const char *filename);
271+
static int append_file(const char *path);
272+
static int append_file_from_file(const char *path);
271273

272274
static error_t parse_arg(int key, char *arg, struct argp_state *state)
273275
{
274-
void *tmp;
275276
int err;
276277

277278
switch (key) {
@@ -381,14 +382,14 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
381382
break;
382383
}
383384
case ARGP_KEY_ARG:
384-
tmp = realloc(env.filenames, (env.filename_cnt + 1) * sizeof(*env.filenames));
385-
if (!tmp)
386-
return -ENOMEM;
387-
env.filenames = tmp;
388-
env.filenames[env.filename_cnt] = strdup(arg);
389-
if (!env.filenames[env.filename_cnt])
390-
return -ENOMEM;
391-
env.filename_cnt++;
385+
if (arg[0] == '@')
386+
err = append_file_from_file(arg + 1);
387+
else
388+
err = append_file(arg);
389+
if (err) {
390+
fprintf(stderr, "Failed to collect BPF object files: %d\n", err);
391+
return err;
392+
}
392393
break;
393394
default:
394395
return ARGP_ERR_UNKNOWN;
@@ -689,6 +690,49 @@ static const struct stat_specs default_output_spec = {
689690
},
690691
};
691692

693+
static int append_file(const char *path)
694+
{
695+
void *tmp;
696+
697+
tmp = realloc(env.filenames, (env.filename_cnt + 1) * sizeof(*env.filenames));
698+
if (!tmp)
699+
return -ENOMEM;
700+
env.filenames = tmp;
701+
env.filenames[env.filename_cnt] = strdup(path);
702+
if (!env.filenames[env.filename_cnt])
703+
return -ENOMEM;
704+
env.filename_cnt++;
705+
return 0;
706+
}
707+
708+
static int append_file_from_file(const char *path)
709+
{
710+
char buf[1024];
711+
int err = 0;
712+
FILE *f;
713+
714+
f = fopen(path, "r");
715+
if (!f) {
716+
err = -errno;
717+
fprintf(stderr, "Failed to open object files list in '%s': %s\n",
718+
path, strerror(errno));
719+
return err;
720+
}
721+
722+
while (fscanf(f, " %1023[^\n]\n", buf) == 1) {
723+
/* lines starting with # are comments, skip them */
724+
if (buf[0] == '\0' || buf[0] == '#')
725+
continue;
726+
err = append_file(buf);
727+
if (err)
728+
goto cleanup;
729+
}
730+
731+
cleanup:
732+
fclose(f);
733+
return err;
734+
}
735+
692736
static const struct stat_specs default_csv_output_spec = {
693737
.spec_cnt = 14,
694738
.ids = {

0 commit comments

Comments
 (0)