Skip to content

Commit

Permalink
selftests/resctrl: Flush stdout file buffer before executing fork()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shaopeng Tan authored and Shuah Khan committed Apr 13, 2023
1 parent 1e359b6 commit a080b6e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/resctrl/cat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/resctrl/resctrl_val.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/resctrl/resctrlfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ int filter_dmesg(void)
perror("pipe");
return ret;
}
fflush(stdout);
pid = fork();
if (pid == 0) {
close(pipefds[0]);
Expand Down

0 comments on commit a080b6e

Please sign in to comment.