aco: add framework for unit testing
[mesa.git] / src / amd / compiler / tests / framework.h
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
46 inline bool set_variant(chip_class cls, const char *rest="")
47 {
48 char buf[8+strlen(rest)];
49 snprintf(buf, sizeof(buf), "gfx%d%s", cls - GFX6 + 6, rest);
50 return set_variant(buf);
51 }
52
53 void fail_test(const char *fmt, ...);
54 void skip_test(const char *fmt, ...);
55
56 #define _PASTE(a, b) a##b
57 #define PASTE(a, b) _PASTE(a, b)
58
59 #define _BEGIN_TEST(name, struct_name) static void struct_name(); static __attribute__((constructor)) void PASTE(add_test_, __COUNTER__)() {\
60 tests[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name};\
61 }\
62 static void struct_name() {\
63
64 #define BEGIN_TEST(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__))
65 #define BEGIN_TEST_TODO(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__))
66 #define BEGIN_TEST_FAIL(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__))
67 #define END_TEST \
68 }
69
70 #endif /* ACO_TEST_COMMON_H */