~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/amd/compiler/tests/main.cpp

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * IN THE SOFTWARE.
22
22
 *
23
23
 */
 
24
#include "aco_ir.h"
 
25
 
 
26
#include <llvm-c/Target.h>
 
27
 
 
28
#include "framework.h"
 
29
#include <getopt.h>
24
30
#include <map>
25
31
#include <set>
26
 
#include <string>
27
 
#include <vector>
 
32
#include <stdarg.h>
28
33
#include <stdio.h>
29
34
#include <string.h>
30
 
#include <getopt.h>
 
35
#include <string>
31
36
#include <unistd.h>
32
 
#include <stdarg.h>
33
 
#include <llvm-c/Target.h>
34
 
#include "aco_ir.h"
35
 
#include "framework.h"
 
37
#include <vector>
36
38
 
37
 
static const char *help_message =
 
39
static const char* help_message =
38
40
   "Usage: %s [-h] [-l --list] [--no-check] [TEST [TEST ...]]\n"
39
41
   "\n"
40
42
   "Run ACO unit test(s). If TEST is not provided, all tests are run.\n"
50
52
   "  --no-check  Print test output instead of checking it.\n";
51
53
 
52
54
std::map<std::string, TestDef> tests;
53
 
FILE *output = NULL;
 
55
FILE* output = NULL;
54
56
 
55
57
static TestDef current_test;
56
58
static unsigned tests_written = 0;
57
 
static FILE *checker_stdin = NULL;
58
 
static char *checker_stdin_data = NULL;
 
59
static FILE* checker_stdin = NULL;
 
60
static char* checker_stdin_data = NULL;
59
61
static size_t checker_stdin_size = 0;
60
62
 
61
 
static char *output_data = NULL;
 
63
static char* output_data = NULL;
62
64
static size_t output_size = 0;
63
65
static size_t output_offset = 0;
64
66
 
65
67
static char current_variant[64] = {0};
66
 
static std::set<std::string> *variant_filter = NULL;
 
68
static std::set<std::string>* variant_filter = NULL;
67
69
 
68
70
bool test_failed = false;
69
71
bool test_skipped = false;
70
72
static char fail_message[256] = {0};
71
73
 
72
 
void write_test()
 
74
void
 
75
write_test()
73
76
{
74
77
   if (!checker_stdin) {
75
78
      /* not entirely correct, but shouldn't matter */
81
84
   if (output_offset == output_size && !test_skipped && !test_failed)
82
85
      return;
83
86
 
84
 
   char *data = output_data + output_offset;
 
87
   char* data = output_data + output_offset;
85
88
   uint32_t size = output_size - output_offset;
86
89
 
87
90
   fwrite("test", 1, 4, checker_stdin);
88
 
   fwrite(current_test.name, 1, strlen(current_test.name)+1, checker_stdin);
89
 
   fwrite(current_variant, 1, strlen(current_variant)+1, checker_stdin);
90
 
   fwrite(current_test.source_file, 1, strlen(current_test.source_file)+1, checker_stdin);
 
91
   fwrite(current_test.name, 1, strlen(current_test.name) + 1, checker_stdin);
 
92
   fwrite(current_variant, 1, strlen(current_variant) + 1, checker_stdin);
 
93
   fwrite(current_test.source_file, 1, strlen(current_test.source_file) + 1, checker_stdin);
91
94
   if (test_failed || test_skipped) {
92
 
      const char *res = test_failed ? "failed" : "skipped";
 
95
      const char* res = test_failed ? "failed" : "skipped";
93
96
      fwrite("\x01", 1, 1, checker_stdin);
94
 
      fwrite(res, 1, strlen(res)+1, checker_stdin);
95
 
      fwrite(fail_message, 1, strlen(fail_message)+1, checker_stdin);
 
97
      fwrite(res, 1, strlen(res) + 1, checker_stdin);
 
98
      fwrite(fail_message, 1, strlen(fail_message) + 1, checker_stdin);
96
99
   } else {
97
100
      fwrite("\x00", 1, 1, checker_stdin);
98
101
   }
103
106
   output_offset += size;
104
107
}
105
108
 
106
 
bool set_variant(const char *name)
 
109
bool
 
110
set_variant(const char* name)
107
111
{
108
112
   if (variant_filter && !variant_filter->count(name))
109
113
      return false;
118
122
   return true;
119
123
}
120
124
 
121
 
void fail_test(const char *fmt, ...)
 
125
void
 
126
fail_test(const char* fmt, ...)
122
127
{
123
128
   va_list args;
124
129
   va_start(args, fmt);
129
134
   va_end(args);
130
135
}
131
136
 
132
 
void skip_test(const char *fmt, ...)
 
137
void
 
138
skip_test(const char* fmt, ...)
133
139
{
134
140
   va_list args;
135
141
   va_start(args, fmt);
140
146
   va_end(args);
141
147
}
142
148
 
143
 
void run_test(TestDef def)
 
149
void
 
150
run_test(TestDef def)
144
151
{
145
152
   current_test = def;
146
153
   output_data = NULL;
163
170
   free(output_data);
164
171
}
165
172
 
166
 
int check_output(char **argv)
 
173
int
 
174
check_output(char** argv)
167
175
{
168
176
   fflush(stdout);
169
177
   fflush(stderr);
183
191
      close(stdin_pipe[0]);
184
192
      close(stdin_pipe[1]);
185
193
 
186
 
      execlp(ACO_TEST_PYTHON_BIN, ACO_TEST_PYTHON_BIN, ACO_TEST_SOURCE_DIR "/check_output.py", NULL);
 
194
      execlp(ACO_TEST_PYTHON_BIN, ACO_TEST_PYTHON_BIN, ACO_TEST_SOURCE_DIR "/check_output.py",
 
195
             NULL);
187
196
      fprintf(stderr, "%s: execlp() failed: %s\n", argv[0], strerror(errno));
188
197
      return 99;
189
198
   } else {
197
206
   }
198
207
}
199
208
 
200
 
bool match_test(std::string name, std::string pattern)
 
209
bool
 
210
match_test(std::string name, std::string pattern)
201
211
{
202
212
   if (name.length() < pattern.length())
203
213
      return false;
206
216
   return name == pattern;
207
217
}
208
218
 
209
 
int main(int argc, char **argv)
 
219
int
 
220
main(int argc, char** argv)
210
221
{
211
222
   int print_help = 0;
212
223
   int do_list = 0;
213
224
   int do_check = 1;
214
 
   const struct option opts[] = {
215
 
      { "help",     no_argument, &print_help, 1 },
216
 
      { "list",     no_argument, &do_list,    1 },
217
 
      { "no-check", no_argument, &do_check,   0 },
218
 
      { NULL,       0,           NULL,        0 }
219
 
   };
 
225
   const struct option opts[] = {{"help", no_argument, &print_help, 1},
 
226
                                 {"list", no_argument, &do_list, 1},
 
227
                                 {"no-check", no_argument, &do_check, 0},
 
228
                                 {NULL, 0, NULL, 0}};
220
229
 
221
230
   int c;
222
231
   while ((c = getopt_long(argc, argv, "hl", opts, NULL)) != -1) {
223
232
      switch (c) {
224
 
      case 'h':
225
 
         print_help = 1;
226
 
         break;
227
 
      case 'l':
228
 
         do_list = 1;
229
 
         break;
230
 
      case 0:
231
 
         break;
 
233
      case 'h': print_help = 1; break;
 
234
      case 'l': do_list = 1; break;
 
235
      case 0: break;
232
236
      case '?':
233
 
      default:
234
 
         fprintf(stderr, "%s: Invalid argument\n", argv[0]);
235
 
         return 99;
 
237
      default: fprintf(stderr, "%s: Invalid argument\n", argv[0]); return 99;
236
238
      }
237
239
   }
238
240
 
262
264
   if (do_check)
263
265
      checker_stdin = open_memstream(&checker_stdin_data, &checker_stdin_size);
264
266
 
265
 
        LLVMInitializeAMDGPUTargetInfo();
266
 
        LLVMInitializeAMDGPUTarget();
267
 
        LLVMInitializeAMDGPUTargetMC();
268
 
        LLVMInitializeAMDGPUDisassembler();
 
267
   LLVMInitializeAMDGPUTargetInfo();
 
268
   LLVMInitializeAMDGPUTarget();
 
269
   LLVMInitializeAMDGPUTargetMC();
 
270
   LLVMInitializeAMDGPUDisassembler();
269
271
 
270
272
   aco::init();
271
273