[LTP] [PATCH v3 4/4] testcaes/lib: Add shell loader

Cyril Hrubis chrubis@suse.cz
Mon Sep 16 12:04:47 CEST 2024


Hi!
> > +static void extract_metadata(void)
> > +{
> > +	FILE *f;
> > +	char line[4096];
> > +	char path[4096];
> > +	enum parser_state state = PAR_NONE;
> > +
> > +	if (tst_get_path(shell_filename, path, sizeof(path)) == -1)
> > +		tst_brk(TBROK, "Failed to find %s in $PATH", shell_filename);
> > +
> > +	f = SAFE_FOPEN(path, "r");
> > +
> > +	while (fgets(line, sizeof(line), f)) {
> > +		switch (state) {
> > +		case PAR_NONE:
> > +			if (!strcmp(line, "# ---\n"))
> What if user defines "#---" or "#   ---" ? IMHO it would be better to 
> parse it following shell comments standards. In particular, "^#\s+---" 
> using a *scan function.

If user sets the line any differently the test will end up with pretty
clear error message that metadata are missing, so I do not see this as
an issue.

> > +				state = PAR_ESC;
> > +		break;
> > +		case PAR_ESC:
> > +			if (!strcmp(line, "# env\n"))
> Same apply here and to the others.

Same here as well.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list