SDL: testtimer: Add basic sanity check for SDL_GetTicks*()

From 4ab7ee1925c4785d70d31b7ed41efe4212319b2d Mon Sep 17 00:00:00 2001
From: Eddy Jansson <[EMAIL REDACTED]>
Date: Tue, 2 Nov 2021 18:58:06 +0100
Subject: [PATCH] testtimer: Add basic sanity check for SDL_GetTicks*()

---
 test/testtimer.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/test/testtimer.c b/test/testtimer.c
index 1e242d7daa..ceb5847ca9 100644
--- a/test/testtimer.c
+++ b/test/testtimer.c
@@ -54,6 +54,23 @@ main(int argc, char *argv[])
         return (1);
     }
 
+    /* Verify SDL_GetTicks* acts monotonically increasing, and not erratic. */
+    SDL_Log("Sanity-checking GetTicks\n");
+    for (i = 0; i < 1000; ++i) {
+        start64 = SDL_GetTicks64();
+        start32 = SDL_GetTicks();
+        SDL_Delay(1);
+        now64 = SDL_GetTicks64();
+        now32 = SDL_GetTicks();
+        Uint32 dt32 = now32-start32;
+        Uint64 dt64 = now64-start64;
+        if (dt32 > 100 || dt64 > 100) {
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testtimer.c: Delta time erratic at iter %d. Delay 1ms = %d ms in ticks, %d ms in ticks64\n", i, (int)dt32, (int)dt64);
+            SDL_Quit();
+            return 1;
+        }
+    }
+
     /* Start the timer */
     desired = 0;
     if (argv[1]) {