Skip to content

Testing and Debugging

Nicholas Renner edited this page May 2, 2024 · 6 revisions

Testing and Debugging

Syscall Test Suite

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

  1. File system tests

    The fs_tests.rs file contains a test suite function test_fs(), which runs a series of tests related to file system operations. Here's a summary of the tests:

    1. 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.

    2. 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.

    3. ut_lind_fs_chmod and ut_lind_fs_fchmod: These tests are checking the functionality of changing file permissions.

    4. ut_lind_fs_dir_chdir and ut_lind_fs_dir_chdir_getcwd: These tests are will checking the ability to change the current working directory and get the current working directory.

    5. ut_lind_fs_dir_mode and ut_lind_fs_dir_multiple: These tests will be checking the creation of directories and handling multiple directories.

    6. ut_lind_fs_dup and ut_lind_fs_dup2: These tests are checking the duplication of file descriptors.

    7. ut_lind_fs_fcntl: This test will be checking the file control operations.

    8. ut_lind_fs_ioctl: This test is checking the input/output control operations.

    9. ut_lind_fs_fdflags: This test will be checking the operations related to file descriptor flags.

    10. ut_lind_fs_file_link_unlink: This test is will checking the linking and unlinking of files.

    11. ut_lind_fs_file_lseek_past_end: This test will be checking the behavior when seeking past the end of a file.

    12. ut_lind_fs_fstat_complex, ut_lind_fs_stat_file_complex, and ut_lind_fs_stat_file_mode: These tests are checking the file status operations.

    13. ut_lind_fs_getuid: This test is will checking the operation to get the user ID.

    14. ut_lind_fs_load_fs: This test will be checking the loading of a file system.

    15. ut_lind_fs_mknod: This test is checking the creation of special files or directories.

    16. ut_lind_fs_multiple_open: This test will be checking the behavior when opening multiple files.

    17. ut_lind_fs_rename: This test is checking the renaming of files.

    18. ut_lind_fs_rmdir: This test is will checking the removal of directories.

    19. ut_lind_fs_statfs and ut_lind_fs_fstatfs: These tests are checking the operations to get file system statistics.

    20. ut_lind_fs_ftruncate and ut_lind_fs_truncate: These tests will be checking the truncation of files.

    21. ut_lind_fs_getdents: This test is checking the reading of directory entries.

    22. rdwrtest and prdwrtest: These tests are will checking read

  2. IPC tests

    The ipc_tests.rs file contains three test functions: ut_lind_ipc_pipe, ut_lind_ipc_domain_socket, and ut_lind_ipc_socketpair. Here's a summary:

    1. 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.

    2. 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.

    3. 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, and recv work as expected, and that the system correctly handles process termination.

  3. Networking tests

    The networking_tests.rs file contains a single function net_tests(), which will be a test suite that runs a series of tests related to networking operations. Here's a summary:

    1. ut_lind_net_bind: This function will test the bind system call, which assigns a local protocol address to a socket.

    2. ut_lind_net_bind_multiple: This function will test the ability to bind multiple sockets to the same address.

    3. 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).

    4. ut_lind_net_connect_basic_udp: This function will test the ability to establish a basic UDP connection.

    5. ut_lind_net_getpeername: This function will test the getpeername system call, which retrieves the remote address of a socket.

    6. ut_lind_net_getsockname: This function will test the getsockname system call, which retrieves the local address of a socket.

    7. ut_lind_net_listen: This function will test the listen system call, which marks a socket as passive and ready to accept incoming connections.

    8. ut_lind_net_poll: This function will test the poll system call, which waits for one of a set of file descriptors to become ready to perform I/O.

    9. ut_lind_net_recvfrom: This function will test the recvfrom system call, which receives a message from a socket and captures the address from which it was sent.

    10. ut_lind_net_select: This function will test the select system call, which waits for one of a set of file descriptors to become ready to perform I/O.

    11. ut_lind_net_shutdown: This function will test the shutdown system call, which disables further send and receive operations on a socket.

    12. ut_lind_net_socket: This function will test the socket system call, which creates an endpoint for communication.

    13. ut_lind_net_socketoptions: This function will test the ability to get and set socket options.

    14. ut_lind_net_socketpair: This function will test the socketpair system call, which creates a pair of connected sockets.

    15. ut_lind_net_udp_bad_bind: This function will test error handling for incorrect usage of the bind system call with UDP sockets.

    16. ut_lind_net_udp_simple: This function will test a simple UDP data transfer scenario.

    17. ut_lind_net_udp_connect: This function will test the ability to establish a UDP connection using the connect system call.

    18. ut_lind_net_gethostname: This function will test the gethostname system call, which retrieves the standard host name for the current machine.

    19. 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.

    20. ut_lind_net_domain_socket: This function will test the ability to create and use Unix domain sockets for inter-process communication.

    21. ut_lind_net_epoll: This function will test the epoll system call, which is a variant of poll that can be used to monitor multiple file descriptors to see if I/O is possible on any of them .

Unit Tests

It's useful to add unit tests for helper functions that can be performed on their own.

Clone this wiki locally