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