selftester.bat 7.59 KB
Newer Older
1 2 3 4 5 6 7
@echo off
setlocal

set CURRENT_SCRIPT_DIR=%~dp0
set DIRNAME=%CURRENT_SCRIPT_DIR%..
cd %DIRNAME%

8 9 10 11 12 13 14 15 16
:: 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

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

del selftest_report.log
type NUL > selftest_report.log
call :nb_report_lines
set REF_SIZE=%nb_report_lines_out%
29
:: -----------------------------------------------------------------------------------
30 31 32 33 34 35 36
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
)
37
call :check_binary lib\python\_otbApplication.pyd
38 39 40

call :nb_report_lines
if %nb_report_lines_out% gtr %REF_SIZE% (
41
  echo Check 1/3 : FAIL
42
) else (
43
  echo Check 1/3 : PASS
44 45
)
set REF_SIZE=%nb_report_lines_out%
46
:: -----------------------------------------------------------------------------------
47 48 49 50 51 52 53 54
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
)
55
call :check_python_wrapping
56 57 58

call :nb_report_lines
if %nb_report_lines_out% gtr %REF_SIZE% (
59
  echo Check 2/3 : FAIL
60
) else (
61
  echo Check 2/3 : PASS
62 63
)
set REF_SIZE=%nb_report_lines_out%
64
:: -----------------------------------------------------------------------------------
65
rem Check 3 : check monteverdi & mapla
66 67
call :check_desktop_app monteverdi
call :check_desktop_app mapla 20
68

69 70 71 72 73 74
call :nb_report_lines
if %nb_report_lines_out% gtr %REF_SIZE% (
  echo Check 3/3 : FAIL
) else (
  echo Check 3/3 : PASS
)
75

76 77 78 79 80 81 82
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
83 84 85
endlocal
goto :eof

86
::########################[ FUNCTIONS ]##################################
87 88 89
:check_binary
setlocal
type NUL > tmp.log
90
tools\otb_loader.exe %1 > tmp.log 2>&1
91 92 93
call :nb_tmp_lines
if %nb_tmp_lines_out% gtr 0 (
  echo ERROR : otb_loader.exe %1
94 95
  echo otb_loader.exe %1 >> selftest_report.log
  type tmp.log >> selftest_report.log
96 97 98
)
endlocal
goto :eof
99
::-----------------------------------------------------------------------
100 101 102 103 104 105
: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%
106
  echo ERROR : missing cli launcher for application %app% >> selftest_report.log
107 108 109
  goto :check_gui
)
type NUL > tmp.log
110
cmd /C bin\otbcli_%app%.bat "-help" ^> tmp.log ^2^>^&^1
111 112 113
call :parse_cli_output
if %parse_cli_result% equ 0 (
  echo ERROR : error launching application otbcli_%app%
114 115
  echo ERROR : error launching application otbcli_%app% >> selftest_report.log
  type tmp.log >> selftest_report.log
116 117 118 119
)
:check_gui
if not exist bin\otbgui_%app%.bat (
  echo ERROR : missing gui launcher for application %app%
120
  echo ERROR : missing gui launcher for application %app% >> selftest_report.log
121 122 123 124
  goto :check_application_end
)
if %app_count% geq 2 goto :check_application_end
type NUL > tmp.log
125
start "otbgui application" /b bin\otbgui_%app%.bat ^> tmp.log ^2^>^&^1
126
timeout 5 >nul
127 128 129 130 131 132
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%
133 134
  echo ERROR : could not launch otbgui_%app% >> selftest_report.log
  type tmp.log >> selftest_report.log
135 136 137 138 139
  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%
140 141
  echo ERROR : could not launch otbApplicationLauncherQt %app% >> selftest_report.log
  type tmp.log >> selftest_report.log
142 143 144 145 146 147 148 149
)
: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
150 151 152 153 154 155 156
::-----------------------------------------------------------------------
:check_desktop_app
setlocal
set appName=%1
set delay=5
if not -%2-==-- set delay=%2
type NUL > tmp.log
157
start "Desktop app" /b bin\%appName%.exe > tmp.log 2>&1
158 159 160 161 162 163 164 165 166 167 168 169 170
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
171
setlocal
172 173 174 175 176 177 178 179
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
)
180 181
endlocal
goto :eof
182
::-----------------------------------------------------------------------
183 184
:parse_cli_output
setlocal
185
set /a ret=1
186 187
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:" (
188
  set /a ret=0
189 190 191 192 193
  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:" (
194
  set /a ret=0
195 196 197 198 199
  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" (
200
  set /a ret=0
201 202 203 204 205
  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" (
206
  set /a ret=0
207 208 209
  goto :parse_cli_output_end
)
:parse_cli_output_end
210
endlocal & set /a parse_cli_result=%ret%
211
goto :eof
212
::-----------------------------------------------------------------------
213 214 215 216 217
: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
218
::-----------------------------------------------------------------------
219 220 221 222 223
: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
224
::-----------------------------------------------------------------------
225 226 227 228 229 230 231 232 233 234
: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
235 236 237 238 239 240 241 242 243 244 245 246 247
::-----------------------------------------------------------------------
: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