mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 01:45:32 +00:00
tests: Fix automated audio tests on Windows and Linux
If a specific audio driver was requested for testing, don't loop over all drivers in the init, open/close, and pause/unpause tests. Additionally, drivers can fail if attempting to open an audio device when no underlying output is present, which is a valid case if the system has no audio hardware available. Check for the presence of audio output devices before attempting to open them. Fixes automated tests with various drivers on Windows and Linux.
This commit is contained in:
parent
06dd70bc8b
commit
f569cc56a9
|
@ -52,6 +52,42 @@ void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
|
||||||
_audio_testCallbackLength += len;
|
_audio_testCallbackLength += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
/* Linux builds can include many audio drivers, but some are very
|
||||||
|
* obscure and typically unsupported on modern systems. They will
|
||||||
|
* be skipped in tests that run against all included drivers, as
|
||||||
|
* they are basically guaranteed to fail.
|
||||||
|
*/
|
||||||
|
static SDL_bool DriverIsProblematic(const char *driver)
|
||||||
|
{
|
||||||
|
static const char *driverList[] = {
|
||||||
|
/* Omnipresent in Linux builds, but deprecated since 2002,
|
||||||
|
* very rarely used on Linux nowadays, and is almost certainly
|
||||||
|
* guaranteed to fail.
|
||||||
|
*/
|
||||||
|
"dsp",
|
||||||
|
|
||||||
|
/* OpenBSD sound API. Can be used on Linux, but very rare. */
|
||||||
|
"sndio",
|
||||||
|
|
||||||
|
/* Always fails on initialization and/or opening a device.
|
||||||
|
* Does anyone or anything actually use this?
|
||||||
|
*/
|
||||||
|
"nas"
|
||||||
|
};
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < SDL_arraysize(driverList); ++i) {
|
||||||
|
if (SDL_strcmp(driver, driverList[i]) == 0) {
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Test case functions */
|
/* Test case functions */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,15 +125,33 @@ int audio_initQuitAudio()
|
||||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
||||||
|
|
||||||
/* Loop over all available audio drivers */
|
/* Was a specific driver requested? */
|
||||||
iMax = SDL_GetNumAudioDrivers();
|
audioDriver = SDL_GetHint(SDL_HINT_AUDIODRIVER);
|
||||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
|
||||||
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
if (audioDriver == NULL) {
|
||||||
|
/* Loop over all available audio drivers */
|
||||||
|
iMax = SDL_GetNumAudioDrivers();
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
||||||
|
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
||||||
|
} else {
|
||||||
|
/* A specific driver was requested for testing */
|
||||||
|
iMax = 1;
|
||||||
|
}
|
||||||
for (i = 0; i < iMax; i++) {
|
for (i = 0; i < iMax; i++) {
|
||||||
audioDriver = SDL_GetAudioDriver(i);
|
if (audioDriver == NULL) {
|
||||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
audioDriver = SDL_GetAudioDriver(i);
|
||||||
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
|
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
||||||
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
|
||||||
|
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
if (DriverIsProblematic(audioDriver)) {
|
||||||
|
SDLTest_Log("Audio driver '%s' flagged as problematic: skipping init/quit test (set SDL_AUDIODRIVER=%s to force)", audioDriver, audioDriver);
|
||||||
|
audioDriver = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
|
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -111,6 +165,8 @@ int audio_initQuitAudio()
|
||||||
/* Call Quit */
|
/* Call Quit */
|
||||||
SDL_AudioQuit();
|
SDL_AudioQuit();
|
||||||
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||||
|
|
||||||
|
audioDriver = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NULL driver specification */
|
/* NULL driver specification */
|
||||||
|
@ -151,15 +207,33 @@ int audio_initOpenCloseQuitAudio()
|
||||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
||||||
|
|
||||||
/* Loop over all available audio drivers */
|
/* Was a specific driver requested? */
|
||||||
iMax = SDL_GetNumAudioDrivers();
|
audioDriver = SDL_GetHint(SDL_HINT_AUDIODRIVER);
|
||||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
|
||||||
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
if (audioDriver == NULL) {
|
||||||
|
/* Loop over all available audio drivers */
|
||||||
|
iMax = SDL_GetNumAudioDrivers();
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
||||||
|
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
||||||
|
} else {
|
||||||
|
/* A specific driver was requested for testing */
|
||||||
|
iMax = 1;
|
||||||
|
}
|
||||||
for (i = 0; i < iMax; i++) {
|
for (i = 0; i < iMax; i++) {
|
||||||
audioDriver = SDL_GetAudioDriver(i);
|
if (audioDriver == NULL) {
|
||||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
audioDriver = SDL_GetAudioDriver(i);
|
||||||
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
|
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
||||||
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
|
||||||
|
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
if (DriverIsProblematic(audioDriver)) {
|
||||||
|
SDLTest_Log("Audio driver '%s' flagged as problematic: skipping device open/close test (set SDL_AUDIODRIVER=%s to force)", audioDriver, audioDriver);
|
||||||
|
audioDriver = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
|
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -173,6 +247,17 @@ int audio_initOpenCloseQuitAudio()
|
||||||
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
|
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
|
||||||
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
||||||
|
|
||||||
|
/* Check for output devices */
|
||||||
|
result = SDL_GetNumAudioDevices(SDL_FALSE);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(SDL_FALSE)");
|
||||||
|
SDLTest_AssertCheck(result >= 0, "Validate result value; expected: >=0 got: %d", result);
|
||||||
|
if (result <= 0) {
|
||||||
|
SDLTest_Log("No output devices for '%s': skipping device open/close test", audioDriver);
|
||||||
|
SDL_AudioQuit();
|
||||||
|
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set spec */
|
/* Set spec */
|
||||||
SDL_memset(&desired, 0, sizeof(desired));
|
SDL_memset(&desired, 0, sizeof(desired));
|
||||||
switch (j) {
|
switch (j) {
|
||||||
|
@ -217,7 +302,10 @@ int audio_initOpenCloseQuitAudio()
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* spec loop */
|
} /* spec loop */
|
||||||
} /* driver loop */
|
|
||||||
|
audioDriver = NULL;
|
||||||
|
|
||||||
|
} /* driver loop */
|
||||||
|
|
||||||
/* Restart audio again */
|
/* Restart audio again */
|
||||||
_audioSetUp(NULL);
|
_audioSetUp(NULL);
|
||||||
|
@ -245,15 +333,33 @@ int audio_pauseUnpauseAudio()
|
||||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
|
||||||
|
|
||||||
/* Loop over all available audio drivers */
|
/* Was a specific driver requested? */
|
||||||
iMax = SDL_GetNumAudioDrivers();
|
audioDriver = SDL_GetHint(SDL_HINT_AUDIODRIVER);
|
||||||
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
|
||||||
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
if (audioDriver == NULL) {
|
||||||
|
/* Loop over all available audio drivers */
|
||||||
|
iMax = SDL_GetNumAudioDrivers();
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
|
||||||
|
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
|
||||||
|
} else {
|
||||||
|
/* A specific driver was requested for testing */
|
||||||
|
iMax = 1;
|
||||||
|
}
|
||||||
for (i = 0; i < iMax; i++) {
|
for (i = 0; i < iMax; i++) {
|
||||||
audioDriver = SDL_GetAudioDriver(i);
|
if (audioDriver == NULL) {
|
||||||
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
audioDriver = SDL_GetAudioDriver(i);
|
||||||
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
|
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
|
||||||
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
|
||||||
|
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
if (DriverIsProblematic(audioDriver)) {
|
||||||
|
SDLTest_Log("Audio driver '%s' flagged as problematic: skipping pause/unpause test (set SDL_AUDIODRIVER=%s to force)", audioDriver, audioDriver);
|
||||||
|
audioDriver = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
|
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -267,6 +373,16 @@ int audio_pauseUnpauseAudio()
|
||||||
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
|
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
|
||||||
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
|
||||||
|
|
||||||
|
result = SDL_GetNumAudioDevices(SDL_FALSE);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(SDL_FALSE)");
|
||||||
|
SDLTest_AssertCheck(result >= 0, "Validate result value; expected: >=0 got: %d", result);
|
||||||
|
if (result <= 0) {
|
||||||
|
SDLTest_Log("No output devices for '%s': skipping pause/unpause test", audioDriver);
|
||||||
|
SDL_AudioQuit();
|
||||||
|
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set spec */
|
/* Set spec */
|
||||||
SDL_memset(&desired, 0, sizeof(desired));
|
SDL_memset(&desired, 0, sizeof(desired));
|
||||||
switch (j) {
|
switch (j) {
|
||||||
|
@ -341,7 +457,10 @@ int audio_pauseUnpauseAudio()
|
||||||
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
SDLTest_AssertPass("Call to SDL_AudioQuit()");
|
||||||
|
|
||||||
} /* spec loop */
|
} /* spec loop */
|
||||||
} /* driver loop */
|
|
||||||
|
audioDriver = NULL;
|
||||||
|
|
||||||
|
} /* driver loop */
|
||||||
|
|
||||||
/* Restart audio again */
|
/* Restart audio again */
|
||||||
_audioSetUp(NULL);
|
_audioSetUp(NULL);
|
||||||
|
|
Loading…
Reference in a new issue