Skip to content

Commit

Permalink
Test native as well as WOW64 toolsets
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Dec 2, 2021
1 parent 79cc8f0 commit 73e60af
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 28 deletions.
30 changes: 20 additions & 10 deletions build_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ if NOT "%1" == "" SET VERB="%1"
rem call build_sdk.bat || goto :error
cd %TOPSRCDIR%

for /f "usebackq delims=#" %%a in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -version 16 -property installationPath`) do call "%%a\VC\Auxiliary\Build\vcvarsall.bat" x86
Call :BUILD_TEST x86 || goto :error
Call :BUILD_TEST x64 || goto :error
Call :BUILD_TEST ARM64 || goto :error
exit /b

:BUILD_TEST
for /f "usebackq delims=#" %%a in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -version 16 -property installationPath`) do call "%%a\VC\Auxiliary\Build\vcvarsall.bat" %1
if %ERRORLEVEL% NEQ 0 goto :error

msbuild ".\npcap-sdk\Examples-pcap\MakeAll.sln" /m /t:%VERB% /p:Configuration=%MODE% /p:Platform="x86" || goto :error
msbuild ".\npcap-sdk\Examples-remote\sendcap\sendcap.vcxproj" /m /t:%VERB% /p:Configuration=%MODE% /p:Platform="x86" || goto :error
if NOT "%VERB%" == "Build" exit /b
msbuild ".\npcap-sdk\Examples-pcap\MakeAll.sln" /m /t:%VERB% /p:Configuration=%MODE% /p:Platform="%1" || goto :error
msbuild ".\npcap-sdk\Examples-remote\sendcap\sendcap.vcxproj" /m /t:%VERB% /p:Configuration=%MODE% /p:Platform="%1" || goto :error
if NOT "%VERB%" == "Build" goto :EOF

copy /b ".\npcap-sdk\Examples-pcap\%MODE%\iflist.exe" test\
copy /b ".\npcap-sdk\Examples-pcap\%MODE%\pcap_filter.exe" test\
copy /b ".\npcap-sdk\Examples-pcap\%MODE%\sendpack.exe" test\
copy /b ".\npcap-sdk\Examples-pcap\%MODE%\readfile.exe" test\
set BINDIR=%1\
if "%1" == "x86" set BINDIR=""

copy /b ".\npcap-sdk\Examples-remote\sendcap\%MODE%\sendcap.exe" test\
mkdir test\%1\
copy /b ".\npcap-sdk\Examples-pcap\%BINDIR%%MODE%\iflist.exe" test\%1\
copy /b ".\npcap-sdk\Examples-pcap\%BINDIR%%MODE%\pcap_filter.exe" test\%1\
copy /b ".\npcap-sdk\Examples-pcap\%BINDIR%%MODE%\sendpack.exe" test\%1\
copy /b ".\npcap-sdk\Examples-pcap\%BINDIR%%MODE%\readfile.exe" test\%1\

exit /b
copy /b ".\npcap-sdk\Examples-remote\sendcap\%BINDIR%%MODE%\sendcap.exe" test\%1\

goto :EOF

:error
echo Something failed: %ERRORLEVEL%
Expand Down
58 changes: 40 additions & 18 deletions test/make_test.bat
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
SET SAVEPID=0

rem All platforms support x86 emulation
Call :DO_TEST x86 || goto :error

rem If we're running in native arch,
if "%PROCESSOR_ARCHITEW6432%" == "" (
rem and it's x86, we're done.
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto :quit

rem Otherwise, test the native arch
Call :DO_TEST %PROCESSOR_ARCHITECTURE% || goto :error
) else (
rem Otherwise, we're running in WOW64, so test the native arch
Call :DO_TEST %PROCESSOR_ARCHITEW6432% || goto :error
)

:quit
pause
exit /b %ERR%

:error
set ERR=%ERRORLEVEL%
if "%ERR%" == "" set ERR=1
echo Failed: %ERR%
if %SAVEPID% NEQ 0 taskkill /PID %SAVEPID%
goto :quit

:DO_TEST

echo Testing iflist...
for /f "TOKENS=1,2" %%a in ('nmap --iflist') do @if %%a==lo0 set devname=%%b
if not %devname:~0,12%==\Device\NPF_ goto :error
.\iflist.exe
if not "%devname%"=="\Device\NPF_Loopback" goto :error
.\%1\iflist.exe || goto :error

echo Testing Loopback operations...
echo Testing pcap_filter...
del loopback.pcap
start .\pcap_filter.exe -o loopback.pcap -s %devname% -f tcp
start .\%1\pcap_filter.exe -o loopback.pcap -s %devname% -f tcp
for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq pcap_filter.exe"') do set SAVEPID=%%b
if "%SAVEPID%" == "" goto :error

echo Running nmap...
nmap -F -O -d -n localhost || goto :error
nmap -F -O -d -n -6 localhost || goto :error

echo Testing sendpack...
.\sendpack.exe %devname% || goto :error
.\%1\sendpack.exe %devname% || goto :error

echo Killing pcap_filter...
taskkill /PID %SAVEPID% || goto :error
SET SAVEPID=0

echo Reading dump file...
.\readfile.exe loopback.pcap || goto :error
.\%1\readfile.exe loopback.pcap || goto :error

echo Replaying dump file...
.\sendcap.exe loopback.pcap %devname% || goto :error
.\%1\sendcap.exe loopback.pcap %devname% || goto :error


echo Checking for Internet...
Expand All @@ -37,7 +66,7 @@ if not %devname:~0,12%==\Device\NPF_ goto :error

echo Testing pcap_filter...
del scanme.pcap
start .\pcap_filter.exe -o scanme.pcap -s %devname% -f tcp
start .\%1\pcap_filter.exe -o scanme.pcap -s %devname% -f tcp
for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq pcap_filter.exe"') do set SAVEPID=%%b

echo Running nmap...
Expand All @@ -46,23 +75,16 @@ rem Need IPv6 connectivity to test this:
rem nmap -F -O -d -n -6 scanme.nmap.org || goto :error

echo Testing sendpack...
.\sendpack.exe %devname% || goto :error
.\%1\sendpack.exe %devname% || goto :error

echo Killing pcap_filter...
taskkill /PID %SAVEPID% || goto :error
SET SAVEPID=0

echo Reading dump file...
.\readfile.exe scanme.pcap || goto :error
.\%1\readfile.exe scanme.pcap || goto :error

echo Replaying dump file...
.\sendcap.exe scanme.pcap %devname% || goto :error

pause
exit /b
.\%1\sendcap.exe scanme.pcap %devname% || goto :error

:error
echo Failed: %errorlevel%
if %SAVEPID% NEQ 0 taskkill /PID %SAVEPID%
pause
exit /b %errorlevel%
goto :EOF

0 comments on commit 73e60af

Please sign in to comment.