18c2ecf20Sopenharmony_ciKSelfTest arm64/signal/ 28c2ecf20Sopenharmony_ci======================= 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ciSignals Tests 58c2ecf20Sopenharmony_ci+++++++++++++ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci- Tests are built around a common main compilation unit: such shared main 88c2ecf20Sopenharmony_ci enforces a standard sequence of operations needed to perform a single 98c2ecf20Sopenharmony_ci signal-test (setup/trigger/run/result/cleanup) 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci- The above mentioned ops are configurable on a test-by-test basis: each test 128c2ecf20Sopenharmony_ci is described (and configured) using the descriptor signals.h::struct tdescr 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci- Each signal testcase is compiled into its own executable: a separate 158c2ecf20Sopenharmony_ci executable is used for each test since many tests complete successfully 168c2ecf20Sopenharmony_ci by receiving some kind of fatal signal from the Kernel, so it's safer 178c2ecf20Sopenharmony_ci to run each test unit in its own standalone process, so as to start each 188c2ecf20Sopenharmony_ci test from a clean slate. 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci- New tests can be simply defined in testcases/ dir providing a proper struct 218c2ecf20Sopenharmony_ci tdescr overriding all the defaults we wish to change (as of now providing a 228c2ecf20Sopenharmony_ci custom run method is mandatory though) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci- Signals' test-cases hereafter defined belong currently to two 258c2ecf20Sopenharmony_ci principal families: 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci - 'mangle_' tests: a real signal (SIGUSR1) is raised and used as a trigger 288c2ecf20Sopenharmony_ci and then the test case code modifies the signal frame from inside the 298c2ecf20Sopenharmony_ci signal handler itself. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci - 'fake_sigreturn_' tests: a brand new custom artificial sigframe structure 328c2ecf20Sopenharmony_ci is placed on the stack and a sigreturn syscall is called to simulate a 338c2ecf20Sopenharmony_ci real signal return. This kind of tests does not use a trigger usually and 348c2ecf20Sopenharmony_ci they are just fired using some simple included assembly trampoline code. 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci - Most of these tests are successfully passing if the process gets killed by 378c2ecf20Sopenharmony_ci some fatal signal: usually SIGSEGV or SIGBUS. Since while writing this 388c2ecf20Sopenharmony_ci kind of tests it is extremely easy in fact to end-up injecting other 398c2ecf20Sopenharmony_ci unrelated SEGV bugs in the testcases, it becomes extremely tricky to 408c2ecf20Sopenharmony_ci be really sure that the tests are really addressing what they are meant 418c2ecf20Sopenharmony_ci to address and they are not instead falling apart due to unplanned bugs 428c2ecf20Sopenharmony_ci in the test code. 438c2ecf20Sopenharmony_ci In order to alleviate the misery of the life of such test-developer, a few 448c2ecf20Sopenharmony_ci helpers are provided: 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci - a couple of ASSERT_BAD/GOOD_CONTEXT() macros to easily parse a ucontext_t 478c2ecf20Sopenharmony_ci and verify if it is indeed GOOD or BAD (depending on what we were 488c2ecf20Sopenharmony_ci expecting), using the same logic/perspective as in the arm64 Kernel signals 498c2ecf20Sopenharmony_ci routines. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci - a sanity mechanism to be used in 'fake_sigreturn_'-alike tests: enabled by 528c2ecf20Sopenharmony_ci default it takes care to verify that the test-execution had at least 538c2ecf20Sopenharmony_ci successfully progressed up to the stage of triggering the fake sigreturn 548c2ecf20Sopenharmony_ci call. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci In both cases test results are expected in terms of: 578c2ecf20Sopenharmony_ci - some fatal signal sent by the Kernel to the test process 588c2ecf20Sopenharmony_ci or 598c2ecf20Sopenharmony_ci - analyzing some final regs state 60