• Home
Name Date Size #Lines LOC

..--

report_base/12-May-2024-611610

src/12-May-2024-214,100170,445

.gitignoreD12-May-202443 87

AUTHORSD12-May-2024103 87

BUILD.gnD12-May-2024415 2117

COPYRIGHTD12-May-20241.3 KiB3022

MakefileD12-May-20244.1 KiB155133

READMED12-May-20244.2 KiB10682

README-HowtoRun.mdD12-May-20242.9 KiB8464

config.mak.defD12-May-2024462 129

test_template.gniD12-May-20248.7 KiB311259

README

1libc-test is developed as part of the musl project
2http://www.musl-libc.org/
3
4configuring:
5	cp config.mak.def config.mak
6	edit config.mak
7build and run tests:
8	make
9clean up:
10	make clean
11
12make builds all test binaries and runs them to create
13a REPORT file that contains all build and runtime errors
14(this means that make does not stop at build failures)
15
16contributing tests:
17
18design goals:
19
20- tests should be easy to run and build even a single test in isolation
21(so test should be self contained if possible)
22- failure of one test should not interfere with others
23(build failure, crash or unexpected results are all failures)
24- test output should point to the cause of the failure
25- test results should be robust
26- the test system should have minimal dependency
27(libc, posix sh, gnu make)
28- the test system should run on all archs and libcs
29- tests should leave the system in a clean state
30
31conventions:
32
33each test is in a separate file at a path like src/directory/file.c with
34its own main
35
36the test should return 0 on success and non-0 on failure, on failure it
37should print error messages to standard out if possible, on success no
38message should be printed
39
40to help with the above test protocol use t_error function for printing
41errors and return t_status from main, see src/common/test.h
42(t_error allows standard printf formatting, outputs at most 512bytes
43in a single write call to fd 1, so there is no buffering, long outputs
44are truncated, it sets the global t_status to 1)
45
46it is common to do many similar checks in a test, in such cases macros
47may be used to simplify the code like
48#define T1(a,b) (check(a,b) || (t_error("check(%s,%s) failed\n", a, b),0))
49#define T2(f,w) (result=(f), result==(w) || (t_error("%s failed: got %s, want %s\n", #f, result, w),0))
50
51binaries should be possible to run from arbitrary directory.
52the build system runs the tests using the src/common/runtest tool which
53kills the test process after a timeout and reports the exit status
54in case of failure
55
56directories:
57
58src/api: interface tests, build time include header tests
59src/common: common utilities compiled into libtest.a
60src/functional: functional tests aiming for large coverage of libc
61src/math: tests for each math function with input-output test vectors
62src/regression: regression tests aiming for testing particular bugs
63
64initial set of functional tests are derived from the libc-testsuit of
65Rich Felker, regression tests should contain reference of the bug
66(musl commit hash, glibc bug tracker url, etc)
67
68build system:
69
70the main non-file make targets are all, run, clean and cleanall.
71(cleanall removes the reports unlike clean, run reruns the dynamically
72linked executables)
73
74make variable can be overridden from config.mak or the make command line,
75the variable B sets the build directory which is src by default
76
77for each directory under src there are targets like $(B)/directory/all,
78$(B)/directory/run and $(B)/directory/clean to make only the contents
79of that directory, each directory has its own Makefile set up so it
80invokes the top level make with B=src src/directory/foo for the foo
81target, so it is possible to work only under a specific test directory
82
83the build and runtime errors of each target are accumulated into a
84target.err file and in the end they are concatenated into a REPORT
85
86each .c file in src/functional and src/regression are built into a
87dynamic linked and a static linked executable test binary by default,
88this behaviour can be changed by a similarly named .mk file changing
89make variables and specifying additional rules:
90
91$(B)/$(N) is the name of the binary target (the file name without the .c)
92$(B)/$(N)-static is the name of the static binary target
93$(B)/$(D) is the build directory
94$(N).CFLAGS are added to the CFLAGS at compilation
95$(N).LDFLAGS are added to the LDFLAGS at linking
96$(N).LDLIBS are added to the LDLIBS at linking
97$(N).BINS are the targets (if empty no binaries are built)
98$(N).LIBS are the non-executable targets (shared objects may use it)
99
100if a binary is linked together from several .o files then they
101have to be specified as prerequisits for the binary targets and
102added to the $(N).LDLIBS as well
103
104if a binary depends on a file at runtime (eg. a .so opened by dlopen)
105then the $(N).err target should depend on that file
106

