Skip to content

Commit

Permalink
Tests: Add initial set of unit tests for Detours (#137)
Browse files Browse the repository at this point in the history
- Import the Catch2 self-contained C++ test framework.
  It's used by many Microsoft OSS projects:
  - https://github.com/microsoft/cppwinrt/tree/master/test
  - https://github.com/microsoft/wil/tree/master/tests
  As well as many OSS projects in general.

  When the CMake PR is merged, we can remove this as
  a checked in development dependency, and can instead
  download it using CMake.

- Start basic set of unit tests to validate failure modes of

- Hook the execution into the existing NMake build system.

- Hook test execution into CI pipeline
  • Loading branch information
bgianfo committed Dec 2, 2020
1 parent d8b8144 commit 2de2bab
Show file tree
Hide file tree
Showing 9 changed files with 18,171 additions and 13 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ on:

jobs:
build:
runs-on: windows-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2019, windows-2016]
arch: [x86, x64, x64_arm, x64_arm64]

steps:
Expand All @@ -43,28 +45,33 @@ jobs:
with:
arch: ${{ matrix.arch }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL for C++
uses: github/codeql-action/init@v1
if: ${{ matrix.os == 'windows-2019' }}
with:
languages: cpp
config-file: ./.github/codeql/codeql-config.yml

# Actually run the build
- name: Build Detours for ${{ matrix.arch }}
- name: Build Detours for ${{ matrix.arch }} on ${{ matrix.os }}
env:
# Tell detours what process to target
DETOURS_TARGET_PROCESSOR: ${{ env.VSCMD_ARG_TGT_ARCH }}
run: nmake

# Upload artifacts for this subsection of the build matrix.
- name: Upload artifacts for ${{ matrix.arch }}
- name: Run unit tests for ${{ matrix.arch }} on ${{ matrix.os }}
id: run-unit-tests
run: cd tests && nmake test
if: ${{ matrix.arch == 'x86' || matrix.arch == 'x64' }}

- name: Upload artifacts for ${{ matrix.arch }} on ${{ matrix.os }}
uses: actions/upload-artifact@v2
with:
with:
name: artifacts-${{ matrix.os }}
path: |
lib.*/
bin.*/
include/
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
if: ${{ matrix.os == 'windows-2019' }}
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,38 @@ ROOT = .

all:
cd "$(MAKEDIR)"
@if exist "$(MAKEDIR)\core\makefile" cd "$(MAKEDIR)\core" && $(MAKE) /NOLOGO /$(MAKEFLAGS)
@if exist "$(MAKEDIR)\core\makefile" cd "$(MAKEDIR)\core" && $(MAKE) /NOLOGO /$(MAKEFLAGS)
cd "$(MAKEDIR)\src"
@$(MAKE) /NOLOGO /$(MAKEFLAGS)
cd "$(MAKEDIR)\samples"
@$(MAKE) /NOLOGO /$(MAKEFLAGS)
@if exist "$(MAKEDIR)\bugs\makefile" cd "$(MAKEDIR)\bugs" && $(MAKE) /NOLOGO /$(MAKEFLAGS)
cd "$(MAKEDIR)\tests"
@$(MAKE) /NOLOGO /$(MAKEFLAGS)
@if exist "$(MAKEDIR)\bugs\makefile" cd "$(MAKEDIR)\bugs" && $(MAKE) /NOLOGO /$(MAKEFLAGS)
cd "$(MAKEDIR)"

clean:
cd "$(MAKEDIR)"
@if exist "$(MAKEDIR)\core\makefile" cd "$(MAKEDIR)\core" && $(MAKE) /NOLOGO /$(MAKEFLAGS) clean
@if exist "$(MAKEDIR)\core\makefile" cd "$(MAKEDIR)\core" && $(MAKE) /NOLOGO /$(MAKEFLAGS) clean
cd "$(MAKEDIR)\src"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) clean
cd "$(MAKEDIR)\samples"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) clean
@if exist "$(MAKEDIR)\bugs\makefile" cd "$(MAKEDIR)\bugs" && $(MAKE) /NOLOGO /$(MAKEFLAGS) clean
cd "$(MAKEDIR)\tests"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) clean
@if exist "$(MAKEDIR)\bugs\makefile" cd "$(MAKEDIR)\bugs" && $(MAKE) /NOLOGO /$(MAKEFLAGS) clean
cd "$(MAKEDIR)"

realclean: clean
cd "$(MAKEDIR)"
@if exist "$(MAKEDIR)\core\makefile" cd "$(MAKEDIR)\core" && $(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
@if exist "$(MAKEDIR)\core\makefile" cd "$(MAKEDIR)\core" && $(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
cd "$(MAKEDIR)\src"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
cd "$(MAKEDIR)\samples"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
@if exist "$(MAKEDIR)\bugs\makefile" cd "$(MAKEDIR)\bugs" && $(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
cd "$(MAKEDIR)\tests"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
@if exist "$(MAKEDIR)\bugs\makefile" cd "$(MAKEDIR)\bugs" && $(MAKE) /NOLOGO /$(MAKEFLAGS) realclean
cd "$(MAKEDIR)"
-rmdir /q /s $(INCDS) 2> nul
-rmdir /q /s $(LIBDS) 2> nul
Expand All @@ -50,6 +56,8 @@ realclean: clean
test:
cd "$(MAKEDIR)\samples"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) test
cd "$(MAKEDIR)\tests"
@$(MAKE) /NOLOGO /$(MAKEFLAGS) test
cd "$(MAKEDIR)"

################################################################# End of File.
66 changes: 66 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
##############################################################################
##
## Detours Unit Tests.
##
## Microsoft Research Detours Package
##
## Copyright (c) Microsoft Corporation. All rights reserved.
##

ROOT = ..
!include ..\samples\common.mak

DEPS = $(LIBD)\detours.lib
LIBS=$(LIBS) kernel32.lib
CFLAGS=$(CFLAGS) /EHsc /DCATCH_CONFIG_NO_WINDOWS_SEH

##############################################################################

all: dirs \
$(BIND)\unittests.exe \
\

##############################################################################

dirs:
@if not exist $(BIND) mkdir $(BIND) && echo. Created $(BIND)
@if not exist $(OBJD) mkdir $(OBJD) && echo. Created $(OBJD)

$(OBJD)\main.obj : main.cpp
$(OBJD)\test_module_api.obj : test_module_api.cpp
$(OBJD)\test_image_api.obj : test_image_api.cpp
$(OBJD)\corruptor.obj : corruptor.cpp

$(BIND)\unittests.exe : $(OBJD)\main.obj \
$(OBJD)\test_module_api.obj \
$(OBJD)\test_image_api.obj \
$(OBJD)\corruptor.obj $(DEPS)
cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
$(OBJD)\main.obj \
$(OBJD)\test_module_api.obj \
$(OBJD)\test_image_api.obj \
$(OBJD)\corruptor.obj \
/link $(LINKFLAGS) $(LIBS) /subsystem:console

##############################################################################

clean:
-del *~ 2>nul
-del $(BIND)\unittests*.* 2>nul
-rmdir /q /s $(OBJD) 2>nul

realclean: clean
-rmdir /q /s $(OBJDS) 2>nul

option:
##############################################################################

test: all
@cls
$(BIND)\unittests.exe --reporter console --success --durations yes

debug: all
windbg -o $(BIND)\unittests.exe


################################################################# End of File.
Loading

0 comments on commit 2de2bab

Please sign in to comment.