Move check for SDL_Delay upper bounds to testtimer
parent
a84389f6bb
commit
f45761908a
|
@ -315,7 +315,7 @@ add_sdl_test_executable(testshape NEEDS_RESOURCES SOURCES testshape.c)
|
|||
add_sdl_test_executable(testsprite NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c)
|
||||
add_sdl_test_executable(testspriteminimal SOURCES testspriteminimal.c ${icon_bmp_header})
|
||||
add_sdl_test_executable(teststreaming NEEDS_RESOURCES TESTUTILS SOURCES teststreaming.c)
|
||||
add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c)
|
||||
add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_ARGS --no-interactive NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c)
|
||||
add_sdl_test_executable(testurl SOURCES testurl.c)
|
||||
add_sdl_test_executable(testver NONINTERACTIVE SOURCES testver.c)
|
||||
add_sdl_test_executable(testviewport NEEDS_RESOURCES TESTUTILS SOURCES testviewport.c)
|
||||
|
|
|
@ -92,7 +92,10 @@ static int timer_delayAndGetTicks(void *arg)
|
|||
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result2);
|
||||
difference = result2 - result;
|
||||
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %" SDL_PRIu64, testDelay - marginOfError, difference);
|
||||
#if 0
|
||||
/* Disabled because this might fail on non-interactive systems. Moved to testtimer. */
|
||||
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %" SDL_PRIu64, testDelay + marginOfError, difference);
|
||||
#endif
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,34 @@
|
|||
|
||||
#define DEFAULT_RESOLUTION 1
|
||||
|
||||
static int test_sdl_delay_within_bounds(void) {
|
||||
const int testDelay = 100;
|
||||
const int marginOfError = 25;
|
||||
Uint64 result;
|
||||
Uint64 result2;
|
||||
Sint64 difference;
|
||||
|
||||
SDLTest_ResetAssertSummary();
|
||||
|
||||
/* Get ticks count - should be non-zero by now */
|
||||
result = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result);
|
||||
|
||||
/* Delay a bit longer and measure ticks and verify difference */
|
||||
SDL_Delay(testDelay);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
|
||||
result2 = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result2);
|
||||
difference = result2 - result;
|
||||
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %" SDL_PRIu64, testDelay - marginOfError, difference);
|
||||
/* Disabled because this might fail on non-interactive systems. */
|
||||
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %" SDL_PRIu64, testDelay + marginOfError, difference);
|
||||
|
||||
return SDLTest_AssertSummaryToTestResult() == TEST_RESULT_PASSED ? 0 : 1;
|
||||
}
|
||||
|
||||
static int ticks = 0;
|
||||
|
||||
static Uint32 SDLCALL
|
||||
|
@ -43,6 +71,8 @@ int main(int argc, char *argv[])
|
|||
Uint64 start, now;
|
||||
Uint64 start_perf, now_perf;
|
||||
SDLTest_CommonState *state;
|
||||
SDL_bool run_interactive_tests = SDL_TRUE;
|
||||
int return_code = 0;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
|
@ -59,7 +89,10 @@ int main(int argc, char *argv[])
|
|||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (!consumed) {
|
||||
if (desired < 0) {
|
||||
if (SDL_strcmp(argv[i], "--no-interactive") == 0) {
|
||||
run_interactive_tests = SDL_FALSE;
|
||||
consumed = 1;
|
||||
} else if (desired < 0) {
|
||||
char *endptr;
|
||||
|
||||
desired = SDL_strtoul(argv[i], &endptr, 0);
|
||||
|
@ -69,7 +102,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
if (consumed <= 0) {
|
||||
static const char *options[] = { "[interval]", NULL };
|
||||
static const char *options[] = { "[--no-interactive]", "[interval]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
|
@ -162,7 +195,11 @@ int main(int argc, char *argv[])
|
|||
now = SDL_GetTicks();
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (int)(now - start), (double)((now_perf - start_perf) * 1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
if (run_interactive_tests) {
|
||||
return_code = test_sdl_delay_within_bounds();
|
||||
}
|
||||
|
||||
SDLTest_CommonDestroyState(state);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
return return_code;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue