1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 *
25 */
26
27 #include "igt.h"
28
29 IGT_TEST_DESCRIPTION("Template test.");
30
31 /*
32 * Note that test function (and code called by them) should generally not return
33 * a variable indicating success/failure. Instead use the igt_require/igt_assert
34 * macros to skip out of the entire subtest.
35 *
36 * Also, helper functions should only return a status code if the callers have a
37 * real need to differentiate. If the only thing they do is call igt_assert or a
38 * similar macro then it'll result in simpler code when the check is moved
39 * completely into the helper.
40 */
test_A(int fd)41 static void test_A(int fd)
42 {
43 }
44
test_B(int fd)45 static void test_B(int fd)
46 {
47 }
48
49 /*
50 * Variables which are written to in igt_fixtures/subtest blocks need to be
51 * allocated outside of the relevant function scope, otherwise gcc will wreak
52 * havoc (since these magic blocks use setjmp/longjmp internally).
53 *
54 * Common practice is to put variables used in the main test function into
55 * global scope, but only right above the main function itself (to avoid leaking
56 * it into other functions).
57 */
58
59 int drm_fd;
60
61 igt_main
62 {
63 igt_fixture {
64 drm_fd = drm_open_driver(DRIVER_INTEL);
65 igt_require(drm_fd >= 0);
66
67 /* Set up other interesting stuff shared by all tests. */
68 }
69
70 igt_subtest("A")
71 test_A(drm_fd);
72 igt_subtest("B")
73 test_B(drm_fd);
74 /*
75 * Note that subtest names can be programatically generated. See the
76 * various uses of igt_subtest_f for a few neat ideas.
77 */
78
79 igt_fixture {
80 close(drm_fd);
81 }
82 }
83