1570af302Sopenharmony_ci## libc-test脚本使用说明 2570af302Sopenharmony_ci 3570af302Sopenharmony_ci### 一、编译 4570af302Sopenharmony_ci 5570af302Sopenharmony_ci编译命令,仅编译libc-test测试用例 6570af302Sopenharmony_ci``` 7570af302Sopenharmony_ci./build.sh --product-name rk3568 --build-target libctest 8570af302Sopenharmony_ci``` 9570af302Sopenharmony_ci用例可执行文件生成的目录位于 `out/rk3568/musl/libc-test` 10570af302Sopenharmony_ci以及相关的动态库位于 `out/rk3568/musl/libc-test-lib` 11570af302Sopenharmony_ci 12570af302Sopenharmony_ci### 二、执行测试 13570af302Sopenharmony_ci 14570af302Sopenharmony_ci1. 将HDC(Windows版)工具hdc.exe加入到windows环境变量。连接上开发板,保证HDC工具可以连接。 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci2. 进入musl/scripts,并根据实际环境,修改runtest_Windows.bat中测试用例生成目录完整路径(必要) 17570af302Sopenharmony_ci ```bat 18570af302Sopenharmony_ci @REM 本地OpenHarmony源码目录,需根据实际环境修改 19570af302Sopenharmony_ci set LOCAL=\\wsl$\ubuntu-20.04\home\code\OpenHarmony 20570af302Sopenharmony_ci @REM 本地编译out目录 21570af302Sopenharmony_ci set OUTDIR=out\rk3568 22570af302Sopenharmony_ci ``` 23570af302Sopenharmony_ci 24570af302Sopenharmony_ci3. 将bat脚本复制到windows环境下使用!windows端双击运行runtest_Windows.bat,执行完毕会将详细错误结果信息REPORT返回到当前bat所在目录,并对结果进行统计生成FileList.txt(本次测试执行用例列表)与Summary.txt(统计报告),内容如下: 25570af302Sopenharmony_ci $\color{red}{提交PR需在提交里附上对应统计报告!}$ 26570af302Sopenharmony_ci ``` 27570af302Sopenharmony_ci SUMMARY 28570af302Sopenharmony_ci All: 1177 | Run: 1147 | Skip: 30 29570af302Sopenharmony_ci Pass: [1083/1147] 30570af302Sopenharmony_ci Fail: [64/1147] 31570af302Sopenharmony_ci Check REPORT for more details. 32570af302Sopenharmony_ci 33570af302Sopenharmony_ci [Failed List]: 34570af302Sopenharmony_ci FAIL __fwritable [signal Segmentation fault] 35570af302Sopenharmony_ci FAIL __fwriting [signal Segmentation fault] 36570af302Sopenharmony_ci FAIL a_stack_chk_fail [status 255] 37570af302Sopenharmony_ci FAIL asctime [status 1] 38570af302Sopenharmony_ci ... 39570af302Sopenharmony_ci 40570af302Sopenharmony_ci [Skip List]: 41570af302Sopenharmony_ci trace_stresstest 42570af302Sopenharmony_ci fatal_message 43570af302Sopenharmony_ci tgkill_ext 44570af302Sopenharmony_ci ... 45570af302Sopenharmony_ci ``` 46570af302Sopenharmony_ci 47570af302Sopenharmony_ci 注:此bat文件是从WSL映射目录传输文件到单板目录下,由于WSL无法直接访问windows端口,所以在WSL目录中使用可能无法传输用例。 48570af302Sopenharmony_ci 49570af302Sopenharmony_ci4. 若要单独执行测试用例,将编译结果目录下的`runtest`与需要执行的用例传输到单板 50570af302Sopenharmony_ci 51570af302Sopenharmony_ci 单板执行 `./runtest -w '' {filename}`,例如: 52570af302Sopenharmony_ci 53570af302Sopenharmony_ci 测试成功,无报错信息 54570af302Sopenharmony_ci ``` 55570af302Sopenharmony_ci # ./runtest -w '' memmem 56570af302Sopenharmony_ci ``` 57570af302Sopenharmony_ci 58570af302Sopenharmony_ci 测试失败,提示FAIL+用例名+错误码 59570af302Sopenharmony_ci ``` 60570af302Sopenharmony_ci # ./runtest -w '' pthread_atfork-errno-clobber 61570af302Sopenharmony_ci ../../third_party/musl/libc-test/src/regression/pthread_atfork-errno-clobber.c:23: (pid = fork()) == -1 failed: fork succeeded despite rlimit 62570af302Sopenharmony_ci FAIL pthread_atfork-errno-clobber [status 1] 63570af302Sopenharmony_ci ``` 64570af302Sopenharmony_ci 65570af302Sopenharmony_ci### 三、增加用例 66570af302Sopenharmony_ci 67570af302Sopenharmony_ci举例:在functional目录中新增用例new_test 68570af302Sopenharmony_ci 69570af302Sopenharmony_ci1. 在libc-test/src/functional目录下新建`new_test.c` 70570af302Sopenharmony_ci 71570af302Sopenharmony_ci2. 编辑libc-test/src/functional目录下的`test_src_functional.gni`,并在`functional_list`末尾添加`"new_test",` 72570af302Sopenharmony_ci 73570af302Sopenharmony_ci3. (可选)利用模板添加编译选项,修改`libc-test/test_template.gni`中编译选项内容或针对指定的用例添加,例如: 74570af302Sopenharmony_ci ``` 75570af302Sopenharmony_ci if (target_name == "tls_init") { 76570af302Sopenharmony_ci cflags += [ "-Wno-literal-range" ] 77570af302Sopenharmony_ci ldflags += [ "-Wl,-rpath=./" ] 78570af302Sopenharmony_ci libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_init_dso.so" ] 79570af302Sopenharmony_ci } 80570af302Sopenharmony_ci ``` 81570af302Sopenharmony_ci 82570af302Sopenharmony_ci3. 执行步骤一(编译)中的编译命令,即可生成对应可执行文件。 83