From 4e51e13bd986cab31dfab5c3bff1678171debbd1 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Thu, 25 Jul 2024 16:08:03 +0500 Subject: selftests: user: remove user suite The user test suite has only one test, test_user_copy which loads test_user_copy module for testing. But test_user_copy module has already been converted to kunit (see fixes). Hence remove the entire suite. Fixes: cf6219ee889f ("usercopy: Convert test_user_copy to KUnit test") Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/testing/selftests/Makefile') diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index bc8fe9e8f7f2..af2429431b6b 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -107,7 +107,6 @@ TARGETS += tmpfs TARGETS += tpm2 TARGETS += tty TARGETS += uevent -TARGETS += user TARGETS += user_events TARGETS += vDSO TARGETS += mm -- cgit v1.2.3 From f0a1ffa6f9771c6a1283afab591781e7c797e2e1 Mon Sep 17 00:00:00 2001 From: Abdulrasaq Lawani Date: Thu, 1 Aug 2024 05:29:52 -0400 Subject: selftest: acct: Add selftest for the acct() syscall The acct() system call enables or disables process accounting. If accounting is turned on, records for each terminating process are appended to a specified filename as it terminates. An argument of NULL causes accounting to be turned off. This patch will add a test for the acct() syscall. Signed-off-by: Abdulrasaq Lawani Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/acct/.gitignore | 3 ++ tools/testing/selftests/acct/Makefile | 5 ++ tools/testing/selftests/acct/acct_syscall.c | 78 +++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 tools/testing/selftests/acct/.gitignore create mode 100644 tools/testing/selftests/acct/Makefile create mode 100644 tools/testing/selftests/acct/acct_syscall.c (limited to 'tools/testing/selftests/Makefile') diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index af2429431b6b..f51fcceb45fd 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +TARGETS += acct TARGETS += alsa TARGETS += amd-pstate TARGETS += arm64 diff --git a/tools/testing/selftests/acct/.gitignore b/tools/testing/selftests/acct/.gitignore new file mode 100644 index 000000000000..7e78aac19038 --- /dev/null +++ b/tools/testing/selftests/acct/.gitignore @@ -0,0 +1,3 @@ +acct_syscall +config +process_log \ No newline at end of file diff --git a/tools/testing/selftests/acct/Makefile b/tools/testing/selftests/acct/Makefile new file mode 100644 index 000000000000..7e025099cf65 --- /dev/null +++ b/tools/testing/selftests/acct/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_GEN_PROGS := acct_syscall +CFLAGS += -Wall + +include ../lib.mk \ No newline at end of file diff --git a/tools/testing/selftests/acct/acct_syscall.c b/tools/testing/selftests/acct/acct_syscall.c new file mode 100644 index 000000000000..e44e8fe1f4a3 --- /dev/null +++ b/tools/testing/selftests/acct/acct_syscall.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* kselftest for acct() system call + * The acct() system call enables or disables process accounting. + */ + +#include +#include +#include +#include + +#include "../kselftest.h" + +int main(void) +{ + char filename[] = "process_log"; + FILE *fp; + pid_t child_pid; + int sz; + + // Setting up kselftest framework + ksft_print_header(); + ksft_set_plan(1); + + // Check if test is run a root + if (geteuid()) { + ksft_test_result_skip("This test needs root to run!\n"); + return 1; + } + + // Create file to log closed processes + fp = fopen(filename, "w"); + + if (!fp) { + ksft_test_result_error("%s.\n", strerror(errno)); + ksft_finished(); + return 1; + } + + acct(filename); + + // Handle error conditions + if (errno) { + ksft_test_result_error("%s.\n", strerror(errno)); + fclose(fp); + ksft_finished(); + return 1; + } + + // Create child process and wait for it to terminate. + + child_pid = fork(); + + if (child_pid < 0) { + ksft_test_result_error("Creating a child process to log failed\n"); + acct(NULL); + return 1; + } else if (child_pid > 0) { + wait(NULL); + fseek(fp, 0L, SEEK_END); + sz = ftell(fp); + + acct(NULL); + + if (sz <= 0) { + ksft_test_result_fail("Terminated child process not logged\n"); + ksft_exit_fail(); + return 1; + } + + ksft_test_result_pass("Successfully logged terminated process.\n"); + fclose(fp); + ksft_exit_pass(); + return 0; + } + + return 1; +} -- cgit v1.2.3