testautomation.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <time.h>
  13. #include "SDL.h"
  14. #include "SDL_test.h"
  15. #include "testautomation_suites.h"
  16. static SDLTest_CommonState *state;
  17. /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
  18. static void
  19. quit(int rc)
  20. {
  21. SDLTest_CommonQuit(state);
  22. exit(rc);
  23. }
  24. int
  25. main(int argc, char *argv[])
  26. {
  27. int result;
  28. int testIterations = 1;
  29. Uint64 userExecKey = 0;
  30. char *userRunSeed = NULL;
  31. char *filter = NULL;
  32. int i, done;
  33. SDL_Event event;
  34. /* Initialize test framework */
  35. state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
  36. if (!state) {
  37. return 1;
  38. }
  39. /* Parse commandline */
  40. for (i = 1; i < argc;) {
  41. int consumed;
  42. consumed = SDLTest_CommonArg(state, i);
  43. if (consumed == 0) {
  44. consumed = -1;
  45. if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
  46. if (argv[i + 1]) {
  47. testIterations = SDL_atoi(argv[i + 1]);
  48. if (testIterations < 1) testIterations = 1;
  49. consumed = 2;
  50. }
  51. }
  52. else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
  53. if (argv[i + 1]) {
  54. SDL_sscanf(argv[i + 1], "%llu", (long long unsigned int *)&userExecKey);
  55. consumed = 2;
  56. }
  57. }
  58. else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
  59. if (argv[i + 1]) {
  60. userRunSeed = SDL_strdup(argv[i + 1]);
  61. consumed = 2;
  62. }
  63. }
  64. else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
  65. if (argv[i + 1]) {
  66. filter = SDL_strdup(argv[i + 1]);
  67. consumed = 2;
  68. }
  69. }
  70. }
  71. if (consumed < 0) {
  72. SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
  73. argv[0], SDLTest_CommonUsage(state));
  74. quit(1);
  75. }
  76. i += consumed;
  77. }
  78. /* Initialize common state */
  79. if (!SDLTest_CommonInit(state)) {
  80. quit(2);
  81. }
  82. /* Create the windows, initialize the renderers */
  83. for (i = 0; i < state->num_windows; ++i) {
  84. SDL_Renderer *renderer = state->renderers[i];
  85. SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
  86. SDL_RenderClear(renderer);
  87. }
  88. /* Call Harness */
  89. result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
  90. /* Empty event queue */
  91. done = 0;
  92. for (i=0; i<100; i++) {
  93. while (SDL_PollEvent(&event)) {
  94. SDLTest_CommonEvent(state, &event, &done);
  95. }
  96. SDL_Delay(10);
  97. }
  98. /* Clean up */
  99. SDL_free(userRunSeed);
  100. SDL_free(filter);
  101. /* Shutdown everything */
  102. quit(result);
  103. return(result);
  104. }
  105. /* vi: set ts=4 sw=4 expandtab: */