1 /**
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "adapter_dynamic/abckit_dynamic.h"
17 #include "adapter_static/abckit_static.h"
18 #include "adapter_dynamic/metadata_inspect_dynamic.h"
19 #include "adapter_static/metadata_inspect_static.h"
20 #include "helpers/helpers.h"
21 #include "helpers/helpers_mode.h"
22
23 #include "libabckit/include/c/abckit.h"
24 #include "libabckit/include/c/metadata_core.h"
25 #include "libabckit/include/c/ir_core.h"
26 #include "ir_impl.h"
27
28 #include <gtest/gtest.h>
29 #include <cstddef>
30
31 static auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
32 static auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 static auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 static auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
35
36 namespace libabckit::test::helpers_mode {
37
38 // NOLINTBEGIN(cppcoreguidelines-pro-type-cstyle-cast)
39 static AbckitCoreModule *g_dummyModule = new AbckitCoreModule();
40 static AbckitString *g_dummyString = (AbckitString *)(0x1);
41 static AbckitBasicBlock *g_dummyBb = new AbckitBasicBlock();
42 static AbckitCoreFunction *g_dummyMethod = new AbckitCoreFunction();
43 static AbckitLiteralArray *g_dummyLitarr = (AbckitLiteralArray *)(0x1);
44 static AbckitInst *g_dummyInsT1 = new AbckitInst();
45 static AbckitInst *g_dummyInsT2 = new AbckitInst();
46 static AbckitInst *g_dummyInsT3 = new AbckitInst();
47 static AbckitInst *g_dummyInsT4 = new AbckitInst();
48 static AbckitInst *g_dummyInsT5 = new AbckitInst();
49 static AbckitCoreImportDescriptor *g_dummyImport = (AbckitCoreImportDescriptor *)(0x1);
50 static AbckitCoreExportDescriptor *g_dummyExport = (AbckitCoreExportDescriptor *)(0x1);
51 static AbckitType *g_dummyType = (AbckitType *)(0x1);
52 static panda::pandasm::Function *g_dummyPandasmFunction = (panda::pandasm::Function *)(0x1);
53 // NOLINTEND(cppcoreguidelines-pro-type-cstyle-cast)
54
OpenWrongModeFile(bool isDynamic)55 AbckitGraph *OpenWrongModeFile(bool isDynamic)
56 {
57 if (isDynamic) {
58 constexpr auto INPUT_PATH = ABCKIT_ABC_DIR "wrong_mode_tests/mode_test_static.abc";
59 auto *file = g_impl->openAbc(INPUT_PATH, strlen(INPUT_PATH));
60 auto *foo = helpers::FindMethodByName(file, "foo");
61 auto *graph = CreateGraphFromFunctionStatic(foo);
62 return graph;
63 }
64 constexpr auto INPUT_PATH = ABCKIT_ABC_DIR "wrong_mode_tests/mode_test_dynamic.abc";
65 auto *file = g_impl->openAbc(INPUT_PATH, strlen(INPUT_PATH));
66 auto *foo = helpers::FindMethodByName(file, "foo");
67 auto *graph = g_implI->createGraphFromFunction(foo);
68 return graph;
69 }
70
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph),bool isDynamic)71 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph), bool isDynamic)
72 {
73 auto *graph = OpenWrongModeFile(isDynamic);
74 auto *inst = apiToCheck(graph);
75
76 ASSERT_EQ(inst, nullptr);
77 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
78 auto *file = graph->file;
79 g_impl->destroyGraph(graph);
80 g_impl->closeFile(file);
81 }
82
TestMode(void (* apiToCheck)(AbckitGraph * graph),bool isDynamic)83 void TestMode(void (*apiToCheck)(AbckitGraph *graph), bool isDynamic)
84 {
85 auto *graph = OpenWrongModeFile(isDynamic);
86 apiToCheck(graph);
87
88 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
89 auto *file = graph->file;
90 g_impl->destroyGraph(graph);
91 g_impl->closeFile(file);
92 }
93
TestMode(void (* apiToCheck)(AbckitGraph * graph,int fd),bool isDynamic)94 void TestMode(void (*apiToCheck)(AbckitGraph *graph, int fd), bool isDynamic)
95 {
96 auto *graph = OpenWrongModeFile(isDynamic);
97 apiToCheck(graph, 0);
98
99 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
100 auto *file = graph->file;
101 g_impl->destroyGraph(graph);
102 g_impl->closeFile(file);
103 }
104
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,uint32_t index),bool isDynamic)105 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, uint32_t index), bool isDynamic)
106 {
107 auto *graph = OpenWrongModeFile(isDynamic);
108 auto *inst = apiToCheck(graph, 0);
109 ASSERT_EQ(inst, nullptr);
110 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
111 auto *file = graph->file;
112 g_impl->destroyGraph(graph);
113 g_impl->closeFile(file);
114 }
115
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,int64_t value),bool isDynamic)116 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, int64_t value), bool isDynamic)
117 {
118 auto *graph = OpenWrongModeFile(isDynamic);
119 int64_t val = 0;
120 AbckitInst *inst = apiToCheck(graph, val);
121 ASSERT_EQ(inst, nullptr);
122 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
123 auto *file = graph->file;
124 g_impl->destroyGraph(graph);
125 g_impl->closeFile(file);
126 }
127
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,uint64_t value),bool isDynamic)128 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, uint64_t value), bool isDynamic)
129 {
130 auto *graph = OpenWrongModeFile(isDynamic);
131 uint64_t val = 0;
132 AbckitInst *inst = apiToCheck(graph, val);
133 ASSERT_EQ(inst, nullptr);
134 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
135 auto *file = graph->file;
136 g_impl->destroyGraph(graph);
137 g_impl->closeFile(file);
138 }
139
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,uint64_t imm0,uint64_t imm1),bool isDynamic)140 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, uint64_t imm0, uint64_t imm1), bool isDynamic)
141 {
142 auto *graph = OpenWrongModeFile(isDynamic);
143 auto *inst = apiToCheck(graph, 0, 0);
144 ASSERT_EQ(inst, nullptr);
145 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
146 auto *file = graph->file;
147 g_impl->destroyGraph(graph);
148 g_impl->closeFile(file);
149 }
150
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,uint64_t imm,AbckitInst * str),bool isDynamic)151 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, uint64_t imm, AbckitInst *str), bool isDynamic)
152 {
153 auto *graph = OpenWrongModeFile(isDynamic);
154 g_dummyInsT1->graph = graph;
155 AbckitInst *inst = apiToCheck(graph, 0, g_dummyInsT1);
156 ASSERT_EQ(inst, nullptr);
157 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
158 auto *file = graph->file;
159 g_impl->destroyGraph(graph);
160 g_impl->closeFile(file);
161 }
162
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,uint64_t imm,AbckitLiteralArray * str),bool isDynamic)163 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, uint64_t imm, AbckitLiteralArray *str), bool isDynamic)
164 {
165 auto *graph = OpenWrongModeFile(isDynamic);
166 AbckitInst *inst = apiToCheck(graph, 0, g_dummyLitarr);
167 ASSERT_EQ(inst, nullptr);
168 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
169 auto *file = graph->file;
170 g_impl->destroyGraph(graph);
171 g_impl->closeFile(file);
172 }
173
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,uint64_t value,AbckitInst * inst1,AbckitInst * inst2),bool isDynamic)174 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, uint64_t value, AbckitInst *inst1, AbckitInst *inst2),
175 bool isDynamic)
176 {
177 auto *graph = OpenWrongModeFile(isDynamic);
178 g_dummyInsT1->graph = graph;
179 g_dummyInsT2->graph = graph;
180 auto *inst = apiToCheck(graph, 0, g_dummyInsT1, g_dummyInsT2);
181 ASSERT_EQ(inst, nullptr);
182 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
183 auto *file = graph->file;
184 g_impl->destroyGraph(graph);
185 g_impl->closeFile(file);
186 }
187
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,double value),bool isDynamic)188 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, double value), bool isDynamic)
189 {
190 auto *graph = OpenWrongModeFile(isDynamic);
191 double val = 0;
192 AbckitInst *inst = apiToCheck(graph, val);
193 ASSERT_EQ(inst, nullptr);
194 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
195 auto *file = graph->file;
196 g_impl->destroyGraph(graph);
197 g_impl->closeFile(file);
198 }
199
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitString * str),bool isDynamic)200 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitString *str), bool isDynamic)
201 {
202 auto *graph = OpenWrongModeFile(isDynamic);
203 AbckitInst *inst = apiToCheck(graph, g_dummyString);
204 ASSERT_EQ(inst, nullptr);
205 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
206 auto *file = graph->file;
207 g_impl->destroyGraph(graph);
208 g_impl->closeFile(file);
209 }
210
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitString * str,uint64_t imm),bool isDynamic)211 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitString *str, uint64_t imm), bool isDynamic)
212 {
213 auto *graph = OpenWrongModeFile(isDynamic);
214 AbckitInst *inst = apiToCheck(graph, g_dummyString, 0);
215 ASSERT_EQ(inst, nullptr);
216 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
217 auto *file = graph->file;
218 g_impl->destroyGraph(graph);
219 g_impl->closeFile(file);
220 }
221
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreExportDescriptor * e),bool isDynamic)222 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreExportDescriptor *e), bool isDynamic)
223 {
224 auto *graph = OpenWrongModeFile(isDynamic);
225 AbckitInst *inst = apiToCheck(graph, g_dummyExport);
226 ASSERT_EQ(inst, nullptr);
227 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
228 auto *file = graph->file;
229 g_impl->destroyGraph(graph);
230 g_impl->closeFile(file);
231 }
232
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreImportDescriptor * i),bool isDynamic)233 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreImportDescriptor *i), bool isDynamic)
234 {
235 auto *graph = OpenWrongModeFile(isDynamic);
236 AbckitInst *inst = apiToCheck(graph, g_dummyImport);
237 ASSERT_EQ(inst, nullptr);
238 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
239 auto *file = graph->file;
240 g_impl->destroyGraph(graph);
241 g_impl->closeFile(file);
242 }
243
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0),bool isDynamic)244 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0), bool isDynamic)
245 {
246 auto *graph = OpenWrongModeFile(isDynamic);
247 g_dummyInsT1->graph = graph;
248 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1);
249 ASSERT_EQ(inst, nullptr);
250 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
251 auto *file = graph->file;
252 g_impl->destroyGraph(graph);
253 g_impl->closeFile(file);
254 }
255
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,AbckitTypeId typeId),bool isDynamic)256 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1,
257 AbckitTypeId typeId),
258 bool isDynamic)
259 {
260 auto *graph = OpenWrongModeFile(isDynamic);
261 g_dummyInsT1->graph = graph;
262 g_dummyInsT2->graph = graph;
263 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, ABCKIT_TYPE_ID_I32);
264 ASSERT_EQ(inst, nullptr);
265 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
266 auto *file = graph->file;
267 g_impl->destroyGraph(graph);
268 g_impl->closeFile(file);
269 }
270
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitCoreExportDescriptor * e),bool isDynamic)271 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitCoreExportDescriptor *e),
272 bool isDynamic)
273 {
274 auto *graph = OpenWrongModeFile(isDynamic);
275 g_dummyInsT1->graph = graph;
276 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, g_dummyExport);
277 ASSERT_EQ(inst, nullptr);
278 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
279 auto *file = graph->file;
280 g_impl->destroyGraph(graph);
281 g_impl->closeFile(file);
282 }
283
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitIsaApiDynamicConditionCode cc),bool isDynamic)284 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitIsaApiDynamicConditionCode cc),
285 bool isDynamic)
286 {
287 auto *graph = OpenWrongModeFile(isDynamic);
288 g_dummyInsT1->graph = graph;
289 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, ABCKIT_ISA_API_DYNAMIC_CONDITION_CODE_CC_EQ);
290 ASSERT_EQ(inst, nullptr);
291 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
292 auto *file = graph->file;
293 g_impl->destroyGraph(graph);
294 g_impl->closeFile(file);
295 }
296
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,uint64_t imm0,uint64_t imm1),bool isDynamic)297 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, uint64_t imm0, uint64_t imm1),
298 bool isDynamic)
299 {
300 auto *graph = OpenWrongModeFile(isDynamic);
301 g_dummyInsT1->graph = graph;
302 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, 0, 0);
303 ASSERT_EQ(inst, nullptr);
304 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
305 auto *file = graph->file;
306 g_impl->destroyGraph(graph);
307 g_impl->closeFile(file);
308 }
309
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,uint64_t imm0,AbckitInst * inst1),bool isDynamic)310 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, uint64_t imm0, AbckitInst *inst1),
311 bool isDynamic)
312 {
313 auto *graph = OpenWrongModeFile(isDynamic);
314 g_dummyInsT1->graph = graph;
315 g_dummyInsT2->graph = graph;
316 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, 0, g_dummyInsT2);
317 ASSERT_EQ(inst, nullptr);
318 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
319 auto *file = graph->file;
320 g_impl->destroyGraph(graph);
321 g_impl->closeFile(file);
322 }
323
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,uint64_t imm0,uint64_t imm1,AbckitInst * input1),bool isDynamic)324 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, uint64_t imm0, uint64_t imm1,
325 AbckitInst *input1),
326 bool isDynamic)
327 {
328 auto *graph = OpenWrongModeFile(isDynamic);
329 g_dummyInsT1->graph = graph;
330 g_dummyInsT2->graph = graph;
331 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, 0, 0, g_dummyInsT2);
332 ASSERT_EQ(inst, nullptr);
333 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
334 auto *file = graph->file;
335 g_impl->destroyGraph(graph);
336 g_impl->closeFile(file);
337 }
338
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * inst,AbckitCoreFunction * method,size_t argCount,...),bool isDynamic)339 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *inst, AbckitCoreFunction *method,
340 size_t argCount, ...),
341 bool isDynamic)
342 {
343 auto *graph = OpenWrongModeFile(isDynamic);
344 g_dummyInsT1->graph = graph;
345 g_dummyModule->file = graph->file;
346 g_dummyMethod->owningModule = g_dummyModule;
347 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyMethod, 0);
348 ASSERT_EQ(inst, nullptr);
349 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
350 auto *file = graph->file;
351 g_impl->destroyGraph(graph);
352 g_impl->closeFile(file);
353 }
354
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input,size_t argCount,...),bool isDynamic)355 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input, size_t argCount, ...), bool isDynamic)
356 {
357 auto *graph = OpenWrongModeFile(isDynamic);
358 g_dummyInsT1->graph = graph;
359 auto *inst = apiToCheck(graph, g_dummyInsT1, 0);
360 ASSERT_EQ(inst, nullptr);
361 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
362 auto *file = graph->file;
363 g_impl->destroyGraph(graph);
364 g_impl->closeFile(file);
365 }
366
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,uint64_t imm0,...),bool isDynamic)367 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1, uint64_t imm0, ...),
368 bool isDynamic)
369 {
370 auto *graph = OpenWrongModeFile(isDynamic);
371 g_dummyInsT1->graph = graph;
372 g_dummyInsT2->graph = graph;
373 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, 0);
374 ASSERT_EQ(inst, nullptr);
375 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
376 auto *file = graph->file;
377 g_impl->destroyGraph(graph);
378 g_impl->closeFile(file);
379 }
380
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,size_t argCount,...),bool isDynamic)381 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, size_t argCount, ...), bool isDynamic)
382 {
383 auto *graph = OpenWrongModeFile(isDynamic);
384 auto *inst = apiToCheck(graph, 0);
385 ASSERT_EQ(inst, nullptr);
386 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
387 auto *file = graph->file;
388 g_impl->destroyGraph(graph);
389 g_impl->closeFile(file);
390 }
391
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitBasicBlock * catchBegin,size_t argCount,...),bool isDynamic)392 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitBasicBlock *catchBegin, size_t argCount, ...),
393 bool isDynamic)
394 {
395 auto *graph = OpenWrongModeFile(isDynamic);
396 auto *inst = apiToCheck(graph, g_dummyBb, 0);
397 ASSERT_EQ(inst, nullptr);
398 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
399 auto *file = graph->file;
400 g_impl->destroyGraph(graph);
401 g_impl->closeFile(file);
402 }
403
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreFunction * method,uint64_t imm),bool isDynamic)404 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreFunction *method, uint64_t imm), bool isDynamic)
405 {
406 auto *graph = OpenWrongModeFile(isDynamic);
407 g_dummyModule->file = graph->file;
408 g_dummyMethod->owningModule = g_dummyModule;
409 auto *inst = apiToCheck(graph, g_dummyMethod, 0);
410 ASSERT_EQ(inst, nullptr);
411 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
412 auto *file = graph->file;
413 g_impl->destroyGraph(graph);
414 g_impl->closeFile(file);
415 }
416
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreFunction * method,size_t argCount,...),bool isDynamic)417 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreFunction *method, size_t argCount, ...),
418 bool isDynamic)
419 {
420 auto *graph = OpenWrongModeFile(isDynamic);
421 g_dummyModule->file = graph->file;
422 g_dummyMethod->owningModule = g_dummyModule;
423 auto *inst = apiToCheck(graph, g_dummyMethod, 0);
424 ASSERT_EQ(inst, nullptr);
425 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
426 auto *file = graph->file;
427 g_impl->destroyGraph(graph);
428 g_impl->closeFile(file);
429 }
430
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreModule * m),bool isDynamic)431 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreModule *m), bool isDynamic)
432 {
433 auto *graph = OpenWrongModeFile(isDynamic);
434 g_dummyModule->file = graph->file;
435 auto *inst = apiToCheck(graph, g_dummyModule);
436 ASSERT_EQ(inst, nullptr);
437 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
438 auto *file = graph->file;
439 g_impl->destroyGraph(graph);
440 g_impl->closeFile(file);
441 }
442
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreClass * klass),bool isDynamic)443 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreClass *klass), bool isDynamic)
444 {
445 auto *graph = OpenWrongModeFile(isDynamic);
446 AbckitArktsClass arktsClass(g_dummyPandasmFunction);
447 AbckitCoreClass klass(g_dummyModule, arktsClass);
448 g_dummyModule->file = graph->file;
449 auto *inst = apiToCheck(graph, &klass);
450 ASSERT_EQ(inst, nullptr);
451 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
452 auto *file = graph->file;
453 g_impl->destroyGraph(graph);
454 g_impl->closeFile(file);
455 }
456
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreClass * klass1,AbckitCoreClass * klass2),bool isDynamic)457 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreClass *klass1, AbckitCoreClass *klass2),
458 bool isDynamic)
459 {
460 auto *graph = OpenWrongModeFile(isDynamic);
461 AbckitArktsClass arktsClass(g_dummyPandasmFunction);
462 AbckitCoreClass klass(g_dummyModule, arktsClass);
463 g_dummyModule->file = graph->file;
464 auto *inst = apiToCheck(graph, &klass, &klass);
465 ASSERT_EQ(inst, nullptr);
466 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
467 auto *file = graph->file;
468 g_impl->destroyGraph(graph);
469 g_impl->closeFile(file);
470 }
471
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreClass * klass,AbckitInst * inst),bool isDynamic)472 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreClass *klass, AbckitInst *inst), bool isDynamic)
473 {
474 auto *graph = OpenWrongModeFile(isDynamic);
475 g_dummyInsT1->graph = graph;
476 AbckitArktsClass arktsClass(g_dummyPandasmFunction);
477 AbckitCoreClass klass(g_dummyModule, arktsClass);
478 g_dummyModule->file = graph->file;
479 auto *inst = apiToCheck(graph, &klass, g_dummyInsT1);
480 ASSERT_EQ(inst, nullptr);
481 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
482 auto *file = graph->file;
483 g_impl->destroyGraph(graph);
484 g_impl->closeFile(file);
485 }
486
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitLiteralArray * litarr),bool isDynamic)487 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitLiteralArray *litarr), bool isDynamic)
488 {
489 auto *graph = OpenWrongModeFile(isDynamic);
490 auto *inst = apiToCheck(graph, g_dummyLitarr);
491 ASSERT_EQ(inst, nullptr);
492 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
493 auto *file = graph->file;
494 g_impl->destroyGraph(graph);
495 g_impl->closeFile(file);
496 }
497
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitCoreFunction * m,AbckitLiteralArray * litarr,uint64_t val,AbckitInst * inst),bool isDynamic)498 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitCoreFunction *m, AbckitLiteralArray *litarr,
499 uint64_t val, AbckitInst *inst),
500 bool isDynamic)
501 {
502 auto *graph = OpenWrongModeFile(isDynamic);
503 g_dummyInsT1->graph = graph;
504 g_dummyModule->file = graph->file;
505 g_dummyMethod->owningModule = g_dummyModule;
506 auto *inst = apiToCheck(graph, g_dummyMethod, g_dummyLitarr, 0, g_dummyInsT1);
507 ASSERT_EQ(inst, nullptr);
508 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
509 auto *file = graph->file;
510 g_impl->destroyGraph(graph);
511 g_impl->closeFile(file);
512 }
513
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitTypeId targetType),bool isDynamic)514 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitTypeId targetType),
515 bool isDynamic)
516 {
517 auto *graph = OpenWrongModeFile(isDynamic);
518 g_dummyInsT1->graph = graph;
519 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, AbckitTypeId::ABCKIT_TYPE_ID_I8);
520 ASSERT_EQ(inst, nullptr);
521 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
522 auto *file = graph->file;
523 g_impl->destroyGraph(graph);
524 g_impl->closeFile(file);
525 }
526
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,uint64_t imm0),bool isDynamic)527 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, uint64_t imm0), bool isDynamic)
528 {
529 auto *graph = OpenWrongModeFile(isDynamic);
530 g_dummyInsT1->graph = graph;
531 auto *inst = apiToCheck(graph, g_dummyInsT1, 0);
532 ASSERT_EQ(inst, nullptr);
533 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
534 auto *file = graph->file;
535 g_impl->destroyGraph(graph);
536 g_impl->closeFile(file);
537 }
538
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1),bool isDynamic)539 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1), bool isDynamic)
540 {
541 auto *graph = OpenWrongModeFile(isDynamic);
542 g_dummyInsT1->graph = graph;
543 g_dummyInsT2->graph = graph;
544 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2);
545 ASSERT_EQ(inst, nullptr);
546 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
547 auto *file = graph->file;
548 g_impl->destroyGraph(graph);
549 g_impl->closeFile(file);
550 }
551
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,AbckitIsaApiStaticConditionCode),bool isDynamic)552 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1,
553 AbckitIsaApiStaticConditionCode),
554 bool isDynamic)
555 {
556 auto *graph = OpenWrongModeFile(isDynamic);
557 g_dummyInsT1->graph = graph;
558 g_dummyInsT2->graph = graph;
559 AbckitInst *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, ABCKIT_ISA_API_STATIC_CONDITION_CODE_CC_EQ);
560 ASSERT_EQ(inst, nullptr);
561 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
562 auto *file = graph->file;
563 g_impl->destroyGraph(graph);
564 g_impl->closeFile(file);
565 }
566
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitString * input1),bool isDynamic)567 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitString *input1), bool isDynamic)
568 {
569 auto *graph = OpenWrongModeFile(isDynamic);
570 g_dummyInsT1->graph = graph;
571 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyString);
572 ASSERT_EQ(inst, nullptr);
573 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
574 auto *file = graph->file;
575 g_impl->destroyGraph(graph);
576 g_impl->closeFile(file);
577 }
578
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,AbckitInst * input2),bool isDynamic)579 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1, AbckitInst *input2),
580 bool isDynamic)
581 {
582 auto *graph = OpenWrongModeFile(isDynamic);
583 g_dummyInsT1->graph = graph;
584 g_dummyInsT2->graph = graph;
585 g_dummyInsT3->graph = graph;
586 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, g_dummyInsT3);
587 ASSERT_EQ(inst, nullptr);
588 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
589 auto *file = graph->file;
590 g_impl->destroyGraph(graph);
591 g_impl->closeFile(file);
592 }
593
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,AbckitInst * input2,AbckitInst * input3),bool isDynamic)594 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1, AbckitInst *input2,
595 AbckitInst *input3),
596 bool isDynamic)
597 {
598 auto *graph = OpenWrongModeFile(isDynamic);
599 g_dummyInsT1->graph = graph;
600 g_dummyInsT2->graph = graph;
601 g_dummyInsT3->graph = graph;
602 g_dummyInsT4->graph = graph;
603 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, g_dummyInsT3, g_dummyInsT4);
604 ASSERT_EQ(inst, nullptr);
605 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
606 auto *file = graph->file;
607 g_impl->destroyGraph(graph);
608 g_impl->closeFile(file);
609 }
610
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,AbckitInst * input2,AbckitInst * input3,AbckitInst * input4),bool isDynamic)611 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1, AbckitInst *input2,
612 AbckitInst *input3, AbckitInst *input4),
613 bool isDynamic)
614 {
615 auto *graph = OpenWrongModeFile(isDynamic);
616 g_dummyInsT1->graph = graph;
617 g_dummyInsT2->graph = graph;
618 g_dummyInsT3->graph = graph;
619 g_dummyInsT4->graph = graph;
620 g_dummyInsT5->graph = graph;
621 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, g_dummyInsT3, g_dummyInsT4, g_dummyInsT5);
622 ASSERT_EQ(inst, nullptr);
623 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
624 auto *file = graph->file;
625 g_impl->destroyGraph(graph);
626 g_impl->closeFile(file);
627 }
628
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitString * input1,AbckitInst * input2),bool isDynamic)629 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitString *input1,
630 AbckitInst *input2),
631 bool isDynamic)
632 {
633 auto *graph = OpenWrongModeFile(isDynamic);
634 g_dummyInsT1->graph = graph;
635 g_dummyInsT2->graph = graph;
636 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyString, g_dummyInsT2);
637 ASSERT_EQ(inst, nullptr);
638 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
639 auto *file = graph->file;
640 g_impl->destroyGraph(graph);
641 g_impl->closeFile(file);
642 }
643
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1,uint64_t imm0),bool isDynamic)644 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1, uint64_t imm0),
645 bool isDynamic)
646 {
647 auto *graph = OpenWrongModeFile(isDynamic);
648 g_dummyInsT1->graph = graph;
649 g_dummyInsT2->graph = graph;
650 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, 0);
651 ASSERT_EQ(inst, nullptr);
652 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
653 auto *file = graph->file;
654 g_impl->destroyGraph(graph);
655 g_impl->closeFile(file);
656 }
657
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * acc,AbckitCoreFunction * method,uint64_t imm0),bool isDynamic)658 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *acc, AbckitCoreFunction *method, uint64_t imm0),
659 bool isDynamic)
660 {
661 auto *graph = OpenWrongModeFile(isDynamic);
662 g_dummyInsT1->graph = graph;
663 g_dummyModule->file = graph->file;
664 g_dummyMethod->owningModule = g_dummyModule;
665 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyMethod, 0);
666 ASSERT_EQ(inst, nullptr);
667 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
668 auto *file = graph->file;
669 g_impl->destroyGraph(graph);
670 g_impl->closeFile(file);
671 }
672
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * arrayRef,AbckitInst * idx,AbckitInst * value,AbckitTypeId valueTypeId),bool isDynamic)673 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *arrayRef, AbckitInst *idx, AbckitInst *value,
674 AbckitTypeId valueTypeId),
675 bool isDynamic)
676 {
677 auto *graph = OpenWrongModeFile(isDynamic);
678 g_dummyInsT1->graph = graph;
679 g_dummyInsT2->graph = graph;
680 g_dummyInsT3->graph = graph;
681 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyInsT2, g_dummyInsT3, ABCKIT_TYPE_ID_I32);
682 ASSERT_EQ(inst, nullptr);
683 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
684 auto *file = graph->file;
685 g_impl->destroyGraph(graph);
686 g_impl->closeFile(file);
687 }
688
TestMode(AbckitInst * (* apiToCheck)(AbckitGraph * graph,AbckitInst * inputObj,AbckitType * targetType),bool isDynamic)689 void TestMode(AbckitInst *(*apiToCheck)(AbckitGraph *graph, AbckitInst *inputObj, AbckitType *targetType),
690 bool isDynamic)
691 {
692 auto *graph = OpenWrongModeFile(isDynamic);
693 g_dummyInsT1->graph = graph;
694 auto *inst = apiToCheck(graph, g_dummyInsT1, g_dummyType);
695 ASSERT_EQ(inst, nullptr);
696 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_WRONG_MODE);
697 auto *file = graph->file;
698 g_impl->destroyGraph(graph);
699 g_impl->closeFile(file);
700 }
701
702 } // namespace libabckit::test::helpers_mode
703