From 57b04ac7f47b69d2dfaa419cbe5c1f8d6a09f5e0 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Tue, 11 Dec 2012 15:17:04 +0100 Subject: [PATCH] Cmake build: First try to use autotests. Many test are not running, but if changed the '-dbg xxx' to '-dbg any' then all of sudden they pass ... (The buffered output of lyx is often disrupted too early with 'kill -9', so the expected data are not available for the appropriate test) --- .gitignore | 1 + CMakeLists.txt | 1 + development/autotests/CMakeLists.txt | 38 +++++++++++++ development/autotests/export.cmake | 25 ++++++++ development/autotests/single-test.cmake | 66 ++++++++++++++++++++++ development/autotests/xvkbd/CMakeLists.txt | 33 +++++++++++ 6 files changed, 164 insertions(+) create mode 100644 development/autotests/CMakeLists.txt create mode 100755 development/autotests/export.cmake create mode 100755 development/autotests/single-test.cmake create mode 100644 development/autotests/xvkbd/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 35ede5be7f..5b82a0ad61 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ config.h config.log config.status lyx.1 +.history stamp-h1 *.old diff --git a/CMakeLists.txt b/CMakeLists.txt index ee59ff77a9..61777ef02e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -716,6 +716,7 @@ if(LYX_INSTALL) endif() add_subdirectory(sourcedoc "${TOP_BINARY_DIR}/sourcedoc") +add_subdirectory(development/autotests "${TOP_BINARY_DIR}/autotests") message(STATUS) message(STATUS "Build options, switch LYX_* variables by -DLYX_*=ON or OFF:") diff --git a/development/autotests/CMakeLists.txt b/development/autotests/CMakeLists.txt new file mode 100644 index 0000000000..9d7629b7a8 --- /dev/null +++ b/development/autotests/CMakeLists.txt @@ -0,0 +1,38 @@ +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. +# +# Copyright (c) 2012 Kornel Benko kornel@lyx.org +# + +if(UNIX) + project(autotests) + + add_subdirectory(xvkbd) + + set(KEYTEST "${CMAKE_CURRENT_SOURCE_DIR}/keytest.py") + set(LYX_HOME "out-home") + set(LYX_USERDIR "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}/.lyx") + set(LOCALE_DIR "${CMAKE_CURRENT_BINARY_DIR}/locale") + file(GLOB TESTST RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.txt") + file(GLOB TESTSS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.sh") + list(REMOVE_ITEM TESTST hello-world-in.txt first-time-in.txt) + list(SORT TESTST) + file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}") + + foreach(_tf first-time-in.txt hello-world-in.txt ${TESTST}) + string(REGEX REPLACE "-in\\.(txt|sh)" "" _t ${_tf}) + add_test(NAME "auto_${_t}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}" + COMMAND ${CMAKE_COMMAND} + -DAUTOTEST_ROOT=${TOP_SRC_DIR}/development/autotests + -DKEYTEST_INFILE=${_tf} + -DBINDIR=${TOP_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR} + -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME} + -DKEYTEST_OUTFILE=${_t}-out.txt + -P ${TOP_SRC_DIR}/development/autotests/single-test.cmake) + endforeach() + add_test(NAME lyx_export + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}" + COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${TOP_SRC_DIR} -Dlyx=${TOP_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/lyx -P "${TOP_SRC_DIR}/development/autotests/export.cmake") + set_tests_properties(lyx_export PROPERTIES DEPENDS lyx) +endif() diff --git a/development/autotests/export.cmake b/development/autotests/export.cmake new file mode 100755 index 0000000000..ceed5e433f --- /dev/null +++ b/development/autotests/export.cmake @@ -0,0 +1,25 @@ + +file(GLOB lyx_files "${LYX_ROOT}/lib/doc/*.lyx") +message(STATUS "lyx_files = ${lyx_files}") + +set(ERRORS) +foreach(format lyx16x xhtml) + foreach(f ${lyx_files}) + message(STATUS "Executing ${lyx} -e ${format} ${f}") + #execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${f} localtest.lyx) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove localtest.xhtml localtest.16.lyx) + execute_process( + COMMAND ${lyx} -E ${format} localtest.lyx ${f} + RESULT_VARIABLE _err) + string(COMPARE NOTEQUAL ${_err} 0 _erg) + if(_erg) + list(APPEND ERRORS "Exporting ${f} to ${format}") + endif() + endforeach() +endforeach() +if(ERRORS) + foreach(m ${ERRORS}) + message(STATUS ${m}) + endforeach() + message(FATAL_ERROR "Export failed") +endif() diff --git a/development/autotests/single-test.cmake b/development/autotests/single-test.cmake new file mode 100755 index 0000000000..5ab03161e0 --- /dev/null +++ b/development/autotests/single-test.cmake @@ -0,0 +1,66 @@ +# This script invokes the keytest.py script with the simple set-up needed +# to re-run deterministic regression tests that one would like to have. +# +# AUTOTEST_ROOT = ${LYX_ROOT}/development/autotests +# KEYTEST_INFILE = xxx-in.txt +# KEYTEST_OUTFILE = xxx-out.txt +# BINDIR = ${BUILD_DIR}/bin +# WORKDIR = ${BUILD_DIR}/autotests/out-home +# +# Script should be called like: +# cmake -DAUTOTEST_ROOT=xxxx \ +# -DKEYTEST_INFILE=xxxx \ +# -DKEYTEST_OUTFILE=xxx \ +# -DBINDIR=xxx \ +# -WWORKDIR=xxx \ +# -P ${AUTOTEST_ROOT}/single-test.cmake + +set(KEYTEST "${AUTOTEST_ROOT}/keytest.py") + +set(MAX_DROP 0) +execute_process(COMMAND pidof lyx OUTPUT_VARIABLE LYX_PID RESULT_VARIABLE pidstat OUTPUT_VARIABLE pidres) +message(STATUS "pidres = ${pidres}") +if (NOT pidstat) + # lyx already running, remove trailing '\n' from pid + string(REGEX REPLACE "\n" "" pidres ${pidres}) + execute_process(COMMAND wmctrl -l -p OUTPUT_VARIABLE _wmco) + string(REGEX REPLACE "[\n]+" ";" _wmc ${_wmco}) + foreach(_w ${_wmc}) + string(REGEX MATCH "${pidres}" _wr ${_w}) + if (${_wr} MATCHES ${pidres}) + # this entry contains the pid, go search for X11-window-id + string(REGEX REPLACE " .*" "" _wr ${_w}) + set(LYX_WINDOW_NAME ${_wr}) + message(STATUS "Set LYX_WINDOW_NAME to ${_wr}") + endif() + endforeach() +else() + set(pidres "") + set(LYX_WINDOW_NAME "") +endif() + +set(LYX_EXE "${BINDIR}/lyx") +set(XVKBD_EXE "${BINDIR}/xvkbd") + +# Environments needed by keytest.py +set(ENV{LYX_USERDIR} ${LYX_USERDIR}) +set(ENV{LYX_PID} ${pidres}) +set(ENV{LYX_WINDOW_NAME} ${LYX_WINDOW_NAME}) +set(ENV{LYX_EXE} ${LYX_EXE}) +set(ENV{XVKBD_EXE} ${XVKBD_EXE}) +set(ENV{KEYTEST_INFILE} "${AUTOTEST_ROOT}/${KEYTEST_INFILE}") +set(ENV{KEYTEST_OUTFILE} "${WORKDIR}/${KEYTEST_OUTFILE}") +set(ENV{MAX_DROP} 1) +file(GLOB _testfiles RELATIVE "${WORKDIR}" "test.*") +if(_testfiles) + # remove some leftover files from previous test + execute_process( + COMMAND ${CMAKE_COMMAND} -E remove -f ${_testfiles} ) +endif() +execute_process( + COMMAND python ${KEYTEST} + RESULT_VARIABLE KEYTEST_RES) +if(KEYTEST_RES) + message(FATAL_ERROR "KEYTEST failed: KEYTEST_RES=${KEYTEST_RES}") +endif() + diff --git a/development/autotests/xvkbd/CMakeLists.txt b/development/autotests/xvkbd/CMakeLists.txt new file mode 100644 index 0000000000..1ba14f68e8 --- /dev/null +++ b/development/autotests/xvkbd/CMakeLists.txt @@ -0,0 +1,33 @@ +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. +# +# Copyright (c) 2012 Kornel Benko kornel@lyx.org +# +project(xvkbd) + +find_package(X11 REQUIRED) +find_package(PkgConfig) + +add_definitions(-DUSE_XTEST -DUSE_I18N) + +add_executable(xvkbd xvkbd.c findwidget.c) + +set(XVFBDLIBS) + +if(PKG_CONFIG_FOUND) + pkg_check_modules(XAWLIB REQUIRED xaw7) + list(APPEND XVFBDLIBS ${XAWLIB_LIBRARIES}) + pkg_check_modules(XTEST REQUIRED xtst) + list(APPEND XVFBDLIBS ${XTEST_LIBRARIES}) +else() + list(APPEND XVFBDLIBS -lXaw7) + foreach(_lb Xt XTest X11) + if(X11_${_lb}_LIB) + list(APPEND XVFBDLIBS ${X11_${_lb}_LIB}) + else() + message(FATAL_ERROR "Library for ${_lb} not found") + endif() + endforeach() +endif() + +target_link_libraries(xvkbd ${XVFBDLIBS})