openssl3.2 - 测试程序的学习

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工程中找代码参考, 也容易和清晰多了.

笔记

这个笔记作为一个索引贴.
如果测试程序很短, 就写在这个笔记中
如果测试程序很长, 就另外开一个笔记, 将具体笔记的索引放在这个索引贴中.

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;
}

END

相关推荐

  1. openSSH学习

    2024-01-27 13:14:03       44 阅读
  2. Win32 MDI 程序学习1

    2024-01-27 13:14:03       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-27 13:14:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-27 13:14:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-27 13:14:03       82 阅读
  4. Python语言-面向对象

    2024-01-27 13:14:03       91 阅读

热门阅读

  1. react mui textfield marquee 跑马灯效果实现

    2024-01-27 13:14:03       53 阅读
  2. react hooks的useContext

    2024-01-27 13:14:03       57 阅读
  3. torch.empty()造成的内存溢出问题

    2024-01-27 13:14:03       53 阅读
  4. Centos安装mysql/mariadb

    2024-01-27 13:14:03       50 阅读
  5. 搭建简单docker swarm集群

    2024-01-27 13:14:03       55 阅读
  6. Python的语法糖

    2024-01-27 13:14:03       58 阅读
  7. MySQL模糊查询通配符转义总结

    2024-01-27 13:14:03       63 阅读
  8. MySQL十部曲之三:字符集和排序规则

    2024-01-27 13:14:03       44 阅读