From 76aa6cc293b32681bb3350bda2be90a97c0acd0f Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 28 Aug 2009 19:13:13 +0000
Subject: [PATCH] DEV-38596: Introduce Mani's LL_ADD_INTEGRATION_TEST macro.
 LL_ADD_INTEGRATION_TEST supports tests that may require linking against one
 or more Linden libraries, or that should be executed with a wrapper script.
 Use this to test lllazy.cpp, llsdmessage.cpp and llcapabilitylistener.cpp.

---
 indra/cmake/LLAddBuildTest.cmake | 76 ++++++++++++++++++++++++++++++++
 indra/llcommon/CMakeLists.txt    |  5 ++-
 indra/llmessage/CMakeLists.txt   | 17 +++++++
 indra/newview/CMakeLists.txt     | 17 +++++++
 4 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/indra/cmake/LLAddBuildTest.cmake b/indra/cmake/LLAddBuildTest.cmake
index 4a61725e091..7d6ef9ab1a7 100644
--- a/indra/cmake/LLAddBuildTest.cmake
+++ b/indra/cmake/LLAddBuildTest.cmake
@@ -148,3 +148,79 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources)
   ADD_DEPENDENCIES(${project} ${project}_tests)
 ENDMACRO(LL_ADD_PROJECT_UNIT_TESTS)
 
+FUNCTION(LL_ADD_INTEGRATION_TEST 
+    testname
+    additional_source_files
+    library_dependencies
+# variable args
+    )
+  if(TEST_DEBUG)
+    message(STATUS "Adding INTEGRATION_TEST_${testname} - debug output is on")
+  endif(TEST_DEBUG)
+  
+  SET(source_files
+    tests/${testname}_test.cpp
+    ${CMAKE_SOURCE_DIR}/test/test.cpp
+    ${CMAKE_SOURCE_DIR}/test/lltut.cpp
+    ${additional_source_files}
+    )
+
+  SET(libraries
+    ${library_dependencies}
+    ${PTHREAD_LIBRARY}
+    )
+
+  # Add test executable build target
+  if(TEST_DEBUG)
+    message(STATUS "ADD_EXECUTABLE(INTEGRATION_TEST_${testname} ${source_files})")
+  endif(TEST_DEBUG)
+  ADD_EXECUTABLE(INTEGRATION_TEST_${testname} ${source_files})
+
+  # Add link deps to the executable
+  if(TEST_DEBUG)
+    message(STATUS "TARGET_LINK_LIBRARIES(INTEGRATION_TEST_${testname} ${libraries})")
+  endif(TEST_DEBUG)
+  TARGET_LINK_LIBRARIES(INTEGRATION_TEST_${testname} ${libraries})
+
+  # Create the test running command
+  SET(test_command ${ARGN})
+  GET_TARGET_PROPERTY(TEST_EXE INTEGRATION_TEST_${testname} LOCATION)
+  LIST(FIND test_command "{}" test_exe_pos)
+  IF(test_exe_pos LESS 0)
+    # The {} marker means "the full pathname of the test executable."
+    # test_exe_pos -1 means we didn't find it -- so append the test executable
+    # name to $ARGN, the variable part of the arg list. This is convenient
+    # shorthand for both straightforward execution of the test program (empty
+    # $ARGN) and for running a "wrapper" program of some kind accepting the
+    # pathname of the test program as the last of its args. You need specify
+    # {} only if the test program's pathname isn't the last argument in the
+    # desired command line.
+    LIST(APPEND test_command "${TEST_EXE}")
+  ELSE (test_exe_pos LESS 0)
+    # Found {} marker at test_exe_pos. Remove the {}...
+    LIST(REMOVE_AT test_command test_exe_pos)
+    # ...and replace it with the actual name of the test executable.
+    LIST(INSERT test_command test_exe_pos "${TEST_EXE}")
+  ENDIF (test_exe_pos LESS 0)
+
+  SET(TEST_SCRIPT_CMD 
+    ${CMAKE_COMMAND} 
+    -DLD_LIBRARY_PATH=${ARCH_PREBUILT_DIRS}:/usr/lib
+    -DTEST_CMD:STRING="${test_command}" 
+    -P ${CMAKE_SOURCE_DIR}/cmake/RunBuildTest.cmake
+    )
+
+  if(TEST_DEBUG)
+    message(STATUS "TEST_SCRIPT_CMD: ${TEST_SCRIPT_CMD}")
+  endif(TEST_DEBUG)
+
+  ADD_CUSTOM_COMMAND(
+    TARGET INTEGRATION_TEST_${testname}
+    POST_BUILD
+    COMMAND ${TEST_SCRIPT_CMD}
+    )
+
+  # Use CTEST? Not sure how to yet...
+  # ADD_TEST(INTEGRATION_TEST_RUNNER_${testname} ${TEST_SCRIPT_CMD})
+
+ENDFUNCTION(LL_ADD_INTEGRATION_TEST)
\ No newline at end of file
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 4b24a7ad2b1..9f1b0b48d8a 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -239,8 +239,11 @@ SET(llcommon_TEST_SOURCE_FILES
   )
 LL_ADD_PROJECT_UNIT_TESTS(llcommon "${llcommon_TEST_SOURCE_FILES}")
 
+#set(TEST_DEBUG on)
+set(test_libs llcommon ${LLCOMMON_LIBRARIES} ${WINDOWS_LIBRARIES})
+LL_ADD_INTEGRATION_TEST(lllazy lllazy.cpp "${test_libs}")
+
 # *TODO - reenable these once tcmalloc libs no longer break the build.
 #ADD_BUILD_TEST(llallocator llcommon)
 #ADD_BUILD_TEST(llallocator_heap_profile llcommon)
 #ADD_BUILD_TEST(llmemtype llcommon)
-
diff --git a/indra/llmessage/CMakeLists.txt b/indra/llmessage/CMakeLists.txt
index 88f83ba78ef..536a586b00f 100644
--- a/indra/llmessage/CMakeLists.txt
+++ b/indra/llmessage/CMakeLists.txt
@@ -222,6 +222,23 @@ IF (NOT LINUX AND VIEWER)
       lltrustedmessageservice.cpp
       lltemplatemessagedispatcher.cpp
       )
+#    set(TEST_DEBUG on)
+    set(test_libs
+      ${LLMESSAGE_LIBRARIES}
+      ${WINDOWS_LIBRARIES}
+      ${LLVFS_LIBRARIES}
+      ${LLMATH_LIBRARIES}
+      ${LLCOMMON_LIBRARIES}
+      )
+
+    LL_ADD_INTEGRATION_TEST(
+      llsdmessage
+      "llsdmessage.cpp"
+      "${test_libs}"
+      ${PYTHON_EXECUTABLE}
+      "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_llsdmessage_peer.py"
+      )
+
     LL_ADD_PROJECT_UNIT_TESTS(llmessage "${llmessage_TEST_SOURCE_FILES}")
     
     # Commented out - see rationale at bottom of newview's build file + poppy 2009-06-05
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 52df1dd2417..43d5f70b2fd 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -1522,6 +1522,23 @@ set_source_files_properties(
   )
 LL_ADD_PROJECT_UNIT_TESTS(${VIEWER_BINARY_NAME} "${viewer_TEST_SOURCE_FILES}")
 
+#set(TEST_DEBUG on)
+set(test_sources llcapabilitylistener.cpp llviewerprecompiledheaders.cpp)
+set(test_libs 
+  ${LLMESSAGE_LIBRARIES} 
+  ${WINDOWS_LIBRARIES} 
+  ${LLVFS_LIBRARIES}
+  ${LLMATH_LIBRARIES}
+  ${LLCOMMON_LIBRARIES} 
+  )
+
+LL_ADD_INTEGRATION_TEST(llcapabilitylistener 
+  "${test_sources}" 
+  "${test_libs}"
+  ${PYTHON_EXECUTABLE}
+  "${CMAKE_SOURCE_DIR}/llmessage/tests/test_llsdmessage_peer.py"
+  )
+
 #ADD_VIEWER_BUILD_TEST(llmemoryview viewer)
 
 
-- 
GitLab