igt/gem_userptr_blits: Fix forked access test
[platform/upstream/intel-gpu-tools.git] / tests / template.c
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 "drmtest.h"
28
29 /*
30  * Note that test function (and code called by them) should generally not return
31  * a variable indicating success/failure. Instead use the igt_require/igt_assert
32  * macros to skip out of the entire subtest.
33  *
34  * Also, helper functions should only return a status code if the callers have a
35  * real need to differentiate. If the only thing they do is call igt_assert or a
36  * similar macro then it'll result in simpler code when the check is moved
37  * completely into the helper.
38  */
39 static void test_A(int fd)
40 {
41 }
42
43 static void test_B(int fd)
44 {
45 }
46
47 /*
48  * Variables which are written to in igt_fixtures/subtest blocks need to be
49  * allocated outside of the relevant function scope, otherwise gcc will wreak
50  * havoc (since these magic blocks use setjmp/longjmp internally).
51  *
52  * Common practice is to put variables used in the main test function into
53  * global scope, but only right above the main function itself (to avoid leaking
54  * it into other functions).
55  */
56
57 int drm_fd;
58
59 igt_main
60 {
61         igt_fixture {
62                 drm_fd = drm_open_any();
63                 igt_require(drm_fd >= 0);
64
65                 /* Set up other interesting stuff shared by all tests. */
66         }
67
68         igt_subtest("A")
69                 test_A(drm_fd);
70         igt_subtest("B")
71                 test_B(drm_fd);
72         /*
73          * Note that subtest names can be programatically generated. See the
74          * various uses of igt_subtest_f for a few neat ideas.
75          */
76
77         igt_fixture {
78                 close(drm_fd);
79         }
80 }