[PATCH v3 3/3] Add tests for the -l/--syscall-limit option

Sahil Siddiq icegambit91 at gmail.com
Wed Mar 1 21:38:44 UTC 2023


This test checks the correctness of the -l/--syscall-limit
option when used with the --trace,--trace-path and --status
options.

* test/strace--syscall-limit.c: New file
* test/strace--syscall-limit-path.c: New file
* test/strace--syscall-limit-status.c: New file
* test/gen_tests.in: Add rules to generate test
* test/Makefile.am (check_PROGRAMS): Add strace--syscall-limit variants
* test/.gitignore: Add strace--syscall-limit variants
* m4/st_warn_cflags.m4: Add Wno-error for old-style-definition

Signed-off-by: Sahil Siddiq <icegambit91 at gmail.com>
---
 m4/st_warn_cflags.m4                 |   1 +
 tests/.gitignore                     |   3 +
 tests/Makefile.am                    |   3 +
 tests/gen_tests.in                   |   3 +
 tests/strace--syscall-limit-path.c   |   2 +
 tests/strace--syscall-limit-status.c |   2 +
 tests/strace--syscall-limit.c        | 153 +++++++++++++++++++++++++++
 7 files changed, 167 insertions(+)
 create mode 100644 tests/strace--syscall-limit-path.c
 create mode 100644 tests/strace--syscall-limit-status.c
 create mode 100644 tests/strace--syscall-limit.c

diff --git a/m4/st_warn_cflags.m4 b/m4/st_warn_cflags.m4
index e226cadb8..dfc59e499 100644
--- a/m4/st_warn_cflags.m4
+++ b/m4/st_warn_cflags.m4
@@ -60,6 +60,7 @@ AC_ARG_ENABLE([gcc-Werror],
 	      [enable_gcc_Werror="$st_cv_enable_Werror"])
 if test "$enable_gcc_Werror" = yes; then
   gl_WARN_ADD([-Werror])
+  gl_WARN_ADD([-Wno-error=old-style-definition])
 fi
 AC_SUBST([WARN_CFLAGS])
 ])
diff --git a/tests/.gitignore b/tests/.gitignore
index 5935c39d9..f5c8e4496 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1020,6 +1020,9 @@ strace--strings-in-hex-all
 strace--strings-in-hex-non-ascii
 strace--strings-in-hex-non-ascii-chars
 strace--strings-in-hex-none
+strace--syscall-limit
+strace--syscall-limit-path
+strace--syscall-limit-status
 strace-Y-0123456789
 strace-n
 strace-no-x
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 00d70fa46..1a6449aaa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -379,6 +379,9 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
 	status-successful-threads \
 	status-unfinished-threads \
 	strace--decode-pids-comm \
+	strace--syscall-limit \
+	strace--syscall-limit-path \
+	strace--syscall-limit-status \
 	strace-Y-0123456789 \
 	strace-p-Y-p2 \
 	strace-p1-Y-p \
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index eceac8d60..321071e40 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -1006,6 +1006,9 @@ strace--strings-in-hex-all		--trace=chdir --strings-in-hex=all --columns=18
 strace--strings-in-hex-non-ascii	--trace=chdir --strings-in-hex=non-ascii --columns=12
 strace--strings-in-hex-non-ascii-chars	--trace=chdir --strings-in-hex=non-ascii-chars --columns=12
 strace--strings-in-hex-none		--trace=chdir --strings-in-hex=none --columns=12
+strace--syscall-limit	--syscall-limit=3 --trace=chdir,getpid --signal='!SIGCHLD,SIGCONT' --quiet=attach,exit -f -a 9
+strace--syscall-limit-path	--syscall-limit=2 --trace=all --trace-path=. --signal='!SIGCHLD,SIGCONT' --quiet=attach,exit,path-resolution -f -a 9
+strace--syscall-limit-status	--syscall-limit=2 --trace=chdir,openat --status=failed --signal='!SIGCHLD,SIGCONT' --quiet=attach,exit -f -a 9
 strace--syscall-times +strace-T_upper.test --syscall-times
 strace--syscall-times-ms +strace-T_upper.test --syscall-times=ms
 strace--syscall-times-ns +strace-T_upper.test --syscall-times=ns
