mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-12-19 19:10:31 +08:00
testthread: parse arguments using SDLTest_CommonState + add arguments
This commit is contained in:
committed by
Anonymous Maarten
parent
64b739bc1e
commit
8bea41f737
@@ -69,7 +69,7 @@ static void closemutex(int sig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int SDLCALL
|
static int SDLCALL
|
||||||
DoWork(void *data)
|
Run(void *data)
|
||||||
{
|
{
|
||||||
if (SDL_ThreadID() == mainthread) {
|
if (SDL_ThreadID() == mainthread) {
|
||||||
(void)signal(SIGTERM, closemutex);
|
(void)signal(SIGTERM, closemutex);
|
||||||
@@ -195,7 +195,7 @@ int main(int argc, char *argv[])
|
|||||||
for (i = 0; i < nb_threads; ++i) {
|
for (i = 0; i < nb_threads; ++i) {
|
||||||
char name[64];
|
char name[64];
|
||||||
(void)SDL_snprintf(name, sizeof(name), "Worker%d", i);
|
(void)SDL_snprintf(name, sizeof(name), "Worker%d", i);
|
||||||
threads[i] = SDL_CreateThread(DoWork, name, &threads[i]);
|
threads[i] = SDL_CreateThread(Run, name, NULL);
|
||||||
if (threads[i] == NULL) {
|
if (threads[i] == NULL) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
(void)signal(SIGINT, terminate);
|
(void)signal(SIGINT, terminate);
|
||||||
DoWork(NULL);
|
Run(NULL);
|
||||||
|
|
||||||
return 0; /* Never reached */
|
return 0; /* Never reached */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,18 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
|
#include <SDL3/SDL_test.h>
|
||||||
|
|
||||||
static SDL_TLSID tls;
|
static SDL_TLSID tls;
|
||||||
static int alive = 0;
|
static int alive = 0;
|
||||||
static int testprio = 0;
|
static int testprio = 0;
|
||||||
|
SDLTest_CommonState *state;
|
||||||
|
|
||||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||||
static void
|
static void
|
||||||
quit(int rc)
|
quit(int rc)
|
||||||
{
|
{
|
||||||
|
SDLTest_CommonDestroyState(state);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
exit(rc);
|
exit(rc);
|
||||||
}
|
}
|
||||||
@@ -82,12 +85,38 @@ killed(int sig)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 1;
|
int i;
|
||||||
SDL_Thread *thread;
|
SDL_Thread *thread;
|
||||||
|
|
||||||
|
/* Initialize test framework */
|
||||||
|
state = SDLTest_CommonCreateState(argv, 0);
|
||||||
|
if (state == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Enable standard application logging */
|
/* Enable standard application logging */
|
||||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||||
|
|
||||||
|
/* Parse commandline */
|
||||||
|
for (i = 1; i < argc;) {
|
||||||
|
int consumed;
|
||||||
|
|
||||||
|
consumed = SDLTest_CommonArg(state, i);
|
||||||
|
if (!consumed) {
|
||||||
|
if (SDL_strcmp("--prio", argv[i]) == 0) {
|
||||||
|
testprio = 1;
|
||||||
|
consumed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (consumed <= 0) {
|
||||||
|
static const char *options[] = { "[--prio]", NULL };
|
||||||
|
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
i += consumed;
|
||||||
|
}
|
||||||
|
|
||||||
/* Load the SDL library */
|
/* Load the SDL library */
|
||||||
if (SDL_Init(0) < 0) {
|
if (SDL_Init(0) < 0) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||||
@@ -100,13 +129,6 @@ int main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (argv[arg] && *argv[arg] == '-') {
|
|
||||||
if (SDL_strcmp(argv[arg], "--prio") == 0) {
|
|
||||||
testprio = 1;
|
|
||||||
}
|
|
||||||
++arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
tls = SDL_TLSCreate();
|
tls = SDL_TLSCreate();
|
||||||
SDL_assert(tls);
|
SDL_assert(tls);
|
||||||
SDL_TLSSet(tls, "main thread", NULL);
|
SDL_TLSSet(tls, "main thread", NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user