Skip to content

Add ZYDIS_BUILD_TESTS option and include tests in CMakeLists.txt #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,15 @@ jobs:
with: { submodules: recursive }
- name: Configuring
run: |
mkdir build
cd build
cmake -DZYAN_DEV_MODE=ON ${{ matrix.cmake_flags }} ..
cmake -B build -DZYDIS_BUILD_TESTS=ON -DZYAN_DEV_MODE=ON ${{ matrix.cmake_flags }} .
- name: Building
run: |
cmake --build build --config Release
- name: Running regression tests (decoder)
run: |
cd tests
python3 regression.py test ../build/ZydisInfo
if: "matrix.image_name != 'windows-2022' && !matrix.skip_tests"
- name: Running regression tests (encoder)
cmake --build build --config Release -j2
- name: Running tests
if: "!matrix.skip_tests"
run: |
cd tests
python3 regression_encoder.py ../build/ZydisFuzzReEncoding ../build/ZydisFuzzEncoder ../build/ZydisTestEncoderAbsolute
if: "matrix.image_name != 'windows-2022' && !matrix.skip_tests"
- name: Running regression tests
run: |
cd tests
python regression.py test ..\\build\\Release\\ZydisInfo.exe
if: "matrix.image_name == 'windows-2022' && !matrix.skip_tests"
cd build
ctest -C Release --output-on-failure

msbuild-build:
name: MSBuild build (windows-2022)
Expand Down
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ option(ZYDIS_BUILD_MAN
option(ZYDIS_BUILD_DOXYGEN
"Build doxygen documentation (requires Doxygen)"
ON)
option(ZYDIS_BUILD_TESTS
"Build tests"
OFF)
option(ZYDIS_FUZZ_AFL_FAST
"Enables AFL persistent mode and reduces prints in ZydisFuzzIn"
OFF)
Expand Down Expand Up @@ -491,3 +494,37 @@ if (ZYDIS_BUILD_MAN)
endforeach()
add_custom_target(man ALL DEPENDS ${MAN_NAMES})
endif ()

# =============================================================================================== #
# Tests #
# =============================================================================================== #

if (ZYDIS_BUILD_TESTS)
enable_testing()
find_package(Python 3 REQUIRED)

if (TARGET ZydisInfo)
add_test(
NAME "ZydisRegression"
COMMAND
"${Python_EXECUTABLE}"
regression.py
test
$<TARGET_FILE:ZydisInfo>
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tests"
)
endif ()

if (TARGET ZydisFuzzReEncoding AND TARGET ZydisFuzzEncoder AND TARGET ZydisTestEncoderAbsolute)
add_test(
NAME "ZydisRegressionEncoder"
COMMAND
"${Python_EXECUTABLE}"
regression_encoder.py
$<TARGET_FILE:ZydisFuzzReEncoding>
$<TARGET_FILE:ZydisFuzzEncoder>
$<TARGET_FILE:ZydisTestEncoderAbsolute>
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tests"
)
endif ()
endif ()
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ configure: dependencies/zycore/CMakeLists.txt
@if ! command -v cmake > /dev/null; then \
echo >&2 "ERROR: cmake is not installed. Please install it first."; \
fi
cmake -B $(BUILD_DIR)
cmake -B $(BUILD_DIR) -DZYDIS_BUILD_TESTS=ON

install: build
cmake --install $(BUILD_DIR)
Expand All @@ -24,8 +24,7 @@ clean:
rm -rf amalgamated-dist

test: build
cd tests && ./regression.py test ../build/ZydisInfo
cd tests && ./regression_encoder.py ../build/Zydis{Fuzz{ReEncoding,Encoder},TestEncoderAbsolute}
cd $(BUILD_DIR) && ctest

doc: configure
cmake --build $(BUILD_DIR) --target ZydisDoc
Expand Down