1 /*
2 * Copyright © 2020 Valve 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 */
24 #ifndef ACO_TEST_COMMON_H
25 #define ACO_TEST_COMMON_H
26 #include <map>
27 #include <string>
28 #include <stdio.h>
29
30 #include "amd_family.h"
31 #include "aco_ir.h"
32 #include "aco_builder.h"
33 #include "vulkan/radv_shader.h"
34
35 struct TestDef {
36 const char *name;
37 const char *source_file;
38 void (*func)();
39 };
40
41 extern std::map<std::string, TestDef> tests;
42 extern FILE *output;
43
44 bool set_variant(const char *name);
45
set_variant(amd_gfx_level cls, const char *rest=�)46 inline bool set_variant(amd_gfx_level cls, const char *rest="")
47 {
48 char buf[8+strlen(rest)];
49 if (cls != GFX10_3) {
50 snprintf(buf, sizeof(buf), "gfx%d%s", cls - GFX6 + 6 - (cls > GFX10_3), rest);
51 } else {
52 snprintf(buf, sizeof(buf), "gfx10_3%s", rest);
53 }
54 return set_variant(buf);
55 }
56
57 void fail_test(const char *fmt, ...);
58 void skip_test(const char *fmt, ...);
59
60 #define _PASTE(a, b) a##b
61 #define PASTE(a, b) _PASTE(a, b)
62
63 #define _BEGIN_TEST(name, struct_name) static void struct_name(); static __attribute__((constructor)) void PASTE(add_test_, __COUNTER__)() {\
64 tests[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name};\
65 }\
66 static void struct_name() {\
67
68 #define BEGIN_TEST(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__))
69 #define BEGIN_TEST_TODO(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__))
70 #define BEGIN_TEST_FAIL(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__))
71 #define END_TEST \
72 }
73
74 #endif /* ACO_TEST_COMMON_H */
75