All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] drop duplicate max/min definitions
@ 2022-04-08 13:36 Geliang Tang
  2022-04-08 13:36 ` [PATCH v2 1/2] selftests: bpf: " Geliang Tang
  2022-04-08 13:36 ` [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition Geliang Tang
  0 siblings, 2 replies; 7+ messages in thread
From: Geliang Tang @ 2022-04-08 13:36 UTC (permalink / raw)
  To: Shuah Khan, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh
  Cc: Geliang Tang, bpf, linux-kselftest

Two small cleanups for selftests, drop duplicate max/min definitions.

v2:
 - do more cleanups as Daniel suggested.

v1:
 - "selftests: bpf: use MIN for TCP CC tests"

Geliang Tang (2):
  selftests: bpf: drop duplicate max/min definitions
  selftests: mqueue: drop duplicate min definition

 tools/testing/selftests/bpf/prog_tests/bpf_iter.c    | 5 ++---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c  | 7 +++----
 tools/testing/selftests/bpf/prog_tests/snprintf.c    | 5 ++---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 2 +-
 tools/testing/selftests/mqueue/mq_perf_tests.c       | 4 ++--
 5 files changed, 10 insertions(+), 13 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] selftests: bpf: drop duplicate max/min definitions
  2022-04-08 13:36 [PATCH v2 0/2] drop duplicate max/min definitions Geliang Tang
@ 2022-04-08 13:36 ` Geliang Tang
  2022-04-08 19:15   ` Shuah Khan
  2022-04-08 20:31   ` Daniel Borkmann
  2022-04-08 13:36 ` [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition Geliang Tang
  1 sibling, 2 replies; 7+ messages in thread
From: Geliang Tang @ 2022-04-08 13:36 UTC (permalink / raw)
  To: Shuah Khan, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh
  Cc: Geliang Tang, bpf, linux-kselftest

Drop duplicate macros min() and MAX() definitions in prog_tests, use MIN()
or MAX() in sys/param.h instead.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c    | 5 ++---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c  | 7 +++----
 tools/testing/selftests/bpf/prog_tests/snprintf.c    | 5 ++---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 2 +-
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
index 5142a7d130b2..86561c0b0dea 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2020 Facebook */
+#include <sys/param.h>
 #include <test_progs.h>
 #include "bpf_iter_ipv6_route.skel.h"
 #include "bpf_iter_netlink.skel.h"
@@ -1192,8 +1193,6 @@ static void str_strip_first_line(char *str)
 	*dst = '\0';
 }
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
 static void test_task_vma(void)
 {
 	int err, iter_fd = -1, proc_maps_fd = -1;
@@ -1229,7 +1228,7 @@ static void test_task_vma(void)
 	len = 0;
 	while (len < CMP_BUFFER_SIZE) {
 		err = read_fd_into_buffer(iter_fd, task_vma_output + len,
-					  min(read_size, CMP_BUFFER_SIZE - len));
+					  MIN(read_size, CMP_BUFFER_SIZE - len));
 		if (!err)
 			break;
 		if (CHECK(err < 0, "read_iter_fd", "read_iter_fd failed\n"))
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index 8f7a1cef7d87..ceed369361fc 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -3,6 +3,7 @@
 
 #include <linux/err.h>
 #include <netinet/tcp.h>
+#include <sys/param.h>
 #include <test_progs.h>
 #include "network_helpers.h"
 #include "bpf_dctcp.skel.h"
@@ -10,8 +11,6 @@
 #include "bpf_tcp_nogpl.skel.h"
 #include "bpf_dctcp_release.skel.h"
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
 #ifndef ENOTSUPP
 #define ENOTSUPP 524
 #endif
@@ -53,7 +52,7 @@ static void *server(void *arg)
 
 	while (bytes < total_bytes && !READ_ONCE(stop)) {
 		nr_sent = send(fd, &batch,
-			       min(total_bytes - bytes, sizeof(batch)), 0);
+			       MIN(total_bytes - bytes, sizeof(batch)), 0);
 		if (nr_sent == -1 && errno == EINTR)
 			continue;
 		if (nr_sent == -1) {
@@ -146,7 +145,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 	/* recv total_bytes */
 	while (bytes < total_bytes && !READ_ONCE(stop)) {
 		nr_recv = recv(fd, &batch,
-			       min(total_bytes - bytes, sizeof(batch)), 0);
+			       MIN(total_bytes - bytes, sizeof(batch)), 0);
 		if (nr_recv == -1 && errno == EINTR)
 			continue;
 		if (nr_recv == -1)
diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf.c b/tools/testing/selftests/bpf/prog_tests/snprintf.c
index 394ebfc3bbf3..5ca70aa15c4a 100644
--- a/tools/testing/selftests/bpf/prog_tests/snprintf.c
+++ b/tools/testing/selftests/bpf/prog_tests/snprintf.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2021 Google LLC. */
 
+#include <sys/param.h>
 #include <test_progs.h>
 #include "test_snprintf.skel.h"
 #include "test_snprintf_single.skel.h"
@@ -83,8 +84,6 @@ static void test_snprintf_positive(void)
 	test_snprintf__destroy(skel);
 }
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
 /* Loads an eBPF object calling bpf_snprintf with up to 10 characters of fmt */
 static int load_single_snprintf(char *fmt)
 {
@@ -95,7 +94,7 @@ static int load_single_snprintf(char *fmt)
 	if (!skel)
 		return -EINVAL;
 
-	memcpy(skel->rodata->fmt, fmt, min(strlen(fmt) + 1, 10));
+	memcpy(skel->rodata->fmt, fmt, MIN(strlen(fmt) + 1, 10));
 
 	ret = test_snprintf_single__load(skel);
 	test_snprintf_single__destroy(skel);
diff --git a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
index 7ad66a247c02..52f1b9139145 100644
--- a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
+++ b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
@@ -20,6 +20,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <unistd.h>
 
 #include "test_progs.h"
@@ -949,7 +950,6 @@ static int tun_open(char *name)
 	return -1;
 }
 
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
 enum {
 	SRC_TO_TARGET = 0,
 	TARGET_TO_SRC = 1,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition
  2022-04-08 13:36 [PATCH v2 0/2] drop duplicate max/min definitions Geliang Tang
  2022-04-08 13:36 ` [PATCH v2 1/2] selftests: bpf: " Geliang Tang
@ 2022-04-08 13:36 ` Geliang Tang
  2022-04-08 19:23   ` Shuah Khan
  1 sibling, 1 reply; 7+ messages in thread
From: Geliang Tang @ 2022-04-08 13:36 UTC (permalink / raw)
  To: Shuah Khan, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh
  Cc: Geliang Tang, bpf, linux-kselftest

Drop duplicate macro min() definition in mq_perf_tests.c, use MIN() in
sys/param.h instead.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
index b019e0b8221c..6df1b2a7ec88 100644
--- a/tools/testing/selftests/mqueue/mq_perf_tests.c
+++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
@@ -35,6 +35,7 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <mqueue.h>
 #include <popt.h>
 #include <error.h>
@@ -73,7 +74,6 @@ static char *usage =
 char *MAX_MSGS = "/proc/sys/fs/mqueue/msg_max";
 char *MAX_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_max";
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
 #define MAX_CPUS 64
 char *cpu_option_string;
 int cpus_to_pin[MAX_CPUS];
@@ -551,7 +551,7 @@ int main(int argc, char *argv[])
 		perror("sysconf(_SC_NPROCESSORS_ONLN)");
 		exit(1);
 	}
-	cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
+	cpus_online = MIN(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
 	cpu_set = CPU_ALLOC(cpus_online);
 	if (cpu_set == NULL) {
 		perror("CPU_ALLOC()");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] selftests: bpf: drop duplicate max/min definitions
  2022-04-08 13:36 ` [PATCH v2 1/2] selftests: bpf: " Geliang Tang
@ 2022-04-08 19:15   ` Shuah Khan
  2022-04-08 20:31   ` Daniel Borkmann
  1 sibling, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2022-04-08 19:15 UTC (permalink / raw)
  To: Geliang Tang, Shuah Khan, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh
  Cc: bpf, linux-kselftest, Shuah Khan

On 4/8/22 7:36 AM, Geliang Tang wrote:
> Drop duplicate macros min() and MAX() definitions in prog_tests, use MIN()
> or MAX() in sys/param.h instead.
> 
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
>   tools/testing/selftests/bpf/prog_tests/bpf_iter.c    | 5 ++---
>   tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c  | 7 +++----
>   tools/testing/selftests/bpf/prog_tests/snprintf.c    | 5 ++---
>   tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 2 +-
>   4 files changed, 8 insertions(+), 11 deletions(-)
> 

Looks good to me. Thanks for cleaning these up.

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition
  2022-04-08 13:36 ` [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition Geliang Tang
@ 2022-04-08 19:23   ` Shuah Khan
  2022-04-13 10:51     ` Geliang Tang
  0 siblings, 1 reply; 7+ messages in thread
From: Shuah Khan @ 2022-04-08 19:23 UTC (permalink / raw)
  To: Geliang Tang, Shuah Khan, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh
  Cc: bpf, linux-kselftest, Shuah Khan

On 4/8/22 7:36 AM, Geliang Tang wrote:
> Drop duplicate macro min() definition in mq_perf_tests.c, use MIN() in
> sys/param.h instead.
> 
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---

Thank you. I will apply this for next.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] selftests: bpf: drop duplicate max/min definitions
  2022-04-08 13:36 ` [PATCH v2 1/2] selftests: bpf: " Geliang Tang
  2022-04-08 19:15   ` Shuah Khan
@ 2022-04-08 20:31   ` Daniel Borkmann
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Borkmann @ 2022-04-08 20:31 UTC (permalink / raw)
  To: Geliang Tang, Shuah Khan, Alexei Starovoitov, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh
  Cc: bpf, linux-kselftest

On 4/8/22 3:36 PM, Geliang Tang wrote:
> Drop duplicate macros min() and MAX() definitions in prog_tests, use MIN()
> or MAX() in sys/param.h instead.
> 
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
[...]

Thanks Geliang! One small final nit and then it's good to go to bpf-next:

> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> index 5142a7d130b2..86561c0b0dea 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> @@ -1,5 +1,6 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /* Copyright (c) 2020 Facebook */
> +#include <sys/param.h>
>   #include <test_progs.h>
>   #include "bpf_iter_ipv6_route.skel.h"
>   #include "bpf_iter_netlink.skel.h"
[...]

> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> index 8f7a1cef7d87..ceed369361fc 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> @@ -3,6 +3,7 @@
>   
>   #include <linux/err.h>
>   #include <netinet/tcp.h>
> +#include <sys/param.h>
>   #include <test_progs.h>
>   #include "network_helpers.h"
>   #include "bpf_dctcp.skel.h"
[...]

> diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf.c b/tools/testing/selftests/bpf/prog_tests/snprintf.c
> index 394ebfc3bbf3..5ca70aa15c4a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/snprintf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/snprintf.c
> @@ -1,6 +1,7 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /* Copyright (c) 2021 Google LLC. */
>   
> +#include <sys/param.h>
>   #include <test_progs.h>
>   #include "test_snprintf.skel.h"
>   #include "test_snprintf_single.skel.h"
> @@ -83,8 +84,6 @@ static void test_snprintf_positive(void)
[...]

> diff --git a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
> index 7ad66a247c02..52f1b9139145 100644
> --- a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
> @@ -20,6 +20,7 @@
>   #include <stdbool.h>
>   #include <stdio.h>
>   #include <sys/stat.h>
> +#include <sys/param.h>
>   #include <unistd.h>
>   
>   #include "test_progs.h"

Just add the sys/param.h to the test_progs.h header in BPF selftests where we also pull
in other sys headers; then all the duplicate includes above are not needed.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition
  2022-04-08 19:23   ` Shuah Khan
@ 2022-04-13 10:51     ` Geliang Tang
  0 siblings, 0 replies; 7+ messages in thread
From: Geliang Tang @ 2022-04-13 10:51 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, bpf, linux-kselftest

On Fri, Apr 08, 2022 at 01:23:52PM -0600, Shuah Khan wrote:
> On 4/8/22 7:36 AM, Geliang Tang wrote:
> > Drop duplicate macro min() definition in mq_perf_tests.c, use MIN() in
> > sys/param.h instead.
> > 
> > Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> > ---
> 
> Thank you. I will apply this for next.

Thanks very much.

I had sent a v3 of this patch, but it's the same as this one. So apply any
one is OK.

Thanks,
-Geliang

> 
> thanks,
> -- Shuah
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-13 10:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08 13:36 [PATCH v2 0/2] drop duplicate max/min definitions Geliang Tang
2022-04-08 13:36 ` [PATCH v2 1/2] selftests: bpf: " Geliang Tang
2022-04-08 19:15   ` Shuah Khan
2022-04-08 20:31   ` Daniel Borkmann
2022-04-08 13:36 ` [PATCH v2 2/2] selftests: mqueue: drop duplicate min definition Geliang Tang
2022-04-08 19:23   ` Shuah Khan
2022-04-13 10:51     ` Geliang Tang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.