Browse Source

ENH: add testing for modules and one two config modes for cmaketest

Bill Hoffman 23 years ago
parent
commit
c6d2312619

+ 11 - 0
Source/CMakeLists.txt

@@ -156,12 +156,23 @@ IF(BUILD_TESTING)
       ${CMake_BINARY_DIR}/Tests/LoadCommand 
       ${CMake_BINARY_DIR}/Tests/LoadCommand 
       LoadedCommand)
       LoadedCommand)
 
 
+    ADD_TEST(LoadedCommandOneConfig ${CMake_BINARY_DIR}/Source/cmaketest 
+      ${CMake_SOURCE_DIR}/Tests/LoadCommand 
+      ${CMake_BINARY_DIR}/Tests/LoadCommandOneConfig
+      LoadedCommand ONLY_ONE_CONFIG)
+
     ADD_TEST(complex ${CMake_BINARY_DIR}/Source/cmaketest 
     ADD_TEST(complex ${CMake_BINARY_DIR}/Source/cmaketest 
       ${CMake_SOURCE_DIR}/Tests/Complex 
       ${CMake_SOURCE_DIR}/Tests/Complex 
       ${CMake_BINARY_DIR}/Tests/Complex 
       ${CMake_BINARY_DIR}/Tests/Complex 
       complex 
       complex 
       ${CMake_BINARY_DIR}/Tests/Complex/bin)
       ${CMake_BINARY_DIR}/Tests/Complex/bin)
 
 
+    ADD_TEST(complexOneConfig ${CMake_BINARY_DIR}/Source/cmaketest 
+      ${CMake_SOURCE_DIR}/Tests/Complex 
+      ${CMake_BINARY_DIR}/Tests/ComplexOneConfig 
+      complex 
+      ${CMake_BINARY_DIR}/Tests/ComplexOneConfig/bin ONLY_ONE_CONFIG)
+
     ADD_TEST(Example ${CMake_BINARY_DIR}/Source/cmaketest 
     ADD_TEST(Example ${CMake_BINARY_DIR}/Source/cmaketest 
       ${CMake_SOURCE_DIR}/Example
       ${CMake_SOURCE_DIR}/Example
       ${CMake_BINARY_DIR}/Example
       ${CMake_BINARY_DIR}/Example

+ 23 - 9
Source/cmaketest.cxx

@@ -49,7 +49,16 @@ int do_cmaketest (int argc, char **argv)
               << "\t                     CMAKE_ARGS argument ...\n";
               << "\t                     CMAKE_ARGS argument ...\n";
     return 1;
     return 1;
     }
     }
-
+  bool onlyOneConfig = false;
+  if(argc > 3)
+    {
+    if(strcmp(argv[argc-1], "ONLY_ONE_CONFIG") == 0)
+      {
+      onlyOneConfig = true;
+      argc--;
+      }
+    }
+    
   // does the directory exist ?
   // does the directory exist ?
   if (!cmSystemTools::FileIsDirectory(argv[2]))
   if (!cmSystemTools::FileIsDirectory(argv[2]))
     {
     {
@@ -138,16 +147,21 @@ int do_cmaketest (int argc, char **argv)
     return 1;
     return 1;
     }
     }
   std::cout << "Done Generating build files.\n";
   std::cout << "Done Generating build files.\n";
-
-  std::cout << "Generating build files (again)...\n";
-  if (cm.Run(args) != 0)
+  // if the option ONLY_ONE_CONFIG is passed to the program
+  // only run the config step once
+  if(!onlyOneConfig)
     {
     {
-    std::cerr << "Error: cmake execution failed\n";
-    // return to the original directory
-    cmSystemTools::ChangeDirectory(cwd.c_str());
-    return 1;
+    std::cout << "Generating build files (again)...\n";
+    if (cm.Run(args) != 0)
+      {
+      std::cerr << "Error: cmake execution failed\n";
+      // return to the original directory
+      cmSystemTools::ChangeDirectory(cwd.c_str());
+      return 1;
+      }
+    std::cout << "Done Generating build files (again).\n";
     }
     }
-  std::cout << "Done Generating build files (again).\n";
+  
 
 
   cmListFileCache::GetInstance()->ClearCache();
   cmListFileCache::GetInstance()->ClearCache();
 
 

