Re: [PATCHv3 bpf-next 3/9] selftests/bpf: Use only stdout in un/load_bpf_testmod functions

David Vernet
2023-02-07T14:42:52Z

On Fri, Feb 03, 2023 at 05:23:30PM +0100, Jiri Olsa wrote:
> We are about to use un/load_bpf_testmod functions in couple tests
> and it's better to print output to stdout, so it's aligned with
> tests ASSERT macros output, which use stdout as well.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: David Vernet <void@manifault.com>

Should we remove FILE *stderr from struct test_env? Seems like it might
be prudent if using it can actually cause a mismatch between testcase
output and the test runner?

> ---
> tools/testing/selftests/bpf/testing_helpers.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c
> index 3a9e7e8e5b14..fd22c64646fc 100644
> --- a/tools/testing/selftests/bpf/testing_helpers.c
> +++ b/tools/testing/selftests/bpf/testing_helpers.c
> @@ -244,14 +244,14 @@ static int delete_module(const char *name, int flags)
> void unload_bpf_testmod(bool verbose)
> {
> if (kern_sync_rcu())
> - fprintf(stderr, "Failed to trigger kernel-side RCU sync!\n");
> + fprintf(stdout, "Failed to trigger kernel-side RCU sync!\n");
> if (delete_module("bpf_testmod", 0)) {
> if (errno == ENOENT) {
> if (verbose)
> fprintf(stdout, "bpf_testmod.ko is already unloaded.\n");
> return;
> }
> - fprintf(stderr, "Failed to unload bpf_testmod.ko from kernel: %d\n", -errno);
> + fprintf(stdout, "Failed to unload bpf_testmod.ko from kernel: %d\n", -errno);
> return;
> }
> if (verbose)
> @@ -270,11 +270,11 @@ int load_bpf_testmod(bool verbose)
>
> fd = open("bpf_testmod.ko", O_RDONLY);
> if (fd < 0) {
> - fprintf(stderr, "Can't find bpf_testmod.ko kernel module: %d\n", -errno);
> + fprintf(stdout, "Can't find bpf_testmod.ko kernel module: %d\n", -errno);
> return -ENOENT;
> }
> if (finit_module(fd, "", 0)) {
> - fprintf(stderr, "Failed to load bpf_testmod.ko into the kernel: %d\n", -errno);
> + fprintf(stdout, "Failed to load bpf_testmod.ko into the kernel: %d\n", -errno);
> close(fd);
> return -EINVAL;
> }
> --
> 2.39.1
>