summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib/PseudoMemcheck
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-12-16 18:59:22 (GMT)
committerBrad King <brad.king@kitware.com>2014-12-18 15:12:16 (GMT)
commit7ca6bdf0355157da9f85f6bbf039a632ffdf66b7 (patch)
tree0665524d4973903b38fa6779d85c328b6f2305b4 /Tests/CMakeLib/PseudoMemcheck
parent1651dc96683282c0af8ef47973db9afa950d6bde (diff)
downloadCMake-7ca6bdf0355157da9f85f6bbf039a632ffdf66b7.zip
CMake-7ca6bdf0355157da9f85f6bbf039a632ffdf66b7.tar.gz
CMake-7ca6bdf0355157da9f85f6bbf039a632ffdf66b7.tar.bz2
Tests: Move CTestTestMemcheck tools into Tests/CMakeLib
The dummy memcheck tools we build for the RunCMake.CTestMemcheck tests require CMakeLib, so put them in a Tests/CMakeLib/PseudoMemcheck directory.
Diffstat (limited to 'Tests/CMakeLib/PseudoMemcheck')
-rw-r--r--Tests/CMakeLib/PseudoMemcheck/CMakeLists.txt41
-rw-r--r--Tests/CMakeLib/PseudoMemcheck/NoLog/CMakeLists.txt22
-rw-r--r--Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in60
3 files changed, 123 insertions, 0 deletions
diff --git a/Tests/CMakeLib/PseudoMemcheck/CMakeLists.txt b/Tests/CMakeLib/PseudoMemcheck/CMakeLists.txt
new file mode 100644
index 0000000..c53befc
--- /dev/null
+++ b/Tests/CMakeLib/PseudoMemcheck/CMakeLists.txt
@@ -0,0 +1,41 @@
+foreach (_retval 0 1)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/memtester.cxx.in" "${CMAKE_CURRENT_BINARY_DIR}/ret${_retval}.cxx" @ONLY)
+endforeach ()
+
+include_directories(${CMake_SOURCE_DIR}/Source ${CMake_BINARY_DIR}/Source)
+
+# create binaries that we will use as a pseudo memory checker
+add_executable(pseudo_valgrind "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx")
+set_target_properties(pseudo_valgrind PROPERTIES OUTPUT_NAME valgrind)
+target_link_libraries(pseudo_valgrind CMakeLib)
+
+add_executable(pseudo_purify "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx")
+set_target_properties(pseudo_purify PROPERTIES OUTPUT_NAME purify)
+target_link_libraries(pseudo_purify CMakeLib)
+add_executable(pseudo_BC "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx")
+set_target_properties(pseudo_BC PROPERTIES OUTPUT_NAME BC)
+target_link_libraries(pseudo_BC CMakeLib)
+
+# binary to be used as pre- and post-memcheck command that fails
+add_executable(memcheck_fail "${CMAKE_CURRENT_BINARY_DIR}/ret1.cxx")
+target_link_libraries(memcheck_fail CMakeLib)
+
+# Binaries that are used as memchecker that do not write the expected
+# output file. Need to be in their own subdirectory as they have the
+# same filenames.
+add_subdirectory(NoLog)
+
+# Xcode 2.x forgets to create the output directory before linking
+# the individual architectures.
+if(CMAKE_OSX_ARCHITECTURES AND XCODE AND NOT "${XCODE_VERSION}" MATCHES "^[^12]")
+ foreach(t
+ memcheck_fail
+ pseudo_BC
+ pseudo_purify
+ pseudo_valgrind
+ )
+ add_custom_command(TARGET ${t}
+ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
+ )
+ endforeach()
+endif()
diff --git a/Tests/CMakeLib/PseudoMemcheck/NoLog/CMakeLists.txt b/Tests/CMakeLib/PseudoMemcheck/NoLog/CMakeLists.txt
new file mode 100644
index 0000000..3a45bfe
--- /dev/null
+++ b/Tests/CMakeLib/PseudoMemcheck/NoLog/CMakeLists.txt
@@ -0,0 +1,22 @@
+# A dummy checker implementation that does not write the requested output file
+# so it triggers an error for every checker.
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ret0.c.in" "int main(){return 0;}\n")
+
+configure_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/ret0.c.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/ret0.c"
+ )
+
+foreach(_pseudo IN ITEMS valgrind purify BC)
+ add_executable(pseudonl_${_pseudo} "${CMAKE_CURRENT_BINARY_DIR}/ret0.c")
+ set_target_properties(pseudonl_${_pseudo} PROPERTIES OUTPUT_NAME ${_pseudo})
+
+ # Xcode 2.x forgets to create the output directory before linking
+ # the individual architectures.
+ if(CMAKE_OSX_ARCHITECTURES AND XCODE AND NOT "${XCODE_VERSION}" MATCHES "^[^12]")
+ add_custom_command(TARGET pseudonl_${_pseudo}
+ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
+ )
+ endif()
+endforeach()
diff --git a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in
new file mode 100644
index 0000000..43c0ba7
--- /dev/null
+++ b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in
@@ -0,0 +1,60 @@
+#include <cmSystemTools.h>
+#include <cmsys/Encoding.hxx>
+#include <string>
+#include <locale.h>
+
+#define RETVAL @_retval@
+
+int
+main(int ac, char **av)
+{
+ setlocale(LC_CTYPE, "");
+ cmsys::Encoding::CommandLineArguments args =
+ cmsys::Encoding::CommandLineArguments::Main(ac, av);
+ int argc = args.argc();
+ const char* const* argv = args.argv();
+
+ std::string exename = argv[0];
+ std::string logarg;
+ bool nextarg = false;
+
+ if (exename.find("valgrind") != exename.npos)
+ logarg = "--log-file=";
+ else if (exename.find("purify") != exename.npos)
+#ifdef _WIN32
+ logarg = "/SAVETEXTDATA=";
+#else
+ logarg = "-log-file=";
+#endif
+ else if (exename.find("BC") != exename.npos)
+ {
+ nextarg = true;
+ logarg = "/X";
+ }
+
+ if (!logarg.empty()) {
+ std::string logfile;
+ for (int i = 1; i < argc; i++) {
+ std::string arg = argv[i];
+ if (arg.find(logarg) == 0)
+ {
+ if (nextarg)
+ {
+ if (i == argc - 1)
+ return 1; // invalid command line
+ logfile = argv[i + 1];
+ }
+ else
+ {
+ logfile = arg.substr(logarg.length());
+ }
+ // keep searching, it may be overridden later to provoke an error
+ }
+ }
+
+ if (!logfile.empty())
+ cmSystemTools::Touch(logfile.c_str(), true);
+ }
+
+ return RETVAL;
+}