selftests: Add _GNU_SOURCE definition when including kselftest_harness.h
Subsystems (12)
PATCH 1/1 selftests: Add _GNU_SOURCE definition when including kselftest_harness.h
asprintf() is declared in stdio.h when defining _GNU_SOURCE, but stdio.h is so common that many files don’t define _GNU_SOURCE before including stdio.h, and defining _GNU_SOURCE after including stdio.h will no longer take effect.
Since kselftest_harness.h introduces asprintf(), it is necessary to add _GNU_SOURCE definition in all selftests including kselftest_harness.h, otherwise, there will be warnings or even errors during compilation. There are already many selftests that define _GNU_SOURCE or put the include of kselftest_harness.h at the very beginning of the .c file, just add the _GNU_SOURCE definition in the tests that have compilation warnings.
--- tools/testing/selftests/alsa/test-pcmtest-driver.c | 1 + tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c | 1 + tools/testing/selftests/nci/nci_dev.c | 1 + tools/testing/selftests/net/bind_wildcard.c | 1 + tools/testing/selftests/net/ip_local_port_range.c | 1 + tools/testing/selftests/net/reuseaddr_ports_exhausted.c | 1 + tools/testing/selftests/prctl/set-anon-vma-name-test.c | 1 + tools/testing/selftests/prctl/set-process-name.c | 1 + tools/testing/selftests/rtc/rtctest.c | 1 + tools/testing/selftests/sgx/main.c | 1 + tools/testing/selftests/tdx/tdx_guest_test.c | 1 + tools/testing/selftests/user_events/dyn_test.c | 1 + tools/testing/selftests/user_events/ftrace_test.c | 1 + tools/testing/selftests/user_events/perf_test.c | 1 + 14 files changed, 14 insertions(+)
tools/testing/selftests/alsa/test-pcmtest-driver.c +1 -0
@@ -5,6 +5,7 @@* * Copyright 2023 Ivan Orlov <[email protected]> */ +#define _GNU_SOURCE#include <string.h> #include <alsa/asoundlib.h> #include "../kselftest_harness.h"
tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +1 -0
@@ -4,6 +4,7 @@* * Tests for KVM paravirtual feature disablement */ +#define _GNU_SOURCE#include <asm/kvm_para.h> #include <linux/kvm_para.h> #include <linux/stringify.h>
tools/testing/selftests/nci/nci_dev.c +1 -0
@@ -6,6 +6,7 @@* Test code for nci */ +#define _GNU_SOURCE#include <stdlib.h> #include <errno.h> #include <string.h>
tools/testing/selftests/net/bind_wildcard.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright Amazon.com Inc. or its affiliates. */ +#define _GNU_SOURCE#include <sys/socket.h> #include <netinet/in.h>
tools/testing/selftests/net/ip_local_port_range.c +1 -0
@@ -7,6 +7,7 @@* Don't run these directly but with ip_local_port_range.sh script. */ +#define _GNU_SOURCE#include <fcntl.h> #include <netinet/ip.h>
tools/testing/selftests/net/reuseaddr_ports_exhausted.c +1 -0
@@ -17,6 +17,7 @@* * Author: Kuniyuki Iwashima <[email protected]> */ +#define _GNU_SOURCE#include <arpa/inet.h> #include <netinet/in.h> #include <sys/socket.h>
tools/testing/selftests/prctl/set-anon-vma-name-test.c +1 -0
@@ -3,6 +3,7 @@* This test covers the anonymous VMA naming functionality through prctl calls */ +#define _GNU_SOURCE#include <errno.h> #include <sys/prctl.h> #include <stdio.h>
tools/testing/selftests/prctl/set-process-name.c +1 -0
@@ -3,6 +3,7 @@* This test covers the PR_SET_NAME functionality of prctl calls */ +#define _GNU_SOURCE#include <errno.h> #include <sys/prctl.h> #include <string.h>
tools/testing/selftests/rtc/rtctest.c +1 -0
@@ -5,6 +5,7 @@* Copyright (c) 2018 Alexandre Belloni <[email protected]> */ +#define _GNU_SOURCE#include <errno.h> #include <fcntl.h> #include <linux/rtc.h>
tools/testing/selftests/sgx/main.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2016-20 Intel Corporation. */ +#define _GNU_SOURCE#include <cpuid.h> #include <elf.h> #include <errno.h>
tools/testing/selftests/tdx/tdx_guest_test.c +1 -0
@@ -7,6 +7,7 @@* Author: Kuppuswamy Sathyanarayanan <[email protected]> */ +#define _GNU_SOURCE#include <sys/ioctl.h> #include <errno.h>
tools/testing/selftests/user_events/dyn_test.c +1 -0
@@ -5,6 +5,7 @@* Copyright (c) 2021 Beau Belgrave <[email protected]> */ +#define _GNU_SOURCE#include <errno.h> #include <linux/user_events.h> #include <stdio.h>
tools/testing/selftests/user_events/ftrace_test.c +1 -0
@@ -5,6 +5,7 @@* Copyright (c) 2021 Beau Belgrave <[email protected]> */ +#define _GNU_SOURCE#include <errno.h> #include <linux/user_events.h> #include <stdio.h>
tools/testing/selftests/user_events/perf_test.c +1 -0
@@ -5,6 +5,7 @@* Copyright (c) 2021 Beau Belgrave <[email protected]> */ +#define _GNU_SOURCE#include <errno.h> #include <linux/user_events.h> #include <linux/perf_event.h>
base-commit: dccb07f2914cdab2ac3a5b6c98406f765acab803
Signature · 1 line
2.34.1
Quoted 11 lines · On Tue, 7 May 2024 14:35:34 +0800 Tao Su <[email protected]> wrote:
asprintf()is declared instdio.hwhen defining_GNU_SOURCE, butstdio.his so common that many files don’t define_GNU_SOURCEbefore includingstdio.h, and defining_GNU_SOURCEafter includingstdio.hwill no longer take effect.Since
kselftest_harness.hintroducesasprintf(), it is necessary to add_GNU_SOURCEdefinition in all selftests includingkselftest_harness.h, otherwise, there will be warnings or even errors during compilation. There are already many selftests that define_GNU_SOURCEor put the include ofkselftest_harness.hat the very beginning of the .c file, just add the_GNU_SOURCEdefinition in the tests that have compilation warnings.
That asprintf() continues to cause problems. How about we just remove it? Do the malloc(snprintf(str, 0, ...)) separately?
Quoted 14 lines · Andrew Morton
Quoted 11 lines · On Tue, 7 May 2024 14:35:34 +0800 Tao Su <[email protected]> wrote:
asprintf()is declared instdio.hwhen defining_GNU_SOURCE, butstdio.his so common that many files don’t define_GNU_SOURCEbefore includingstdio.h, and defining_GNU_SOURCEafter includingstdio.hwill no longer take effect.Since
kselftest_harness.hintroducesasprintf(), it is necessary to add_GNU_SOURCEdefinition in all selftests includingkselftest_harness.h, otherwise, there will be warnings or even errors during compilation. There are already many selftests that define_GNU_SOURCEor put the include ofkselftest_harness.hat the very beginning of the .c file, just add the_GNU_SOURCEdefinition in the tests that have compilation warnings.
Quoted 2 lines
That
asprintf()continues to cause problems. How about we just remove it? Do themalloc(snprintf(str, 0, ...))separately?
Removing asprintf() is indeed an good option, but using snprintf(str, 0, ...) to get string size may go against the original intention of commit 38c957f07038.
Back to commit 38c957f07038, I don't see any advantage in using LINE_MAX. Can we use a fixed value instead of LINE_MAX? E.g., 1024, 2048. Then we just need to revert commit 809216233555.
Jakub Kicinski
maintainerQuoted 3 lines · On Wed, 8 May 2024 10:55:05 +0800 Tao Su wrote:
Back to commit
38c957f07038, I don't see any advantage in usingLINE_MAX. Can we use a fixed value instead ofLINE_MAX? E.g., 1024, 2048. Then we just need to revert commit 809216233555.
SGTM, FWIW. The print is printing a test summary line, printing more than 1k seems rather unreasonable. Other facilities, like TH_LOG(), should be used for displaying longer info.
Quoted 9 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 8 May 2024 10:55:05 +0800 Tao Su wrote:
Back to commit
38c957f07038, I don't see any advantage in usingLINE_MAX. Can we use a fixed value instead ofLINE_MAX? E.g., 1024, 2048. Then we just need to revert commit 809216233555.SGTM, FWIW. The print is printing a test summary line, printing more than 1k seems rather unreasonable. Other facilities, like
TH_LOG(), should be used for displaying longer info.
I also submitted some patches to fix the _GNU_SOURCE issues here:
https://lore.kernel.org/linux-kselftest/[email protected]/
I'm fine with this approach. It's aligned to what Sean suggested there, since it's causing a lot of troubles for the release cycle.
Quoted 11 lines · Edward Liaw
Quoted 9 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 8 May 2024 10:55:05 +0800 Tao Su wrote:
Back to commit
38c957f07038, I don't see any advantage in usingLINE_MAX. Can we use a fixed value instead ofLINE_MAX? E.g., 1024, 2048. Then we just need to revert commit 809216233555.SGTM, FWIW. The print is printing a test summary line, printing more than 1k seems rather unreasonable. Other facilities, like
TH_LOG(), should be used for displaying longer info.
Quoted 5 lines
I also submitted some patches to fix the
_GNU_SOURCEissues here:
https://lore.kernel.org/linux-kselftest/[email protected]/I'm fine with this approach. It's aligned to what Sean suggested there, since it's causing a lot of troubles for the release cycle.
Thanks, I will submit patches with this approach soon.
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 8 May 2024 10:55:05 +0800 Tao Su wrote:
Back to commit
38c957f07038, I don't see any advantage in usingLINE_MAX. Can we use a fixed value instead ofLINE_MAX? E.g., 1024, 2048. Then we just need to revert commit 809216233555.SGTM, FWIW. The print is printing a test summary line, printing more than 1k seems rather unreasonable. Other facilities, like
TH_LOG(), should be used for displaying longer info.
Thanks, do you think 1k is enough for test_name?
Quoted 1 line
Jakub Kicinski
maintainerQuoted 5 lines · On Thu, 9 May 2024 13:08:36 +0800 Tao Su wrote:
Quoted 3 lines
SGTM, FWIW. The print is printing a test summary line, printing more than 1k seems rather unreasonable. Other facilities, like
TH_LOG(), should be used for displaying longer info.Thanks, do you think 1k is enough for
test_name?
Definitely.