Add tests to audio suite; update harness filter logic
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Thu, 31 Jan 2013 08:45:30 -0800
changeset 68300cd3e2e9b2c5
parent 6829 36ce2e6166e7
child 6831 935b871e1ffe
Add tests to audio suite; update harness filter logic
src/test/SDL_test_harness.c
test/testautomation.c
test/testautomation_audio.c
     1.1 --- a/src/test/SDL_test_harness.c	Sun Jan 27 20:37:14 2013 -0800
     1.2 +++ b/src/test/SDL_test_harness.c	Thu Jan 31 08:45:30 2013 -0800
     1.3 @@ -221,7 +221,7 @@
     1.4  * \returns Test case result.
     1.5  */
     1.6  int
     1.7 -	SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey)
     1.8 +SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey)
     1.9  {
    1.10  	SDL_TimerID timer = 0;
    1.11  	int testResult = 0;
    1.12 @@ -479,6 +479,11 @@
    1.13  							testCounter,
    1.14  							currentTestName);
    1.15  				} else {
    1.16 +					// Override 'disabled' flag if we specified a test filter (i.e. force run for debugging)
    1.17 +					if (testFilter == 1 && !testCase->enabled) {
    1.18 +						SDLTest_Log("Force run of disabled test since test filter was set");
    1.19 +						testCase->enabled = 1;
    1.20 +					}
    1.21  
    1.22  					// Take time - test start
    1.23  					testStartSeconds = GetClock();
     2.1 --- a/test/testautomation.c	Sun Jan 27 20:37:14 2013 -0800
     2.2 +++ b/test/testautomation.c	Thu Jan 31 08:45:30 2013 -0800
     2.3 @@ -37,7 +37,8 @@
     2.4      Uint64 userExecKey = 0;
     2.5      char *userRunSeed = NULL;
     2.6      char *filter = NULL;
     2.7 -    int i;
     2.8 +    int i, done;
     2.9 +    SDL_Event event;
    2.10  
    2.11      /* Initialize test framework */
    2.12      state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    2.13 @@ -103,6 +104,15 @@
    2.14      /* Call Harness */
    2.15      result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
    2.16  
    2.17 +    /* Empty event queue */    
    2.18 +    done = 0;
    2.19 +    for (i=0; i<100; i++)  {
    2.20 +      while (SDL_PollEvent(&event)) {
    2.21 +        SDLTest_CommonEvent(state, &event, &done);
    2.22 +      }
    2.23 +      SDL_Delay(10);
    2.24 +    }
    2.25 +
    2.26      /* Clean up */
    2.27      if (userRunSeed != NULL) {
    2.28          SDL_free(userRunSeed);
     3.1 --- a/test/testautomation_audio.c	Sun Jan 27 20:37:14 2013 -0800
     3.2 +++ b/test/testautomation_audio.c	Thu Jan 31 08:45:30 2013 -0800
     3.3 @@ -173,10 +173,8 @@
     3.4   */
     3.5  int audio_printCurrentAudioDriver()
     3.6  {
     3.7 -   const char *name;
     3.8 -
     3.9     /* Check current audio driver */
    3.10 -   name = SDL_GetCurrentAudioDriver();
    3.11 +   const char *name = SDL_GetCurrentAudioDriver();
    3.12     SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
    3.13     SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
    3.14     if (name != NULL) {
    3.15 @@ -186,6 +184,19 @@
    3.16     return TEST_COMPLETED;
    3.17  }
    3.18  
    3.19 +/* Definition of all formats, channels, and frequencies used to test audio conversions */
    3.20 +const int _numFormats = 18;
    3.21 +SDL_AudioFormat _formats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB, 
    3.22 +				AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32, 
    3.23 +                                AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
    3.24 +char *_formatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB", 
    3.25 +				"AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32", 
    3.26 +                                "AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
    3.27 +const int _numChannels = 4;
    3.28 +Uint8 _channels[] = { 1, 2, 4, 6 };
    3.29 +const int _numFrequencies = 4;
    3.30 +int _frequencies[] = { 11025, 22050, 44100, 48000 };
    3.31 +
    3.32  
    3.33  /**
    3.34   * \brief Builds various audio conversion structures
    3.35 @@ -198,15 +209,7 @@
    3.36    SDL_AudioCVT  cvt;
    3.37    SDL_AudioSpec spec1;
    3.38    SDL_AudioSpec spec2;
    3.39 -  int i, j, k;
    3.40 -  const int numFormats = 18;
    3.41 -  SDL_AudioFormat formats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB, 
    3.42 -                                AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32, 
    3.43 -                                AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
    3.44 -  const int numChannels = 4;
    3.45 -  Uint8 channels[] = { 1, 2, 4, 6 };
    3.46 -  const int numFrequencies = 4;
    3.47 -  int frequencies[] = { 11025, 22050, 44100, 48000 };
    3.48 +  int i, ii, j, jj, k, kk;
    3.49    
    3.50    /* No conversion needed */
    3.51    spec1.format = AUDIO_S16LSB;
    3.52 @@ -229,23 +232,28 @@
    3.53    SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
    3.54    SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
    3.55  
    3.56 -  /* All source conversions with random conversion targets */
    3.57 -  for (i=0; i<numFormats; i++) {
    3.58 -    for (j=0; j<numChannels; j++) {
    3.59 -      for (k=0; k<numFrequencies; k++) {
    3.60 -        spec1.format = formats[i];
    3.61 -        spec1.channels = channels[j];
    3.62 -        spec1.freq = frequencies[k];
    3.63 -        spec2.format = formats[SDLTest_RandomIntegerInRange(0, numFormats - 1)];
    3.64 -        spec2.channels = channels[SDLTest_RandomIntegerInRange(0, numChannels - 1)];
    3.65 -        spec2.freq = frequencies[SDLTest_RandomIntegerInRange(0, numFrequencies - 1)];
    3.66 +  /* All source conversions with random conversion targets, allow 'null' conversions */
    3.67 +  for (i = 0; i < _numFormats; i++) {
    3.68 +    for (j = 0; j < _numChannels; j++) {
    3.69 +      for (k = 0; k < _numFrequencies; k++) {
    3.70 +        spec1.format = _formats[i];
    3.71 +        spec1.channels = _channels[j];
    3.72 +        spec1.freq = _frequencies[k];
    3.73 +        ii = SDLTest_RandomIntegerInRange(0, _numFormats - 1);
    3.74 +        jj = SDLTest_RandomIntegerInRange(0, _numChannels - 1);
    3.75 +        kk = SDLTest_RandomIntegerInRange(0, _numFrequencies - 1);
    3.76 +        spec2.format = _formats[ii];
    3.77 +        spec2.channels = _channels[jj];
    3.78 +        spec2.freq = _frequencies[kk];
    3.79          result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
    3.80 -                                        spec2.format, spec2.channels, spec2.freq);
    3.81 -        SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format=%i,channels=%i,freq=%i ==> format=%i,channels=%i,freq=%i)", 
    3.82 -            spec1.format, spec1.channels, spec1.freq, spec2.format, spec2.channels, spec2.freq);
    3.83 +                                         spec2.format, spec2.channels, spec2.freq);
    3.84 +        SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)", 
    3.85 +            i, _formatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _formatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
    3.86          SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
    3.87          if (result<0) {
    3.88            SDLTest_LogError(SDL_GetError());
    3.89 +        } else {
    3.90 +          SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
    3.91          }
    3.92        }
    3.93      }
    3.94 @@ -372,6 +380,7 @@
    3.95  /* Test callback function */
    3.96  void _audio_testCallback(void *userdata, Uint8 *stream, int len)
    3.97  {
    3.98 +   /* TODO: add tracking if callback was called */
    3.99  }
   3.100  
   3.101  /**
   3.102 @@ -391,8 +400,8 @@
   3.103     /* Get number of devices. */
   3.104     count = SDL_GetNumAudioDevices(0);
   3.105     SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   3.106 -   if (count>0) {
   3.107 -     for (i=0; i< count; i++) {
   3.108 +   if (count > 0) {
   3.109 +     for (i = 0; i < count; i++) {
   3.110         /* Get device name */
   3.111         device = (char *)SDL_GetAudioDeviceName(i, 0);
   3.112         SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
   3.113 @@ -449,8 +458,8 @@
   3.114     /* Get number of devices. */
   3.115     count = SDL_GetNumAudioDevices(0);
   3.116     SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   3.117 -   if (count>0) {
   3.118 -     for (i=0; i< count; i++) {
   3.119 +   if (count > 0) {
   3.120 +     for (i = 0; i < count; i++) {
   3.121         /* Get device name */
   3.122         device = (char *)SDL_GetAudioDeviceName(i, 0);
   3.123         SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
   3.124 @@ -495,6 +504,168 @@
   3.125  }
   3.126  
   3.127  
   3.128 +/**
   3.129 + * \brief Convert audio using various conversion structures
   3.130 + *
   3.131 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
   3.132 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_ConvertAudio
   3.133 + */
   3.134 +int audio_convertAudio()
   3.135 +{
   3.136 +  int result;
   3.137 +  SDL_AudioCVT  cvt;
   3.138 +  SDL_AudioSpec spec1;
   3.139 +  SDL_AudioSpec spec2;
   3.140 +  int c;
   3.141 +  char message[128];
   3.142 +  int i, ii, j, jj, k, kk, l, ll;
   3.143 +
   3.144 +  /* Iterate over bitmask that determines which parameters are modified in the conversion */
   3.145 +  for (c = 1; c < 8; c++) {
   3.146 +    SDL_strlcpy(message, "Changing:", 128);
   3.147 +    if (c & 1) {
   3.148 +      SDL_strlcat(message, " Format", 128);
   3.149 +    }
   3.150 +    if (c & 2) {
   3.151 +      SDL_strlcat(message, " Channels", 128);
   3.152 +    }
   3.153 +    if (c & 4) {
   3.154 +      SDL_strlcat(message, " Frequencies", 128);
   3.155 +    }
   3.156 +    SDLTest_Log(message);
   3.157 +    /* All source conversions with random conversion targets */
   3.158 +    for (i = 0; i < _numFormats; i++) {
   3.159 +      for (j = 0; j < _numChannels; j++) {
   3.160 +        for (k = 0; k < _numFrequencies; k++) {        
   3.161 +          spec1.format = _formats[i];
   3.162 +          spec1.channels = _channels[j];
   3.163 +          spec1.freq = _frequencies[k];
   3.164 +        
   3.165 +          /* Ensure we have a different target format */
   3.166 +          do {
   3.167 +            if (c & 1) {
   3.168 +              ii = SDLTest_RandomIntegerInRange(0, _numFormats - 1);
   3.169 +            } else {
   3.170 +              ii = 1;
   3.171 +            }
   3.172 +            if (c & 2) {
   3.173 +              jj = SDLTest_RandomIntegerInRange(0, _numChannels - 1);
   3.174 +            } else {
   3.175 +              jj= j;
   3.176 +            }
   3.177 +            if (c & 4) {
   3.178 +              kk = SDLTest_RandomIntegerInRange(0, _numFrequencies - 1);
   3.179 +            } else {
   3.180 +              kk = k;
   3.181 +            }
   3.182 +          } while ((i == ii) && (j == jj) && (k == kk));
   3.183 +          spec2.format = _formats[ii];
   3.184 +          spec2.channels = _channels[jj];
   3.185 +          spec2.freq = _frequencies[kk];
   3.186 +        
   3.187 +          result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
   3.188 +                                           spec2.format, spec2.channels, spec2.freq);
   3.189 +          SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)", 
   3.190 +            i, _formatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, _formatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
   3.191 +          SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
   3.192 +          if (result != 1) {
   3.193 +            SDLTest_LogError(SDL_GetError());
   3.194 +          } else {
   3.195 +            SDLTest_AssertCheck(cvt.len_mult > 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult);
   3.196 +            if (cvt.len_mult < 1) return TEST_ABORTED;
   3.197 +          
   3.198 +            /* Create some random data to convert */
   3.199 +            l = 64;
   3.200 +            ll = l * cvt.len_mult;
   3.201 +            SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, ll);
   3.202 +            cvt.len = l;
   3.203 +            cvt.buf = (Uint8 *)SDL_malloc(ll);
   3.204 +            SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL");
   3.205 +            if (cvt.buf == NULL) return TEST_ABORTED;
   3.206 +          
   3.207 +            /* Convert the data */
   3.208 +            result = SDL_ConvertAudio(&cvt);
   3.209 +            SDLTest_AssertPass("Call to SDL_ConvertAudio()");
   3.210 +            SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0; got: %i", result);
   3.211 +            SDLTest_AssertCheck(cvt.buf != NULL, "Verify conversion buffer is not NULL");
   3.212 +            SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
   3.213 +          
   3.214 +            /* Free converted buffer */
   3.215 +            if (cvt.buf != NULL) {
   3.216 +          	SDL_free(cvt.buf);
   3.217 +          	cvt.buf = NULL;
   3.218 +	    }
   3.219 +	  }
   3.220 +        }
   3.221 +      }
   3.222 +    }
   3.223 +  }
   3.224 +
   3.225 +   return TEST_COMPLETED;
   3.226 +}
   3.227 +
   3.228 +
   3.229 +/**
   3.230 + * \brief Opens, checks current connected status, and closes a device.
   3.231 + *
   3.232 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_AudioDeviceConnected
   3.233 + */
   3.234 +int audio_openCloseAudioDeviceConnected()
   3.235 +{
   3.236 +   int result;
   3.237 +   int i;
   3.238 +   int count;
   3.239 +   char *device;   
   3.240 +   SDL_AudioDeviceID id;
   3.241 +   SDL_AudioSpec desired, obtained;
   3.242 +   
   3.243 +   /* Get number of devices. */
   3.244 +   count = SDL_GetNumAudioDevices(0);
   3.245 +   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   3.246 +   if (count > 0) {
   3.247 +     for (i = 0; i < count; i++) {
   3.248 +       /* Get device name */
   3.249 +       device = (char *)SDL_GetAudioDeviceName(i, 0);
   3.250 +       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
   3.251 +       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
   3.252 +       if (device == NULL) return TEST_ABORTED;
   3.253 +
   3.254 +       /* Set standard desired spec */
   3.255 +       desired.freq=22050;
   3.256 +       desired.format=AUDIO_S16SYS;
   3.257 +       desired.channels=2;
   3.258 +       desired.samples=4096;
   3.259 +       desired.callback=_audio_testCallback;
   3.260 +       desired.userdata=NULL;
   3.261 +       
   3.262 +       /* Open device */
   3.263 +       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
   3.264 +       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
   3.265 +       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
   3.266 +       if (id > 1) {
   3.267 +
   3.268 +/* TODO: enable test code when function is available in SDL2 */
   3.269 +
   3.270 +#ifdef AUDIODEVICECONNECTED_DEFINED     
   3.271 +         /* Get connected status */
   3.272 +         result = SDL_AudioDeviceConnected(id);
   3.273 +         SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
   3.274 +         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 0; got: %i", result);
   3.275 +#endif
   3.276 +         
   3.277 +         /* Close device again */
   3.278 +         SDL_CloseAudioDevice(id);
   3.279 +         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
   3.280 +       }
   3.281 +     }
   3.282 +   } else {
   3.283 +     SDLTest_Log("No devices to test with");
   3.284 +   }
   3.285 +   
   3.286 +   return TEST_COMPLETED;
   3.287 +}
   3.288 +
   3.289 +
   3.290  
   3.291  /* ================= Test Case References ================== */
   3.292  
   3.293 @@ -526,9 +697,21 @@
   3.294  static const SDLTest_TestCaseReference audioTest9 =
   3.295  		{ (SDLTest_TestCaseFp)audio_lockUnlockOpenAudioDevice, "audio_lockUnlockOpenAudioDevice", "Locks and unlocks an open audio device.", TEST_ENABLED };
   3.296  
   3.297 +/* TODO: enable test when SDL_ConvertAudio segfaults on cygwin have been fixed.    */
   3.298 +/* For debugging, test case can be run manually using --filter audio_convertAudio  */
   3.299 +
   3.300 +static const SDLTest_TestCaseReference audioTest10 =
   3.301 +		{ (SDLTest_TestCaseFp)audio_convertAudio, "audio_convertAudio", "Convert audio using available formats.", TEST_DISABLED };
   3.302 +
   3.303 +/* TODO: enable test when SDL_AudioDeviceConnected has been implemented.           */
   3.304 +
   3.305 +static const SDLTest_TestCaseReference audioTest11 =
   3.306 +		{ (SDLTest_TestCaseFp)audio_openCloseAudioDeviceConnected, "audio_openCloseAudioDeviceConnected", "Opens and closes audio device and get connected status.", TEST_DISABLED };
   3.307 +
   3.308  /* Sequence of Audio test cases */
   3.309  static const SDLTest_TestCaseReference *audioTests[] =  {
   3.310 -	&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6, &audioTest7, &audioTest8, &audioTest9, NULL
   3.311 +	&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6, 
   3.312 +	&audioTest7, &audioTest8, &audioTest9, &audioTest10, &audioTest11, NULL
   3.313  };
   3.314  
   3.315  /* Audio test suite (global) */