anchor.diff:          exit /b 0
       )
   
  -    start "" "%~dp0PresentBench.exe" /Width=320 /Height=240 /Api=DX12
  +    start /b "" "%~dp0PresentBench.exe" %* >NUL
       for /f "tokens=1,2 delims=:" %%a in ('tasklist /fi "imagename eq PresentBench.exe" /fo list') do (
           if "%%a" EQU "PID" (
  -            set started_target_app_pid=%%b
  +            set /a started_target_app_pid=%%b
               exit /b 0
           )
       )
       exit /b 0
   
   :stop_target_app
  -    if %started_target_app_pid% NEQ 0 taskkill /PID %started_target_app_pid%
  -    exit /b 0
  +    if %started_target_app_pid% EQU 0 exit /b 0
  +    taskkill /PID %started_target_app_pid% >NUL
  +    :until_killed
  +        call :is_app_running /fi "imagename eq PresentBench.exe" /fi "pid eq %started_target_app_pid%"
  +        if %errorlevel% NEQ 0 goto until_killed
  +    set started_target_app_pid=0
  +    exit /b 0
  +
  +:is_app_running
  +    for /f "tokens=1,2 delims=:" %%a in ('tasklist %* /fo list') do (
  +        if "%%a" EQU "PID" exit /b 1
  +    )
  +    exit /b 0
  +
  +:: -----------------------------------------------------------------------------
  +:realtime_test
  +    set test_api=%~1
  +    set expected_runtime=%~2
  +
  +    call :start_target_app /width=320 /height=240 /api=%test_api%
  +    if %errorlevel% NEQ 0 (
  +        echo [31merror: realtime tests cannot run with a process named PresentBench.exe already running[0m
  +        set /a errorcount=%errorcount%+1
  +        exit /b 0
  +    )
  +
  +    set saw_row=0
  +    set saw_error=0
  +    set present_mode=
  +    for /f "tokens=4,12 delims=," %%a in ('"%pmdir%\build\%test_config%\PresentMon-%version%-x64.exe" -process_id %started_target_app_pid% -output_stdout -timed 2 -terminate_after_timed 2^>NUL') do (
  +        if "%%a" NEQ "Runtime" (
  +            if !saw_row! EQU 0 (
  +                set present_mode=%%b
  +                set saw_row=1
  +            )
  +            if "%%a" NEQ "%expected_runtime%" (
  +                if !saw_error! EQU 0 (
  +                    echo [31merror: expecting runtime "%expected_runtime%", but got "%%a"[0m
  +                    set saw_error=1
  +                )
  +            )
  +        )
  +    )
  +
  +    call :stop_target_app
  +
  +    if %saw_error% NEQ 0 (
  +        set /a errorcount=%errorcount%+1
  +        exit /b 0
  +    )
  +    if %saw_row% EQU 0 (
  +        echo [31merror: realtime tests did not record any presents[0m
  +        set /a errorcount=%errorcount%+1
  +        exit /b 0
  +    )
  +
  +    echo.   [90m%test_api%: %expected_runtime%, %present_mode%[0m
  +    exit /b 0
  +
  
positive.code: :start_target_app
      set started_target_app_pid=0
  
      :: Check if there's already one running, if so just leave it running and don't kill it after
      for /f "tokens=1,2 delims=:" %%a in ('tasklist /fi "imagename eq PresentBench.exe" /fo list') do (
          if "%%a" EQU "PID" exit /b 0
      )
  
      if not exist "%~dp0PresentBench.exe" (
          echo [31mwarning: dependency not found: %~dp0PresentBench.exe[0m
  
negative.code:         echo     debug        Only test the debug build
          echo     release      Only test the release build
          echo     nobuild      Don't build any configurations
          echo     norealtime   Don't run tests for realtime collection
          echo     nogtests     Don't run default test suite
          exit /b 1
      ))))))
      shift
      goto args_begin
  :args_end
  