162306a36Sopenharmony_ciKSelfTest arm64/signal/ 262306a36Sopenharmony_ci======================= 362306a36Sopenharmony_ci 462306a36Sopenharmony_ciSignals Tests 562306a36Sopenharmony_ci+++++++++++++ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci- Tests are built around a common main compilation unit: such shared main 862306a36Sopenharmony_ci enforces a standard sequence of operations needed to perform a single 962306a36Sopenharmony_ci signal-test (setup/trigger/run/result/cleanup) 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci- The above mentioned ops are configurable on a test-by-test basis: each test 1262306a36Sopenharmony_ci is described (and configured) using the descriptor signals.h::struct tdescr 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci- Each signal testcase is compiled into its own executable: a separate 1562306a36Sopenharmony_ci executable is used for each test since many tests complete successfully 1662306a36Sopenharmony_ci by receiving some kind of fatal signal from the Kernel, so it's safer 1762306a36Sopenharmony_ci to run each test unit in its own standalone process, so as to start each 1862306a36Sopenharmony_ci test from a clean slate. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci- New tests can be simply defined in testcases/ dir providing a proper struct 2162306a36Sopenharmony_ci tdescr overriding all the defaults we wish to change (as of now providing a 2262306a36Sopenharmony_ci custom run method is mandatory though) 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci- Signals' test-cases hereafter defined belong currently to two 2562306a36Sopenharmony_ci principal families: 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci - 'mangle_' tests: a real signal (SIGUSR1) is raised and used as a trigger 2862306a36Sopenharmony_ci and then the test case code modifies the signal frame from inside the 2962306a36Sopenharmony_ci signal handler itself. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci - 'fake_sigreturn_' tests: a brand new custom artificial sigframe structure 3262306a36Sopenharmony_ci is placed on the stack and a sigreturn syscall is called to simulate a 3362306a36Sopenharmony_ci real signal return. This kind of tests does not use a trigger usually and 3462306a36Sopenharmony_ci they are just fired using some simple included assembly trampoline code. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci - Most of these tests are successfully passing if the process gets killed by 3762306a36Sopenharmony_ci some fatal signal: usually SIGSEGV or SIGBUS. Since while writing this 3862306a36Sopenharmony_ci kind of tests it is extremely easy in fact to end-up injecting other 3962306a36Sopenharmony_ci unrelated SEGV bugs in the testcases, it becomes extremely tricky to 4062306a36Sopenharmony_ci be really sure that the tests are really addressing what they are meant 4162306a36Sopenharmony_ci to address and they are not instead falling apart due to unplanned bugs 4262306a36Sopenharmony_ci in the test code. 4362306a36Sopenharmony_ci In order to alleviate the misery of the life of such test-developer, a few 4462306a36Sopenharmony_ci helpers are provided: 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci - a couple of ASSERT_BAD/GOOD_CONTEXT() macros to easily parse a ucontext_t 4762306a36Sopenharmony_ci and verify if it is indeed GOOD or BAD (depending on what we were 4862306a36Sopenharmony_ci expecting), using the same logic/perspective as in the arm64 Kernel signals 4962306a36Sopenharmony_ci routines. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci - a sanity mechanism to be used in 'fake_sigreturn_'-alike tests: enabled by 5262306a36Sopenharmony_ci default it takes care to verify that the test-execution had at least 5362306a36Sopenharmony_ci successfully progressed up to the stage of triggering the fake sigreturn 5462306a36Sopenharmony_ci call. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci In both cases test results are expected in terms of: 5762306a36Sopenharmony_ci - some fatal signal sent by the Kernel to the test process 5862306a36Sopenharmony_ci or 5962306a36Sopenharmony_ci - analyzing some final regs state 60