Do more tests in non-interactive mode (resubmit)

Francois Gouget fgouget at codeweavers.com
Fri Aug 6 08:08:35 CDT 2004


I'm resubmitting this patch as it was not committed yet (maybe it 
conflicted with another patch?). This time around I'm only sending the 
winmm part as the dsound tests changed quite a bit.


This patch is based on the following email:
http://www.winehq.org/hypermail/wine-devel/2004/07/0287.html

As pointed out in the above email, if not in interactive mode we can
make the test tones/captures much shorter so that the test does not take
too long to run. Here is some more details about what we do:
    * test tones are always played
    * if not in interactive mode we only play silence
    * if not in interactive mode tones/captures last only 0.1 (resp. 0.5)
seconds
    * if not in interactive mode we don't touch the volume
    * if in interactive mode nothing is changed

The difference is that the patch now applies the technique to the
following tests:
   * dsound - wave
   * winmm  - wave
   * winmm  - capture

This way we exercise almost as much of the API as in interactive mode
without disturbing users, and the tests still run fast. The slowest one
is the winmm test which takes 16 seconds on my machine which supports
all the tested sound formats (but has only one sound card). Given that
winetest's timeout is two minutes this gives a wide margin.


Changelog:

  * dlls/winmm/tests/capture.c
    dlls/winmm/tests/wave.c

    Francois Gouget <fgouget at codeweavers.com>
    Do more tests in non-interactive mode by playing silence instead of
the 440Hz test tone, not touching the volume settings and shortening the
test tones/captures.


-- 
Francois Gouget
fgouget at codeweavers.com

-------------- next part --------------
Index: dlls/winmm/tests/capture.c
===================================================================
RCS file: /var/cvs/wine/dlls/winmm/tests/capture.c,v
retrieving revision 1.8
diff -u -r1.8 capture.c
--- dlls/winmm/tests/capture.c	2 Aug 2004 22:29:03 -0000	1.8
+++ dlls/winmm/tests/capture.c	6 Aug 2004 12:34:36 -0000
@@ -56,6 +56,7 @@
     WORD nChannels = pwfx->nChannels;
     WORD wBitsPerSample = pwfx->wBitsPerSample;
     DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
+    double duration;
 
     hevent=CreateEvent(NULL,FALSE,FALSE,NULL);
     ok(hevent!=NULL,"CreateEvent: error=%ld\n",GetLastError());
@@ -98,8 +99,9 @@
        pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
        pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
 
-    frag.lpData=malloc(pwfx->nAvgBytesPerSec);
-    frag.dwBufferLength=pwfx->nAvgBytesPerSec;
+    duration=winetest_interactive?1.0:0.1;
+    frag.dwBufferLength=((DWORD)(duration*pwfx->nSamplesPerSec))*pwfx->nBlockAlign;
+    frag.lpData=malloc(frag.dwBufferLength);
     frag.dwBytesRecorded=0;
     frag.dwUser=0;
     frag.dwFlags=0;
@@ -110,9 +112,10 @@
     ok(rc==MMSYSERR_NOERROR, "waveInPrepareHeader: device=%s rc=%s\n",dev_name(device),wave_in_error(rc));
     ok(frag.dwFlags&WHDR_PREPARED,"waveInPrepareHeader: prepared flag not set\n");
 
