Commit e0daa71d authored by Guillaume Pasero's avatar Guillaume Pasero

MRG: Merge branch 'pkg-self-test' into develop

parents 207b7e41 a8398f25
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <iostream>
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "Usage : "<< argv[0] << " library_file" << std::endl;
return 1;
}
const char* input = argv[1];
#if defined(_WIN32) && !defined(__CYGWIN__)
HMODULE library = LoadLibrary(input);
if (library == NULL)
{
std::cout << "Failed to load "<< input << std::endl;
LPVOID lpMsgBuf=NULL;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
if(lpMsgBuf)
{
std::cout << (char*)lpMsgBuf << std::endl;
LocalFree( lpMsgBuf );
}
}
else
{
FreeLibrary(library);
}
#else
void* library = dlopen(input, RTLD_LAZY);
if (library == NULL)
{
std::cout << "Failed to load "<< input << std::endl;
std::cout << dlerror() << std::endl;
}
else
{
dlclose(library);
}
#endif
return 0;
}
@echo off
setlocal
set CURRENT_SCRIPT_DIR=%~dp0
set DIRNAME=%CURRENT_SCRIPT_DIR%..
cd %DIRNAME%
:: if "/q" is given, hide the error dialogs (hence make the script non-interactive)
if /i not -%1-==-/q- (
goto :skip_hide_error
)
echo Hide error dialogs
call :getDontShowUI
if %DONTSHOWUI_VALUE% equ 0 call :setDontShowUI 1
:skip_hide_error
:: Get current PID
type NUL > pid.log
wmic PROCESS where "Name='WMIC.exe'" get ParentProcessId >pid.log 2>&1
for /F "TOKENS=1" %%b in ('type pid.log ^| findstr [0-9]') do set CURRENT_PID=%%b
:: setup the otbenv
call otbenv.cmd
del selftest_report.log
type NUL > selftest_report.log
call :nb_report_lines
set REF_SIZE=%nb_report_lines_out%
:: -----------------------------------------------------------------------------------
rem Check 1 : check binaries
for /R %%i in (*.dll) do (
call :check_binary %%i
)
for %%i in (bin\mapla.exe,bin\monteverdi.exe,bin\otbApplicationLauncherCommandLine.exe,bin\otbApplicationLauncherQt.exe) do (
call :check_binary %%i
)
call :check_binary lib\python\_otbApplication.pyd
call :nb_report_lines
if %nb_report_lines_out% gtr %REF_SIZE% (
echo Check 1/3 : FAIL
) else (
echo Check 1/3 : PASS
)
set REF_SIZE=%nb_report_lines_out%
:: -----------------------------------------------------------------------------------
rem Check 2 : check applications and Python wrapping
set /a app_count=0
for /R %%i in (lib\otb\applications\otbapp_*.dll) do (
call :check_application %%i
)
if %app_count% leq 90 (
echo WARNING: only %app_count% applications found ! Expected at least 90
)
call :check_python_wrapping
call :nb_report_lines
if %nb_report_lines_out% gtr %REF_SIZE% (
echo Check 2/3 : FAIL
) else (
echo Check 2/3 : PASS
)
set REF_SIZE=%nb_report_lines_out%
:: -----------------------------------------------------------------------------------
rem Check 3 : check monteverdi & mapla
call :check_desktop_app monteverdi
call :check_desktop_app mapla 20
call :nb_report_lines
if %nb_report_lines_out% gtr %REF_SIZE% (
echo Check 3/3 : FAIL
) else (
echo Check 3/3 : PASS
)
if /i not -%1-==-/q- (
goto :skip_restore_error
)
if %DONTSHOWUI_VALUE% equ 0 call :setDontShowUI 0
:skip_restore_error
del pid.log
del tmp.log
endlocal
goto :eof
::########################[ FUNCTIONS ]##################################
:check_binary
setlocal
type NUL > tmp.log
bin\otb_loader.exe %1 > tmp.log 2>&1
call :nb_tmp_lines
if %nb_tmp_lines_out% gtr 0 (
echo ERROR : otb_loader.exe %1
echo otb_loader.exe %1 >> selftest_report.log
type tmp.log >> selftest_report.log
)
endlocal
goto :eof
::-----------------------------------------------------------------------
:check_application
setlocal
set dll_path=%~n1
set app=%dll_path:~7%
if not exist bin\otbcli_%app%.bat (
echo ERROR : missing cli launcher for application %app%
echo ERROR : missing cli launcher for application %app% >> selftest_report.log
goto :check_gui
)
type NUL > tmp.log
cmd /C bin\otbcli_%app%.bat "-help" ^> tmp.log ^2^>^&^1
call :parse_cli_output
if %parse_cli_result% equ 0 (
echo ERROR : error launching application otbcli_%app%
echo ERROR : error launching application otbcli_%app% >> selftest_report.log
type tmp.log >> selftest_report.log
)
:check_gui
if not exist bin\otbgui_%app%.bat (
echo ERROR : missing gui launcher for application %app%
echo ERROR : missing gui launcher for application %app% >> selftest_report.log
goto :check_application_end
)
if %app_count% geq 2 goto :check_application_end
type NUL > tmp.log
start "otbgui application" /b bin\otbgui_%app%.bat ^> tmp.log ^2^>^&^1
timeout 5 >nul
call :get_child_pid %CURRENT_PID% cmd.exe
set first_child=0
if %child_pid% gtr 1 (
set first_child=%child_pid%
) else (
echo ERROR : could not launch otbgui_%app%
echo ERROR : could not launch otbgui_%app% >> selftest_report.log
type tmp.log >> selftest_report.log
goto :check_application_clean
)
call :get_child_pid %first_child% otbApplicationLauncherQt.exe
if not %child_pid% gtr 1 (
echo ERROR : could not launch otbApplicationLauncherQt %app%
echo ERROR : could not launch otbApplicationLauncherQt %app% >> selftest_report.log
type tmp.log >> selftest_report.log
)
:check_application_clean
if not %first_child% == 0 (
taskkill /PID %first_child% /F /T > NUL 2>&1
)
:check_application_end
endlocal & set /a app_count=app_count+1
goto :eof
::-----------------------------------------------------------------------
:check_desktop_app
setlocal
set appName=%1
set delay=5
if not -%2-==-- set delay=%2
type NUL > tmp.log
start "Desktop app" /b bin\%appName%.exe > tmp.log 2>&1
timeout %delay% >nul
call :get_child_pid %CURRENT_PID% %appName%.exe
if %child_pid% gtr 1 (
taskkill /PID %child_pid% /F /T > NUL 2>&1
) else (
echo ERROR : could not launch %appName%.exe
echo ERROR : could not launch %appName%.exe >> selftest_report.log
type tmp.log >> selftest_report.log
)
endlocal
goto :eof
::-----------------------------------------------------------------------
:check_python_wrapping
setlocal
type NUL > tmp.log
python -c "import otbApplication" > tmp.log 2>&1
call :nb_tmp_lines
if %nb_tmp_lines_out% gtr 0 (
echo ERROR : failed to run python wrapping
echo ERROR : failed to run python wrapping >> selftest_report.log
type tmp.log >> selftest_report.log
)
endlocal
goto :eof
::-----------------------------------------------------------------------
:parse_cli_output
setlocal
set /a ret=1
for /F %%a in ('findstr /n /r /c:"^This is the %app% application, version " tmp.log') do set output=%%a
if not "%output%" gtr "1:" (
set /a ret=0
goto :parse_cli_output_end
)
set output=
for /F %%a in ('findstr /n /r /c:"^Parameters:" tmp.log') do set output=%%a
if not "%output%" gtr "3:" (
set /a ret=0
goto :parse_cli_output_end
)
set output=
for /F %%a in ('findstr /n /r /c:"^Examples:" tmp.log') do set output=%%a
if not "%output%" gtr "1" (
set /a ret=0
goto :parse_cli_output_end
)
set output=
for /F %%a in ('findstr /n /r /c:"FATAL" tmp.log') do set output=%%a
if "%output%" gtr "1" (
set /a ret=0
goto :parse_cli_output_end
)
:parse_cli_output_end
endlocal & set /a parse_cli_result=%ret%
goto :eof
::-----------------------------------------------------------------------
:nb_report_lines
setlocal
for /F "delims=" %%i in ('find /C /V "" ^< selftest_report.log') do set output=%%i
endlocal & set nb_report_lines_out=%output%
goto :eof
::-----------------------------------------------------------------------
:nb_tmp_lines
setlocal
for /F "delims=" %%i in ('find /C /V "" ^< tmp.log') do set output=%%i
endlocal & set nb_tmp_lines_out=%output%
goto :eof
::-----------------------------------------------------------------------
:get_child_pid
setlocal
set parent_pid=%1
set process_name=%2
set output=0
type NUL > pid.log
wmic PROCESS where (ParentProcessId=%parent_pid% AND Name="%process_name%") get ProcessId >pid.log 2>&1
for /F "TOKENS=1" %%a in ('type pid.log ^| findstr [0-9]') do set output=%%a
endlocal & set child_pid=%output%
goto :eof
::-----------------------------------------------------------------------
:getDontShowUI
setlocal
set output=0
for /F "TOKENS=3" %%a in ('reg query "HKCU\Software\Microsoft\Windows\Windows Error Reporting" /v DontShowUI ^| findstr DontShowUI') do set output=%%a
endlocal & set DONTSHOWUI_VALUE=%output:~2%
goto :eof
::-----------------------------------------------------------------------
:setDontShowUI
setlocal
reg add "HKCU\Software\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d %1 /f
endlocal
goto :eof
#!/bin/sh
# Setup test environment
DIRNAME_0=$(dirname "$0")
DIRNAME=$(readlink "$DIRNAME_0/..")
cd "$DIRNAME" || exit
# define convenient functions
# ps_children( parentPID ) : get PIDs of children processes
ps_children () {
ps -e -o pid -o command=COMMAND-WIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIDE-COLUMN -o ppid | grep " $1$" | grep -v -e ' grep ' -e ' ps -e '
}
# nb_report_lines( ) : get number of lines in report
nb_report_lines () {
report_lines="$(wc -l selftest_report.log)"
echo $report_lines | cut -d ' ' -f 1
}
# echo_and_report ( string ) : echo and print to report
echo_and_report () {
echo "$1" | tee -a selftest_report.log
}
# -------------------------------------------------------------------------
. ./otbenv.profile
rm -f selftest_report.log
touch selftest_report.log
REF_SIZE=0
REF_SIZE=$(nb_report_lines)
# Check 1 : check binaries
OTB_SO_LIBRARIES=$(find lib -name '*.so*')
OTB_DY_LIBRARIES=$(find lib -name '*.dylib')
OTB_EXE="bin/mapla bin/monteverdi bin/otbApplicationLauncherQt bin/otbApplicationLauncherCommandLine"
for name in $OTB_SO_LIBRARIES $OTB_DY_LIBRARIES $OTB_EXE; do
F_OUTPUT=$(file "$name")
if echo "$F_OUTPUT" | grep -q 'cannot open'; then
echo_and_report "$F_OUTPUT"
elif echo "$F_OUTPUT" | grep -q ': broken symbolic link'; then
echo_and_report "$F_OUTPUT"
elif echo "$F_OUTPUT" | grep -q -i -e ': ELF .*shared object' -e ': ELF .*executable'; then
LDD_ERRORS=$(bin/otb_loader "$name")
if [ -n "$LDD_ERRORS" ]; then
echo_and_report "otb_loader $name"
echo_and_report "$LDD_ERRORS"
fi
elif echo "$F_OUTPUT" | grep -q -i -e ': Mach-O .*shared library' -e ': Mach-O .*bundle' -e ': Mach-O .*executable'; then
DL_ERRORS=$(bin/otb_loader "$name")
if [ -n "$DL_ERRORS" ]; then
echo_and_report "otb_loader $name"
echo_and_report "$DL_ERRORS"
fi
elif echo "$F_OUTPUT" | grep -q ': symbolic link'; then
:
else
echo_and_report "Unkown file type : $F_OUTPUT"
fi
done
REPORT_SIZE=$(nb_report_lines)
if [ "$REPORT_SIZE" -ne "$REF_SIZE" ]; then
echo "Check 1/3 : FAIL"
else
echo "Check 1/3 : PASS"
fi
REF_SIZE=$REPORT_SIZE
# Check 2 : OTB applications and Python wrapping
OTB_APP_COUNT=$(find lib/otb/applications -name 'otbapp_*.*' | wc -w)
OTB_APPS=$(find lib/otb/applications -name 'otbapp_*.*' | cut -d '_' -f 2 | cut -d '.' -f 1)
if [ "$OTB_APP_COUNT" -le 90 ]; then
echo "WARNING: Only $OTB_APP_COUNT applications found ! Expected at least 90"
fi
app_index=0
for app in $OTB_APPS; do
if [ ! -f "bin/otbcli_$app" ]; then
echo_and_report "ERROR: missing cli launcher for application $app"
else
CLI_OUTPUT=$("bin/otbcli_$app" -help 2>&1)
CLI_FILTER=$(echo "${CLI_OUTPUT}"| tr '\n' ' ' | grep -E "^This is the $app application, version.* Parameters:( +(MISSING )?-[0-9a-z]+ .*)+ Examples:.*otbcli_$app.*")
CLI_FILTER2=$(echo "$CLI_FILTER" | grep -v 'FATAL')
if [ -z "$CLI_FILTER2" ]; then
echo_and_report "ERROR: bin/otbcli_$app"
echo_and_report "$CLI_OUTPUT"
fi
fi
# test the gui launcher only on 2 first applications
if [ ! -f "bin/otbgui_$app" ]; then
echo_and_report "ERROR: missing gui launcher for application $app"
elif [ $app_index -lt 2 ]; then
echo "" >tmp.log
"bin/otbgui_$app" >tmp.log 2>&1 &
GUI_PID=$!
sleep 5s
# Check process tree
CHILD_PROC=$(ps_children $GUI_PID | grep "bin/otbgui $app")
if [ -n "$CHILD_PROC" ]; then
CHILD_PID=$(echo "$CHILD_PROC" | cut -d ' ' -f 1)
NEXT_CHILD_PROC=$(ps_children "$CHILD_PID" | grep 'otbApplicationLauncherQt')
if [ -n "$NEXT_CHILD_PROC" ]; then
NEXT_CHILD_PID=$(echo "$NEXT_CHILD_PROC" | cut -d ' ' -f 1)
kill -9 "$NEXT_CHILD_PID"
wait "$NEXT_CHILD_PID" 2>/dev/null
else
echo_and_report "ERROR: otbApplicationLauncherQt $app failed to launch"
tee -a selftest_report.log < tmp.log
fi
else
echo_and_report "ERROR: bin/otbgui_$app failed to launch"
tee -a selftest_report.log < tmp.log
fi
fi
app_index=$(( app_index + 1 ))
done
# test python wrapping
PY_OUTPUT=$(python -c 'import otbApplication' 2>&1)
if [ -n "$PY_OUTPUT" ]; then
echo_and_report "ERROR: python wrapping test failed :"
echo_and_report "$PY_OUTPUT"
fi
REPORT_SIZE=$(nb_report_lines)
if [ "$REPORT_SIZE" -ne "$REF_SIZE" ]; then
echo "Check 2/3 : FAIL"
else
echo "Check 2/3 : PASS"
fi
REF_SIZE=$REPORT_SIZE
# Check 3 : OTB binaries monteverdi & mapla
# Monteverdi
echo "" >tmp.log
bin/monteverdi >tmp.log 2>&1 &
MVD_PID=$!
sleep 5s
if pgrep monteverdi | grep -q $MVD_PID; then
MVD_LOG=$(grep -i -e 'error' -e 'exception' tmp.log)
if [ -n "$MVD_LOG" ]; then
echo_and_report "ERROR: launching monteverdi"
tee -a selftest_report.log < tmp.log
fi
kill -9 $MVD_PID
wait $MVD_PID 2>/dev/null
else
echo_and_report "ERROR: failed to launch monteverdi"
tee -a selftest_report.log < tmp.log
fi
# Mapla
echo "" >tmp.log
bin/mapla >tmp.log 2>&1 &
MAPLA_PID=$!
sleep 5s
if pgrep mapla | grep -q $MAPLA_PID; then
MAPLA_LOG=$(grep -i -e 'error' -e 'exception' tmp.log)
if [ -n "$MAPLA_LOG" ]; then
echo_and_report "ERROR: launching mapla"
tee -a selftest_report.log < tmp.log
fi
kill -9 $MAPLA_PID
wait $MAPLA_PID 2>/dev/null
else
echo_and_report "ERROR: failed to launch mapla"
tee -a selftest_report.log < tmp.log
fi
REPORT_SIZE=$(nb_report_lines)
if [ "$REPORT_SIZE" -ne "$REF_SIZE" ]; then
echo "Check 3/3 : FAIL"
else
echo "Check 3/3 : PASS"
fi
# clean any background process
ps_children $$ >tmp.log
for pid in $(cut -d ' ' -f 1 < tmp.log); do
kill -9 "$pid"
done
rm -f tmp.log
......@@ -319,6 +319,17 @@ function(func_install_otb_support_files)
##################### install cli and gui scripts #######################
install(PROGRAMS ${PKG_APP_SCRIPTS} DESTINATION ${PKG_STAGE_BIN_DIR})
########################## selftest script ##############################
if(WIN32)
set(PACKAGE_SELFTEST_SCRIPT selftester.bat)
else()
set(PACKAGE_SELFTEST_SCRIPT selftester.sh)
endif()
install(
FILES ${PACKAGE_SUPPORT_FILES_DIR}/${PACKAGE_SELFTEST_SCRIPT}
DESTINATION ${PKG_STAGE_BIN_DIR}
)
endfunction()
......
......@@ -219,16 +219,19 @@ macro(macro_super_package)
if(LINUX)
list(APPEND program_list "${PATCHELF_PROGRAM}")
endif()
endif()
foreach(prog ${program_list})
install(
PROGRAMS ${prog}
DESTINATION ${PKG_STAGE_DIR})
endforeach()
############# otb_loader executable ################
add_executable(otb_loader ${PACKAGE_SUPPORT_FILES_DIR}/otb_loader.cxx)
target_link_libraries(otb_loader ${CMAKE_DL_LIBS})
install(TARGETS otb_loader
RUNTIME DESTINATION ${PKG_STAGE_DIR}/bin COMPONENT Runtime)
# We need qt.conf on windows. for macx and linux we write it
# after extracting package
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment