-
Notifications
You must be signed in to change notification settings - Fork 10
Testing and Debugging
To run all the unit tests of syscalls, simply witch 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.
To debug, you firstly run the cargo test. After it runs. at the top you of the output, you will see a path starting with target/ and whatever else that follows. You copy that path, and then do rr record (paste target path here). Then do rr replay, and set a breakpoint at one of these tests.
If meet net device couldn't find error, run the script gen_netdevs.sh then do the test again.
The RustPosix test suite majorly performs three kinds of tests
-
The
fs_tests.rsfile 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_chmodandut_lind_fs_fchmod: These tests are checking the functionality of changing file permissions. -
ut_lind_fs_dir_chdirandut_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_modeandut_lind_fs_dir_multiple: These tests will be checking the creation of directories and handling multiple directories. -
ut_lind_fs_dupandut_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_statfsandut_lind_fs_fstatfs: These tests are checking the operations to get file system statistics. -
ut_lind_fs_ftruncateandut_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. -
rdwrtestandprdwrtest: These tests are will checking read
-
-
The
ipc_tests.rsfile 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, andrecvwork as expected, and that the system correctly handles process termination. -
-
The
networking_tests.rsfile 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 thebindsystem 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 thegetpeernamesystem call, which retrieves the remote address of a socket. -
ut_lind_net_getsockname: This function will test thegetsocknamesystem call, which retrieves the local address of a socket. -
ut_lind_net_listen: This function will test thelistensystem call, which marks a socket as passive and ready to accept incoming connections. -
ut_lind_net_poll: This function will test thepollsystem 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 therecvfromsystem 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 theselectsystem 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 theshutdownsystem call, which disables further send and receive operations on a socket. -
ut_lind_net_socket: This function will test thesocketsystem 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 thesocketpairsystem call, which creates a pair of connected sockets. -
ut_lind_net_udp_bad_bind: This function will test error handling for incorrect usage of thebindsystem 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 theconnectsystem call. -
ut_lind_net_gethostname: This function will test thegethostnamesystem 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 theepollsystem call, which is a variant ofpollthat can be used to monitor multiple file descriptors to see if I/O is possible on any of them .
-
It's useful to add unit tests for helper functions that can be performed on their own.