-    if (winetest_interactive && rc==MMSYSERR_NOERROR) {
-        trace("Recording for 1 second at %5ldx%2dx%d %s\n",
-              pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels,
+    if (rc==MMSYSERR_NOERROR) {
+        trace("Recording for %g second at %5ldx%2dx%d %s\n",
+              duration, pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
+              pwfx->nChannels,
               flags & WAVE_FORMAT_DIRECT ? "WAVE_FORMAT_DIRECT" :
               flags & WAVE_MAPPED ? "WAVE_MAPPED" : "");
         rc=waveInAddBuffer(win, &frag, sizeof(frag));
@@ -121,11 +124,12 @@
         rc=waveInStart(win);
         ok(rc==MMSYSERR_NOERROR,"waveInStart: device=%s rc=%s\n",dev_name(device),wave_in_error(rc));
 
-        res = WaitForSingleObject(hevent,1200);
+        res = WaitForSingleObject(hevent,duration*1200.0);
         ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for header\n");
         ok(frag.dwFlags&WHDR_DONE,"WHDR_DONE not set in frag.dwFlags\n");
-        ok(frag.dwBytesRecorded==pwfx->nAvgBytesPerSec,"frag.dwBytesRecorded=%ld, should=%ld\n",
-           frag.dwBytesRecorded,pwfx->nAvgBytesPerSec);
+        ok(frag.dwBytesRecorded==frag.dwBufferLength,
+           "frag.dwBytesRecorded=%ld, should be %ld\n",
+           frag.dwBytesRecorded,frag.dwBufferLength);
         /* stop playing on error */
         if (res!=WAIT_OBJECT_0) {
             rc=waveInStop(win);
@@ -284,7 +288,7 @@
             wave_in_test_deviceIn(device,&format,win_formats[f][0],WAVE_MAPPED, &capsA);
     }
 
-    /* Try a PCMWAVEFORMAT aligned next to an unaccessable page for bounds checking */
+    /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds checking */
     twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
     ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
     if (twoPages) {
Index: dlls/winmm/tests/wave.c
===================================================================
RCS file: /var/cvs/wine/dlls/winmm/tests/wave.c,v
retrieving revision 1.38
diff -u -r1.38 wave.c
--- dlls/winmm/tests/wave.c	2 Aug 2004 22:29:03 -0000	1.38
+++ dlls/winmm/tests/wave.c	6 Aug 2004 12:34:36 -0000
@@ -75,6 +75,21 @@
     return buf;
 }
 
+static char* wave_generate_silence(WAVEFORMATEX* wfx, double duration, DWORD* size)
+{
+    DWORD nb_samples;
+    char* buf;
+
+    nb_samples=(DWORD)(duration*wfx->nSamplesPerSec);
+    *size=nb_samples*wfx->nBlockAlign;
+    buf=malloc(*size);
+    if (wfx->wBitsPerSample==8)
+        memset(buf,0x80,*size);
+    else
+        memset(buf,0,*size);
+    return buf;
+}
+
 const char * dev_name(int device)
 {
     static char name[16];
@@ -286,6 +301,7 @@
     WORD nChannels = pwfx->nChannels;
     WORD wBitsPerSample = pwfx->wBitsPerSample;
     DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
+    char* wave_desc;
 
     hevent=CreateEvent(NULL,FALSE,FALSE,NULL);
     ok(hevent!=NULL,"CreateEvent: error=%ld\n",GetLastError());
@@ -327,7 +343,16 @@
        pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
        pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
 
-    frag.lpData=wave_generate_la(pwfx,duration,&frag.dwBufferLength);
+    if (winetest_interactive)
+    {
+        wave_desc="440Hz tone";
+        frag.lpData=wave_generate_la(pwfx,duration,&frag.dwBufferLength);
+    }
+    else
+    {
+        wave_desc="of silence";
+        frag.lpData=wave_generate_silence(pwfx,duration,&frag.dwBufferLength);
+    }
     frag.dwFlags=0;
     frag.dwLoops=0;
 
@@ -338,9 +363,11 @@
     ok(rc==MMSYSERR_NOERROR,
        "waveOutPrepareHeader: device=%s rc=%s\n",dev_name(device),wave_out_error(rc));
 
-    if (winetest_interactive && rc==MMSYSERR_NOERROR) {
+    if (rc==MMSYSERR_NOERROR) {
         DWORD start,end;
-        trace("Playing %g second 440Hz tone at %5ldx%2dx%d %s\n",duration,
+        double tolerance;
+
+        trace("Playing %g second %s at %5ldx%2dx%d %s\n",duration,wave_desc,
               pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels,
               flags & WAVE_FORMAT_DIRECT ? "WAVE_FORMAT_DIRECT" :
               flags & WAVE_MAPPED ? "WAVE_MAPPED" : "");
@@ -348,22 +375,28 @@
         /* Check that the position is 0 at start */
         check_position(device, wout, 0.0, pwfx);
 
-        rc=waveOutSetVolume(wout,0x20002000);
-        ok(rc==MMSYSERR_NOERROR,"waveOutSetVolume: device=%s rc=%s\n",dev_name(device),wave_out_error(rc));
-        WaitForSingleObject(hevent,INFINITE);
+        if (winetest_interactive)
+        {
+            rc=waveOutSetVolume(wout,0x20002000);
+            ok(rc==MMSYSERR_NOERROR,"waveOutSetVolume: device=%s rc=%s\n",dev_name(device),wave_out_error(rc));
+        }
 
+        WaitForSingleObject(hevent,INFINITE);
         start=GetTickCount();
         rc=waveOutWrite(wout, &frag, sizeof(frag));
         ok(rc==MMSYSERR_NOERROR,"waveOutWrite: device=%s rc=%s\n",dev_name(device),wave_out_error(rc));
         WaitForSingleObject(hevent,INFINITE);
 
-        /* Check the sound duration was within 10% of the expected value */
+        /* Check that the tone duration was about right */
         end=GetTickCount();
-        trace("sound duration=%ld\n",end-start);
-        ok(fabs(1000*duration-end+start)<=100*duration,"The sound played for %ld ms instead of %g ms\n",end-start,1000*duration);
+        tolerance=duration<1.0?0.2:0.1;
+        ok(fabs(1000*duration-end+start)<=10.0+tolerance*1000.0*duration,"The sound played for %ld ms instead of %g ms\n",end-start,1000*duration);
 
-        rc=waveOutSetVolume(wout,volume);
-        ok(rc==MMSYSERR_NOERROR,"waveOutSetVolume: device=%s rc=%s\n",dev_name(device),wave_out_error(rc));
+        if (winetest_interactive)
+        {
+            rc=waveOutSetVolume(wout,volume);
+            ok(rc==MMSYSERR_NOERROR,"waveOutSetVolume: device=%s rc=%s\n",dev_name(device),wave_out_error(rc));
+        }
 
         check_position(device, wout, frag.dwBufferLength, pwfx);
     }
@@ -393,6 +426,7 @@
     BYTE * twoPages;
     SYSTEM_INFO sSysInfo;
     DWORD flOldProtect;
+    double duration;
     BOOL res;
 
     GetSystemInfo(&sSysInfo);
@@ -460,9 +494,10 @@
           capsA.wChannels,capsA.dwFormats,capsA.dwSupport,wave_out_caps(capsA.dwSupport));
     free(nameA);
 
-    if (winetest_interactive && (device != WAVE_MAPPER))
+    duration=winetest_interactive?1.0:0.1;
+    if (device != WAVE_MAPPER)
     {
-        trace("Playing a 5 seconds reference tone.\n");
+        trace("Playing a %g seconds reference tone.\n",5*duration);
         trace("All subsequent tones should be identical to this one.\n");
         trace("Listen for stutter, changes in pitch, volume, etc.\n");
         format.wFormatTag=WAVE_FORMAT_PCM;
@@ -472,7 +507,7 @@
         format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
         format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
         format.cbSize=0;
-        wave_out_test_deviceOut(device,5.0,&format,WAVE_FORMAT_2M08,0,&capsA);
+        wave_out_test_deviceOut(device,5*duration,&format,WAVE_FORMAT_2M08,0,&capsA);
     }
 
     for (f=0;f<NB_WIN_FORMATS;f++) {
@@ -483,13 +518,14 @@
         format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
         format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
         format.cbSize=0;
-        wave_out_test_deviceOut(device,1.0,&format,win_formats[f][0],0,&capsA);
-        wave_out_test_deviceOut(device,1.0,&format,win_formats[f][0],WAVE_FORMAT_DIRECT,&capsA);
+        wave_out_test_deviceOut(device,duration,&format,win_formats[f][0],0,&capsA);
+        wave_out_test_deviceOut(device,duration,&format,win_formats[f][0],0,&capsA);
+        wave_out_test_deviceOut(device,duration,&format,win_formats[f][0],WAVE_FORMAT_DIRECT,&capsA);
         if (device != WAVE_MAPPER)
-            wave_out_test_deviceOut(device,1.0,&format,win_formats[f][0],WAVE_MAPPED,&capsA);
+            wave_out_test_deviceOut(device,duration,&format,win_formats[f][0],WAVE_MAPPED,&capsA);
     }
 
-    /* Try a PCMWAVEFORMAT aligned next to an unaccessable page for bounds checking */
+    /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds checking */
     twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
     ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
     if (twoPages) {
@@ -503,10 +539,10 @@
             pwfx->nSamplesPerSec=22050;
             pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
             pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
-            wave_out_test_deviceOut(device,1.0,pwfx,WAVE_FORMAT_2M08,0,&capsA);
-            wave_out_test_deviceOut(device,1.0,pwfx,WAVE_FORMAT_2M08,WAVE_FORMAT_DIRECT,&capsA);
+            wave_out_test_deviceOut(device,duration,pwfx,WAVE_FORMAT_2M08,0,&capsA);
+            wave_out_test_deviceOut(device,duration,pwfx,WAVE_FORMAT_2M08,WAVE_FORMAT_DIRECT,&capsA);
             if (device != WAVE_MAPPER)
-                wave_out_test_deviceOut(device,1.0,pwfx,WAVE_FORMAT_2M08,WAVE_MAPPED,&capsA);
+                wave_out_test_deviceOut(device,duration,pwfx,WAVE_FORMAT_2M08,WAVE_MAPPED,&capsA);
         }
         VirtualFree(twoPages, 2 * dwPageSize, MEM_RELEASE);
     }


More information about the wine-patches mailing list