Skip to content

Commit

Permalink
Add simple test and corkami test suite using Catch2
Browse files Browse the repository at this point in the history
* Enable testing with CMake option '-DPEPARSE_ENABLE_TESTING=ON'.

* The simple test is extremely basic just as an example of using Catch2.

* Corkami test suite is a git submodule within assets and the tests can
be run with or without cloning it. You are able to configure CMake
without the submodule and it will warn you that the tests are not
included, and then it will pick them up automatically on next cmake
rebuild.

There are a few Corkami files which pe-parse is unable to process. They
have been added as exceptions for now (just to get this merged), but we
can open new issues to track them. This will also catch any regressions
that could prevent the successful parsing of files that have been
parse-able in the past.

* Raise C++ standard from 11 to 17 for easier filesystem handling in
tests. Also included CMake script for handling how std::filesystem is
found/linked.

* Rename directory 'test' to 'tests'.

* Update README with testing instructions.

* Catch2 is downloaded and built unless otherwise specified
(undocumented, aside from reading CMake).
  • Loading branch information
ekilmer committed Mar 10, 2021
1 parent d38c7da commit 35baa3f
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 12 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

Expand All @@ -30,7 +30,7 @@ jobs:
pe-parse:
strategy:
matrix:
platform: ["ubuntu-latest", "macos-latest"]
platform: ["ubuntu-18.04", "macos-latest"]
build-type: ["Debug", "Release"]
build-shared: ["0", "1"]
compiler:
Expand All @@ -42,6 +42,8 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: build
env:
CC: ${{ matrix.compiler.CC }}
Expand All @@ -52,16 +54,20 @@ jobs:
cmake \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DPEPARSE_ENABLE_TESTING=ON \
..
cmake --build .
- name: test
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: |
./build/dump-pe/dump-pe ./test/assets/example.exe
cd build && ctest -V
./dump-pe/dump-pe ../tests/assets/example.exe
pepy:
strategy:
matrix:
platform: ["ubuntu-latest", "macos-latest"]
platform: ["ubuntu-18.04", "macos-latest"]
python:
- "3.6"
- "3.7"
Expand All @@ -81,7 +87,7 @@ jobs:
python3 -m pip install --user dist/*.tar.gz
- name: test
run: |
python3 test/test_pepy.py test/assets/example.exe
python3 tests/test_pepy.py tests/assets/example.exe
pe-parse-windows:
strategy:
Expand All @@ -92,6 +98,8 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: build
run: |
mkdir build
Expand All @@ -100,15 +108,20 @@ jobs:
-G "Visual Studio 16 2019" `
-A ${{ matrix.build-arch }} `
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} `
-DPEPARSE_ENABLE_TESTING=ON `
..
cmake --build . --config ${{ matrix.build-type }}
- name: install
run: |
cd build
cmake --build . --target install
cmake --build . --config ${{ matrix.build-type }} --target install
- name: test
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: |
.\build\bin\dump-pe.exe .\test\assets\example.exe
cd build
ctest -V
.\bin\dump-pe.exe ..\tests\assets\example.exe
pepy-windows:
strategy:
Expand All @@ -131,4 +144,4 @@ jobs:
python -m pip install --user .
- name: test
run: |
python test/test_pepy.py test/assets/example.exe
python tests/test_pepy.py tests/assets/example.exe
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test/assets/corkami-poc-dataset"]
path = tests/assets/corkami-poc-dataset
url = https://github.com/corkami/pocs
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ if (NOT CMAKE_BUILD_TYPE)
endif ()

include(cmake/compilation_flags.cmake)
# Greater c++17 filesystem compatibility (like with experimental)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
find_package(Filesystem COMPONENTS Experimental Final REQUIRED)
list(APPEND GLOBAL_CXXFLAGS ${DEFAULT_CXX_FLAGS})

option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
Expand Down Expand Up @@ -45,6 +48,8 @@ file(
dump-pe/*.cpp
examples/*.cpp
examples/*.h
tests/*.cpp
tests/*.h
)
add_custom_target(
peparse_format
Expand All @@ -58,3 +63,9 @@ message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Build Shared: ${BUILD_SHARED_LIBS} ${BUILD_SHARED_LIBS_MESSAGE}")
message(STATUS "Build Command Line Tools: ${BUILD_COMMAND_LINE_TOOLS}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")

option(PEPARSE_ENABLE_TESTING "Enable building tests" OFF)
if (PEPARSE_ENABLE_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ cmake -G "Visual Studio 16 2019" -A Win64 ..
cmake --build . --config Release
```

## Testing

You can build the (catch2-based) tests by adding `-DPEPARSE_ENABLE_TESTING=ON` during CMake configuration. Build, and then run with `ctest` or `cmake --build . --target test`.

To run the full test suite with the [Corkami test suite](https://github.com/corkami/pocs/tree/master/PE), you must clone the submodule with `git submodule update --init`.

## Using the library

Once the library is installed, linking to it is easy! Add the following lines in your CMake project:
Expand Down
8 changes: 4 additions & 4 deletions cmake/compilation_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (MSVC)
list(APPEND DEFAULT_CXX_FLAGS /W4 /analyze)

Expand All @@ -10,10 +14,6 @@ if (MSVC)
endif ()

else ()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (NOT MINGW)
list(APPEND DEFAULT_CXX_FLAGS -fPIC)
endif ()
Expand Down
Loading

0 comments on commit 35baa3f

Please sign in to comment.