文章目录
- openssl3.2 - 测试程序的学习
- 概述
- 笔记
- openssl3.2 - 测试程序的学习 - test\aborttest.c
- openssl3.2 - 测试程序的学习 - test\sanitytest.c
- openssl3.2 - 测试程序的学习 - test\acvp_test.c
- openssl3.2 - 测试程序的学习 - test\aesgcmtest.c
- END
openssl3.2 - 测试程序的学习
概述
namke test时, 记录日志.
nmake test > nmake_test_log.txt
可以看到生成了很多测试程序.
"link" /nologo /debug setargv.obj /subsystem:console /opt:ref /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmCACF.tmp
IF EXIST test\x509_test.exe.manifest "mt" -nologo -manifest test\x509_test.exe.manifest -outputresource:test\x509_test.exe
IF EXIST test\x509_time_test.exe.manifest DEL /F /Q test\x509_time_test.exe.manifest
"link" /nologo /debug setargv.obj /subsystem:console /opt:ref /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmCC66.tmp
IF EXIST test\x509_time_test.exe.manifest "mt" -nologo -manifest test\x509_time_test.exe.manifest -outputresource:test\x509_time_test.exe
IF EXIST test\x509aux.exe.manifest DEL /F /Q test\x509aux.exe.manifest
"link" /nologo /debug setargv.obj /subsystem:console /opt:ref /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmCD90.tmp
IF EXIST test\x509aux.exe.manifest "mt" -nologo -manifest test\x509aux.exe.manifest -outputresource:test\x509aux.exe
IF EXIST engines\capi.dll.manifest DEL /F /Q engines\capi.dll.manifest
cmd /C ""link" /nologo /debug /dll /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmCEAB.tmp || (DEL /Q capi.* engines\capi.* & EXIT 1)"
IF EXIST engines\capi.dll.manifest "mt" -nologo -manifest engines\capi.dll.manifest -outputresource:engines\capi.dll
IF EXIST engines\dasync.dll.manifest DEL /F /Q engines\dasync.dll.manifest
cmd /C ""link" /nologo /debug /dll /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmD003.tmp || (DEL /Q dasync.* engines\dasync.* & EXIT 1)"
IF EXIST engines\dasync.dll.manifest "mt" -nologo -manifest engines\dasync.dll.manifest -outputresource:engines\dasync.dll
IF EXIST engines\loader_attic.dll.manifest DEL /F /Q engines\loader_attic.dll.manifest
cmd /C ""link" /nologo /debug /dll /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmD7D4.tmp || (DEL /Q loader_attic.* engines\loader_attic.* & EXIT 1)"
IF EXIST engines\loader_attic.dll.manifest "mt" -nologo -manifest engines\loader_attic.dll.manifest -outputresource:engines\loader_attic.dll
IF EXIST engines\ossltest.dll.manifest DEL /F /Q engines\ossltest.dll.manifest
cmd /C ""link" /nologo /debug /dll /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmD9AA.tmp || (DEL /Q ossltest.* engines\ossltest.* & EXIT 1)"
IF EXIST engines\ossltest.dll.manifest "mt" -nologo -manifest engines\ossltest.dll.manifest -outputresource:engines\ossltest.dll
IF EXIST engines\padlock.dll.manifest DEL /F /Q engines\padlock.dll.manifest
cmd /C ""link" /nologo /debug /dll /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmDAF3.tmp || (DEL /Q padlock.* engines\padlock.* & EXIT 1)"
IF EXIST engines\padlock.dll.manifest "mt" -nologo -manifest engines\padlock.dll.manifest -outputresource:engines\padlock.dll
IF EXIST providers\legacy.dll.manifest DEL /F /Q providers\legacy.dll.manifest
cmd /C ""link" /nologo /debug /dll /nologo /debug @C:\Users\chenx\AppData\Local\Temp\nmE18C.tmp || (DEL /Q legacy.* providers\legacy.* & EXIT 1)"
IF EXIST providers\legacy.dll.manifest "mt" -nologo -manifest providers\legacy.dll.manifest -outputresource:providers\legacy.dll
cmd /C "set "SRCTOP=." & set "BLDTOP=." & set "PERL=C:\Perl\bin\perl.exe" & set "FIPSKEY=f4556650ac31d35461610bac4ed81b1a181b2d8a43ea2854cbae22ca74560813" & "C:\Perl\bin\perl.exe" ".\test\run_tests.pl" "
00-prep_fipsmodule_cnf.t .. skipped: FIPS module config file only supported in a fips build
Files=1, Tests=0, 0 wallclock secs ( 0.02 usr + 0.00 sys = 0.02 CPU)
Result: NOTESTS
01-test_abort.t ......................... ok
01-test_fipsmodule_cnf.t ................ skipped: Test only supported in a fips build
测试脚本是用perl写的, 挺复杂的. 但是大概齐能看懂意思.
cmd /C "set "SRCTOP=." & set "BLDTOP=." & set "PERL=C:\Perl\bin\perl.exe" & set "FIPSKEY=f4556650ac31d35461610bac4ed81b1a181b2d8a43ea2854cbae22ca74560813" & "C:\Perl\bin\perl.exe" ".\test\run_tests.pl"
run_tests.pl 中找测试配置文件*.t
# prep recipes are mandatory and need to be always run first
my @preps = glob(catfile($recipesdir,"00-prep_*.t"));
foreach my $test (@preps) {
delete $tests{$test};
}
sub find_matching_tests {
my ($glob) = @_;
if ($glob =~ m|^[\d\[\]\?\-]+$|) {
return glob(catfile($recipesdir,"$glob-*.t"));
}
return glob(catfile($recipesdir,"*-$glob.t"));
}
openssl-3.2.0\test\recipes/.t
查看具体的.t
use OpenSSL::Test;
setup("test_abort");
plan tests => 1;
is(run(test(["aborttest"])), 0, "Testing that abort is caught correctly");
最终都是调用了生成好的测试程序.
run(test(["用C写的测试程序"]))
结合make test的日志和makefile, 就可以知道具体测试程序(e.g. aborttest.exe ) 编译时, 需要哪些工程文件.
这些测试程序, 是用来对编译好的openssl组件(主要是DLL)来测试. 是真正对openssl外部接口的测试.
这些测试程序是在调用openssl的DLL的接口, 和我们正常使用openssl DLL的场景是一样的, 不同的时, 官方提供的测试程序, 是在测试各种细节场景, 保证编译出的openssl DLL是正常可用的. 如果通不过测试, 那就说明从源码编译出的openssl的可执行文件(exe, DLL)是有问题的.
我想将openssl的这些测试exe的工程实现过一遍. 等过完后, openssl DLL接口细节的使用, 就没啥不知道的了.
等于是, 我们自己工程中如何用openssl, 在这些官方内部使用的nmake test相关工程中, 已经全部演示了.
看完这些测试程序, 在openssl.exe工程中找代码参考, 也容易和清晰多了.
笔记
这个笔记作为一个索引贴.
如果测试程序很短, 就写在这个笔记中
如果测试程序很长, 就另外开一个笔记, 将具体笔记的索引放在这个索引贴中.
openssl源码目录下的\test下, 用everything搜索全部的*.c, 拷贝到自己工程的备用目录下, 这些.c就是要学习的官方测试程序的C实现.
全部过一遍. 过一个工程, 就删掉一个实现, 等实现都没了, 就搞定了.
openssl3.2 - 测试程序的学习 - test\aborttest.c
#include "my_openSSL_lib.h"
#include <openssl/crypto.h>
int main(int argc, char **argv)
{
// 打印错误原因, 报错点(file, line), 结束程序
OPENSSL_die("Voluntary abort", __FILE__, __LINE__);
return 0;
}
openssl3.2 - 测试程序的学习 - test\sanitytest.c
openssl3.2 - 测试程序的学习 - test\sanitytest.c
openssl3.2 - 测试程序的学习 - test\acvp_test.c
openssl3.2 - 测试程序的学习 - test\acvp_test.c
openssl3.2 - 测试程序的学习 - test\aesgcmtest.c
openssl3.2 - 测试程序的学习 - test\aesgcmtest.c