aboutsummaryrefslogtreecommitdiff
path: root/tests/CMakeLists.txt
diff options
context:
space:
mode:
authorZeex <zeex@rocketmail.com>2018-09-06 15:44:52 +0600
committerZeex <zeex@rocketmail.com>2018-09-06 15:46:22 +0600
commit221648a4f9dde4fc84bb373061809cc435f1aa0b (patch)
treeb8892e528c4879529113877248b7d863add73e83 /tests/CMakeLists.txt
parent208062855a81f88456a87f6624ca21847c33f48f (diff)
downloadsubhook-221648a4f9dde4fc84bb373061809cc435f1aa0b.zip
subhook-221648a4f9dde4fc84bb373061809cc435f1aa0b.tar.gz
subhook-221648a4f9dde4fc84bb373061809cc435f1aa0b.tar.bz2
Rename test executable target to subhook_test and test -> tests
Diffstat (limited to 'tests/CMakeLists.txt')
-rw-r--r--tests/CMakeLists.txt92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..1b2514e
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,92 @@
+find_package(Yasm REQUIRED)
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUBHOOK_FORCE_32BIT)
+ set(BITS 32)
+else()
+ set(BITS 64)
+endif()
+
+set(asm_file foo_${BITS}.asm)
+if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT SUBHOOK_FORCE_32BIT)
+ if(WIN32)
+ set(asm_file foo_64_win.asm)
+ elseif(UNIX)
+ set(asm_file foo_64_unix.asm)
+ endif()
+endif()
+
+if(WIN32)
+ set(asm_format "win${BITS}")
+elseif(APPLE)
+ set(asm_format "macho${BITS}")
+else()
+ set(asm_format "elf${BITS}")
+endif()
+
+set(options "-f" "${asm_format}")
+if(APPLE
+ OR (WIN32 AND (CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUBHOOK_FORCE_32BIT)))
+ list(APPEND options "--prefix=_")
+endif()
+if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ list(APPEND options "-DUSE_PLT")
+endif()
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${asm_file}.obj"
+ COMMAND "${YASM_EXECUTABLE}" ${options} "-o"
+ "${CMAKE_CURRENT_BINARY_DIR}/${asm_file}.obj"
+ "${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}"
+ MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}"
+)
+
+add_executable(subhook_test
+ test.c
+ "${CMAKE_CURRENT_BINARY_DIR}/${asm_file}.obj"
+)
+
+set_target_properties(subhook_test PROPERTIES OUTPUT_NAME test)
+
+if(SUBHOOK_FORCE_32BIT)
+ if(APPLE)
+ set_target_properties(subhook_test PROPERTIES OSX_ARCHITECTURES i386)
+ endif()
+ if(UNIX)
+ set_property(TARGET subhook_test APPEND_STRING PROPERTY
+ COMPILE_FLAGS " -m32")
+ set_property(TARGET subhook_test APPEND_STRING PROPERTY LINK_FLAGS " -m32")
+ endif()
+endif()
+
+target_link_libraries(subhook_test subhook)
+
+if(MSVC)
+ set_property(TARGET subhook_test
+ APPEND_STRING PROPERTY LINK_FLAGS " /INCREMENTAL:NO")
+endif()
+
+if(APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT SUBHOOK_FORCE_32BIT)
+ set_property(TARGET subhook_test APPEND_STRING PROPERTY
+ LINK_FLAGS " -Wl,-no_pie")
+endif()
+
+add_test(NAME test COMMAND $<TARGET_FILE:subhook_test>)
+
+set(expected_output "\
+Testing initial install[\r\n]+\
+foo_hooked\\(\\) called[\r\n]+\
+foo\\(\\) called[\r\n]+\
+Testing re-install[\r\n]+\
+foo_hooked\\(\\) called[\r\n]+\
+foo\\(\\) called[\r\n]+\
+Testing trampoline[\r\n]+\
+foo_hooked_tr\\(\\) called[\r\n]+\
+foo\\(\\) called[\r\n]+\
+")
+set_tests_properties(test PROPERTIES
+ PASS_REGULAR_EXPRESSION "${expected_output}")
+
+if(WIN32 AND NOT SUBHOOK_STATIC)
+ set_tests_properties(test PROPERTIES
+ ENVIRONMENT PATH=$<TARGET_FILE_DIR:subhook>)
+endif()