[yocto] [ptest-runner] Run ptests via stdbuf configured to line-buffering

Joshua Watt jpewhacker at gmail.com
Thu Apr 4 10:31:43 PDT 2019


On Thu, 2019-04-04 at 18:00 +0200, Alexander Kanavin wrote:
> As ptest-runner communicates with child processes via pipe2(),
> the corresponding channels are not attached to a pty. In that
> situation stdio facilities like printf() or fwrite() are fully
> buffered. If a ptest would use them, without bothering
> to fflush() the output, ptest-runner will only receive what
> was written by the child ptest process after a buffer gets filled.
> If the unit tests are proceeding slowly, this may mean that
> ptest-runner will erroneously timeout due to an apparent lack of
> 'signs of life' from the child process.
> 
> stdbuf utility from coreutils adjusts the buffering to a line-
> buffered
> one, and so ptest-runner will get the lines as soon as they are
> written.
> 
> Signed-off-by: Alexander Kanavin <alex.kanavin at gmail.com>
> ---
>  utils.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/utils.c b/utils.c
> index 504df0b..1376e39 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -243,16 +243,13 @@ filter_ptests(struct ptest_list *head, char
> **ptests, int ptest_num)
>  static inline void
>  run_child(char *run_ptest, int fd_stdout, int fd_stderr)
>  {
> -	char **argv = malloc(sizeof(char) * 2);
> +	char* argv[] = {"stdbuf", "-oL", "-eL", "./run-ptest", NULL};

Should be run_ptest the from the function argument, not the string
literal "./run-ptest" ?


>  	chdir(dirname(strdup(run_ptest)));
>  
> -	argv[0] = run_ptest;
> -	argv[1] = NULL;
> -
>  	dup2(fd_stdout, STDOUT_FILENO);
>  	// XXX: Redirect stderr to stdout to avoid buffer ordering
> problems.
>  	dup2(fd_stdout, STDERR_FILENO);
> -	execv(run_ptest, argv);
> +	execvp(argv[0], argv);
>  
>  	exit(1);
>  }
> -- 
> 2.17.1
> 
-- 
Joshua Watt <JPEWhacker at gmail.com>



More information about the yocto mailing list