1*f96bf434SCristian MarussiKSelfTest arm64/signal/ 2*f96bf434SCristian Marussi======================= 3*f96bf434SCristian Marussi 4*f96bf434SCristian MarussiSignals Tests 5*f96bf434SCristian Marussi+++++++++++++ 6*f96bf434SCristian Marussi 7*f96bf434SCristian Marussi- Tests are built around a common main compilation unit: such shared main 8*f96bf434SCristian Marussi enforces a standard sequence of operations needed to perform a single 9*f96bf434SCristian Marussi signal-test (setup/trigger/run/result/cleanup) 10*f96bf434SCristian Marussi 11*f96bf434SCristian Marussi- The above mentioned ops are configurable on a test-by-test basis: each test 12*f96bf434SCristian Marussi is described (and configured) using the descriptor signals.h::struct tdescr 13*f96bf434SCristian Marussi 14*f96bf434SCristian Marussi- Each signal testcase is compiled into its own executable: a separate 15*f96bf434SCristian Marussi executable is used for each test since many tests complete successfully 16*f96bf434SCristian Marussi by receiving some kind of fatal signal from the Kernel, so it's safer 17*f96bf434SCristian Marussi to run each test unit in its own standalone process, so as to start each 18*f96bf434SCristian Marussi test from a clean slate. 19*f96bf434SCristian Marussi 20*f96bf434SCristian Marussi- New tests can be simply defined in testcases/ dir providing a proper struct 21*f96bf434SCristian Marussi tdescr overriding all the defaults we wish to change (as of now providing a 22*f96bf434SCristian Marussi custom run method is mandatory though) 23*f96bf434SCristian Marussi 24*f96bf434SCristian Marussi- Signals' test-cases hereafter defined belong currently to two 25*f96bf434SCristian Marussi principal families: 26*f96bf434SCristian Marussi 27*f96bf434SCristian Marussi - 'mangle_' tests: a real signal (SIGUSR1) is raised and used as a trigger 28*f96bf434SCristian Marussi and then the test case code modifies the signal frame from inside the 29*f96bf434SCristian Marussi signal handler itself. 30*f96bf434SCristian Marussi 31*f96bf434SCristian Marussi - 'fake_sigreturn_' tests: a brand new custom artificial sigframe structure 32*f96bf434SCristian Marussi is placed on the stack and a sigreturn syscall is called to simulate a 33*f96bf434SCristian Marussi real signal return. This kind of tests does not use a trigger usually and 34*f96bf434SCristian Marussi they are just fired using some simple included assembly trampoline code. 35*f96bf434SCristian Marussi 36*f96bf434SCristian Marussi - Most of these tests are successfully passing if the process gets killed by 37*f96bf434SCristian Marussi some fatal signal: usually SIGSEGV or SIGBUS. Since while writing this 38*f96bf434SCristian Marussi kind of tests it is extremely easy in fact to end-up injecting other 39*f96bf434SCristian Marussi unrelated SEGV bugs in the testcases, it becomes extremely tricky to 40*f96bf434SCristian Marussi be really sure that the tests are really addressing what they are meant 41*f96bf434SCristian Marussi to address and they are not instead falling apart due to unplanned bugs 42*f96bf434SCristian Marussi in the test code. 43*f96bf434SCristian Marussi In order to alleviate the misery of the life of such test-developer, a few 44*f96bf434SCristian Marussi helpers are provided: 45*f96bf434SCristian Marussi 46*f96bf434SCristian Marussi - a couple of ASSERT_BAD/GOOD_CONTEXT() macros to easily parse a ucontext_t 47*f96bf434SCristian Marussi and verify if it is indeed GOOD or BAD (depending on what we were 48*f96bf434SCristian Marussi expecting), using the same logic/perspective as in the arm64 Kernel signals 49*f96bf434SCristian Marussi routines. 50*f96bf434SCristian Marussi 51*f96bf434SCristian Marussi - a sanity mechanism to be used in 'fake_sigreturn_'-alike tests: enabled by 52*f96bf434SCristian Marussi default it takes care to verify that the test-execution had at least 53*f96bf434SCristian Marussi successfully progressed up to the stage of triggering the fake sigreturn 54*f96bf434SCristian Marussi call. 55*f96bf434SCristian Marussi 56*f96bf434SCristian Marussi In both cases test results are expected in terms of: 57*f96bf434SCristian Marussi - some fatal signal sent by the Kernel to the test process 58*f96bf434SCristian Marussi or 59*f96bf434SCristian Marussi - analyzing some final regs state 60