selftests/resctrl: Flush stdout file buffer before executing fork()

When a process has buffered output, a child process created by fork()
will also copy buffered output. When using kselftest framework,
the output (resctrl test result message) will be printed multiple times.

Add fflush() to flush out the buffered output before executing fork().

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Shaopeng Tan 2023-04-13 16:22:56 +09:00 committed by Shuah Khan
parent 1e359b6a94
commit a080b6e74b
3 changed files with 3 additions and 0 deletions

View File

@ -167,6 +167,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
return errno;
}
fflush(stdout);
bm_pid = fork();
/* Set param values for child thread which will be allocated bitmask

View File

@ -629,6 +629,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
* Fork to start benchmark, save child's pid so that it can be killed
* when needed
*/
fflush(stdout);
bm_pid = fork();
if (bm_pid == -1) {
perror("# Unable to fork");

View File

@ -678,6 +678,7 @@ int filter_dmesg(void)
perror("pipe");
return ret;
}
fflush(stdout);
pid = fork();
if (pid == 0) {
close(pipefds[0]);