selftests/resctrl: Flush stdout file buffer before executing fork()
authorShaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Thu, 13 Apr 2023 07:22:56 +0000 (16:22 +0900)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 13 Apr 2023 17:34:12 +0000 (11:34 -0600)
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>
tools/testing/selftests/resctrl/cat_test.c
tools/testing/selftests/resctrl/resctrl_val.c
tools/testing/selftests/resctrl/resctrlfs.c

index 08070d4fa73592f9cd06b6f2659a23d25ac4188f..38c10a8c1814a33e9a3d1dbc86c52e3e22dfe777 100644 (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
index 00864242d76c64011ed7dd73dbf87676092c85ac..e632657995c7e729e2aec758ba98d867a896bb26 100644 (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");
index b31b1d9e41d1ab99f921df595038fdee6c019bb1..fb00245dee92e8b035d881cbe556cd09023de939 100644 (file)
@@ -678,6 +678,7 @@ int filter_dmesg(void)
                perror("pipe");
                return ret;
        }
+       fflush(stdout);
        pid = fork();
        if (pid == 0) {
                close(pipefds[0]);