+ 26 - 0
Tests/Complex/Executable/complex.cxx

@@ -10,6 +10,7 @@ extern "C" {
 }
 }
 #include "cmStandardIncludes.h"
 #include "cmStandardIncludes.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
+#include "cmDynamicLoader.h"
 
 
 int cm_passed = 0;
 int cm_passed = 0;
 int cm_failed = 0;
 int cm_failed = 0;
@@ -101,6 +102,31 @@ void TestDir(const char* filename)
 
 
 int main()
 int main()
 {
 {
+  std::string lib = BINARY_DIR;
+  lib += "/bin/";
+  lib += cmDynamicLoader::LibPrefix();
+  lib += "CMakeTestModule";
+  lib += cmDynamicLoader::LibExtension();
+  
+  cmLibHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
+  if(!handle)
+    {
+    cmFailed("Can not open CMakeTestModule");
+    }
+  else
+    {
+    cmDynamicLoaderFunction fun = 
+      cmDynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); 
+    typedef int (*TEST_FUNCTION)();
+    TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
+    int ret = (*testFun)();
+    if(!ret)
+      {
+      cmFailed("ModuleFunction called from module did not return valid return");
+      }
+    cmPassed("Module loaded and ModuleFunction called correctly");
+    }
+    
   if(sharedFunction() != 1)
   if(sharedFunction() != 1)
     {
     {
     cmFailed("Call to sharedFunction from shared library failed.");
     cmFailed("Call to sharedFunction from shared library failed.");

+ 2 - 1
Tests/Complex/Library/CMakeLists.txt

@@ -38,6 +38,7 @@ ENDIF(WIN32)
 #
 #
 SOURCE_FILES(SharedLibrarySources sharedFile)
 SOURCE_FILES(SharedLibrarySources sharedFile)
 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
+ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c)
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
@@ -55,7 +56,7 @@ ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
 # The 'complex' executable will then test if this file exists and remove it.
 # The 'complex' executable will then test if this file exists and remove it.
 #
 #
 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
-
+MESSAGE("complex bin dir is ${Complex_BINARY_DIR}")
 ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
 ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
                    TARGET CMakeTestLibraryShared)
                    TARGET CMakeTestLibraryShared)

+ 6 - 0
Tests/Complex/Library/moduleFile.c

@@ -0,0 +1,6 @@
+#include "moduleFile.h"
+
+int ModuleFunction()
+{
+  return 1;
+}

+ 12 - 0
Tests/Complex/Library/moduleFile.h

@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestModule_EXPORTS
+#  define CMakeTest_EXPORT __declspec(dllexport)
+#else
+#  define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int ModuleFunction();

+ 26 - 0
Tests/ComplexOneConfig/Executable/complex.cxx

@@ -10,6 +10,7 @@ extern "C" {
 }
 }
 #include "cmStandardIncludes.h"
 #include "cmStandardIncludes.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
+#include "cmDynamicLoader.h"
 
 
 int cm_passed = 0;
 int cm_passed = 0;
 int cm_failed = 0;
 int cm_failed = 0;
@@ -101,6 +102,31 @@ void TestDir(const char* filename)
 
 
 int main()
 int main()
 {
 {
+  std::string lib = BINARY_DIR;
+  lib += "/bin/";
+  lib += cmDynamicLoader::LibPrefix();
+  lib += "CMakeTestModule";
+  lib += cmDynamicLoader::LibExtension();
+  
+  cmLibHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
+  if(!handle)
+    {
+    cmFailed("Can not open CMakeTestModule");
+    }
+  else
+    {
+    cmDynamicLoaderFunction fun = 
+      cmDynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); 
+    typedef int (*TEST_FUNCTION)();
+    TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
+    int ret = (*testFun)();
+    if(!ret)
+      {
+      cmFailed("ModuleFunction called from module did not return valid return");
+      }
+    cmPassed("Module loaded and ModuleFunction called correctly");
+    }
+    
   if(sharedFunction() != 1)
   if(sharedFunction() != 1)
     {
     {
     cmFailed("Call to sharedFunction from shared library failed.");
     cmFailed("Call to sharedFunction from shared library failed.");

+ 2 - 1
Tests/ComplexOneConfig/Library/CMakeLists.txt

@@ -38,6 +38,7 @@ ENDIF(WIN32)
 #
 #
 SOURCE_FILES(SharedLibrarySources sharedFile)
 SOURCE_FILES(SharedLibrarySources sharedFile)
 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
+ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c)
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
@@ -55,7 +56,7 @@ ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
 # The 'complex' executable will then test if this file exists and remove it.
 # The 'complex' executable will then test if this file exists and remove it.
 #
 #
 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
-
+MESSAGE("complex bin dir is ${Complex_BINARY_DIR}")
 ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
 ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
                    TARGET CMakeTestLibraryShared)
                    TARGET CMakeTestLibraryShared)

