17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2020 Valve Corporation 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg * 237ec681f3Smrg */ 247ec681f3Smrg#ifndef ACO_TEST_COMMON_H 257ec681f3Smrg#define ACO_TEST_COMMON_H 267ec681f3Smrg#include <map> 277ec681f3Smrg#include <string> 287ec681f3Smrg#include <stdio.h> 297ec681f3Smrg 307ec681f3Smrg#include "amd_family.h" 317ec681f3Smrg#include "aco_ir.h" 327ec681f3Smrg#include "aco_builder.h" 337ec681f3Smrg#include "vulkan/radv_shader.h" 347ec681f3Smrg 357ec681f3Smrgstruct TestDef { 367ec681f3Smrg const char *name; 377ec681f3Smrg const char *source_file; 387ec681f3Smrg void (*func)(); 397ec681f3Smrg}; 407ec681f3Smrg 417ec681f3Smrgextern std::map<std::string, TestDef> tests; 427ec681f3Smrgextern FILE *output; 437ec681f3Smrg 447ec681f3Smrgbool set_variant(const char *name); 457ec681f3Smrg 467ec681f3Smrginline bool set_variant(chip_class cls, const char *rest="") 477ec681f3Smrg{ 487ec681f3Smrg char buf[8+strlen(rest)]; 497ec681f3Smrg if (cls != GFX10_3) { 507ec681f3Smrg snprintf(buf, sizeof(buf), "gfx%d%s", cls - GFX6 + 6, rest); 517ec681f3Smrg } else { 527ec681f3Smrg snprintf(buf, sizeof(buf), "gfx10_3%s", rest); 537ec681f3Smrg } 547ec681f3Smrg return set_variant(buf); 557ec681f3Smrg} 567ec681f3Smrg 577ec681f3Smrgvoid fail_test(const char *fmt, ...); 587ec681f3Smrgvoid skip_test(const char *fmt, ...); 597ec681f3Smrg 607ec681f3Smrg#define _PASTE(a, b) a##b 617ec681f3Smrg#define PASTE(a, b) _PASTE(a, b) 627ec681f3Smrg 637ec681f3Smrg#define _BEGIN_TEST(name, struct_name) static void struct_name(); static __attribute__((constructor)) void PASTE(add_test_, __COUNTER__)() {\ 647ec681f3Smrg tests[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name};\ 657ec681f3Smrg }\ 667ec681f3Smrg static void struct_name() {\ 677ec681f3Smrg 687ec681f3Smrg#define BEGIN_TEST(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__)) 697ec681f3Smrg#define BEGIN_TEST_TODO(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__)) 707ec681f3Smrg#define BEGIN_TEST_FAIL(name) _BEGIN_TEST(name, PASTE(Test_, __COUNTER__)) 717ec681f3Smrg#define END_TEST \ 727ec681f3Smrg } 737ec681f3Smrg 747ec681f3Smrg#endif /* ACO_TEST_COMMON_H */ 75