Skip to contentSkip to conversation

drop duplicate max/min definitions

PATCH In review Geliang Tang 3 participants 5 messages Apr 8, 2022 – Apr 11, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover drop duplicate max/min definitions

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

v3:
- move '#include <sys/param.h>' into test_progs.h.

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    | 4 +---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c  | 6 ++----
 tools/testing/selftests/bpf/prog_tests/snprintf.c    | 4 +---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 1 -
 tools/testing/selftests/bpf/test_progs.h             | 1 +
 tools/testing/selftests/mqueue/mq_perf_tests.c       | 4 ++--
 6 files changed, 7 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/2 selftests: bpf: drop duplicate max/min definitions

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

---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c    | 4 +---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c  | 6 ++----
 tools/testing/selftests/bpf/prog_tests/snprintf.c    | 4 +---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 1 -
 tools/testing/selftests/bpf/test_progs.h             | 1 +
 5 files changed, 5 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +1 -3
index 5142a7d130b2..2c403ddc8076 100644
@@ -1192,8 +1192,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 +1227,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"))
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -4
index 8f7a1cef7d87..e9a9a31b2ffe 100644
@@ -10,8 +10,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 +51,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 +144,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)
tools/testing/selftests/bpf/prog_tests/snprintf.c +1 -3
index 394ebfc3bbf3..4be6fdb78c6a 100644
@@ -83,8 +83,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 +93,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);
tools/testing/selftests/bpf/prog_tests/tc_redirect.c +0 -1
index 7ad66a247c02..958dae769c52 100644
@@ -949,7 +949,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,
tools/testing/selftests/bpf/test_progs.h +1 -0
index eec4c7385b14..e6ae2e52a668 100644
@@ -25,6 +25,7 @@ typedef __u16 __sum16;
 #include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/param.h>
 #include <fcntl.h>
 #include <pthread.h>
 #include <linux/bpf.h>
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 2/2 selftests: mqueue: drop duplicate min definition

In reply to Geliang Tang

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

---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mqueue/mq_perf_tests.c +2 -2
index b019e0b8221c..6df1b2a7ec88 100644
@@ -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()");
Signature · 1 line
2.34.1
#4 lore raw
In reply to Geliang Tang
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 9 lines · On Sat, 9 Apr 2022 07:58:16 +0800 you wrote:

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

v3:
- move '#include <sys/param.h>' into test_progs.h.

v2:
- do more cleanups as Daniel suggested.

[...]

Here is the summary with links:
- [v3,1/2] selftests: bpf: drop duplicate max/min definitions

    https://git.kernel.org/bpf/bpf-next/c/f4fd706f7383

- [v3,2/2] selftests: mqueue: drop duplicate min definition (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html