From bb5a1e0149fe9a224af27755cc663a2eb648ac1e Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Mon, 18 Jul 2022 08:12:23 -0300 Subject: [PATCH] Add test framework in common library. --- .github/workflows/main.yml | 7 + builds/docker/windows/scripts/build-x64.bat | 2 + builds/docker/windows/scripts/build-x86.bat | 2 + builds/posix/Makefile.in | 20 ++ builds/posix/make.defaults | 3 + builds/posix/make.rules | 4 + builds/posix/make.shared.variables | 8 +- builds/win32/make_tests.bat | 24 ++ builds/win32/msvc15/FirebirdCommon.props | 2 +- builds/win32/msvc15/FirebirdTests.sln | 40 ++++ builds/win32/msvc15/common_test.vcxproj | 205 ++++++++++++++++++ .../win32/msvc15/common_test.vcxproj.filters | 22 ++ builds/win32/run_all.bat | 2 + builds/win32/run_tests.bat | 12 + builds/win32/set_build_target.bat | 1 + configure.ac | 2 + src/common/tests/CommonTest.cpp | 22 ++ 17 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 builds/win32/make_tests.bat create mode 100644 builds/win32/msvc15/FirebirdTests.sln create mode 100644 builds/win32/msvc15/common_test.vcxproj create mode 100644 builds/win32/msvc15/common_test.vcxproj.filters create mode 100644 builds/win32/run_tests.bat create mode 100644 src/common/tests/CommonTest.cpp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8902ebffbe..01cdfb9bab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,6 +58,8 @@ jobs: run: | CC=clang CXX=clang++ ./autogen.sh --enable-binreloc --prefix=/opt/firebird make -j4 + make tests -j4 + make run_tests make dist tar xzvf gen/Firebird-[0-9]*.tar.gz (cd Firebird-[0-9]*; sudo ./install.sh -silent) @@ -82,6 +84,8 @@ jobs: run: | ./autogen.sh --enable-binreloc-threads --with-builtin-tommath --with-builtin-tomcrypt --prefix=/opt/firebird make -j4 + make tests -j4 + make run_tests make dist tar xzvf gen/Firebird-[0-9]*.tar.gz @@ -128,6 +132,8 @@ jobs: LIBRARY_PATH="$ICU_INSTALL_PATH/lib:$LIBRARY_PATH" ./autogen.sh --with-builtin-tommath --with-builtin-tomcrypt make -j4 + make tests -j4 + make run_tests (cd gen; make -B -f make.platform.postfix ICU_LOC="$ICU_INSTALL_PATH/lib/") (cd gen; make -B -f Makefile.install) @@ -167,6 +173,7 @@ jobs: call "%VS_SCRIPT%" -arch=%FB_VS_ARCH% cd builds\win32 run_all.bat JUSTBUILD + run_tests.bat - name: Build (Windows, Docker) if: startsWith(matrix.os, 'windows-') && matrix.docker diff --git a/builds/docker/windows/scripts/build-x64.bat b/builds/docker/windows/scripts/build-x64.bat index 664294bfa7..a759bfc3e0 100644 --- a/builds/docker/windows/scripts/build-x64.bat +++ b/builds/docker/windows/scripts/build-x64.bat @@ -11,4 +11,6 @@ cd /d C:\firebird-build\builds\win32 REM call run_all.bat call run_all.bat JUSTBUILD +call run_tests.bat + xcopy /h /e /i /q C:\firebird-build\output_%FB_OUTPUT_SUFFIX%\* C:\firebird-out diff --git a/builds/docker/windows/scripts/build-x86.bat b/builds/docker/windows/scripts/build-x86.bat index f5955e899b..4b601c2cf0 100644 --- a/builds/docker/windows/scripts/build-x86.bat +++ b/builds/docker/windows/scripts/build-x86.bat @@ -11,4 +11,6 @@ cd /d C:\firebird-build\builds\win32 REM call run_all.bat call run_all.bat JUSTBUILD +call run_tests.bat + xcopy /h /e /i /q C:\firebird-build\output_%FB_OUTPUT_SUFFIX%\* C:\firebird-out diff --git a/builds/posix/Makefile.in b/builds/posix/Makefile.in index 2f90b3edb8..ea2f3bf70f 100644 --- a/builds/posix/Makefile.in +++ b/builds/posix/Makefile.in @@ -361,6 +361,8 @@ $(COMMON_LIB): $(Common_Objects) -$(RM) $@ $(STATICLIB_LINK) $@ $^ +$(COMMON_TEST): $(Common_Test_Objects) $(COMMON_LIB) + $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ -L$(LIB) $(LINK_LIBS) #___________________________________________________________________________ # gpre_boot @@ -711,6 +713,24 @@ install install-embedded silent_install package packages dist: $(MAKE) -f Makefile.install $@ +#___________________________________________________________________________ +# tests +# + +.PHONY: tests tests_process run_tests run_tests_process + +tests: + $(MAKE) TARGET=$(DefaultTarget) tests_process + +tests_process: $(COMMON_TEST) + +run_tests: + $(MAKE) TARGET=$(DefaultTarget) run_tests_process + +run_tests_process: tests_process + $(COMMON_TEST) --log_level=all + + #___________________________________________________________________________ # various cleaning # diff --git a/builds/posix/make.defaults b/builds/posix/make.defaults index b676a01083..400bc4d94f 100755 --- a/builds/posix/make.defaults +++ b/builds/posix/make.defaults @@ -53,6 +53,8 @@ RE2_BUILD_FLG=@RE2_BUILD@ SYSTEM_BOOST_FLG=@SYSTEM_BOOST@ FB_BUILD=$(GEN_ROOT)/$(TARGET)/firebird +FB_TEST_BUILD=$(GEN_ROOT)/$(TARGET)/tests + ifeq ($(IsCross), Y) FIREBIRD=$(GEN_ROOT)/Native/firebird else @@ -386,6 +388,7 @@ LINK_PLUG_LIBS = -L$(LIB) $(SO_LINK_LIBS) # Pay attention - we place common library into obj, not lib dir # It's just a set of object files, prepared to be used by ld, not an output library COMMON_LIB = $(OBJ)/common.a +COMMON_TEST = $(FB_TEST_BUILD)/common_test$(EXEC_EXT) # From utilities CREATE_DB = $(RBIN)/create_db$(EXEC_EXT) diff --git a/builds/posix/make.rules b/builds/posix/make.rules index 4731032b5a..997981cdb5 100644 --- a/builds/posix/make.rules +++ b/builds/posix/make.rules @@ -34,6 +34,10 @@ # Please don't use compiler/platform specific flags here - nmcc 02-Nov-2002 WFLAGS =-I$(SRC_ROOT)/include/gen -I$(SRC_ROOT)/include $(CPPFLAGS) $(LTCSOURCE) +ifneq ($(SYSTEM_BOOST_FLG),Y) + WFLAGS += -I$(ROOT)/extern/boost +endif + ifeq ($(TOMMATH_BUILD_FLG),Y) WFLAGS += -I$(TOMMATH_INC) endif diff --git a/builds/posix/make.shared.variables b/builds/posix/make.shared.variables index c5d555b1ad..a583be362a 100644 --- a/builds/posix/make.shared.variables +++ b/builds/posix/make.shared.variables @@ -36,12 +36,18 @@ Common_Objects:= $(CO1) $(CO2) $(CO3) $(CO4) AllObjects += $(Common_Objects) +# Common test files +COT1:= $(call dirObjects,common/tests) +Common_Test_Objects:= $(COT1) + +AllObjects += $(Common_Test_Objects) + # gpre GPRE_Common_Objects:= $(call dirObjects,gpre) $(call makeObjects,gpre/languages,@GPRE_LANGUAGE_MODULES@) GPRE_std:= $(call dirObjects,gpre/std) GPRE_Objects:= $(GPRE_Common_Objects) $(GPRE_std) -GPRE_boot:= $(call dirObjects,gpre/boot) $(call makeObjects,yvalve,gds.cpp) +GPRE_boot:= $(call dirObjects,gpre/boot) GPRE_Boot_Objects:= $(GPRE_Common_Objects) $(GPRE_boot) AllObjects += $(GPRE_Common_Objects) $(GPRE_std) $(GPRE_boot) diff --git a/builds/win32/make_tests.bat b/builds/win32/make_tests.bat new file mode 100644 index 0000000000..8384c7c65d --- /dev/null +++ b/builds/win32/make_tests.bat @@ -0,0 +1,24 @@ +@echo off +set ERRLEV=0 + +:: Set env vars +@call setenvvar.bat + +@if errorlevel 1 (call :ERROR Executing setenvvar.bat failed & goto :EOF) + +:: verify that boot was run before + +@if not exist %FB_GEN_DIR%\firebird.msg (goto :HELP_BOOT & goto :EOF) + + +@call set_build_target.bat %* + +::========== +:: MAIN + +@echo Building %FB_OBJ_DIR% + +call compile.bat builds\win32\%VS_VER%\FirebirdTests make_tests_%FB_TARGET_PLATFORM%.log +if errorlevel 1 call :ERROR build failed - see make_tests_%FB_TARGET_PLATFORM%.log for details + +@goto :EOF diff --git a/builds/win32/msvc15/FirebirdCommon.props b/builds/win32/msvc15/FirebirdCommon.props index 483376de00..1f9c9b12cc 100644 --- a/builds/win32/msvc15/FirebirdCommon.props +++ b/builds/win32/msvc15/FirebirdCommon.props @@ -10,7 +10,7 @@ /EHsc- %(AdditionalOptions) true - ../../../src/include;../../../src/include/gen;../../../extern/libtomcrypt/src/headers;../../../extern/libtommath;../../../extern/icu/include;../../../extern/zlib;../../../extern/re2;%(AdditionalIncludeDirectories) + ../../../src/include;../../../src/include/gen;../../../extern/libtomcrypt/src/headers;../../../extern/libtommath;../../../extern/icu/include;../../../extern/zlib;../../../extern/re2;../../../extern/boost;%(AdditionalIncludeDirectories) false diff --git a/builds/win32/msvc15/FirebirdTests.sln b/builds/win32/msvc15/FirebirdTests.sln new file mode 100644 index 0000000000..88151d8b56 --- /dev/null +++ b/builds/win32/msvc15/FirebirdTests.sln @@ -0,0 +1,40 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2047 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common.vcxproj", "{15605F44-BFFD-444F-AD4C-55DC9D704465}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common_test", "common_test.vcxproj", "{035D26F9-B406-4D60-A8B7-172098479254}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Debug|Win32.ActiveCfg = Debug|Win32 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Debug|Win32.Build.0 = Debug|Win32 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Debug|x64.ActiveCfg = Debug|x64 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Debug|x64.Build.0 = Debug|x64 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Release|Win32.ActiveCfg = Release|Win32 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Release|Win32.Build.0 = Release|Win32 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Release|x64.ActiveCfg = Release|x64 + {15605F44-BFFD-444F-AD4C-55DC9D704465}.Release|x64.Build.0 = Release|x64 + {035D26F9-B406-4D60-A8B7-172098479254}.Debug|Win32.ActiveCfg = Debug|Win32 + {035D26F9-B406-4D60-A8B7-172098479254}.Debug|Win32.Build.0 = Debug|Win32 + {035D26F9-B406-4D60-A8B7-172098479254}.Debug|x64.ActiveCfg = Debug|x64 + {035D26F9-B406-4D60-A8B7-172098479254}.Debug|x64.Build.0 = Debug|x64 + {035D26F9-B406-4D60-A8B7-172098479254}.Release|Win32.ActiveCfg = Release|Win32 + {035D26F9-B406-4D60-A8B7-172098479254}.Release|Win32.Build.0 = Release|Win32 + {035D26F9-B406-4D60-A8B7-172098479254}.Release|x64.ActiveCfg = Release|x64 + {035D26F9-B406-4D60-A8B7-172098479254}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {97076DB2-CFCD-4277-BDF0-A6407852E1AC} + EndGlobalSection +EndGlobal diff --git a/builds/win32/msvc15/common_test.vcxproj b/builds/win32/msvc15/common_test.vcxproj new file mode 100644 index 0000000000..2d13d43ac4 --- /dev/null +++ b/builds/win32/msvc15/common_test.vcxproj @@ -0,0 +1,205 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {035D26F9-B406-4D60-A8B7-172098479254} + common_test + 10.0.17763.0 + 10.0 + 10.0 + + + + Application + false + MultiByte + v141_xp + v142 + v143 + + + Application + false + MultiByte + v141_xp + v142 + v143 + + + Application + false + MultiByte + v141 + v142 + v143 + + + Application + false + MultiByte + v141 + v142 + v143 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + false + false + false + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + ..\..\..\temp\$(PlatformName)\$(Configuration)\tests\ + ..\..\..\temp\$(PlatformName)\$(Configuration)\tests\ + ..\..\..\temp\$(PlatformName)\$(Configuration)\tests\ + ..\..\..\temp\$(PlatformName)\$(Configuration)\tests\ + + + + MaxSpeed + OnlyExplicitInline + true + Speed + NDEBUG;_CONSOLE;SUPERCLIENT;WIN32;%(PreprocessorDefinitions) + true + + + comctl32.lib;ws2_32.lib;mpr.lib;version.lib;%(AdditionalDependencies) + Console + false + + + + + + + Disabled + _DEBUG;_CONSOLE;SUPERCLIENT;WIN32;DEV_BUILD;_WINDOWS;_USRDLL;CLIENT;%(PreprocessorDefinitions) + true + + + comctl32.lib;ws2_32.lib;mpr.lib;version.lib;%(AdditionalDependencies) + Console + false + + + + + + + X64 + + + MaxSpeed + OnlyExplicitInline + true + Speed + NDEBUG;_CONSOLE;SUPERCLIENT;WIN32;%(PreprocessorDefinitions) + + + comctl32.lib;ws2_32.lib;mpr.lib;version.lib;%(AdditionalDependencies) + Console + false + + + MachineX64 + + + + + X64 + + + Disabled + _DEBUG;_CONSOLE;SUPERCLIENT;WIN32;DEV_BUILD;_WINDOWS;_USRDLL;CLIENT;%(PreprocessorDefinitions) + true + + + comctl32.lib;ws2_32.lib;mpr.lib;version.lib;%(AdditionalDependencies) + Console + false + + + MachineX64 + + + + + ..\..\..\src\jrd + ..\..\..\src\jrd + ..\..\..\src\jrd + ..\..\..\src\jrd + + + + + + + + {15605f44-bffd-444f-ad4c-55dc9d704465} + true + false + false + true + false + + + + + + diff --git a/builds/win32/msvc15/common_test.vcxproj.filters b/builds/win32/msvc15/common_test.vcxproj.filters new file mode 100644 index 0000000000..78a0c1ab76 --- /dev/null +++ b/builds/win32/msvc15/common_test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {59426d65-9f63-49b9-b8c1-9416f4875c62} + + + {487dc529-1110-47e9-a3aa-907ca1b16858} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + + + Resource files + + + + + source + + + diff --git a/builds/win32/run_all.bat b/builds/win32/run_all.bat index b9596911a6..389d24af8e 100644 --- a/builds/win32/run_all.bat +++ b/builds/win32/run_all.bat @@ -47,6 +47,8 @@ call make_boot %FBBUILD_BUILDTYPE% if "%ERRLEV%"=="1" goto :END call make_all %FBBUILD_BUILDTYPE% if "%ERRLEV%"=="1" goto :END +call make_tests %FBBUILD_BUILDTYPE% +if "%ERRLEV%"=="1" goto :END call make_examples %FBBUILD_BUILDTYPE% if "%ERRLEV%"=="1" goto :END diff --git a/builds/win32/run_tests.bat b/builds/win32/run_tests.bat new file mode 100644 index 0000000000..02be23ca42 --- /dev/null +++ b/builds/win32/run_tests.bat @@ -0,0 +1,12 @@ +@echo off + +@echo. + +@call setenvvar.bat +@if errorlevel 1 (goto :END) + +@call set_build_target.bat %* + +@%FB_TESTS_DIR%\common_test --log_level=all + +:END diff --git a/builds/win32/set_build_target.bat b/builds/win32/set_build_target.bat index ba27fac14f..8e49482aa7 100644 --- a/builds/win32/set_build_target.bat +++ b/builds/win32/set_build_target.bat @@ -13,6 +13,7 @@ for %%v in ( %* ) do ( set FB_OBJ_DIR=%FB_TARGET_PLATFORM%\%FB_CONFIG% set FB_BIN_DIR=%FB_ROOT_PATH%\temp\%FB_OBJ_DIR%\firebird\ +set FB_TESTS_DIR=%FB_ROOT_PATH%\temp\%FB_OBJ_DIR%\tests\ @echo Executed %0 @echo. diff --git a/configure.ac b/configure.ac index f6aa655f98..bae40d2366 100644 --- a/configure.ac +++ b/configure.ac @@ -574,6 +574,7 @@ AC_ARG_WITH(system-re2, [RE2_BUILD=N]) AC_SUBST(RE2_BUILD) +dnl This is currently used for internal and public (API headers) needs SYSTEM_BOOST=N AC_ARG_WITH(system-boost, [ --with-system-boost use system-wide boost library instead of embedded copy], @@ -1310,6 +1311,7 @@ dnl # output mkdir -p gen/\$fb_tgt/firebird/include/firebird/impl mkdir -p gen/\$fb_tgt/firebird/lib mkdir -p gen/\$fb_tgt/firebird/misc + mkdir -p gen/\$fb_tgt/tests dnl ### TEMP ### directories for generated .cpp, .o and .d by module name for src_dir in `cd src; ls -R -1 * | grep : | tr -d : | tr "\n" " "; cd ..`; do diff --git a/src/common/tests/CommonTest.cpp b/src/common/tests/CommonTest.cpp new file mode 100644 index 0000000000..45026c2d75 --- /dev/null +++ b/src/common/tests/CommonTest.cpp @@ -0,0 +1,22 @@ +#include "firebird.h" +#include "firebird/Interface.h" +#include "../common/gdsassert.h" + +#define BOOST_TEST_MODULE CommonTest +#include "boost/test/included/unit_test.hpp" + + +int ISC_EXPORT fb_shutdown(unsigned int, const int) +{ + fb_assert(false); + return 0; +} + +namespace Firebird +{ + IMaster* API_ROUTINE fb_get_master_interface() + { + fb_assert(false); + return nullptr; + } +}