2 <title>Writing Conformance tests
</title>
4 <sect1 id=
"testing-intro">
5 <title>Introduction
</title>
7 The Windows API follows no standard, it is itself a de facto standard,
8 and deviations from that standard, even small ones, often cause
9 applications to crash or misbehave in some way.
12 The question becomes,
"How do we ensure compliance with that standard?"
13 The answer is,
"By using the API documentation available to us and
14 backing that up with conformance tests." Furthermore, a conformance
15 test suite is the most accurate (if not necessarily the most complete)
16 form of API documentation and can be used to supplement the Windows
20 Writing a conformance test suite for more than
10000 APIs is no small
21 undertaking. Fortunately it can prove very useful to the development
22 of Wine way before it is complete.
26 The conformance test suite must run on Windows. This is
27 necessary to provide a reasonable way to verify its accuracy.
28 Furthermore the tests must pass successfully on all Windows
29 platforms (tests not relevant to a given platform should be
33 A consequence of this is that the test suite will provide a
34 great way to detect variations in the API between different
35 Windows versions. For instance, this can provide insights
36 into the differences between the, often undocumented, Win9x and
40 However, one must remember that the goal of Wine is to run
41 Windows applications on Linux, not to be a clone of any specific
42 Windows version. So such variations must only be tested for when
43 relevant to that goal.
48 Writing conformance tests is also an easy way to discover
49 bugs in Wine. Of course, before fixing the bugs discovered in
50 this way, one must first make sure that the new tests do pass
51 successfully on at least one Windows
9x and one Windows NT
55 Bugs discovered this way should also be easier to fix. Unlike
56 some mysterious application crashes, when a conformance test
57 fails, the expected behavior and APIs tested for are known thus
58 greatly simplifying the diagnosis.
63 To detect regressions. Simply running the test suite regularly
64 in Wine turns it into a great tool to detect regressions.
65 When a test fails, one immediately knows what was the expected
66 behavior and which APIs are involved. Thus regressions caught
67 this way should be detected earlier, because it is easy to run
68 all tests on a regular basis, and easier to fix because of the
69 reduced diagnosis work.
74 Tests written in advance of the Wine development (possibly even
75 by non Wine developers) can also simplify the work of the
76 future implementer by making it easier for him to check the
77 correctness of his code.
82 Conformance tests will also come in handy when testing Wine on
83 new (or not as widely used) architectures such as FreeBSD,
84 Solaris x86 or even non-x86 systems. Even when the port does
85 not involve any significant change in the thread management,
86 exception handling or other low-level aspects of Wine, new
87 architectures can expose subtle bugs that can be hard to
88 diagnose when debugging regular (complex) applications.
96 <sect1 id=
"testing-what">
97 <title>What to test for?
</title>
99 The first thing to test for is the documented behavior of APIs
100 and such as CreateFile. For instance one can create a file using a
101 long pathname, check that the behavior is correct when the file
102 already exists, try to open the file using the corresponding short
103 pathname, convert the filename to Unicode and try to open it using
104 CreateFileW, and all other things which are documented and that
105 applications rely on.
108 While the testing framework is not specifically geared towards this
109 type of tests, it is also possible to test the behavior of Windows
110 messages. To do so, create a window, preferably a hidden one so that
111 it does not steal the focus when running the tests, and send messages
112 to that window or to controls in that window. Then, in the message
113 procedure, check that you receive the expected messages and with the
117 For instance you could create an edit control and use WM_SETTEXT to
118 set its contents, possibly check length restrictions, and verify the
119 results using WM_GETTEXT. Similarly one could create a listbox and
120 check the effect of LB_DELETESTRING on the list's number of items,
121 selected items list, highlighted item, etc.
124 However, undocumented behavior should not be tested for unless there
125 is an application that relies on this behavior, and in that case the
126 test should mention that application, or unless one can strongly
127 expect applications to rely on this behavior, typically APIs that
128 return the required buffer size when the buffer pointer is NULL.
133 <sect1 id=
"testing-wine">
134 <title>Running the tests in Wine
</title>
136 The simplest way to run the tests in Wine is to type 'make test' in
137 the Wine sources top level directory. This will run all the Wine
141 The tests for a specific Wine library are located in a 'tests'
142 directory in that library's directory. Each test is contained in a
143 file (e.g.
<filename>dlls/kernel/tests/thread.c<
/>). Each
144 file itself contains many checks concerning one or more related APIs.
147 So to run all the tests related to a given Wine library, go to the
148 corresponding 'tests' directory and type 'make test'. This will
149 compile the tests, run them, and create an '
<replaceable>xxx<
/>.ok'
150 file for each test that passes successfully. And if you only want to
151 run the tests contained in the
<filename>thread.c<
/> file of the
152 kernel library, you would do:
154 <prompt>$ <
/>cd dlls/kernel/tests
155 <prompt>$ <
/>make thread.ok
159 Note that if the test has already been run and is up to date (i.e. if
160 neither the kernel library nor the
<filename>thread.c<
/> file has
161 changed since the
<filename>thread.ok<
/> file was created), then make
162 will say so. To force the test to be re-run, delete the
163 <filename>thread.ok<
/> file, and run the make command again.
166 You can also run tests manually using a command similar to the
169 <prompt>$ <
/>../../../tools/runtest -q -M kernel32.dll -p kernel32_test.exe.so thread.c
170 <prompt>$ <
/>../../../tools/runtest -p kernel32_test.exe.so thread.c
171 thread.c:
86 tests executed,
5 marked as todo,
0 failures.
173 The '-P wine' options defines the platform that is currently being
174 tested. Remove the '-q' option if you want the testing framework
175 to report statistics about the number of successful and failed tests.
176 Run
<command>runtest -h<
/> for more details.
181 <sect1 id=
"cross-compiling-tests">
182 <title>Cross-compiling the tests with MinGW
</title>
184 <title>Setup of the MinGW cross-compiling environment
</title>
186 Here are some instructions to setup MinGW on different Linux
187 distributions and *BSD.
190 <title>Debian GNU/Linux
</title>
192 On Debian all you need to do is type
<command>apt-get install
197 <title>Red Hat Linux like rpm systems
</title>
199 This includes Fedora Core, Red Hat Enterprise Linux, Mandrake,
200 most probably SuSE Linux too, etc. But this list isn't exhaustive;
201 the following steps should probably work on any rpm based system.
204 Download and install the latest rpm's from
205 <ulink url=
"http://mirzam.it.vu.nl/mingw/">MinGW RPM packages<
/>.
206 Alternatively you can follow the instructions on that page and
207 build your own packages from the source rpm's listed there as well.
213 The *BSD systems have in their ports collection a port for the
214 MinGW cross-compiling environment. Please see the documentation
215 of your system about how to build and install a port.
220 <title>Compiling the tests
</title>
222 Having the cross-compiling environment set up the generation of the
223 Windows executables is easy by using the Wine build system.
226 If you had already run
<command>configure<
/>, then delete
227 <filename>config.cache<
/> and re-run
<command>configure<
/>.
228 You can then run
<command>make crosstest<
/>. To sum up:
230 <prompt>$ <
/><userinput>rm config.cache<
/>
231 <prompt>$ <
/><userinput>./configure<
/>
232 <prompt>$ <
/><userinput>make crosstest<
/>
239 <sect1 id=
"testing-windows">
240 <title>Building and running the tests on Windows
</title>
242 <title>Using pre-compiled binaries
</title>
244 Unfortunately there are no pre-compiled binaries yet. However if
245 send an email to the Wine development list you can probably get
246 someone to send them to you, and maybe motivate some kind soul to
247 put in place a mechanism for publishing such binaries on a regular
252 <title>With Visual C++
</title>
254 Visual Studio
6 users:
255 - MSVC headers may not work well, try with Wine headers
256 - Ensure that you have the
"processor pack" from
257 <ulink url=
"http://msdn.microsoft.com/vstudio/downloads/tools/ppack/default.aspx">http://msdn.microsoft.com/vstudio/downloads/tools/ppack/default.aspx<
/>
258 as well as the latest service packs. The processor pack fixes
<emphasis>"error C2520: conversion from unsigned
259 __int64 to double not implemented, use signed __int64"<
/>
266 Run msvcmaker to generate Visual C++ project files for the tests.
267 'msvcmaker' is a perl script so you may be able to run it on
270 <prompt>$ <
/>./tools/winapi/msvcmaker --no-wine
274 If the previous steps were done on your Linux development
275 machine, make the Wine sources accessible to the Windows machine
276 on which you are going to compile them. Typically you would do
277 this using Samba but copying them altogether would work too.
280 On the Windows machine, open the
<filename>winetest.dsw<
/>
281 workspace. This will load each test's project. For each test there
282 are two configurations: one compiles the test with the Wine
283 headers, and the other uses the Visual C++ headers. Some tests
284 will compile fine with the former, but most will require the
288 Open the
<menuchoice><guimenu>Build<
/> <guimenu>Batch
289 build...<
/><
/> menu and select the tests and build configurations
290 you want to build. Then click on
<guibutton>Build<
/>.
293 To run a specific test from Visual C++, go to
294 <menuchoice><guimenu>Project<
/> <guimenu>Settings...<
/><
/>. There
295 select that test's project and build configuration and go to the
296 <guilabel>Debug<
/> tab. There type the name of the specific test
297 to run (e.g. 'thread') in the
<guilabel>Program arguments<
/>
298 field. Validate your change by clicking on
<guibutton>Ok<
/> and
299 start the test by clicking the red exclamation mark (or hitting
300 'F5' or any other usual method).
303 You can also run the tests from the command line. You will find
304 them in either
<filename>Output\Win32_Wine_Headers<
/> or
305 <filename>Output\Win32_MSVC_Headers<
/> depending on the build
306 method. So to run the kernel 'path' tests you would do:
308 <prompt>C:\
><
/>cd dlls\kernel\tests\Output\Win32_MSVC_Headers
309 <prompt>C:\dlls\kernel\tests\Output\Win32_MSVC_Headers
><
/>kernel32_test path
315 <title>With MinGW
</title>
317 Wine's build system already has support for building tests with a MinGW
318 cross-compiler. See the section above called 'Setup of the MinGW
319 cross-compiling environment' for instructions on how to set things up.
320 When you have a MinGW environment installed all you need to do is rerun
321 configure and it should detect the MinGW compiler and tools. Then run
322 'make crosstest' to start building the tests.
328 <sect1 id=
"testing-test">
329 <title>Inside a test
</title>
332 When writing new checks you can either modify an existing test file or
333 add a new one. If your tests are related to the tests performed by an
334 existing file, then add them to that file. Otherwise create a new .c
335 file in the tests directory and add that file to the
336 <varname>CTESTS<
/> variable in
<filename>Makefile.in<
/>.
339 A new test file will look something like the following:
341 #include
<wine/test.h
>
342 #include
<winbase.h
>
344 /* Maybe auxiliary functions and definitions here */
348 /* Write your checks there or put them in functions you will call from
355 The test's entry point is the START_TEST section. This is where
356 execution will start. You can put all your tests in that section but
357 it may be better to split related checks in functions you will call
358 from the START_TEST section. The parameter to START_TEST must match
359 the name of the C file. So in the above example the C file would be
360 called
<filename>paths.c<
/>.
363 Tests should start by including the
<filename>wine/test.h<
/> header.
364 This header will provide you access to all the testing framework
365 functions. You can then include the windows header you need, but make
366 sure to not include any Unix or Wine specific header: tests must
370 You can use
<function>trace<
/> to print informational messages. Note
371 that these messages will only be printed if 'runtest -v' is being used.
373 trace(
"testing GlobalAddAtomA");
378 Then just call functions and use
<function>ok<
/> to make sure that
379 they behaved as expected:
381 ATOM atom = GlobalAddAtomA(
"foobar" );
382 ok( GlobalFindAtomA(
"foobar" ) == atom,
"could not find atom foobar" );
383 ok( GlobalFindAtomA(
"FOOBAR" ) == atom,
"could not find atom FOOBAR" );
385 The first parameter of
<function>ok<
/> is an expression which must
386 evaluate to true if the test was successful. The next parameter is a
387 printf-compatible format string which is displayed in case the test
388 failed, and the following optional parameters depend on the format
393 <sect1 id=
"testing-error-messages">
394 <title>Writing good error messages
</title>
396 The message that is printed when a test fails is
397 <emphasis>extremely<
/> important.
400 Someone will take your test, run it on a Windows platform that
401 you don't have access to, and discover that it fails. They will then
402 post an email with the output of the test, and in particular your
403 error message. Someone, maybe you, will then have to figure out from
404 this error message why the test failed.
407 If the error message contains all the relevant information that will
408 be easy. If not, then it will require modifying the test, finding
409 someone to compile it on Windows, sending the modified version to the
410 original tester and waiting for his reply. In other words, it will
414 So how do you write a good error message? Let's start with an example
415 of a bad error message:
417 ok(GetThreadPriorityBoost(curthread,
&disabled)!=
0,
418 "GetThreadPriorityBoost Failed");
422 thread.c:
123: Test failed: GetThreadPriorityBoost Failed
426 Did you notice how the error message provides no information about
427 why the test failed? We already know from the line number exactly
428 which test failed. In fact the error message gives strictly no
429 information that cannot already be obtained by reading the code. In
430 other words it provides no more information than an empty string!
433 Let's look at how to rewrite it:
437 rc=GetThreadPriorityBoost(curthread,
&disabled);
438 ok(rc!=
0 && disabled==
0,
"rc=%d error=%ld disabled=%d",
439 rc,GetLastError(),disabled);
443 thread.c:
123: Test failed: rc=
0 error=
120 disabled=
0
447 When receiving such a message, one would check the source, see that
448 it's a call to GetThreadPriorityBoost, that the test failed not
449 because the API returned the wrong value, but because it returned an
450 error code. Furthermore we see that GetLastError() returned
120 which
451 winerror.h defines as ERROR_CALL_NOT_IMPLEMENTED. So the source of
452 the problem is obvious: this Windows platform (here Windows
98) does
453 not support this API and thus the test must be modified to detect
454 such a condition and skip the test.
457 So a good error message should provide all the information which
458 cannot be obtained by reading the source, typically the function
459 return value, error codes, and any function output parameter. Even if
460 more information is needed to fully understand a problem,
461 systematically providing the above is easy and will help cut down the
462 number of iterations required to get to a resolution.
465 It may also be a good idea to dump items that may be hard to retrieve
466 from the source, like the expected value in a test if it is the
467 result of an earlier computation, or comes from a large array of test
468 values (e.g. index
112 of _pTestStrA in vartest.c). In that respect,
469 for some tests you may want to define a macro such as the following:
471 #define eq(received, expected, label, type) \
472 ok((received) == (expected),
"%s: got " type
" instead of " type, (label),(received),(expected))
476 eq( b, curr_val,
"SPI_{GET,SET}BEEP",
"%d" );
482 <sect1 id=
"testing-platforms">
483 <title>Handling platform issues
</title>
485 Some checks may be written before they pass successfully in Wine.
486 Without some mechanism, such checks would potentially generate
487 hundred of known failures for months each time the tests are being run.
488 This would make it hard to detect new failures caused by a regression.
489 or to detect that a patch fixed a long standing issue.
492 Thus the Wine testing framework has the concept of platforms and
493 groups of checks can be declared as expected to fail on some of them.
494 In the most common case, one would declare a group of tests as
495 expected to fail in Wine. To do so, use the following construct:
498 SetLastError(
0xdeadbeef );
499 ok( GlobalAddAtomA(
0) ==
0 && GetLastError() ==
0xdeadbeef,
"failed to add atom 0" );
502 On Windows the above check would be performed normally, but on Wine it
503 would be expected to fail, and not cause the failure of the whole
504 test. However. If that check were to succeed in Wine, it would
505 cause the test to fail, thus making it easy to detect when something
506 has changed that fixes a bug. Also note that todo checks are accounted
507 separately from regular checks so that the testing statistics remain
508 meaningful. Finally, note that todo sections can be nested so that if
509 a test only fails on the cygwin and reactos platforms, one would
518 <!-- FIXME: Would we really have platforms such as reactos, cygwin, freebsd & co? -->
519 But specific platforms should not be nested inside a todo_wine section
520 since that would be redundant.
523 When writing tests you will also encounter differences between Windows
524 9x and Windows NT platforms. Such differences should be treated
525 differently from the platform issues mentioned above. In particular
526 you should remember that the goal of Wine is not to be a clone of any
527 specific Windows version but to run Windows applications on Unix.
530 So, if an API returns a different error code on Windows
9x and
531 Windows NT, your check should just verify that Wine returns one or
534 ok ( GetLastError() == WIN9X_ERROR || GetLastError() == NT_ERROR, ...);
538 If an API is only present on some Windows platforms, then use
539 LoadLibrary and GetProcAddress to check if it is implemented and
540 invoke it. Remember, tests must run on all Windows platforms.
541 Similarly, conformance tests should nor try to correlate the Windows
542 version returned by GetVersion with whether given APIs are
543 implemented or not. Again, the goal of Wine is to run Windows
544 applications (which do not do such checks), and not be a clone of a
545 specific Windows version.
548 FIXME: What about checks that cause the process to crash due to a bug?
553 <!-- FIXME: Strategies for testing threads, testing network stuff,
554 file handling, eq macro... -->
558 <!-- Keep this comment at the end of the file
561 sgml-parent-document:("wine-devel.sgml" "set" "book" "part" "chapter" "")