文章目录
- openssl3.2 - 测试程序的学习 - 准备openssl测试专用工程的模板
- 概述
- 笔记
- 工程中需要的openssl的库实现
- END
openssl3.2 - 测试程序的学习 - 准备openssl测试专用工程的模板
概述
openssl3.2 - 测试程序的学习
整了几个test.c, 每开一个新的测试工程, 总要改这改那的. 挺麻烦的.
想建立一个专门用于学习openssl测试工程的VS2019模板工程. 等做新实验时, 将openssl的测试程序加入工程, 做少量改动, 就能做实验.
如果每次做一个实验, 都要向工程中加入大量支持文件, 受不了.
观察了一下makefile中的测试工程的生成, 普遍都是一个测试程序的.c + 一个测试库 + openssl的公共库.
// 测试.exe的实现组成
test\afalgtest.exe: test\afalgtest-bin-afalgtest.obj test\libtestutil.lib libcrypto.libIF EXIST test\afalgtest.exe.manifest DEL /F /Q test\afalgtest.exe.manifest$(LD) $(LDFLAGS) $(BIN_LDFLAGS) @<<
test\afalgtest-bin-afalgtest.obj// 测试.c的实现组成
test\afalgtest-bin-afalgtest.obj: test\afalgtest.c$(CC) $(BIN_CFLAGS) -I"include" -I"apps\include" $(BIN_CPPFLAGS) -c $(COUTFLAG)$@ "test\afalgtest.c"cmd /C "$(CC) /Zs /showIncludes $(BIN_CFLAGS) -I"include" -I"apps\include" $(BIN_CPPFLAGS) "test\afalgtest.c" > test\afalgtest-bin-afalgtest.d 2>&1"// libtestutil.lib的实现组成
test\libtestutil.lib: apps\lib\libtestutil-lib-opt.obj apps\lib\libtestutil-lib-win32_init.obj test\testutil\libtestutil-lib-apps_shims.obj test\testutil\libtestutil-lib-basic_output.obj test\testutil\libtestutil-lib-cb.obj test\testutil\libtestutil-lib-driver.obj test\testutil\libtestutil-lib-fake_random.obj test\testutil\libtestutil-lib-format_output.obj test\testutil\libtestutil-lib-load.obj test\testutil\libtestutil-lib-main.obj test\testutil\libtestutil-lib-options.obj test\testutil\libtestutil-lib-output.obj test\testutil\libtestutil-lib-provider.obj test\testutil\libtestutil-lib-random.obj test\testutil\libtestutil-lib-stanza.obj test\testutil\libtestutil-lib-test_cleanup.obj test\testutil\libtestutil-lib-test_options.obj test\testutil\libtestutil-lib-tests.obj test\testutil\libtestutil-lib-testutil_init.obj$(AR) $(ARFLAGS) $(AROUTFLAG)test\libtestutil.lib @<<
apps\lib\libtestutil-lib-opt.obj
apps\lib\libtestutil-lib-win32_init.obj
test\testutil\libtestutil-lib-apps_shims.obj
test\testutil\libtestutil-lib-basic_output.obj
test\testutil\libtestutil-lib-cb.obj
test\testutil\libtestutil-lib-driver.obj
test\testutil\libtestutil-lib-fake_random.obj
test\testutil\libtestutil-lib-format_output.obj
test\testutil\libtestutil-lib-load.obj
test\testutil\libtestutil-lib-main.obj
test\testutil\libtestutil-lib-options.obj
test\testutil\libtestutil-lib-output.obj
test\testutil\libtestutil-lib-provider.obj
test\testutil\libtestutil-lib-random.obj
test\testutil\libtestutil-lib-stanza.obj
test\testutil\libtestutil-lib-test_cleanup.obj
test\testutil\libtestutil-lib-test_options.obj
test\testutil\libtestutil-lib-tests.obj
test\testutil\libtestutil-lib-testutil_init.obj
<<
apps\lib\libtestutil-lib-opt.obj: apps\lib\opt.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "apps\lib\opt.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "apps\lib\opt.c" > apps\lib\libtestutil-lib-opt.d 2>&1"
apps\lib\libtestutil-lib-win32_init.obj: apps\lib\win32_init.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "apps\lib\win32_init.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "apps\lib\win32_init.c" > apps\lib\libtestutil-lib-win32_init.d 2>&1"
test\testutil\libtestutil-lib-apps_shims.obj: test\testutil\apps_shims.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\apps_shims.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\apps_shims.c" > test\testutil\libtestutil-lib-apps_shims.d 2>&1"
test\testutil\libtestutil-lib-basic_output.obj: test\testutil\basic_output.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\basic_output.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\basic_output.c" > test\testutil\libtestutil-lib-basic_output.d 2>&1"
test\testutil\libtestutil-lib-cb.obj: test\testutil\cb.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\cb.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\cb.c" > test\testutil\libtestutil-lib-cb.d 2>&1"
test\testutil\libtestutil-lib-driver.obj: test\testutil\driver.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\driver.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\driver.c" > test\testutil\libtestutil-lib-driver.d 2>&1"
test\testutil\libtestutil-lib-fake_random.obj: test\testutil\fake_random.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\fake_random.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\fake_random.c" > test\testutil\libtestutil-lib-fake_random.d 2>&1"
test\testutil\libtestutil-lib-format_output.obj: test\testutil\format_output.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\format_output.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\format_output.c" > test\testutil\libtestutil-lib-format_output.d 2>&1"
test\testutil\libtestutil-lib-load.obj: test\testutil\load.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\load.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\load.c" > test\testutil\libtestutil-lib-load.d 2>&1"
test\testutil\libtestutil-lib-main.obj: test\testutil\main.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\main.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\main.c" > test\testutil\libtestutil-lib-main.d 2>&1"
test\testutil\libtestutil-lib-options.obj: test\testutil\options.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\options.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\options.c" > test\testutil\libtestutil-lib-options.d 2>&1"
test\testutil\libtestutil-lib-output.obj: test\testutil\output.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\output.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\output.c" > test\testutil\libtestutil-lib-output.d 2>&1"
test\testutil\libtestutil-lib-provider.obj: test\testutil\provider.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\provider.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\provider.c" > test\testutil\libtestutil-lib-provider.d 2>&1"
test\testutil\libtestutil-lib-random.obj: test\testutil\random.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\random.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\random.c" > test\testutil\libtestutil-lib-random.d 2>&1"
test\testutil\libtestutil-lib-stanza.obj: test\testutil\stanza.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\stanza.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\stanza.c" > test\testutil\libtestutil-lib-stanza.d 2>&1"
test\testutil\libtestutil-lib-test_cleanup.obj: test\testutil\test_cleanup.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\test_cleanup.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\test_cleanup.c" > test\testutil\libtestutil-lib-test_cleanup.d 2>&1"
test\testutil\libtestutil-lib-test_options.obj: test\testutil\test_options.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\test_options.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\test_options.c" > test\testutil\libtestutil-lib-test_options.d 2>&1"
test\testutil\libtestutil-lib-tests.obj: test\testutil\tests.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\tests.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\tests.c" > test\testutil\libtestutil-lib-tests.d 2>&1"
test\testutil\libtestutil-lib-testutil_init.obj: test\testutil\testutil_init.c$(CC) $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) -c $(COUTFLAG)$@ "test\testutil\testutil_init.c"cmd /C "$(CC) /Zs /showIncludes $(LIB_CFLAGS) -I"include" -I"apps\include" -I"." $(LIB_CPPFLAGS) "test\testutil\testutil_init.c" > test\testutil\libtestutil-lib-testutil_init.d 2>&1"
engines\capi.dll: engines\capi-dso-e_capi.obj engines\capi.def libcrypto.libIF EXIST engines\capi.dll.manifest DEL /F /Q engines\capi.dll.manifestcmd /C "$(LD) $(LDFLAGS) $(DSO_LDFLAGS) @<< || (DEL /Q $(@B).* engines\capi.* & EXIT 1)"
那应该建立一个以 libtestutil.lib 实现为主的工程, 补充一些空实现(在自己添加的2个公共实现里面, 用宏来控制空实现的有无), 让这个.exe工程能自编译过.
那么这就是专门做openssl测试程序实验的工程.
等做openssl测试程序新实验时, 如果测试.c有程序里面需要的要求的几个必须实现, 用宏关掉模板公共实现中的空实现即可.
试了一下好使, 做新实验时方便多了.
笔记
工程中需要的openssl的库实现
将编译过的openssl源码目录中的apps, test/testutil 目录直接拷贝到模板工程下, 将垃圾都删掉(只保留.c, .h)
工程设置合适的头文件路径和库路径
按照makefile中, test\libtestutil.lib 的实现要求, 加入对应的.c
加入自己做的2个公共文件, 里面有头文件包含和库包含, 还有宏控制的openssl测试专用的几个空实现.
/*!
\file my_openSSL_lib.h
*/#ifndef __MY_OPENSSL_LIB_H__
#define __MY_OPENSSL_LIB_H__#ifdef _WIN32
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib") // for select()#include <windows.h>
#endif /* #ifdef _WIN32 */#pragma comment(lib, "libcrypto.lib")
#pragma comment(lib, "libssl.lib")#ifdef _WIN32
#define MY_SLEEP(x) Sleep(x)
#else
#define MY_SLEEP(x) sleep(x)
#endif /* #ifdef _WIN32 */#define USE_MY_SETUP_TEST// #define USE_MY_OPTION_choice#ifdef USE_MY_OPTION_choice#include "testutil.h"// 需要将其他实现中的enum定义拷贝过来
typedef enum OPTION_choice {OPT_ERR = -1,OPT_EOF = 0,OPT_CONFIG_FILE,OPT_TEST_ENUM
} OPTION_CHOICE;#endif // #ifdef USE_MY_OPTION_choice#endif /* #ifndef __MY_OPENSSL_LIB_H__ */
/*!
* \file D:\my_dev\my_local_git_prj\study\openSSL\nmake_test\test_c\prj_005_afalgtest.c\my_openSSL_lib.c
*/#include "my_openSSL_lib.h"#define MY_USE_APPLINK
#ifdef MY_USE_APPLINK
#include <openssl/applink.c> /*! for OPENSSL_Uplink(00007FF8B7EF0FE8,08): no OPENSSL_Applink */
#endif // #ifdef MY_USE_APPLINK#ifdef USE_MY_OPTION_choiceconst OPTIONS* test_get_options(void)
{// 这个函数返回不能为空, 从其他有实现的函数中拷贝一个实现过来, 否则有崩溃报错static const OPTIONS test_options[] = {OPT_TEST_OPTIONS_DEFAULT_USAGE,{ "config", OPT_CONFIG_FILE, '<',"The configuration file to use for the libctx" },{ NULL }};return test_options;
}#endif // #ifdef USE_MY_OPTION_choice#ifdef USE_MY_SETUP_TEST
int setup_tests(void)
{return 0;
}# endif //
编译通过
1> 正在创建库 D:\my_dev\my_local_git_prj\study\openSSL\nmake_test\test_c\prj_openssl_test_template\x64\Debug\prj_template.lib 和对象 D:\my_dev\my_local_git_prj\study\openSSL\nmake_test\test_c\prj_openssl_test_template\x64\Debug\prj_template.exp
1>prj_template.vcxproj -> D:\my_dev\my_local_git_prj\study\openSSL\nmake_test\test_c\prj_openssl_test_template\x64\Debug\prj_template.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
就将这个工程作为openssl测试(test/*.c)专用的工程模板