vrts: add -Pm option

This commit is contained in:
bnnm 2021-03-14 16:25:39 +01:00
parent 0db3b799c0
commit 6ee9e48511

View File

@ -1,261 +1,273 @@
@echo off @echo off
chcp 65001 chcp 65001
REM #------------------------------------------------------------------------- REM #-------------------------------------------------------------------------
REM # VGMSTREAM REGRESSION TESTING SCRIPT REM # VGMSTREAM REGRESSION TESTING SCRIPT
REM # REM #
REM # Searches for files in a directory (or optionally subdirs) and compares REM # Searches for files in a directory (or optionally subdirs) and compares
REM # the output of two test.exe versions, both wav and stdout, for regression REM # the output of two test.exe versions, both wav and stdout, for regression
REM # testing. This creates and deletes temp files, trying to process all REM # testing. This creates and deletes temp files, trying to process all
REM # extensions found unless specified (except a few). REM # extensions found unless specified (except a few).
REM # REM #
REM # Options: see below. REM # Options: see below.
REM #------------------------------------------------------------------------- REM #-------------------------------------------------------------------------
REM #TODO: escape & ! % in file/folder names REM #TODO: escape & ! % in file/folder names
setlocal enableDelayedExpansion setlocal enableDelayedExpansion
REM #------------------------------------------------------------------------- REM #-------------------------------------------------------------------------
REM #options REM #options
REM #------------------------------------------------------------------------- REM #-------------------------------------------------------------------------
REM # -vo <exe> -vn <exe>: path to old/new exe REM # -vo <exe> -vn <exe>: path to old/new exe
set OP_CMD_OLD=test_old.exe set OP_CMD_OLD=test_old.exe
set OP_CMD_NEW=test.exe set OP_CMD_NEW=test.exe
REM # -f <filename>: search wildcard (ex. -f "*.adx") REM # -f <filename>: search wildcard (ex. -f "*.adx")
set OP_SEARCH="*.*" set OP_SEARCH="*.*"
REM # -r: recursive subfolders REM # -r: recursive subfolders
set OP_RECURSIVE= set OP_RECURSIVE=
REM # -nd: don't delete compared files REM # -nd: don't delete compared files
set OP_NODELETE= set OP_NODELETE=
REM # -nc: don't report correct files REM # -nc: don't report correct files
set OP_NOCORRECT= set OP_NOCORRECT=
REM # -p: performance test new (decode with new exe and no comparison done) REM # -p: performance test new (decode with new exe and no comparison done)
REM # -P: performance test new (same but also don't write file) REM # -P: performance test new (same but also don't write file)
REM # -po: performance test old (decode with new old and no comparison done) REM # -po: performance test old (decode with new old and no comparison done)
REM # -Po: performance test old (same but also don't write file) REM # -Po: performance test old (same but also don't write file)
set OP_PERFORMANCE= REM # -Pm: performance test new (only parse meta)
REM # -fc <exe>: file comparer (Windows's FC is slow) REM # -Pmo: performance test old (only parse meta)
set OP_CMD_FC=fc /a /b set OP_PERFORMANCE=
REM # -fc <exe>: file comparer (Windows's FC is slow)
set OP_CMD_FC=fc /a /b
REM # parse options
:set_options
if "%~1"=="" goto end_options REM # parse options
if "%~1"=="-vo" set OP_CMD_OLD=%2 :set_options
if "%~1"=="-vn" set OP_CMD_NEW=%2 if "%~1"=="" goto end_options
if "%~1"=="-f" set OP_SEARCH=%2 if "%~1"=="-vo" set OP_CMD_OLD=%2
if "%~1"=="-r" set OP_RECURSIVE=/s if "%~1"=="-vn" set OP_CMD_NEW=%2
if "%~1"=="-nd" set OP_NODELETE=true if "%~1"=="-f" set OP_SEARCH=%2
if "%~1"=="-nc" set OP_NOCORRECT=true if "%~1"=="-r" set OP_RECURSIVE=/s
if "%~1"=="-p" set OP_PERFORMANCE=1 if "%~1"=="-nd" set OP_NODELETE=true
if "%~1"=="-P" set OP_PERFORMANCE=2 if "%~1"=="-nc" set OP_NOCORRECT=true
if "%~1"=="-po" set OP_PERFORMANCE=3 if "%~1"=="-p" set OP_PERFORMANCE=1
if "%~1"=="-Po" set OP_PERFORMANCE=4 if "%~1"=="-P" set OP_PERFORMANCE=2
if "%~1"=="-fc" set OP_CMD_FC=%2 if "%~1"=="-po" set OP_PERFORMANCE=3
shift if "%~1"=="-Po" set OP_PERFORMANCE=4
goto set_options if "%~1"=="-Pm" set OP_PERFORMANCE=5
:end_options if "%~1"=="-Pmo" set OP_PERFORMANCE=6
if "%~1"=="-fc" set OP_CMD_FC=%2
REM # output color defs shift
set C_W=0e goto set_options
set C_E=0c :end_options
set C_O=0f
REM # output color defs
REM # remove command options and possibly " set C_W=0e
for /f "tokens=1-1 delims= " %%A in ("%OP_CMD_OLD%") do set CHECK_OLD=%%A set C_E=0c
for /f "tokens=1-1 delims= " %%A in ("%OP_CMD_NEW%") do set CHECK_NEW=%%A set C_O=0f
set CHECK_OLD=%CHECK_OLD:"=%
set CHECK_NEW=%CHECK_NEW:"=% REM # remove command options and possibly "
for /f "tokens=1-1 delims= " %%A in ("%OP_CMD_OLD%") do set CHECK_OLD=%%A
REM # check exe for /f "tokens=1-1 delims= " %%A in ("%OP_CMD_NEW%") do set CHECK_NEW=%%A
set CMD_CHECK=where "%CHECK_OLD%" "%CHECK_NEW%" set CHECK_OLD=%CHECK_OLD:"=%
%CMD_CHECK% > nul set CHECK_NEW=%CHECK_NEW:"=%
if %ERRORLEVEL% NEQ 0 (
echo Old/new exe not found REM # check exe
goto error set CMD_CHECK=where "%CHECK_OLD%" "%CHECK_NEW%"
) %CMD_CHECK% > nul
if %ERRORLEVEL% NEQ 0 (
if %OP_SEARCH%=="" ( echo Old/new exe not found
echo Search wildcard not specified goto error
goto error )
)
if %OP_SEARCH%=="" (
REM # process start echo Search wildcard not specified
set TIME_START=%time% goto error
set FILES_OK=0 )
set FILES_KO=0
echo VRTS: start @%TIME_START% REM # process start
set TIME_START=%time%
REM # search for files set FILES_OK=0
set CMD_DIR=dir /a:-d /b %OP_RECURSIVE% %OP_SEARCH% set FILES_KO=0
set CMD_FIND=findstr /i /v "\.exe$ \.dll$ \.zip$ \.7z$ \.rar$ \.bat$ \.sh$ \.txt$ \.lnk$ \.wav$" echo VRTS: start @%TIME_START%
REM # process files REM # search for files
for /f "delims=" %%x in ('%CMD_DIR% ^| %CMD_FIND%') do ( set CMD_DIR=dir /a:-d /b %OP_RECURSIVE% %OP_SEARCH%
set CMD_FILE=%%x set CMD_FIND=findstr /i /v "\.exe$ \.dll$ \.zip$ \.7z$ \.rar$ \.bat$ \.sh$ \.txt$ \.lnk$ \.wav$"
if "%OP_PERFORMANCE%" == "" ( REM # process files
call :process_file "!CMD_FILE!" for /f "delims=" %%x in ('%CMD_DIR% ^| %CMD_FIND%') do (
) else ( set CMD_FILE=%%x
call :performance_file "!CMD_FILE!"
) if "%OP_PERFORMANCE%" == "" (
) call :process_file "!CMD_FILE!"
) else (
REM # find time elapsed call :performance_file "!CMD_FILE!"
set TIME_END=%time% )
for /F "tokens=1-4 delims=:.," %%a in ("%TIME_START%") do ( )
set /A "TIME_START_S=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
) REM # find time elapsed
for /F "tokens=1-4 delims=:.," %%a in ("%TIME_END%") do ( set TIME_END=%time%
set /A "TIME_END_S=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" for /F "tokens=1-4 delims=:.," %%a in ("%TIME_START%") do (
) set /A "TIME_START_S=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
set /A TIME_ELAPSED_S=(TIME_END_S-TIME_START_S)/100 )
set /A TIME_ELAPSED_C=(TIME_END_S-TIME_START_S)%%100 for /F "tokens=1-4 delims=:.," %%a in ("%TIME_END%") do (
set /A "TIME_END_S=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
)
REM # process end (ok) set /A TIME_ELAPSED_S=(TIME_END_S-TIME_START_S)/100
echo VRTS: done @%TIME_END% (%TIME_ELAPSED_S%,%TIME_ELAPSED_C%s) set /A TIME_ELAPSED_C=(TIME_END_S-TIME_START_S)%%100
echo VRTS: ok=%FILES_OK%, ko=%FILES_KO%
goto exit REM # process end (ok)
echo VRTS: done @%TIME_END% (%TIME_ELAPSED_S%,%TIME_ELAPSED_C%s)
echo VRTS: ok=%FILES_OK%, ko=%FILES_KO%
REM # ########################################################################
REM # test a single file goto exit
REM # ########################################################################
:process_file outer
REM # ignore files starting with dot (no filename) REM # ########################################################################
set CMD_SHORTNAME=%~n1 REM # test a single file
if "%CMD_SHORTNAME%" == "" goto process_file_continue REM # ########################################################################
:process_file outer
REM # get file REM # ignore files starting with dot (no filename)
set CMD_FILE=%1 set CMD_SHORTNAME=%~n1
set CMD_FILE=%CMD_FILE:"=% if "%CMD_SHORTNAME%" == "" goto process_file_continue
REM echo VTRS: file %CMD_FILE%
REM # get file
REM # old/new temp output set CMD_FILE=%1
set WAV_OLD=%CMD_FILE%.old.wav set CMD_FILE=%CMD_FILE:"=%
set TXT_OLD=%CMD_FILE%.old.txt REM echo VTRS: file %CMD_FILE%
set CMD_VGM_OLD="%OP_CMD_OLD%" -o "%WAV_OLD%" "%CMD_FILE%"
%CMD_VGM_OLD% 1> "%TXT_OLD%" 2>&1 & REM || goto error REM # old/new temp output
set WAV_OLD=%CMD_FILE%.old.wav
set WAV_NEW=%CMD_FILE%.new.wav set TXT_OLD=%CMD_FILE%.old.txt
set TXT_NEW=%CMD_FILE%.new.txt set CMD_VGM_OLD="%OP_CMD_OLD%" -o "%WAV_OLD%" "%CMD_FILE%"
set CMD_VGM_NEW="%OP_CMD_NEW%" -o "%WAV_NEW%" "%CMD_FILE%" %CMD_VGM_OLD% 1> "%TXT_OLD%" 2>&1 & REM || goto error
%CMD_VGM_NEW% 1> "%TXT_NEW%" 2>&1 & REM || goto error
set WAV_NEW=%CMD_FILE%.new.wav
REM # ignore if no files are created (unsupported formats) set TXT_NEW=%CMD_FILE%.new.txt
if not exist "%WAV_NEW%" ( set CMD_VGM_NEW="%OP_CMD_NEW%" -o "%WAV_NEW%" "%CMD_FILE%"
if not exist "%WAV_OLD%" ( %CMD_VGM_NEW% 1> "%TXT_NEW%" 2>&1 & REM || goto error
REM echo VRTS: nothing created for file %CMD_FILE%
if exist "%TXT_NEW%" del /a:a "%TXT_NEW%" REM # ignore if no files are created (unsupported formats)
if exist "%TXT_OLD%" del /a:a "%TXT_OLD%" if not exist "%WAV_NEW%" (
goto process_file_continue if not exist "%WAV_OLD%" (
) REM echo VRTS: nothing created for file %CMD_FILE%
) if exist "%TXT_NEW%" del /a:a "%TXT_NEW%"
if exist "%TXT_OLD%" del /a:a "%TXT_OLD%"
REM # compare files (without /b may to be faster for small files?) goto process_file_continue
set CMP_WAV=%OP_CMD_FC% "%WAV_OLD%" "%WAV_NEW%" )
set CMP_TXT=%OP_CMD_FC% "%TXT_OLD%" "%TXT_NEW%" )
%CMP_WAV% 1> nul 2>&1 REM # compare files (without /b may to be faster for small files?)
set CMP_WAV_ERROR=0 set CMP_WAV=%OP_CMD_FC% "%WAV_OLD%" "%WAV_NEW%"
if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1 set CMP_TXT=%OP_CMD_FC% "%TXT_OLD%" "%TXT_NEW%"
%CMP_TXT% 1> nul 2>&1 %CMP_WAV% 1> nul 2>&1
set CMP_TXT_ERROR=0 set CMP_WAV_ERROR=0
if %ERRORLEVEL% NEQ 0 set CMP_TXT_ERROR=1 if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1
REM # print output %CMP_TXT% 1> nul 2>&1
if %CMP_WAV_ERROR% EQU 1 ( set CMP_TXT_ERROR=0
if %CMP_TXT_ERROR% EQU 1 ( if %ERRORLEVEL% NEQ 0 set CMP_TXT_ERROR=1
call :echo_color %C_E% "%CMD_FILE%" "wav and txt diffs"
) else ( REM # print output
call :echo_color %C_E% "%CMD_FILE%" "wav diffs" if %CMP_WAV_ERROR% EQU 1 (
) if %CMP_TXT_ERROR% EQU 1 (
set /a "FILES_KO+=1" call :echo_color %C_E% "%CMD_FILE%" "wav and txt diffs"
) else ( ) else (
if %CMP_TXT_ERROR% EQU 1 ( call :echo_color %C_E% "%CMD_FILE%" "wav diffs"
call :echo_color %C_W% "%CMD_FILE%" "txt diffs" )
) else ( set /a "FILES_KO+=1"
if "%OP_NOCORRECT%" == "" ( ) else (
call :echo_color %C_O% "%CMD_FILE%" "no diffs" if %CMP_TXT_ERROR% EQU 1 (
) call :echo_color %C_W% "%CMD_FILE%" "txt diffs"
) ) else (
set /a "FILES_OK+=1" if "%OP_NOCORRECT%" == "" (
) call :echo_color %C_O% "%CMD_FILE%" "no diffs"
)
REM # delete temp files )
if "%OP_NODELETE%" == "" ( set /a "FILES_OK+=1"
if exist "%WAV_OLD%" del /a:a "%WAV_OLD%" )
if exist "%TXT_OLD%" del /a:a "%TXT_OLD%"
if exist "%WAV_NEW%" del /a:a "%WAV_NEW%" REM # delete temp files
if exist "%TXT_NEW%" del /a:a "%TXT_NEW%" if "%OP_NODELETE%" == "" (
) if exist "%WAV_OLD%" del /a:a "%WAV_OLD%"
if exist "%TXT_OLD%" del /a:a "%TXT_OLD%"
:process_file_continue if exist "%WAV_NEW%" del /a:a "%WAV_NEW%"
exit /B if exist "%TXT_NEW%" del /a:a "%TXT_NEW%"
REM :process_file end, continue from last call )
:process_file_continue
REM # ######################################################################## exit /B
REM # decode only (no comparisons done), for performance testing REM :process_file end, continue from last call
REM # ########################################################################
:performance_file
REM # ignore files starting with dot (no filename) REM # ########################################################################
set CMD_SHORTNAME=%~n1 REM # decode only (no comparisons done), for performance testing
if "%CMD_SHORTNAME%" == "" goto performance_file_continue REM # ########################################################################
:performance_file outer
REM # get file REM # ignore files starting with dot (no filename)
set CMD_FILE=%1 set CMD_SHORTNAME=%~n1
set CMD_FILE=%CMD_FILE:"=% if "%CMD_SHORTNAME%" == "" goto performance_file_continue
REM echo VTRS: file %CMD_FILE%
REM # get file
set WAV_NEW=%CMD_FILE%.test.wav set CMD_FILE=%1
if "%OP_PERFORMANCE%" == "1" ( set CMD_FILE=%CMD_FILE:"=%
set CMD_VGM="%OP_CMD_NEW%" -o "%WAV_NEW%" "%CMD_FILE%" REM echo VTRS: file %CMD_FILE%
)
if "%OP_PERFORMANCE%" == "2" ( set WAV_NEW=%CMD_FILE%.test.wav
set CMD_VGM="%OP_CMD_NEW%" -O "%CMD_FILE%" if "%OP_PERFORMANCE%" == "1" (
) set CMD_VGM="%OP_CMD_NEW%" -o "%WAV_NEW%" "%CMD_FILE%"
if "%OP_PERFORMANCE%" == "3" ( )
set CMD_VGM="%OP_CMD_OLD%" -o "%WAV_OLD%" "%CMD_FILE%" if "%OP_PERFORMANCE%" == "2" (
) set CMD_VGM="%OP_CMD_NEW%" -O "%CMD_FILE%"
if "%OP_PERFORMANCE%" == "4" ( )
set CMD_VGM="%OP_CMD_OLD%" -O "%CMD_FILE%" if "%OP_PERFORMANCE%" == "3" (
) set CMD_VGM="%OP_CMD_OLD%" -o "%WAV_OLD%" "%CMD_FILE%"
)
%CMD_VGM% 1> nul 2>&1 & REM || goto error if "%OP_PERFORMANCE%" == "4" (
set CMD_VGM="%OP_CMD_OLD%" -O "%CMD_FILE%"
call :echo_color %C_O% "%CMD_FILE%" "done" )
if "%OP_PERFORMANCE%" == "5" (
REM # ignore output set CMD_VGM="%OP_CMD_NEW%" -m "%CMD_FILE%"
if exist "%WAV_NEW%" del /a:a "%WAV_NEW%" )
if "%OP_PERFORMANCE%" == "6" (
:performance_file_continue set CMD_VGM="%OP_CMD_OLD%" -m "%CMD_FILE%"
exit /B )
REM :performance_file end, continue from last call
%CMD_VGM% 1> nul 2>&1 & REM || goto error
set CMP_WAV_ERROR=0
REM # ######################################################################## if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1
REM # hack to get colored output in Windows CMD using findstr + temp file
REM # ######################################################################## call :echo_color %C_O% "%CMD_FILE%" "done"
:echo_color
set TEMP_FILE=%2-result REM # ignore output
set TEMP_FILE=%TEMP_FILE:"=% if exist "%WAV_NEW%" del /a:a "%WAV_NEW%"
set TEMP_TEXT=%3
set TEMP_TEXT=%TEMP_TEXT:"=% :performance_file_continue
echo %TEMP_TEXT% > "%TEMP_FILE%" exit /B
REM # show colored filename + any text in temp file REM :performance_file end, continue from last call
findstr /v /a:%1 /r "^$" "%TEMP_FILE%" nul
del "%TEMP_FILE%"
exit /B REM # ########################################################################
REM :echo_color end, continue from last call REM # hack to get colored output in Windows CMD using findstr + temp file
REM # ########################################################################
:echo_color
REM # ######################################################################## set TEMP_FILE=%2-result
set TEMP_FILE=%TEMP_FILE:"=%
:error set TEMP_TEXT=%3
echo VRTS: error set TEMP_TEXT=%TEMP_TEXT:"=%
goto exit echo %TEMP_TEXT% > "%TEMP_FILE%"
REM # show colored filename + any text in temp file
:exit findstr /v /a:%1 /r "^$" "%TEMP_FILE%" nul
del "%TEMP_FILE%"
exit /B
REM :echo_color end, continue from last call
REM # ########################################################################
:error
echo VRTS: error
goto exit
:exit