From 914bc03c4ed200f495288d8483f4b9909368b4fd Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 18 Mar 2015 17:57:29 +0100 Subject: [PATCH] Properly allow plugins to load for testing Loads stuff from the cmake binary directory for testing -- so tests use the newly built plugins and not some old installed ones (or fail if none exist) --- CMakeLists.txt | 6 +++--- src/Config.hxx.in | 6 +++++- src/bindings/Guile.cxx | 2 +- src/main.cxx | 2 +- src/test.cxx | 18 ++++++++++++------ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 242fbfc..aa3d082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ find_package(PkgConfig) pkg_check_modules(LOG4CXX REQUIRED liblog4cxx) pkg_check_modules(GUILE REQUIRED guile-2.0) FIND_PACKAGE(SWIG REQUIRED) +find_program(SWIG_EXECUTABLE NAMES swig3.0) INCLUDE(${SWIG_USE_FILE}) add_definitions(${LOG4CXX_CFLAGS}) @@ -134,10 +135,9 @@ qt5_use_modules(fridatest Widgets) #ADD_SUBDIRECTORY(/usr/src/gtest gtest) ADD_SUBDIRECTORY(/usr/src/gmock gmock) enable_testing() -target_link_libraries(fridatest gmock gtest ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES}) add_test(NAME fridatest COMMAND fridatest ${CMAKE_SOURCE_DIR}) - - +target_link_libraries(fridatest gmock gtest ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES}) +target_compile_options(fridatest PRIVATE -DCONFIG_TEST) install(TARGETS frida RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/Config.hxx.in b/src/Config.hxx.in index 6ad3f49..394e5d6 100644 --- a/src/Config.hxx.in +++ b/src/Config.hxx.in @@ -1,6 +1,10 @@ #ifndef INCLUDE__Config_hxx_ #define INCLUDE__Config_hxx_ -#cmakedefine CMAKE_INSTALL_FULL_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@" +#ifdef CONFIG_TEST +# define CONFIG_LIBDIR "@CMAKE_CURRENT_BINARY_DIR@" +#else +# define CONFIG_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@" +#endif #endif /* INCLUDE__Config_hxx_ */ diff --git a/src/bindings/Guile.cxx b/src/bindings/Guile.cxx index 86ab6dd..c452e76 100644 --- a/src/bindings/Guile.cxx +++ b/src/bindings/Guile.cxx @@ -13,7 +13,7 @@ GuileInterpreter::GuileInterpreter() { scm_c_use_module("system repl server"); scm_call_0(scm_c_public_ref("system repl server", "spawn-server")); - scm_c_load_extension(CMAKE_INSTALL_FULL_LIBDIR "/frida/plugins/Interpreter/libguile-frida-binding", + scm_c_load_extension(CONFIG_LIBDIR "/frida/plugins/Interpreter/libguile-frida-binding", "scm_init_frida_module"); guile_output_port = scm_open_output_string(); diff --git a/src/main.cxx b/src/main.cxx index a627b61..d284d4f 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -33,7 +33,7 @@ int main(int argc, char** argv) QApplication::setApplicationName("frida"); QApplication::setApplicationVersion("0.0"); - QApplication::addLibraryPath(CMAKE_INSTALL_FULL_LIBDIR "/frida/plugins/Interpreter"); + QApplication::addLibraryPath(CONFIG_LIBDIR "/frida/plugins/Interpreter"); #ifdef ARGPARSE parser.addHelpOption(); parser.addVersionOption(); diff --git a/src/test.cxx b/src/test.cxx index 596fe3d..9f73274 100644 --- a/src/test.cxx +++ b/src/test.cxx @@ -1,14 +1,20 @@ #include +#include "log4cxx/logger.h" +#include "log4cxx/basicconfigurator.h" +#include +#include "Config.hxx" char* TEST_DATA_DIRECTORY; int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); + log4cxx::BasicConfigurator::configure(); - if (argc > 1) - TEST_DATA_DIRECTORY = argv[1]; - else - TEST_DATA_DIRECTORY = "./"; + QApplication::addLibraryPath(CONFIG_LIBDIR); + if (argc > 1) + TEST_DATA_DIRECTORY = argv[1]; + else + TEST_DATA_DIRECTORY = "./"; - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); } -- 2.39.2