README-HowtoRun.md

1## libc-test脚本使用说明
2
3### 一、编译
4
5编译命令,仅编译libc-test测试用例
6```
7./build.sh --product-name rk3568 --build-target libctest
8```
9用例可执行文件生成的目录位于  `out/rk3568/musl/libc-test`
10以及相关的动态库位于 `out/rk3568/musl/libc-test-lib`
11
12### 二、执行测试
13
141. 将HDC(Windows版)工具hdc.exe加入到windows环境变量。连接上开发板,保证HDC工具可以连接。
15
162. 进入musl/scripts,并根据实际环境,修改runtest_Windows.bat中测试用例生成目录完整路径(必要)
17   ```bat
18   @REM 本地OpenHarmony源码目录,需根据实际环境修改
19   set LOCAL=\\wsl$\ubuntu-20.04\home\code\OpenHarmony
20   @REM 本地编译out目录
21   set OUTDIR=out\rk3568
22   ```
23
243. 将bat脚本复制到windows环境下使用!windows端双击运行runtest_Windows.bat,执行完毕会将详细错误结果信息REPORT返回到当前bat所在目录,并对结果进行统计生成FileList.txt(本次测试执行用例列表)与Summary.txt(统计报告),内容如下:
25   $\color{red}{提交PR需在提交里附上对应统计报告!}$
26   ```
27   SUMMARY
28   All: 1177 | Run: 1147 | Skip: 30
29   Pass: [1083/1147]
30   Fail: [64/1147]
31   Check REPORT for more details.
32
33   [Failed List]:
34   FAIL __fwritable [signal Segmentation fault]
35   FAIL __fwriting [signal Segmentation fault]
36   FAIL a_stack_chk_fail [status 255]
37   FAIL asctime [status 1]
38   ...
39
40   [Skip List]:
41   trace_stresstest
42   fatal_message
43   tgkill_ext
44   exittest01
45   ...
46   ```
47
48   注:此bat文件是从WSL映射目录传输文件到单板目录下,由于WSL无法直接访问windows端口,所以在WSL目录中使用可能无法传输用例。
49
504. 若要单独执行测试用例,将编译结果目录下的`runtest`与需要执行的用例传输到单板
51
52   单板执行 `./runtest -w '' {filename}`,例如:
53
54   测试成功,无报错信息
55   ```
56   # ./runtest -w '' memmem
57   ```
58
59   测试失败,提示FAIL+用例名+错误码
60   ```
61   # ./runtest -w '' pthread_atfork-errno-clobber
62   ../../third_party/musl/libc-test/src/regression/pthread_atfork-errno-clobber.c:23: (pid = fork()) == -1 failed: fork succeeded despite rlimit
63   FAIL pthread_atfork-errno-clobber [status 1]
64   ```
65
66### 三、增加用例
67
68举例:在functional目录中新增用例new_test
69
701. 在libc-test/src/functional目录下新建`new_test.c`
71
722. 编辑libc-test/src/functional目录下的`test_src_functional.gni`,并在`functional_list`末尾添加`"new_test",`
73
743. (可选)利用模板添加编译选项,修改`libc-test/test_template.gni`中编译选项内容或针对指定的用例添加,例如:
75   ```
76   if (target_name == "tls_init") {
77     cflags += [ "-Wno-literal-range" ]
78     ldflags += [ "-Wl,-rpath=./" ]
79     libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_init_dso.so" ]
80   }
81   ```
82
833. 执行步骤一(编译)中的编译命令,即可生成对应可执行文件。
84