selftester.bat 6.73 KB
Newer Older
1 2
@echo off

3 4 5 6 7 8 9 10 11
set MY_TOOLS_DIR=%~dp0
cd %MY_TOOLS_DIR%..
set MY_INSTALL_DIR=%cd%
echo "MY_INSTALL_DIR=%MY_INSTALL_DIR%"

:: this is set in wrapper script
::set EXIT_ON_ERROR=0
IF %EXIT_ON_ERROR%.==. ( set EXIT_ON_ERROR=0)
IF %VERBOSE%.==. ( set VERBOSE=1)
12

13 14 15 16 17 18 19 20
:: 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
21 22 23 24 25 26
:: 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
27
call otbenv.bat
28

29
:: -----------------------------------------------------------------------------------
30
REM Check 1 : check binaries
31 32 33 34 35 36
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
)
37
call :check_binary lib\python\_otbApplication.pyd
38

39
:: -----------------------------------------------------------------------------------
40 41 42 43 44 45 46 47
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
)
48
call :check_python_wrapping
49

50
:: -----------------------------------------------------------------------------------
51
rem Check 3 : check monteverdi & mapla
52 53
call :check_desktop_app monteverdi
call :check_desktop_app mapla 20
54

55 56 57 58 59
if /i not -%1-==-/q- (
  goto :skip_restore_error
)
if %DONTSHOWUI_VALUE% equ 0 call :setDontShowUI 0
:skip_restore_error
60
setlocal
61 62
del pid.log
del tmp.log
63 64 65
endlocal
goto :eof

66
::########################[ FUNCTIONS ]##################################
67 68
:check_binary
setlocal
69
if %VERBOSE% equ  1 ( echo ":check_binary %1" )
70
type NUL > tmp.log
71
tools\otb_loader.exe %1 > tmp.log 2>&1
72 73
call :nb_tmp_lines
if %nb_tmp_lines_out% gtr 0 (
74 75 76
  echo "ERROR: otb_loader.exe %1"
  type tmp.log
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
77 78 79
)
endlocal
goto :eof
80
::-----------------------------------------------------------------------
81 82 83 84
:check_application
setlocal
set dll_path=%~n1
set app=%dll_path:~7%
85
if %VERBOSE% equ  1 ( echo ":check_application %app%" )
86 87
if not exist bin\otbcli_%app%.bat (
  echo ERROR : missing cli launcher for application %app%
88
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
89 90 91
  goto :check_gui
)
type NUL > tmp.log
92
cmd /C bin\otbcli_%app%.bat "-help" ^> tmp.log ^2^>^&^1
93 94 95
call :parse_cli_output
if %parse_cli_result% equ 0 (
  echo ERROR : error launching application otbcli_%app%
96 97 98 99
  type results.txt 
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
  )

100 101 102
:check_gui
if not exist bin\otbgui_%app%.bat (
  echo ERROR : missing gui launcher for application %app%
103
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
104 105 106 107
  goto :check_application_end
)
if %app_count% geq 2 goto :check_application_end
type NUL > tmp.log
108
start "otbgui application" /b bin\otbgui_%app%.bat ^> tmp.log ^2^>^&^1
109
timeout 5 >nul
110 111 112 113 114 115
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%
116
  type tmp.log 
117 118 119 120 121
  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%
122 123
  type tmp.log
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
124
)
125
  
126 127 128 129
:check_application_clean
if not %first_child% == 0 (
  taskkill /PID %first_child% /F /T > NUL 2>&1
)
130
  
131 132 133
:check_application_end
endlocal & set /a app_count=app_count+1
goto :eof
134 135 136 137 138 139 140
::-----------------------------------------------------------------------
:check_desktop_app
setlocal
set appName=%1
set delay=5
if not -%2-==-- set delay=%2
type NUL > tmp.log
141
start "Desktop app" /b bin\%appName%.exe > tmp.log 2>&1
142 143 144 145 146 147
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
148 149
  type tmp.log
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
150 151 152 153 154
)
endlocal
goto :eof
::-----------------------------------------------------------------------
:check_python_wrapping
155
setlocal
156 157 158 159 160
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
161 162
  type tmp.log
  if %EXIT_ON_ERROR% equ 1 ( exit 1 )
163
)
164 165
endlocal
goto :eof
166
::-----------------------------------------------------------------------
167 168
:parse_cli_output
setlocal
169
set /a ret=1
170 171
findstr /n /r /c:"^This is the *.*(%app%) application, version " tmp.log  > results.txt
if %errorlevel%==1 (
172
  set /a ret=0
173 174
  echo "findstr failed 1st regex in parse_cli_output"
  goto :parse_cli_output_end  
175
)
176 177
findstr /n /r /c:"^Parameters: " tmp.log  > results.txt
if %errorlevel%==1 (
178
  set /a ret=0
179 180
  echo "findstr failed 2nd regex in parse_cli_output"
  goto :parse_cli_output_end  
181
)
182 183
findstr /n /r /c:"^Examples: " tmp.log  > results.txt
if %errorlevel%==1 (
184
  set /a ret=0
185 186
    echo "findstr failed 3rd regex in parse_cli_output"
  goto :parse_cli_output_end  
187
)
188 189
findstr /n /r /c:"FATAL" tmp.log  > results.txt
if %errorlevel%==0 (
190
  set /a ret=0
191 192
    echo "findstr passed 4th regex in parse_cli_output"
  goto :parse_cli_output_end  
193
)
194

195
:parse_cli_output_end
196
endlocal & set /a parse_cli_result=%ret%
197
goto :eof
198
::-----------------------------------------------------------------------
199

200 201 202 203 204
: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
205
::-----------------------------------------------------------------------
206 207 208 209 210 211 212 213 214 215
: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
216 217 218 219 220 221 222 223 224 225 226 227 228
::-----------------------------------------------------------------------
: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
229