Add Selftest to test fork() syscall
PATCH 1/1 Add Selftest to test fork() syscall
This test verifies the correct behavior of the fork() system call, which creates a child process by duplicating the parent process.
The test checks the following:
- The child PID returned by fork() is present in /proc.
- The child PID is different from the parent PID.
- The memory allocated to a variable in the child process is independent of the parent process.
Test logs :
- Run without root
TAP version 13
1..1
ok 1 # SKIP This test needs root to run!
- Run with root
TAP version 13
1..1
# Inside the parent process.
# Child PID got from fork() return : 56038
# Parent PID from getpid(): 56037
# Inside the child process.
1..2
ok 1 Child Pid from /proc and fork() matching
ok 2 Child Pid != Parent pid
1..3
ok 3 After modification in child No effect on the value of 'var' in parent # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
---
Here is my proposal for a new directory, /syscalls, to add syscall selftests, as there is currently no dedicated space for these tests. I encountered this issue while writing the test case for the delete_module syscall and was unsure where to place it. As a heads-up, the delete_module test is currently under review, and I would like to add it to this directory.
tools/testing/selftests/Makefile | 1 + tools/testing/selftests/syscalls/.gitignore | 1 + .../syscalls/fork_syscall/.gitignore | 1 + .../selftests/syscalls/fork_syscall/Makefile | 5 + .../syscalls/fork_syscall/fork_syscall.c | 151 ++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 tools/testing/selftests/syscalls/.gitignore create mode 100644 tools/testing/selftests/syscalls/fork_syscall/.gitignore create mode 100644 tools/testing/selftests/syscalls/fork_syscall/Makefile create mode 100644 tools/testing/selftests/syscalls/fork_syscall/fork_syscall.c
tools/testing/selftests/Makefile +1 -0
@@ -97,6 +97,7 @@ TARGETS += sparc64 TARGETS += splice TARGETS += static_keys TARGETS += sync +TARGETS += syscalls/fork_syscall TARGETS += syscall_user_dispatch TARGETS += sysctl TARGETS += tc-testing
tools/testing/selftests/syscalls/.gitignore new file +1 -0
@@ -0,0 +1 @@ +// SPDX-License-Identifier: GPL-2.0
tools/testing/selftests/syscalls/fork_syscall/.gitignore new file +1 -0
@@ -0,0 +1 @@ +# SPDX-License-Identifier: GPL-2.0-only
tools/testing/selftests/syscalls/fork_syscall/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_GEN_PROGS := fork_syscall +CFLAGS += -Wall + +include ../lib.mk
tools/testing/selftests/syscalls/fork_syscall/fork_syscall.c new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.34.1
Shuah Khan
maintainerQuoted 8 lines · Shivam Chaudhary
This test verifies the correct behavior of the
fork()system call, which creates a child process by duplicating the parent process.The test checks the following:
- The child PID returned byfork()is present in /proc.
- The child PID is different from the parent PID.
- The memory allocated to a variable in the child process is independent of the parent process.
Short log should incude the subsystem:
e.g: selftests: add test for fork() syscall
In anycase, I don't see any value to adding this test. fork() is a heavily used system call.
thanks,
-- Shuah
Quoted 10 lines · Shuah Khan
Quoted 8 lines · Shivam Chaudhary
This test verifies the correct behavior of the
fork()system call, which creates a child process by duplicating the parent process.The test checks the following:
- The child PID returned byfork()is present in /proc.
- The child PID is different from the parent PID.
- The memory allocated to a variable in the child process is independent of the parent process.
Quoted 7 lines
Short log should incude the subsystem:
e.g: selftests: add test for
fork()syscallIn anycase, I don't see any value to adding this test.
fork()is a heavily used system call.
Thanks for responding Shuah,
Yes, you are correct that fork() is a heavily used syscall, that is why my concern is that
it could fail millions of other program that depends on fork() if any error or regression
occurs in the future. In my opinion, that is why we should test it every way possible.
thanks
Shivam
Shuah Khan
maintainerQuoted 20 lines · Shivam Chaudhary
Quoted 10 lines · Shuah Khan
Quoted 8 lines · Shivam Chaudhary
This test verifies the correct behavior of the
fork()system call, which creates a child process by duplicating the parent process.The test checks the following:
- The child PID returned byfork()is present in /proc.
- The child PID is different from the parent PID.
- The memory allocated to a variable in the child process is independent of the parent process.Quoted 7 lines
Short log should incude the subsystem:
e.g: selftests: add test for
fork()syscallIn anycase, I don't see any value to adding this test.
fork()is a heavily used system call.
Quoted 9 lines
Thanks for responding Shuah,
Yes, you are correct that
fork()is a heavily used syscall, that is why my concern is thatit could fail millions of other program that depends on
fork()if any error or regressionoccurs in the future. In my opinion, that is why we should test it every way possible.
Sorry. I don't see any value in adding this test.
thanks,
-- Shuah