tests: add --no-threads argument to disable threads
This is useful for Emscripten that can be built without threads support
This commit is contained in:
parent
3fccb77da6
commit
50f50df8b1
3 changed files with 82 additions and 27 deletions
|
@ -703,6 +703,8 @@ static void RunFIFOTest(SDL_bool lock_free)
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDLTest_CommonState *state;
|
SDLTest_CommonState *state;
|
||||||
|
int i;
|
||||||
|
SDL_bool enable_threads = SDL_TRUE;
|
||||||
|
|
||||||
/* Initialize test framework */
|
/* Initialize test framework */
|
||||||
state = SDLTest_CommonCreateState(argv, 0);
|
state = SDLTest_CommonCreateState(argv, 0);
|
||||||
|
@ -714,8 +716,26 @@ int main(int argc, char *argv[])
|
||||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||||
|
|
||||||
/* Parse commandline */
|
/* Parse commandline */
|
||||||
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
for (i = 1; i < argc;) {
|
||||||
return 1;
|
int consumed;
|
||||||
|
|
||||||
|
consumed = SDLTest_CommonArg(state, i);
|
||||||
|
if (consumed == 0) {
|
||||||
|
consumed = -1;
|
||||||
|
if (SDL_strcasecmp(argv[i], "--no-threads") == 0) {
|
||||||
|
enable_threads = SDL_FALSE;
|
||||||
|
consumed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (consumed < 0) {
|
||||||
|
static const char *options[] = {
|
||||||
|
"[--no-threads]",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
i += consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
RunBasicTest();
|
RunBasicTest();
|
||||||
|
@ -725,7 +745,9 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RunEpicTest();
|
if (enable_threads) {
|
||||||
|
RunEpicTest();
|
||||||
|
}
|
||||||
/* This test is really slow, so don't run it by default */
|
/* This test is really slow, so don't run it by default */
|
||||||
#if 0
|
#if 0
|
||||||
RunFIFOTest(SDL_FALSE);
|
RunFIFOTest(SDL_FALSE);
|
||||||
|
|
|
@ -49,6 +49,8 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDL_Thread *thread;
|
SDL_Thread *thread;
|
||||||
SDLTest_CommonState *state;
|
SDLTest_CommonState *state;
|
||||||
|
int i;
|
||||||
|
SDL_bool enable_threads = SDL_TRUE;
|
||||||
|
|
||||||
/* Initialize test framework */
|
/* Initialize test framework */
|
||||||
state = SDLTest_CommonCreateState(argv, 0);
|
state = SDLTest_CommonCreateState(argv, 0);
|
||||||
|
@ -60,8 +62,26 @@ int main(int argc, char *argv[])
|
||||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||||
|
|
||||||
/* Parse commandline */
|
/* Parse commandline */
|
||||||
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
for (i = 1; i < argc;) {
|
||||||
return 1;
|
int consumed;
|
||||||
|
|
||||||
|
consumed = SDLTest_CommonArg(state, i);
|
||||||
|
if (consumed == 0) {
|
||||||
|
consumed = -1;
|
||||||
|
if (SDL_strcasecmp(argv[i], "--no-threads") == 0) {
|
||||||
|
enable_threads = SDL_FALSE;
|
||||||
|
consumed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (consumed < 0) {
|
||||||
|
static const char *options[] = {
|
||||||
|
"[--no-threads]",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
i += consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load the SDL library */
|
/* Load the SDL library */
|
||||||
|
@ -79,16 +99,18 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
alive = 1;
|
if (enable_threads) {
|
||||||
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
|
alive = 1;
|
||||||
if (!thread) {
|
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
if (!thread) {
|
||||||
quit(1);
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||||
|
quit(1);
|
||||||
|
}
|
||||||
|
SDL_Delay(5 * 1000);
|
||||||
|
SDL_Log("Waiting for thread #1\n");
|
||||||
|
alive = 0;
|
||||||
|
SDL_WaitThread(thread, NULL);
|
||||||
}
|
}
|
||||||
SDL_Delay(5 * 1000);
|
|
||||||
SDL_Log("Waiting for thread #1\n");
|
|
||||||
alive = 0;
|
|
||||||
SDL_WaitThread(thread, NULL);
|
|
||||||
|
|
||||||
SDL_Log("Main thread error string: %s\n", SDL_GetError());
|
SDL_Log("Main thread error string: %s\n", SDL_GetError());
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ typedef struct Thread_State
|
||||||
} Thread_State;
|
} Thread_State;
|
||||||
|
|
||||||
static void log_usage(char *progname, SDLTest_CommonState *state) {
|
static void log_usage(char *progname, SDLTest_CommonState *state) {
|
||||||
static const char *options[] = { "init_value", NULL };
|
static const char *options[] = { "[--no-threads]", "init_value", NULL };
|
||||||
SDLTest_CommonLogUsage(state, progname, options);
|
SDLTest_CommonLogUsage(state, progname, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ TestWaitTimeout(void)
|
||||||
duration = end_ticks - start_ticks;
|
duration = end_ticks - start_ticks;
|
||||||
|
|
||||||
/* Accept a little offset in the effective wait */
|
/* Accept a little offset in the effective wait */
|
||||||
SDL_assert(duration > 1900 && duration < 2050);
|
|
||||||
SDL_Log("Wait took %" SDL_PRIu64 " milliseconds\n\n", duration);
|
SDL_Log("Wait took %" SDL_PRIu64 " milliseconds\n\n", duration);
|
||||||
|
SDL_assert(duration > 1900 && duration < 2050);
|
||||||
|
|
||||||
/* Check to make sure the return value indicates timed out */
|
/* Check to make sure the return value indicates timed out */
|
||||||
if (retval != SDL_MUTEX_TIMEDOUT) {
|
if (retval != SDL_MUTEX_TIMEDOUT) {
|
||||||
|
@ -257,6 +257,7 @@ int main(int argc, char **argv)
|
||||||
int arg_count = 0;
|
int arg_count = 0;
|
||||||
int i;
|
int i;
|
||||||
int init_sem = 0;
|
int init_sem = 0;
|
||||||
|
SDL_bool enable_threads = SDL_TRUE;
|
||||||
SDLTest_CommonState *state;
|
SDLTest_CommonState *state;
|
||||||
|
|
||||||
/* Initialize test framework */
|
/* Initialize test framework */
|
||||||
|
@ -273,12 +274,18 @@ int main(int argc, char **argv)
|
||||||
int consumed;
|
int consumed;
|
||||||
|
|
||||||
consumed = SDLTest_CommonArg(state, i);
|
consumed = SDLTest_CommonArg(state, i);
|
||||||
if (arg_count == 0) {
|
if (consumed == 0) {
|
||||||
char *endptr;
|
consumed = -1;
|
||||||
init_sem = SDL_strtol(argv[i], &endptr, 0);
|
if (SDL_strcasecmp(argv[i], "--no-threads") == 0) {
|
||||||
if (endptr != argv[i] && *endptr == '\0') {
|
enable_threads = SDL_FALSE;
|
||||||
arg_count++;
|
|
||||||
consumed = 1;
|
consumed = 1;
|
||||||
|
} else if (arg_count == 0) {
|
||||||
|
char *endptr;
|
||||||
|
init_sem = SDL_strtol(argv[i], &endptr, 0);
|
||||||
|
if (endptr != argv[i] && *endptr == '\0') {
|
||||||
|
arg_count++;
|
||||||
|
consumed = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (consumed <= 0) {
|
if (consumed <= 0) {
|
||||||
|
@ -302,17 +309,21 @@ int main(int argc, char **argv)
|
||||||
(void)signal(SIGTERM, killed);
|
(void)signal(SIGTERM, killed);
|
||||||
(void)signal(SIGINT, killed);
|
(void)signal(SIGINT, killed);
|
||||||
|
|
||||||
if (init_sem > 0) {
|
if (enable_threads) {
|
||||||
TestRealWorld(init_sem);
|
if (init_sem > 0) {
|
||||||
}
|
TestRealWorld(init_sem);
|
||||||
|
}
|
||||||
|
|
||||||
TestWaitTimeout();
|
TestWaitTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
TestOverheadUncontended();
|
TestOverheadUncontended();
|
||||||
|
|
||||||
TestOverheadContended(SDL_FALSE);
|
if (enable_threads) {
|
||||||
|
TestOverheadContended(SDL_FALSE);
|
||||||
|
|
||||||
TestOverheadContended(SDL_TRUE);
|
TestOverheadContended(SDL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
SDLTest_CommonDestroyState(state);
|
SDLTest_CommonDestroyState(state);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue