From 5fe7b17d989f66bee8bd461d8558d0e60f18df0b Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 8 Dec 2008 17:39:30 -0500 Subject: [PATCH] ENH: adding functionality for finding Squish, adding Squish tests from CMake, and running Squish tests from ctest --- Modules/FindSquish.cmake | 119 +++++++++++++++++++++++++++++++++ Modules/SquishRunTestCase.bat | 11 +++ Modules/SquishRunTestCase.sh | 13 ++++ Modules/SquishTestScript.cmake | 59 ++++++++++++++++ 4 files changed, 202 insertions(+) create mode 100644 Modules/FindSquish.cmake create mode 100755 Modules/SquishRunTestCase.bat create mode 100755 Modules/SquishRunTestCase.sh create mode 100644 Modules/SquishTestScript.cmake diff --git a/Modules/FindSquish.cmake b/Modules/FindSquish.cmake new file mode 100644 index 000000000..d51a04b8a --- /dev/null +++ b/Modules/FindSquish.cmake @@ -0,0 +1,119 @@ +# +# ---- Find Squish +# This module can be used to find Squish (currently support is aimed at version 3). +# +# ---- Variables and Macros +# SQUISH_FOUND If false, don't try to use Squish +# SQUISH_VERSION_MAJOR The major version of Squish found +# SQUISH_VERSION_MINOR The minor version of Squish found +# SQUISH_VERSION_PATCH The patch version of Squish found +# +# SQUISH_INSTALL_DIR The Squish installation directory (containing bin, lib, etc) +# SQUISH_SERVER_EXECUTABLE The squishserver executable +# SQUISH_CLIENT_EXECUTABLE The squishrunner executable +# +# SQUISH_INSTALL_DIR_FOUND Was the install directory found? +# SQUISH_SERVER_EXECUTABLE_FOUND Was the server executable found? +# SQUISH_CLIENT_EXECUTABLE_FOUND Was the client executable found? +# +# macro SQUISH_ADD_TEST(testName applicationUnderTest testSuite testCase) +# +# ---- Typical Use +# ENABLE_TESTING() +# FIND_PACKAGE(Squish) +# IF (SQUISH_FOUND) +# SQUISH_ADD_TEST(myTestName myApplication testSuiteName testCaseName) +# ENDIF (SQUISH_FOUND) +# + +SET(SQUISH_INSTALL_DIR_STRING "Directory containing the bin, doc, and lib directories for Squish; this should be the root of the installation directory.") +SET(SQUISH_SERVER_EXECUTABLE_STRING "The squishserver executable program.") +SET(SQUISH_CLIENT_EXECUTABLE_STRING "The squishclient executable program.") + +# Search only if the location is not already known. +IF(NOT SQUISH_INSTALL_DIR) + # Get the system search path as a list. + IF(UNIX) + STRING(REGEX MATCHALL "[^:]+" SQUISH_INSTALL_DIR_SEARCH1 "$ENV{PATH}") + ELSE(UNIX) + STRING(REGEX REPLACE "\\\\" "/" SQUISH_INSTALL_DIR_SEARCH1 "$ENV{PATH}") + ENDIF(UNIX) + STRING(REGEX REPLACE "/;" ";" SQUISH_INSTALL_DIR_SEARCH2 ${SQUISH_INSTALL_DIR_SEARCH1}) + + # Construct a set of paths relative to the system search path. + SET(SQUISH_INSTALL_DIR_SEARCH "") + FOREACH(dir ${SQUISH_INSTALL_DIR_SEARCH2}) + SET(SQUISH_INSTALL_DIR_SEARCH ${SQUISH_INSTALL_DIR_SEARCH} "${dir}/../lib/fltk") + ENDFOREACH(dir) + + # Look for an installation + FIND_PATH(SQUISH_INSTALL_DIR bin/squishrunner + # Look for an environment variable SQUISH_INSTALL_DIR. + $ENV{SQUISH_INSTALL_DIR} + + # Look in places relative to the system executable search path. + ${SQUISH_INSTALL_DIR_SEARCH} + + # Look in standard UNIX install locations. + #/usr/local/squish + + DOC "The ${SQUISH_INSTALL_DIR_STRING}" + ) +ENDIF(NOT SQUISH_INSTALL_DIR) + +# search for the executables +IF(SQUISH_INSTALL_DIR) + SET(SQUISH_INSTALL_DIR_FOUND 1) + + # find the client program + IF(NOT SQUISH_CLIENT_EXECUTABLE) + FIND_PROGRAM(SQUISH_CLIENT_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishrunner DOC "The ${SQUISH_CLIENT_EXECUTABLE_STRING}") + ENDIF(NOT SQUISH_CLIENT_EXECUTABLE) + + # find the server program + IF(NOT SQUISH_SERVER_EXECUTABLE) + FIND_PROGRAM(SQUISH_SERVER_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishserver DOC "The ${SQUISH_SERVER_EXECUTABLE_STRING}") + ENDIF(NOT SQUISH_SERVER_EXECUTABLE) + +ELSE(SQUISH_INSTALL_DIR) + SET(SQUISH_INSTALL_DIR_FOUND 0) +ENDIF(SQUISH_INSTALL_DIR) + +# record if executables are set +IF(SQUISH_CLIENT_EXECUTABLE) + SET(SQUISH_CLIENT_EXECUTABLE_FOUND 1) +ELSE(SQUISH_CLIENT_EXECUTABLE) + SET(SQUISH_CLIENT_EXECUTABLE_FOUND 0) +ENDIF(SQUISH_CLIENT_EXECUTABLE) + +IF(SQUISH_SERVER_EXECUTABLE) + SET(SQUISH_SERVER_EXECUTABLE_FOUND 1) +ELSE(SQUISH_SERVER_EXECUTABLE) + SET(SQUISH_SERVER_EXECUTABLE_FOUND 0) +ENDIF(SQUISH_SERVER_EXECUTABLE) + +# record if Squish was found +SET(SQUISH_FOUND 1) +FOREACH(var SQUISH_INSTALL_DIR_FOUND SQUISH_CLIENT_EXECUTABLE_FOUND SQUISH_SERVER_EXECUTABLE_FOUND) + IF(NOT ${var}) + SET(SQUISH_FOUND 0) + ENDIF(NOT ${var}) +ENDFOREACH(var) + +MACRO(SQUISH_ADD_TEST testName testAUT testCase envVars testWraper) + ADD_TEST(${testName} + ${CMAKE_COMMAND} -V -VV + "-Dsquish_aut:STRING=${testAUT}" + "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}" + "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}" + "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}" + "-Dsquish_test_case:STRING=${testCase}" + "-Dsquish_env_vars:STRING=${envVars}" + "-Dsquish_wrapper:STRING=${testWraper}" + -P "${CMAKE_ROOT}/Modules/SquishTestScript.cmake" + ) + SET_TESTS_PROPERTIES(${testName} + PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED;ERROR;FATAL" + ) +ENDMACRO(SQUISH_ADD_TEST) + diff --git a/Modules/SquishRunTestCase.bat b/Modules/SquishRunTestCase.bat new file mode 100755 index 000000000..5c5d388b0 --- /dev/null +++ b/Modules/SquishRunTestCase.bat @@ -0,0 +1,11 @@ +echo 'Starting the squish server...' +start %1 + +echo 'Running the test case...' +%2 --testcase %3 --wrapper %4 --aut %5 +set result=%ERRORLEVEL% + +echo 'Stopping the squish server...' +%1 --stop + +exit \b %result% diff --git a/Modules/SquishRunTestCase.sh b/Modules/SquishRunTestCase.sh new file mode 100755 index 000000000..409b46a3e --- /dev/null +++ b/Modules/SquishRunTestCase.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +echo "Starting the squish server...$1 --daemon" +$1 --daemon + +echo "Running the test case...$2 --testcase $3 --wrapper $4 --aut $5" +$2 --testcase $3 --wrapper $4 --aut $5 +returnValue=$? + +echo "Stopping the squish server...$1 --stop" +$1 --stop + +exit $returnValue diff --git a/Modules/SquishTestScript.cmake b/Modules/SquishTestScript.cmake new file mode 100644 index 000000000..775134579 --- /dev/null +++ b/Modules/SquishTestScript.cmake @@ -0,0 +1,59 @@ +# +# This script launches a GUI test using Squish. You should not call +# the script directly; instead, you should acces it via the +# SQUISH_ADD_TEST macro that is defined in FindSquish.cmake. +# +# This script starts the Squish server, launches the test on the +# client, and finally stops the squish server. If any of these steps +# fail (including if the tests do not pass) then a fatal error is +# raised. +# + +cmake_minimum_required(VERSION 2.6 FATAL_ERROR) + +# print out the variable that we are using +message(STATUS "squish_aut='${squish_aut}'") + +message(STATUS "squish_server_executable='${squish_server_executable}'") +message(STATUS "squish_client_executable='${squish_client_executable}'") +message(STATUS "squish_libqtdir ='${squish_libqtdir}'") +message(STATUS "squish_test_case='${squish_test_case}'") +message(STATUS "squish_wrapper='${squish_wrapper}'") +message(STATUS "squish_env_vars='${squish_env_vars}'") + +# parse enviornment variables +foreach(i ${squish_env_vars}) + message(STATUS "parsing env var key/value pair ${i}") + string(REGEX MATCH "([^=]*)=(.*)" squish_env_name ${i}) + message(STATUS "key=${CMAKE_MATCH_1}") + message(STATUS "value=${CMAKE_MATCH_2}") + set ( ENV{${CMAKE_MATCH_1}} ${CMAKE_MATCH_2} ) +endforeach() + +if (QT4_INSTALLED) + # record qt lib directory + set ( ENV{${SQUISH_LIBQTDIR}} ${squish_libqtdir} ) +endif (QT4_INSTALLED) + +# run the test +if (WIN32) + execute_process( + COMMAND ${CMAKE_ROOT}/Modules/SquishRunTestCase.bat ${squish_server_executable} ${squish_client_executable} ${squish_test_case} ${squish_wrapper} ${squish_aut} + RESULT_VARIABLE test_rv + ) +endif (WIN32) + +if (UNIX) + execute_process( + COMMAND ${CMAKE_ROOT}/Modules/SquishRunTestCase.sh ${squish_server_executable} ${squish_client_executable} ${squish_test_case} ${squish_wrapper} ${squish_aut} + RESULT_VARIABLE test_rv + ) +endif (UNIX) + +# check for an error with running the test +if(NOT "${test_rv}" STREQUAL "0") + message(FATAL_ERROR "Error running Squish test") +endif(NOT "${test_rv}" STREQUAL "0") + + +