-
To run the whole test suite
cargo test --lib
-
To run a specific set of tests, we can tap into cargo's pattern matching feature
cargo test tests::networking_tests::net_tests
This runs all the tests in the networking suite
-
To run one specific test
cargo test tests::fs_tests::fs_tests::ut_lind_fs_simple -- --exact
uses the pattern matching logic again but has to be an exact match.
-
To list all the tests we have in the test suite
cargo test --list
It's useful to add unit tests for helper functions that can be performed on their own.
To run all the unit tests of syscalls, switch to the safeposix-rust
directory and run cargo test --lib
. To skip some tests, you can comment out unwanted tests at safeposix-rust/src/tests/mod.rs
.
If you meet net device couldn't find
error, run the script gen_netdevs.sh
and repeat.
Use the Develop branch for the most up to date behavior, or Main for most stable.
The RustPosix test suite majorly performs three kinds of tests
BUG: There is a issue with how sockets are bound that requires waiting ~1 min between running tests for the kernel to let those addresses be bound to again. Either wait the required time or comment out networking_tests to avoid this error.
-
The
fs_tests.rs
file contains a test suite functiontest_fs()
, which runs a series of tests related to file system operations. Here's a summary of the tests:-
ut_lind_fs_simple
: This test checks some basic file system operations. It's run first because the data files it creates could interfere with other tests. -
ut_lind_fs_broken_close
: This test will be checking the behavior of the system when trying to close a file that isn't open or doesn't exist. -
ut_lind_fs_chmod
andut_lind_fs_fchmod
: These tests are checking the functionality of changing file permissions. -
ut_lind_fs_dir_chdir
andut_lind_fs_dir_chdir_getcwd
: These tests are will checking the ability to change the current working directory and get the current working directory. -
ut_lind_fs_dir_mode
andut_lind_fs_dir_multiple
: These tests will be checking the creation of directories and handling multiple directories. -
ut_lind_fs_dup
andut_lind_fs_dup2
: These tests are checking the duplication of file descriptors. -
ut_lind_fs_fcntl
: This test will be checking the file control operations. -
ut_lind_fs_ioctl
: This test is checking the input/output control operations. -
ut_lind_fs_fdflags
: This test will be checking the operations related to file descriptor flags. -
ut_lind_fs_file_link_unlink
: This test is will checking the linking and unlinking of files. -
ut_lind_fs_file_lseek_past_end
: This test will be checking the behavior when seeking past the end of a file. -
ut_lind_fs_fstat_complex
,ut_lind_fs_stat_file_complex
, andut_lind_fs_stat_file_mode
: These tests are checking the file status operations. -
ut_lind_fs_getuid
: This test is will checking the operation to get the user ID. -
ut_lind_fs_load_fs
: This test will be checking the loading of a file system. -
ut_lind_fs_mknod
: This test is checking the creation of special files or directories. -
ut_lind_fs_multiple_open
: This test will be checking the behavior when opening multiple files. -
ut_lind_fs_rename
: This test is checking the renaming of files. -
ut_lind_fs_rmdir
: This test is will checking the removal of directories. -
ut_lind_fs_statfs
andut_lind_fs_fstatfs
: These tests are checking the operations to get file system statistics. -
ut_lind_fs_ftruncate
andut_lind_fs_truncate
: These tests will be checking the truncation of files. -
ut_lind_fs_getdents
: This test is checking the reading of directory entries. -
rdwrtest
andprdwrtest
: These tests are will checking read
-
-
The
ipc_tests.rs
file contains three test functions:ut_lind_ipc_pipe
,ut_lind_ipc_domain_socket
, andut_lind_ipc_socketpair
. Here's a summary:-
ut_lind_ipc_pipe
: This function tests inter-process communication (IPC) using pipes. It creates a pipe and forks a new process. The parent process writes data to the pipe, and the child process reads from it. The test checks that the data is correctly transferred from the parent to the child process. -
ut_lind_ipc_domain_socket
: This function tests IPC using Unix domain sockets. It creates a server socket and a client socket, binds them to file paths, and then forks a new process. The parent process (client) sends data to the server, and the server reads the data in various ways (peeking, reading a portion, etc.). The test checks that the data is correctly transferred and read in different scenarios. -
ut_lind_ipc_socketpair
: This function tests IPC using a socket pair. It creates a socket pair, forks a new process, and then sends data between the two sockets. The test checks that the data is correctly transferred from one socket to the other.
These tests are designed to verify the correct operation of various IPC mechanisms in the Lind Rust environment. They check that data can be sent and received correctly, that system calls like
fork
,pipe
,bind
,listen
,accept
,send
, andrecv
work as expected, and that the system correctly handles process termination. -
-
The
networking_tests.rs
file contains a single functionnet_tests()
, which will be a test suite that runs a series of tests related to networking operations. Here's a summary:-
ut_lind_net_bind
: This function will test thebind
system call, which assigns a local protocol address to a socket. -
ut_lind_net_bind_multiple
: This function will test the ability to bind multiple sockets to the same address. -
ut_lind_net_bind_on_zero
: This function will test the ability to bind a socket to a system-selected port number (by specifying port number 0). -
ut_lind_net_connect_basic_udp
: This function will test the ability to establish a basic UDP connection. -
ut_lind_net_getpeername
: This function will test thegetpeername
system call, which retrieves the remote address of a socket. -
ut_lind_net_getsockname
: This function will test thegetsockname
system call, which retrieves the local address of a socket. -
ut_lind_net_listen
: This function will test thelisten
system call, which marks a socket as passive and ready to accept incoming connections. -
ut_lind_net_poll
: This function will test thepoll
system call, which waits for one of a set of file descriptors to become ready to perform I/O. -
ut_lind_net_recvfrom
: This function will test therecvfrom
system call, which receives a message from a socket and captures the address from which it was sent. -
ut_lind_net_select
: This function will test theselect
system call, which waits for one of a set of file descriptors to become ready to perform I/O. -
ut_lind_net_shutdown
: This function will test theshutdown
system call, which disables further send and receive operations on a socket. -
ut_lind_net_socket
: This function will test thesocket
system call, which creates an endpoint for communication. -
ut_lind_net_socketoptions
: This function will test the ability to get and set socket options. -
ut_lind_net_socketpair
: This function will test thesocketpair
system call, which creates a pair of connected sockets. -
ut_lind_net_udp_bad_bind
: This function will test error handling for incorrect usage of thebind
system call with UDP sockets. -
ut_lind_net_udp_simple
: This function will test a simple UDP data transfer scenario. -
ut_lind_net_udp_connect
: This function will test the ability to establish a UDP connection using theconnect
system call. -
ut_lind_net_gethostname
: This function will test thegethostname
system call, which retrieves the standard host name for the current machine. -
ut_lind_net_dns_rootserver_ping
: This function will test the ability to send a DNS query to a root server and receive a response. -
ut_lind_net_domain_socket
: This function will test the ability to create and use Unix domain sockets for inter-process communication. -
ut_lind_net_epoll
: This function will test theepoll
system call, which is a variant ofpoll
that can be used to monitor multiple file descriptors to see if I/O is possible on any of them .
To debug, you should first run
cargo test --lib
. After it runs. at the top you of the output, you will see a path starting withtarget/
and whatever else that follows. Copy that path, and then can userr record (paste target path here)
thenrr replay
orgdb (target path)
. -
To run all of the benchmarks, run cargo bench
. If you want to run a specific test, try: cargo bench TXnn
where TXnn is
the test number.
For information about how to write a benchmark, see the Style-Guide.