xref: /aosp_15_r20/external/cronet/third_party/lss/tests/README.md (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker# LSS Tests
2*6777b538SAndroid Build Coastguard Worker
3*6777b538SAndroid Build Coastguard Worker## Source Layout
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard WorkerThe general layout of the tests:
6*6777b538SAndroid Build Coastguard Worker* [test_skel.h]: Test helpers for common checks/etc...
7*6777b538SAndroid Build Coastguard Worker* xxx.c: Unittest for the xxx syscall (e.g. `open.c`).
8*6777b538SAndroid Build Coastguard Worker* [Makefile]: New tests should be registered in the `TESTS` variable.
9*6777b538SAndroid Build Coastguard Worker
10*6777b538SAndroid Build Coastguard Worker## Test Guidelines
11*6777b538SAndroid Build Coastguard Worker
12*6777b538SAndroid Build Coastguard WorkerThe unittest itself generally follows the conventions:
13*6777b538SAndroid Build Coastguard Worker* Written in C (unless a very specific language behavior is needed).
14*6777b538SAndroid Build Coastguard Worker* You should only need to `#include "test_skel.h"`.  For new system headers, try
15*6777b538SAndroid Build Coastguard Worker  to add them here rather than copying to exact unittest (if possible).
16*6777b538SAndroid Build Coastguard Worker  It might slow compilation down slightly, but makes the code easier to manage.
17*6777b538SAndroid Build Coastguard Worker  Make sure it is included first.
18*6777b538SAndroid Build Coastguard Worker* Use `assert()` on everything to check return values.
19*6777b538SAndroid Build Coastguard Worker* Use `sys_xxx()` to access the syscall via LSS (compared to `xxx()` which tends
20*6777b538SAndroid Build Coastguard Worker  to come from the C library).
21*6777b538SAndroid Build Coastguard Worker* If you need a tempfile, use `tempfile.XXXXXX` for templates with helpers like
22*6777b538SAndroid Build Coastguard Worker  `mkstemp`.  Try to clean them up when you're done with them.
23*6777b538SAndroid Build Coastguard Worker  These will be created in the cwd, but that's fine.
24*6777b538SAndroid Build Coastguard Worker* Don't worry about trying to verify the kernel/C library API and various edge
25*6777b538SAndroid Build Coastguard Worker  cases.  The goal of LSS is to make sure that we pass args along correctly to
26*6777b538SAndroid Build Coastguard Worker  the syscall only.
27*6777b538SAndroid Build Coastguard Worker* Make sure to leave comments in the test so it's clear what behavior you're
28*6777b538SAndroid Build Coastguard Worker  trying to verify (and how).
29*6777b538SAndroid Build Coastguard Worker
30*6777b538SAndroid Build Coastguard WorkerFeel free to extend [test_skel.h] with more helpers if they're useful to more
31*6777b538SAndroid Build Coastguard Workerthan one test.
32*6777b538SAndroid Build Coastguard Worker
33*6777b538SAndroid Build Coastguard WorkerIf you're looking for a simple example, start with [unlink.c](./unlink.c).
34*6777b538SAndroid Build Coastguard WorkerYou should be able to copy this over and replace the content of `main()`.
35*6777b538SAndroid Build Coastguard Worker
36*6777b538SAndroid Build Coastguard Worker## Running The Tests
37*6777b538SAndroid Build Coastguard Worker
38*6777b538SAndroid Build Coastguard WorkerSimply run `make`.  This will compile & execute all the tests on your local
39*6777b538SAndroid Build Coastguard Workersystem.  A standard `make clean` will clean up all the objects.
40*6777b538SAndroid Build Coastguard Worker
41*6777b538SAndroid Build Coastguard WorkerIf you need to debug something, then the programs are simply named `xxx_test`
42*6777b538SAndroid Build Coastguard Workerand can easily be thrown into `gdb ./xxx_test`.
43*6777b538SAndroid Build Coastguard Worker
44*6777b538SAndroid Build Coastguard WorkerWe have rudimentary cross-compile testing via gcc and clang.  Try running
45*6777b538SAndroid Build Coastguard Worker`make cross` -- for any toolchains you don't have available, it should skip
46*6777b538SAndroid Build Coastguard Workerthings automatically.  This only verifies the compilation & linking stages
47*6777b538SAndroid Build Coastguard Workerthough.
48*6777b538SAndroid Build Coastguard Worker
49*6777b538SAndroid Build Coastguard WorkerThe cross-compilers can be created using <http://crosstool-ng.github.io/>.
50*6777b538SAndroid Build Coastguard Worker
51*6777b538SAndroid Build Coastguard Worker[Makefile]: ./Makefile
52*6777b538SAndroid Build Coastguard Worker[test_skel.h]: ./test_skel.h
53