src/test/SDL_test_common.c
changeset 11610 6dea196ecbcb
parent 11604 634c34c79fbc
child 11615 f5b657276413
     1.1 --- a/src/test/SDL_test_common.c	Thu Oct 12 13:28:48 2017 -0700
     1.2 +++ b/src/test/SDL_test_common.c	Thu Oct 12 13:44:28 2017 -0700
     1.3 @@ -47,7 +47,18 @@
     1.4  SDLTest_CommonState *
     1.5  SDLTest_CommonCreateState(char **argv, Uint32 flags)
     1.6  {
     1.7 -    SDLTest_CommonState *state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
     1.8 +    int i;
     1.9 +    SDLTest_CommonState *state;
    1.10 +
    1.11 +    /* Do this first so we catch all allocations */
    1.12 +    for (i = 1; argv[i]; ++i) {
    1.13 +        if (SDL_strcasecmp(argv[i], "--trackmem") == 0) {
    1.14 +            SDLTest_TrackAllocations();
    1.15 +            break;
    1.16 +        }
    1.17 +    }
    1.18 +
    1.19 +    state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
    1.20      if (!state) {
    1.21          SDL_OutOfMemory();
    1.22          return NULL;
    1.23 @@ -447,6 +458,10 @@
    1.24          state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
    1.25          return 2;
    1.26      }
    1.27 +    if (SDL_strcasecmp(argv[index], "--trackmem") == 0) {
    1.28 +        /* Already handled in SDLTest_CommonCreateState() */
    1.29 +        return 1;
    1.30 +    }
    1.31      if ((SDL_strcasecmp(argv[index], "-h") == 0)
    1.32          || (SDL_strcasecmp(argv[index], "--help") == 0)) {
    1.33          /* Print the usage message */
    1.34 @@ -464,13 +479,13 @@
    1.35  {
    1.36      switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
    1.37      case SDL_INIT_VIDEO:
    1.38 -        return VIDEO_USAGE;
    1.39 +        return "[--trackmem] " VIDEO_USAGE;
    1.40      case SDL_INIT_AUDIO:
    1.41 -        return AUDIO_USAGE;
    1.42 +        return "[--trackmem] " AUDIO_USAGE;
    1.43      case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
    1.44 -        return VIDEO_USAGE " " AUDIO_USAGE;
    1.45 +        return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE;
    1.46      default:
    1.47 -        return "";
    1.48 +        return "[--trackmem]";
    1.49      }
    1.50  }
    1.51  
    1.52 @@ -1762,6 +1777,7 @@
    1.53      }
    1.54      SDL_free(state);
    1.55      SDL_Quit();
    1.56 +    SDLTest_LogAllocations();
    1.57  }
    1.58  
    1.59  /* vi: set ts=4 sw=4 expandtab: */