+ 6 - 0
Tests/ComplexOneConfig/Library/moduleFile.c

@@ -0,0 +1,6 @@
+#include "moduleFile.h"
+
+int ModuleFunction()
+{
+  return 1;
+}

+ 12 - 0
Tests/ComplexOneConfig/Library/moduleFile.h

@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestModule_EXPORTS
+#  define CMakeTest_EXPORT __declspec(dllexport)
+#else
+#  define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int ModuleFunction();

+ 26 - 0
Tests/ComplexRelativePaths/Executable/complex.cxx

@@ -10,6 +10,7 @@ extern "C" {
 }
 }
 #include "cmStandardIncludes.h"
 #include "cmStandardIncludes.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
+#include "cmDynamicLoader.h"
 
 
 int cm_passed = 0;
 int cm_passed = 0;
 int cm_failed = 0;
 int cm_failed = 0;
@@ -101,6 +102,31 @@ void TestDir(const char* filename)
 
 
 int main()
 int main()
 {
 {
+  std::string lib = BINARY_DIR;
+  lib += "/bin/";
+  lib += cmDynamicLoader::LibPrefix();
+  lib += "CMakeTestModule";
+  lib += cmDynamicLoader::LibExtension();
+  
+  cmLibHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
+  if(!handle)
+    {
+    cmFailed("Can not open CMakeTestModule");
+    }
+  else
+    {
+    cmDynamicLoaderFunction fun = 
+      cmDynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); 
+    typedef int (*TEST_FUNCTION)();
+    TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
+    int ret = (*testFun)();
+    if(!ret)
+      {
+      cmFailed("ModuleFunction called from module did not return valid return");
+      }
+    cmPassed("Module loaded and ModuleFunction called correctly");
+    }
+    
   if(sharedFunction() != 1)
   if(sharedFunction() != 1)
     {
     {
     cmFailed("Call to sharedFunction from shared library failed.");
     cmFailed("Call to sharedFunction from shared library failed.");

+ 2 - 1
Tests/ComplexRelativePaths/Library/CMakeLists.txt

@@ -38,6 +38,7 @@ ENDIF(WIN32)
 #
 #
 SOURCE_FILES(SharedLibrarySources sharedFile)
 SOURCE_FILES(SharedLibrarySources sharedFile)
 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
+ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c)
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
@@ -55,7 +56,7 @@ ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
 # The 'complex' executable will then test if this file exists and remove it.
 # The 'complex' executable will then test if this file exists and remove it.
 #
 #
 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
-
+MESSAGE("complex bin dir is ${Complex_BINARY_DIR}")
 ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
 ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
                    TARGET CMakeTestLibraryShared)
                    TARGET CMakeTestLibraryShared)

+ 6 - 0
Tests/ComplexRelativePaths/Library/moduleFile.c

@@ -0,0 +1,6 @@
+#include "moduleFile.h"
+
+int ModuleFunction()
+{
+  return 1;
+}

+ 12 - 0
Tests/ComplexRelativePaths/Library/moduleFile.h

@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(WIN32) /* Win32 version */
+#ifdef CMakeTestModule_EXPORTS
+#  define CMakeTest_EXPORT __declspec(dllexport)
+#else
+#  define CMakeTest_EXPORT __declspec(dllimport)
+#endif
+#else
+/* unix needs nothing */
+#define CMakeTest_EXPORT
+#endif
+
+CMakeTest_EXPORT int ModuleFunction();