diff --git a/tests/strace--syscall-limit-path.c b/tests/strace--syscall-limit-path.c
new file mode 100644
index 000000000..3501124bf
--- /dev/null
+++ b/tests/strace--syscall-limit-path.c
@@ -0,0 +1,2 @@
+#define TRACE 2
+#include "strace--syscall-limit.c"
\ No newline at end of file
diff --git a/tests/strace--syscall-limit-status.c b/tests/strace--syscall-limit-status.c
new file mode 100644
index 000000000..aff6c255f
--- /dev/null
+++ b/tests/strace--syscall-limit-status.c
@@ -0,0 +1,2 @@
+#define TRACE 3
+#include "strace--syscall-limit.c"
\ No newline at end of file
diff --git a/tests/strace--syscall-limit.c b/tests/strace--syscall-limit.c
new file mode 100644
index 000000000..592b9ab90
--- /dev/null
+++ b/tests/strace--syscall-limit.c
@@ -0,0 +1,153 @@
+/*
+ * Helper functions for testing -l/--syscall-limit
+ *
+ * Copyright (c) 2023 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#ifndef TRACE
+#define TRACE 1
+#endif
+
+#if TRACE == 1
+static int
+syscall_limit__trace(void)
+{
+	int pid = getpid();
+	int ret = chdir(".");
+
+	printf("%-5u getpid() = %d\n", pid, pid);
+	printf("%-5u chdir(\".\") = %d\n", pid, ret);
+	fflush(stdout);
+
+	pid_t child = fork();
+	if (child < 0)
+		perror_msg_and_fail("fork");
+	else if (child == 0) {
+		int pid = getpid();
+		chdir(".");
+
+		printf("%-5u getpid() = %d\n", pid, pid);
+		puts(" <detached ...>");
+		fflush(stdout);
+
+		return 0;
+	}
+	int status;
+	while ((waitpid(child, &status, 0)) != child) {
+		if (errno == EINTR)
+			continue;
+		perror_msg_and_fail("waitpid: %d", child);
+	}
+
+	chdir(".");
+	puts(" <detached ...>");
+
+	return WEXITSTATUS(status);
+}
+#endif
+
+#if TRACE == 2
+static int
+syscall_limit__trace_path(void)
+{
+	int pid = getpid();
+	int ret = chdir(".");
+
+	printf("%-5u chdir(\".\") = %d\n", pid, ret);
+	fflush(stdout);
+
+	pid_t child = fork();
+	if (child < 0)
+		perror_msg_and_fail("fork");
+	else if (child == 0) {
+		int pid = getpid();
+		int ret = chdir(".");
+
+		printf("%-5u chdir(\".\") = %d\n", pid, ret);
+		printf(" <detached ...>\n");
+		fflush(stdout);
+
+		return 0;
+	}
+	int status;
+	while ((waitpid(child, &status, 0)) != child) {
+		if (errno == EINTR)
+			continue;
+		perror_msg_and_fail("waitpid: %d", child);
+	}
+
+	chdir(".");
+	puts(" <detached ...>");
+
+	return WEXITSTATUS(status);
+}
+#endif
+
+#if TRACE == 3
+static int
+syscall_limit__status(void)
+{
+	int pid = getpid();
+	long ret = chdir("invalid.dir");
+
+	if (ret == -1) {
+		printf("%-5u chdir(\"invalid.dir\") = %s\n", pid, sprintrc(ret));
+		fflush(stdout);
+	}
+
+	pid_t child = fork();
+	if (child < 0)
+		perror_msg_and_fail("fork");
+	else if (child == 0) {
+		int pid = getpid();
+		FILE *f = fopen("dummy.file", "r");
+
+		if (f == NULL)
+			printf("%-5u openat(AT_FDCWD, \"dummy.file\", O_RDONLY) = %s\n", pid, sprintrc(-1));
+		puts(" <detached ...>");
+		fflush(stdout);
+
+		return 0;
+	}
+	int status;
+	while ((waitpid(child, &status, 0)) != child) {
+		if (errno == EINTR)
+			continue;
+		perror_msg_and_fail("waitpid: %d", child);
+	}
+
+	ret = chdir("invalid.dir");
+	puts(" <detached ...>");
+
+	return WEXITSTATUS(status);
+}
+#endif
+
+int
+main()
+{
+	int ret;
+
+	#if TRACE == 1
+		ret = syscall_limit__trace();
+	#elif TRACE == 2
+		ret = syscall_limit__trace_path();
+	#elif TRACE == 3
+		ret = syscall_limit__status();
+	#endif
+
+	return ret;
+}
-- 
2.39.2



More information about the Strace-devel mailing list