1 /* 2 * Copyright © 2020 Valve Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 */ 6 #ifndef ACO_TEST_COMMON_H 7 #define ACO_TEST_COMMON_H 8 #include "aco_builder.h" 9 #include "aco_ir.h" 10 11 #include "util/macros.h" 12 13 #include "ac_shader_util.h" 14 #include "amd_family.h" 15 #include <map> 16 #include <stdio.h> 17 #include <string> 18 19 struct TestDef { 20 const char* name; 21 const char* source_file; 22 void (*func)(); 23 }; 24 25 extern std::map<std::string, TestDef> *tests; 26 extern FILE* output; 27 28 bool set_variant(const char* name); 29 30 inline bool 31 set_variant(amd_gfx_level cls, const char* rest = "") 32 { 33 char buf[8 + strlen(rest)]; 34 if (cls == GFX10_3) { 35 snprintf(buf, sizeof(buf), "gfx10_3%s", rest); 36 } else if (cls == GFX11_5) { 37 snprintf(buf, sizeof(buf), "gfx11_5%s", rest); 38 } else { 39 unsigned num = cls - GFX6 + 6; 40 num -= (cls > GFX10_3) + (cls > GFX11_5); 41 snprintf(buf, sizeof(buf), "gfx%d%s", num, rest); 42 } 43 return set_variant(buf); 44 } 45 46 void fail_test(const char* fmt, ...); 47 void skip_test(const char* fmt, ...); 48 49 #define _BEGIN_TEST(name, struct_name) \ 50 static void struct_name(); \ 51 static __attribute__((constructor)) void CONCAT2(add_test_, __COUNTER__)() \ 52 { \ 53 if (!tests) \ 54 tests = new std::map<std::string, TestDef>; \ 55 (*tests)[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name}; \ 56 } \ 57 static void struct_name() \ 58 { 59 60 #define BEGIN_TEST(name) _BEGIN_TEST(name, CONCAT2(Test_, __COUNTER__)) 61 #define BEGIN_TEST_TODO(name) _BEGIN_TEST(name, CONCAT2(Test_, __COUNTER__)) 62 #define BEGIN_TEST_FAIL(name) _BEGIN_TEST(name, CONCAT2(Test_, __COUNTER__)) 63 #define END_TEST } 64 65 #endif /* ACO_TEST_COMMON_H */ 66