test/testautomation.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2019 09:10:56 -0700
changeset 12928 3c4a4b1077cd
parent 12758 3c6a6dad3487
permissions -rw-r--r--
Fixed bug 4710 - audio/alsa: avoid configuring hardware parameters with only a single period

Anthony Pesch

The previous code first configured the period size using snd_pcm_hw_par-
ams_set_period_size_near. Then, it further narrowed the configuration
space by calling snd_pcm_hw_params_set_buffer_size_near using a buffer
size of 2 times the _requested_ period size in order to try and get a
configuration with only 2 periods. If the configured period size was
larger than the requested size, the second call could inadvertently
narrow the configuration space to contain only a single period.

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