Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
android_libpthread/ | 12-May-2024 | - | 9 | 4 | ||
android_librt/ | 12-May-2024 | - | 9 | 4 | ||
newlib_tests/ | 12-May-2024 | - | 3,928 | 2,552 | ||
tests/ | 12-May-2024 | - | 950 | 429 | ||
Makefile | D | 12-May-2024 | 654 | 29 | 16 | |
README.md | D | 12-May-2024 | 7.5 KiB | 153 | 121 | |
cloner.c | D | 12-May-2024 | 4.7 KiB | 176 | 94 | |
errnos.h | D | 12-May-2024 | 3.8 KiB | 187 | 154 | |
get_path.c | D | 12-May-2024 | 2.7 KiB | 104 | 48 | |
ltp.pc.in | D | 12-May-2024 | 192 | 11 | 9 | |
parse_opts.c | D | 12-May-2024 | 16 KiB | 622 | 422 | |
random_range.c | D | 12-May-2024 | 21.6 KiB | 893 | 504 | |
safe_file_ops.c | D | 12-May-2024 | 9.5 KiB | 454 | 345 | |
safe_macros.c | D | 12-May-2024 | 28.6 KiB | 1,277 | 992 | |
safe_net.c | D | 12-May-2024 | 12.9 KiB | 536 | 414 | |
safe_pthread.c | D | 12-May-2024 | 911 | 44 | 29 | |
safe_stdio.c | D | 12-May-2024 | 2.5 KiB | 102 | 67 | |
self_exec.c | D | 12-May-2024 | 4.7 KiB | 226 | 164 | |
signame.h | D | 12-May-2024 | 2.1 KiB | 107 | 78 | |
tlibio.c | D | 12-May-2024 | 60.1 KiB | 2,162 | 1,488 | |
tst_af_alg.c | D | 12-May-2024 | 5.8 KiB | 253 | 201 | |
tst_ansi_color.c | D | 12-May-2024 | 966 | 65 | 49 | |
tst_arch.c | D | 12-May-2024 | 1.8 KiB | 95 | 79 | |
tst_assert.c | D | 12-May-2024 | 2.2 KiB | 84 | 58 | |
tst_bool_expr.c | D | 12-May-2024 | 8.1 KiB | 407 | 293 | |
tst_buffers.c | D | 12-May-2024 | 2.5 KiB | 144 | 110 | |
tst_capability.c | D | 12-May-2024 | 2 KiB | 91 | 70 | |
tst_cgroup.c | D | 12-May-2024 | 29.9 KiB | 1,209 | 830 | |
tst_checkpoint.c | D | 12-May-2024 | 4.5 KiB | 170 | 103 | |
tst_checksum.c | D | 12-May-2024 | 3.4 KiB | 82 | 74 | |
tst_clocks.c | D | 12-May-2024 | 3.4 KiB | 158 | 127 | |
tst_clone.c | D | 12-May-2024 | 820 | 47 | 30 | |
tst_cmd.c | D | 12-May-2024 | 8.2 KiB | 348 | 261 | |
tst_coredump.c | D | 12-May-2024 | 731 | 36 | 20 | |
tst_cpu.c | D | 12-May-2024 | 2.8 KiB | 100 | 58 | |
tst_crypto.c | D | 12-May-2024 | 2.5 KiB | 113 | 80 | |
tst_device.c | D | 12-May-2024 | 11.5 KiB | 550 | 395 | |
tst_dir_is_empty.c | D | 12-May-2024 | 1.3 KiB | 50 | 22 | |
tst_fill_file.c | D | 12-May-2024 | 2.3 KiB | 119 | 72 | |
tst_fill_fs.c | D | 12-May-2024 | 1.2 KiB | 69 | 48 | |
tst_fips.c | D | 12-May-2024 | 452 | 25 | 14 | |
tst_fs_has_free.c | D | 12-May-2024 | 1.2 KiB | 45 | 17 | |
tst_fs_link_count.c | D | 12-May-2024 | 4.8 KiB | 183 | 130 | |
tst_fs_setup.c | D | 12-May-2024 | 1.1 KiB | 51 | 42 | |
tst_fs_type.c | D | 12-May-2024 | 2.5 KiB | 95 | 62 | |
tst_get_bad_addr.c | D | 12-May-2024 | 1 KiB | 32 | 11 | |
tst_hugepage.c | D | 12-May-2024 | 1.5 KiB | 68 | 49 | |
tst_ioctl.c | D | 12-May-2024 | 728 | 38 | 28 | |
tst_kconfig.c | D | 12-May-2024 | 9.9 KiB | 563 | 404 | |
tst_kernel.c | D | 12-May-2024 | 4.3 KiB | 187 | 112 | |
tst_kvercmp.c | D | 12-May-2024 | 4 KiB | 202 | 131 | |
tst_lockdown.c | D | 12-May-2024 | 1.5 KiB | 71 | 51 | |
tst_memutils.c | D | 12-May-2024 | 3.7 KiB | 174 | 117 | |
tst_mkfs.c | D | 12-May-2024 | 2.9 KiB | 126 | 87 | |
tst_module.c | D | 12-May-2024 | 3 KiB | 125 | 87 | |
tst_net.c | D | 12-May-2024 | 4.7 KiB | 223 | 160 | |
tst_netdevice.c | D | 12-May-2024 | 12.9 KiB | 515 | 416 | |
tst_parse_opts.c | D | 12-May-2024 | 1.3 KiB | 37 | 10 | |
tst_path_has_mnt_flags.c | D | 12-May-2024 | 2 KiB | 84 | 47 | |
tst_pid.c | D | 12-May-2024 | 4 KiB | 151 | 98 | |
tst_process_state.c | D | 12-May-2024 | 1.6 KiB | 91 | 64 | |
tst_res.c | D | 12-May-2024 | 14.7 KiB | 607 | 386 | |
tst_resource.c | D | 12-May-2024 | 3.7 KiB | 138 | 87 | |
tst_rtctime.c | D | 12-May-2024 | 2.9 KiB | 128 | 84 | |
tst_rtnetlink.c | D | 12-May-2024 | 8.9 KiB | 415 | 313 | |
tst_safe_file_at.c | D | 12-May-2024 | 3.7 KiB | 198 | 148 | |
tst_safe_io_uring.c | D | 12-May-2024 | 3.3 KiB | 109 | 86 | |
tst_safe_macros.c | D | 12-May-2024 | 11.4 KiB | 555 | 438 | |
tst_safe_sysv_ipc.c | D | 12-May-2024 | 5.7 KiB | 274 | 210 | |
tst_safe_timerfd.c | D | 12-May-2024 | 1.5 KiB | 70 | 51 | |
tst_sig.c | D | 12-May-2024 | 7.1 KiB | 256 | 126 | |
tst_sig_proc.c | D | 12-May-2024 | 471 | 32 | 20 | |
tst_status.c | D | 12-May-2024 | 872 | 52 | 34 | |
tst_supported_fs_types.c | D | 12-May-2024 | 4.1 KiB | 208 | 155 | |
tst_sys_conf.c | D | 12-May-2024 | 1.9 KiB | 106 | 78 | |
tst_taint.c | D | 12-May-2024 | 2 KiB | 114 | 87 | |
tst_test.c | D | 12-May-2024 | 32.7 KiB | 1,571 | 1,191 | |
tst_timer.c | D | 12-May-2024 | 1.2 KiB | 60 | 42 | |
tst_timer_test.c | D | 12-May-2024 | 10.7 KiB | 473 | 319 | |
tst_tmpdir.c | D | 12-May-2024 | 8.4 KiB | 354 | 206 | |
tst_uid.c | D | 12-May-2024 | 2.6 KiB | 121 | 91 | |
tst_virt.c | D | 12-May-2024 | 4 KiB | 188 | 124 | |
tst_wallclock.c | D | 12-May-2024 | 3.1 KiB | 119 | 68 |
README.md
1# Test library design document 2 3## High-level picture 4 5 library process 6 +----------------------------+ 7 | main | 8 | tst_run_tcases | 9 | do_setup | 10 | for_each_variant | 11 | for_each_filesystem | test process 12 | fork_testrun ------------->+--------------------------------------------+ 13 | waitpid | | testrun | 14 | | | do_test_setup | 15 | | | tst_test->setup | 16 | | | run_tests | 17 | | | tst_test->test(i) or tst_test->test_all | 18 | | | do_test_cleanup | 19 | | | tst_test->cleanup | 20 | | | exit(0) | 21 | do_exit | +--------------------------------------------+ 22 | do_cleanup | 23 | exit(ret) | 24 +----------------------------+ 25 26## Test lifetime overview 27 28When a test is executed the very first thing to happen is that we check for 29various test prerequisites. These are described in the tst\_test structure and 30range from simple '.require\_root' to a more complicated kernel .config boolean 31expressions such as: "CONFIG\_X86\_INTEL\_UMIP=y | CONFIG\_X86\_UMIP=y". 32 33If all checks are passed the process carries on with setting up the test 34environment as requested in the tst\_test structure. There are many different 35setup steps that have been put into the test library again ranging from rather 36simple creation of a unique test temporary directory to a bit more complicated 37ones such as preparing, formatting, and mounting a block device. 38 39The test library also intializes shrared memory used for IPC at this step. 40 41Once all the prerequisites are checked and test environment has been prepared 42we can move on executing the testcase itself. The actual test is executed in a 43forked process, however there are a few hops before we get there. 44 45First of all there are test variants, which means that the test is re-executed 46several times with a slightly different setting. This is usually used to test a 47family of similar syscalls, where we test each of these syscalls exactly the 48same, but without re-executing the test binary itself. Test variants are 49implemented as a simple global variable counter that gets increased on each 50iteration. In a case of syscall tests we switch between which syscall to call 51based on the global counter. 52 53Then there is all\_filesystems flag which is mostly the same as test variants 54but executes the test for each filesystem supported by the system. Note that we 55can get cartesian product between test variants and all filesystems as well. 56 57In a pseudo code it could be expressed as: 58 59``` 60for test_variants: 61 for all_filesystems: 62 fork_testrun() 63``` 64 65Before we fork() the test process the test library sets up a timeout alarm and 66also a heartbeat signal handlers and also sets up an alarm(2) accordingly to 67the test timeout. When a test times out the test library gets SIGALRM and the 68alarm handler mercilessly kills all forked children by sending SIGKILL to the 69whole process group. The heartbeat handler is used by the test process to reset 70this timer for example when the test functions run in a loop. 71 72With that done we finally fork() the test process. The test process firstly 73resets signal handlers and sets its pid to be a process group leader so that we 74can slaughter all children if needed. The test library proceeds with suspending 75itself in waitpid() syscall and waits for the child to finish at this point. 76 77The test process goes ahead and calls the test setup() function if present in 78the tst\_test structure. It's important that we execute all test callbacks 79after we have forked the process, that way we cannot crash the test library 80process. The setup can also cause the test to exit prematurely by either direct 81or indirect (SAFE\_MACROS()) call to tst\_brk(). In this case the 82fork\_testrun() function exits, but the loops for test variants or filesystems 83carries on. 84 85All that is left to be done is to actually execute the tests, what happnes now 86depends on the -i and -I command line parameters that can request that the 87run() or run\_all() callbacks are executed N times or for N seconds. Again the 88test can exit at any time by direct or indirect call to tst\_brk(). 89 90Once the test is finished all that is left for the test process is the test 91cleanup(). So if a there is a cleanup() callback in the tst\_test structure 92it's executed. The cleanup() callback runs in a special context where the 93tst\_brk(TBROK, ...) calls are converted into tst\_res(TWARN, ...) calls. This 94is because we found out that carrying on with partially broken cleanup is 95usually better option than exiting it in the middle. 96 97The test cleanup() is also called by the tst\_brk() handler in order to cleanup 98before exiting the test process, hence it must be able to cope even with 99partial test setup. Usually it suffices to make sure to clean up only 100resources that already have been set up and to do that in an inverse order that 101we did in setup(). 102 103Once the test process exits or leaves the run() or run\_all() function the test 104library wakes up from the waitpid() call, and checks if the test process 105exitted normally. 106 107Once the testrun is finished the test library does a cleanup() as well to clean 108up resources set up in the test library setup(), reports test results and 109finally exits the process. 110 111### Test library and fork()-ing 112 113Things are a bit more complicated when fork()-ing is involved, however the test 114results are stored in a page of a shared memory and incremented by atomic 115operations, hence the results are stored right after the test reporting 116function returns from the test library and the access is, by definition, 117race-free as well. 118 119On the other hand the test library, apart from sending a SIGKILL to the whole 120process group on timeout, does not track grandchildren. 121 122This especially means that: 123 124- The test exits once the main test process exits. 125 126- While the test results are, by the design, propagated to the test library 127 we may still miss a child that gets killed by a signal or exits unexpectedly. 128 129The test writer should, because of this, take care for reaping these proceses 130properly, in most cases this could be simply done by calling 131tst\_reap\_children() to collect and dissect deceased. 132 133Also note that tst\_brk() does exit only the current process, so if a child 134process calls tst\_brk() the counters are incremented and only the process 135exits. 136 137### Test library and exec() 138 139The piece of mapped memory to store the results to is not preserved over 140exec(2), hence to use the test library from a binary started by an exec() it 141has to be remaped. In this case the process must to call tst\_reinit() before 142calling any other library functions. In order to make this happen the program 143environment carries LTP\_IPC\_PATH variable with a path to the backing file on 144tmpfs. This also allows us to use the test library from shell testcases. 145 146### Test library and process synchronization 147 148The piece of mapped memory is also used as a base for a futex-based 149synchronization primitives called checkpoints. And as said previously the 150memory can be mapped to any process by calling the tst\_reinit() function. As a 151matter of a fact there is even a tst\_checkpoint binary that allows us to use 152the checkpoints from shell code as well. 153