• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdlib>
17 #include <gtest/gtest.h>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 #include "abc2program_driver.h"
22 #include "abc2program_test_utils.h"
23 #include "common/abc_file_utils.h"
24 #include "dump_utils.h"
25 #include "modifiers.h"
26 
27 using namespace testing::ext;
28 
29 namespace panda::abc2program {
30 
31 struct FuncName {
32     std::string hello_world = ".#~@0=#HelloWorld";
33     std::string foo = ".#*#foo";
34     std::string goo = ".#*#goo";
35     std::string hoo = ".#*#hoo";
36     std::string main = ".func_main_0";
37     std::string method = ".#*@3*#method";
38     std::string lit = ".#~@1>#lit";
39     std::string add = ".#*#add";
40     std::string generate = ".#*#generateFunc";
41     std::string async_generate = ".#*#asyncGenerateFunc";
42     std::string async_arrow = ".#*#asyncArrowFunc";
43     std::string nested_literal_array = ".#~@2>#NestedLiteralArray";
44     std::string class_with_default_annotation = ".#~A=#A";
45     std::string class_with_spec_annotation = ".#~B=#B";
46 };
47 
48 struct RecordName {
49     std::string annotation = "Anno";
50 };
51 
52 const FuncName FUNC_NAME;
53 const RecordName RECORD_NAME;
54 const std::string HELLO_WORLD_ABC_TEST_FILE_NAME = GRAPH_TEST_ABC_DIR "HelloWorld.abc";
55 const std::string HELLO_WORLD_DEBUG_ABC_TEST_FILE_NAME = GRAPH_TEST_ABC_DIR "HelloWorldDebug.abc";
56 const std::string JSON_ABC_TEST_FILE_NAME = GRAPH_TEST_ABC_DIR "JsonTest.abc";
57 const std::string JSON_TEST_FILE_NAME = "JsonTest";
58 const bool REMOVE_DUMP_RESULT_FILES = true;
59 const std::string HELLO_WORLD_DUMP_RESULT_FILE_NAME = GRAPH_TEST_ABC_DUMP_DIR "HelloWorldDumpResult.txt";
60 const std::string HELLO_WORLD_DEBUG_DUMP_RESULT_FILE_NAME = GRAPH_TEST_ABC_DUMP_DIR "HelloWorldDebugDumpResult.txt";
61 const std::string HELLO_WORLD_DUMP_EXPECTED_FILE_NAME = GRAPH_TEST_ABC_DUMP_DIR "HelloWorldDumpExpected.txt";
62 const std::string HELLO_WORLD_DEBUG_DUMP_EXPECTED_FILE_NAME = GRAPH_TEST_ABC_DUMP_DIR "HelloWorldDebugDumpExpected.txt";
63 constexpr uint32_t NUM_OF_CODE_TEST_UT_FOO_METHOD_INS = 85;
64 constexpr uint8_t INS_SIZE_OF_FUNCTION_HOO = 4;
65 constexpr uint8_t IMMS_SIZE_OF_OPCODE_FLDAI = 1;
66 constexpr uint8_t SIZE_OF_LITERAL_ARRAY_TABLE = 7;
67 constexpr uint8_t TOTAL_NUM_OF_ASYNC_METHOD_LITERALS = 6;
68 constexpr uint8_t TOTAL_NUM_OF_MODULE_LITERALS = 21;
69 constexpr uint8_t TOTAL_NUM_OF_NESTED_LITERALS = 10;
70 constexpr uint8_t NUM_OF_MODULE_REQUESTS = 4;
71 constexpr uint8_t NUM_OF_REGULAR_IMPORTS = 1;
72 constexpr uint8_t NUM_OF_NAMESPACE_IMPORTS = 1;
73 constexpr uint8_t NUM_OF_LOCAL_EXPORTS = 1;
74 constexpr uint8_t NUM_OF_INDIRECT_EXPORTS = 1;
75 constexpr uint8_t NUM_OF_STAR_EXPORTS = 1;
76 const std::string ANNOTATIONS_ABC_TEST_FILE_NAME = GRAPH_TEST_ABC_DIR "Annotations.abc";
77 
78 
GetFunction(const std::string & name,const pandasm::Program & program)79 static const pandasm::Function *GetFunction(const std::string &name,
80                                             const pandasm::Program &program)
81 {
82     ASSERT(program.function_table.find(name) != program.function_table.end());
83     return &(program.function_table.find(name)->second);
84 }
85 
GetRecord(const std::string & name,const pandasm::Program & program)86 static const pandasm::Record *GetRecord(const std::string &name,
87                                         const pandasm::Program &program)
88 {
89     ASSERT(program.record_table.find(name) != program.record_table.end());
90     return &(program.record_table.find(name)->second);
91 }
92 
93 class Abc2ProgramHelloWorldTest : public testing::Test {
94 public:
SetUpTestCase(void)95     static void SetUpTestCase(void) {}
TearDownTestCase(void)96     static void TearDownTestCase(void) {}
SetUp()97     void SetUp()
98     {
99         (void)driver_.Compile(HELLO_WORLD_ABC_TEST_FILE_NAME);
100         prog_ = &(driver_.GetProgram());
101         hello_world_function_ = GetFunction(FUNC_NAME.hello_world, *prog_);
102         foo_function_ = GetFunction(FUNC_NAME.foo, *prog_);
103         goo_function_ = GetFunction(FUNC_NAME.goo, *prog_);
104         hoo_function_ = GetFunction(FUNC_NAME.hoo, *prog_);
105         main_function_ = GetFunction(FUNC_NAME.main, *prog_);
106         method_function_ = GetFunction(FUNC_NAME.method, *prog_);
107         lit_function_ = GetFunction(FUNC_NAME.lit, *prog_);
108         add_function_ = GetFunction(FUNC_NAME.add, *prog_);
109         generate_function_ = GetFunction(FUNC_NAME.generate, *prog_);
110         async_generate_function_ = GetFunction(FUNC_NAME.async_generate, *prog_);
111         async_arrow_function_ = GetFunction(FUNC_NAME.async_arrow, *prog_);
112     }
113 
TearDown()114     void TearDown() {}
115 
116     Abc2ProgramDriver driver_;
117     const pandasm::Program *prog_ = nullptr;
118     const pandasm::Function *hello_world_function_ = nullptr;
119     const pandasm::Function *foo_function_ = nullptr;
120     const pandasm::Function *goo_function_ = nullptr;
121     const pandasm::Function *hoo_function_ = nullptr;
122     const pandasm::Function *main_function_ = nullptr;
123     const pandasm::Function *method_function_ = nullptr;
124     const pandasm::Function *lit_function_ = nullptr;
125     const pandasm::Function *add_function_ = nullptr;
126     const pandasm::Function *generate_function_ = nullptr;
127     const pandasm::Function *async_generate_function_ = nullptr;
128     const pandasm::Function *async_arrow_function_ = nullptr;
129 };
130 
131 class Abc2ProgramHelloWorldDebugTest : public testing::Test {
132 public:
SetUpTestCase(void)133     static void SetUpTestCase(void) {}
TearDownTestCase(void)134     static void TearDownTestCase(void) {}
SetUp()135     void SetUp()
136     {
137         (void)driver_.Compile(HELLO_WORLD_DEBUG_ABC_TEST_FILE_NAME);
138         prog_ = &(driver_.GetProgram());
139         foo_function_ = GetFunction(FUNC_NAME.foo, *prog_);
140         main_function_ = GetFunction(FUNC_NAME.main, *prog_);
141     }
142 
TearDown()143     void TearDown() {}
144 
145     Abc2ProgramDriver driver_;
146     const pandasm::Program *prog_ = nullptr;
147     const pandasm::Function *foo_function_ = nullptr;
148     const pandasm::Function *main_function_ = nullptr;
149 };
150 
151 class Abc2ProgramJsonTest : public testing::Test {
152 public:
SetUpTestCase(void)153     static void SetUpTestCase(void) {}
TearDownTestCase(void)154     static void TearDownTestCase(void) {}
SetUp()155     void SetUp()
156     {
157         (void)driver_.Compile(JSON_ABC_TEST_FILE_NAME);
158         prog_ = &(driver_.GetProgram());
159     }
160 
TearDown()161     void TearDown() {}
162 
163     Abc2ProgramDriver driver_;
164     const pandasm::Program *prog_ = nullptr;
165 };
166 
167 class Abc2ProgramAnnotationTest : public testing::Test {
168 public:
SetUpTestCase(void)169     static void SetUpTestCase(void) {}
TearDownTestCase(void)170     static void TearDownTestCase(void) {}
SetUp()171     void SetUp()
172     {
173         (void)driver_.Compile(ANNOTATIONS_ABC_TEST_FILE_NAME);
174         prog_ = &(driver_.GetProgram());
175         a_function_ = GetFunction(FUNC_NAME.class_with_default_annotation, *prog_);
176         b_function_ = GetFunction(FUNC_NAME.class_with_spec_annotation, *prog_);
177         anno_record_ = GetRecord(RECORD_NAME.annotation, *prog_);
178     }
179 
TearDown()180     void TearDown() {}
181 
182     Abc2ProgramDriver driver_;
183     const pandasm::Program *prog_ = nullptr;
184     const pandasm::Function *a_function_ = nullptr;
185     const pandasm::Function *b_function_ = nullptr;
186     const pandasm::Record *anno_record_ = nullptr;
187 };
188 
189 /*------------------------------------- Cases of release mode below -------------------------------------*/
190 
191 /**
192  * @tc.name: abc2program_hello_world_test_dump
193  * @tc.desc: check dump result in release mode.
194  * @tc.type: FUNC
195  * @tc.require: IADG92
196  */
197 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_dump, TestSize.Level1)
198 {
199     driver_.Dump(HELLO_WORLD_DUMP_RESULT_FILE_NAME);
200     EXPECT_TRUE(Abc2ProgramTestUtils::ValidateDumpResult(HELLO_WORLD_DUMP_RESULT_FILE_NAME,
201                                                          HELLO_WORLD_DUMP_EXPECTED_FILE_NAME));
202     if (REMOVE_DUMP_RESULT_FILES) {
203         Abc2ProgramTestUtils::RemoveDumpResultFile(HELLO_WORLD_DUMP_RESULT_FILE_NAME);
204     }
205 }
206 
207 /**
208  * @tc.name: abc2program_hello_world_test_func_annotation
209  * @tc.desc: get program function annotation.
210  * @tc.type: FUNC
211  * @tc.require: #I9AQ3K
212  */
213 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_func_annotation, TestSize.Level1)
214 {
215     constexpr uint32_t NUM_OF_HELLO_WORLD_TEST_UT_HELLO_WORLD_SLOTS_NUM = 2;
216     constexpr uint32_t NUM_OF_HELLO_WORLD_TEST_UT_FOO_SLOTS_NUM = 24;
217     constexpr uint32_t NUM_OF_HELLO_WORLD_TEST_UT_GOO_SLOTS_NUM = 0;
218     EXPECT_TRUE(hello_world_function_->GetSlotsNum() == NUM_OF_HELLO_WORLD_TEST_UT_HELLO_WORLD_SLOTS_NUM);
219     EXPECT_TRUE(foo_function_->GetSlotsNum() == NUM_OF_HELLO_WORLD_TEST_UT_FOO_SLOTS_NUM);
220     EXPECT_TRUE(goo_function_->GetSlotsNum() == NUM_OF_HELLO_WORLD_TEST_UT_GOO_SLOTS_NUM);
221     EXPECT_TRUE(hello_world_function_->concurrent_module_requests.empty());
222     EXPECT_TRUE(foo_function_->concurrent_module_requests.empty());
223     EXPECT_TRUE(goo_function_->concurrent_module_requests.empty());
224 }
225 
226 /**
227  * @tc.name: abc2program_hello_world_test_field_metadata
228  * @tc.desc: get program field metadata.
229  * @tc.type: FUNC
230  * @tc.require: issueI98NGN
231  */
232 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_field_metadata, TestSize.Level1)
233 {
234     for (const auto &it : prog_->record_table) {
235         if (it.first == "_ESModuleRecord") {
236             const pandasm::Record &record = it.second;
237             const std::vector<pandasm::Field> &field_list = record.field_list;
238             const pandasm::Field &field = field_list[0];
239             EXPECT_TRUE(field.type.GetPandasmName() == "u32");
240             EXPECT_TRUE(field.name.find("HelloWorld.ts") != std::string::npos);
241         }
242     }
243 }
244 
245 /**
246  * @tc.name: abc2program_hello_world_test_lang
247  * @tc.desc: get program language.
248  * @tc.type: FUNC
249  * @tc.require: issueI96G2J
250  */
251 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_lang, TestSize.Level1)
252 {
253     panda_file::SourceLang expected_lang = panda_file::SourceLang::ECMASCRIPT;
254     bool lang_matched = (prog_->lang == expected_lang);
255     EXPECT_TRUE(lang_matched);
256 }
257 
258 /**
259  * @tc.name: abc2program_hello_world_test_literalarray_table
260  * @tc.desc: get program literalarray_table.
261  * @tc.type: FUNC
262  * @tc.require: issueI9DK5D
263  */
264 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_literalarray_table, TestSize.Level1)
265 {
266     std::set<size_t> literals_sizes;
267     std::vector<std::string> literal_array_keys;
268     for (const auto &it : prog_->literalarray_table) {
269         const pandasm::LiteralArray &literal_array = it.second;
270         size_t literals_size = literal_array.literals_.size();
271         literals_sizes.insert(literals_size);
272         literal_array_keys.emplace_back(it.first);
273     }
274     EXPECT_TRUE(Abc2ProgramTestUtils::ValidateLiteralsSizes(literals_sizes));
275     EXPECT_TRUE(Abc2ProgramTestUtils::ValidateLiteralArrayKeys(literal_array_keys));
276 }
277 
278 /**
279  * @tc.name: abc2program_async_method_literals
280  * @tc.desc: get and check literals of async generator method.
281  * @tc.type: FUNC
282  * @tc.require: issueI9SLHH
283  */
284 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_async_method_literals, TestSize.Level1)
285 {
286     auto &literal_array_table = prog_->literalarray_table;
287     EXPECT_EQ(literal_array_table.size(), SIZE_OF_LITERAL_ARRAY_TABLE);
288     panda::pandasm::LiteralArray async_literals;
289     for (auto &item : literal_array_table) {
290         for (auto &literal : item.second.literals_) {
291             if (literal.tag_ == panda_file::LiteralTag::ASYNCGENERATORMETHOD) {
292                 async_literals = item.second;
293                 break;
294             }
295         }
296         if (async_literals.literals_.size() != 0) {
297             break;
298         }
299     }
300     EXPECT_EQ(async_literals.literals_.size(), TOTAL_NUM_OF_ASYNC_METHOD_LITERALS);
301     auto it = async_literals.literals_.begin();
302     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
303     ++it;
304     EXPECT_EQ(it->tag_, panda_file::LiteralTag::STRING);
305     ++it;
306     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
307     ++it;
308     EXPECT_EQ(it->tag_, panda_file::LiteralTag::ASYNCGENERATORMETHOD);
309     EXPECT_EQ(std::get<std::string>(it->value_), FUNC_NAME.method);
310     ++it;
311     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
312     ++it;
313     EXPECT_EQ(it->tag_, panda_file::LiteralTag::METHODAFFILIATE);
314 }
315 
316 /**
317  * @tc.name: abc2program_hello_world_test_record_table
318  * @tc.desc: get program record_table.
319  * @tc.type: FUNC
320  * @tc.require: issueI96G2J
321  */
322 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_record_table, TestSize.Level1)
323 {
324     panda_file::SourceLang expected_lang = panda_file::SourceLang::ECMASCRIPT;
325     std::vector<std::string> record_names;
326     for (const auto &it : prog_->record_table) {
327         EXPECT_TRUE(it.second.language == expected_lang);
328         EXPECT_TRUE(it.second.source_file == "");
329         EXPECT_TRUE(it.first == it.second.name);
330         record_names.emplace_back(it.first);
331     }
332     EXPECT_TRUE(Abc2ProgramTestUtils::ValidateRecordNames(record_names));
333 }
334 
335 /**
336  * @tc.name: abc2program_hello_world_test_fields
337  * @tc.desc: get program record_table.
338  * @tc.type: FUNC
339  * @tc.require: issueI98NGN
340  */
341 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_fields, TestSize.Level1)
342 {
343     for (const auto &it : prog_->record_table) {
344         if (it.first == "_ESModuleRecord" || it.first == "_ESScopeNamesRecord") {
345             const pandasm::Record &record = it.second;
346             const std::vector<pandasm::Field> &field_list = record.field_list;
347             EXPECT_EQ(field_list.size(), 1);
348             const pandasm::Field &field = field_list[0];
349             EXPECT_EQ(field.type.GetPandasmName(), "u32");
350             EXPECT_NE(field.name.find("HelloWorld.ts"), std::string::npos);
351         } else {
352             EXPECT_EQ(it.second.field_list.size(), 0);
353         }
354     }
355 }
356 
357 /**
358  * @tc.name: abc2program_hello_world_test_strings
359  * @tc.desc: get existed string.
360  * @tc.type: FUNC
361  * @tc.require: issueI96G2J
362  */
363 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_strings, TestSize.Level1)
364 {
365     bool string_matched = Abc2ProgramTestUtils::ValidateProgramStrings(prog_->strings);
366     EXPECT_TRUE(string_matched);
367 }
368 
369 /**
370  * @tc.name: abc2program_hello_world_test_function_kind_access_flags
371  * @tc.desc: get existed function_kind.
372  * @tc.type: FUNC
373  * @tc.require: issueI9BPIO
374  */
375 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_function_kind_access_flags, TestSize.Level1)
376 {
377     const pandasm::Function &function = *foo_function_;
378     panda_file::FunctionKind function_kind = function.function_kind;
379     EXPECT_TRUE(function_kind == panda_file::FunctionKind::FUNCTION);
380     uint32_t access_flags = function.metadata->GetAccessFlags();
381     EXPECT_TRUE((access_flags & ACC_STATIC) != 0);
382     EXPECT_TRUE(lit_function_->GetFunctionKind() == panda::panda_file::FunctionKind::NONE);
383     EXPECT_TRUE(foo_function_->GetFunctionKind() == panda::panda_file::FunctionKind::FUNCTION);
384     EXPECT_TRUE(add_function_->GetFunctionKind() == panda::panda_file::FunctionKind::NC_FUNCTION);
385     EXPECT_TRUE(generate_function_->GetFunctionKind() == panda::panda_file::FunctionKind::GENERATOR_FUNCTION);
386     EXPECT_TRUE(method_function_->GetFunctionKind() == panda::panda_file::FunctionKind::ASYNC_FUNCTION);
387     EXPECT_TRUE(async_generate_function_->GetFunctionKind() ==
388         panda::panda_file::FunctionKind::ASYNC_GENERATOR_FUNCTION);
389     EXPECT_TRUE(async_arrow_function_->GetFunctionKind() == panda::panda_file::FunctionKind::ASYNC_NC_FUNCTION);
390 }
391 
392 /**
393  * @tc.name: abc2program_code_test_function_foo_part1
394  * @tc.desc: get program fuction foo.
395  * @tc.type: FUNC
396  * @tc.require: issueI989S6
397  */
398 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_code_test_function_foo_part1, TestSize.Level1)
399 {
400     const pandasm::Function &function = *foo_function_;
401     size_t regs_num = function.regs_num;
402     constexpr size_t NUM_OF_ARGS_FOR_FOO_METHOD = 3;
403     EXPECT_TRUE(function.params.size() == NUM_OF_ARGS_FOR_FOO_METHOD);
404     for (size_t i = 0; i < function.params.size(); ++i) {
405         EXPECT_TRUE(function.params[i].type.GetPandasmName() == ANY_TYPE_NAME);
406     }
407     EXPECT_TRUE(function.name == FUNC_NAME.foo);
408     EXPECT_TRUE(function.ins.size() == NUM_OF_CODE_TEST_UT_FOO_METHOD_INS);
409     // check ins[0]
410     const pandasm::InsPtr &ins0 = function.ins[0];
411     std::string pa_ins_str0 = ins0->ToString("", true, regs_num);
412     EXPECT_TRUE(pa_ins_str0 == "nop");
413     EXPECT_TRUE(ins0->Label() == "");
414     EXPECT_FALSE(ins0->IsLabel());
415     // check ins[3]
416     const pandasm::InsPtr &ins3 = function.ins[3];
417     std::string pa_ins_str3 = ins3->ToString("", true, regs_num);
418     EXPECT_TRUE(pa_ins_str3 == "label@3: ");
419     EXPECT_TRUE(ins3->Label() == "label@3");
420     EXPECT_TRUE(ins3->IsLabel());
421     // check ins[10]
422     const pandasm::InsPtr &ins10 = function.ins[10];
423     std::string pa_ins_str10 = ins10->ToString("", true, regs_num);
424     EXPECT_TRUE(pa_ins_str10 == "label@9: ");
425     EXPECT_TRUE(ins10->Label() == "label@9");
426     EXPECT_TRUE(ins10->IsLabel());
427     // check ins[13]
428     const pandasm::InsPtr &ins13 = function.ins[13];
429     std::string pa_ins_str13 = ins13->ToString("", true, regs_num);
430     EXPECT_TRUE(pa_ins_str13 == "label@11: ");
431     EXPECT_TRUE(ins13->Label() == "label@11");
432     EXPECT_TRUE(ins13->IsLabel());
433 }
434 
435 /**
436  * @tc.name: abc2program_code_test_function_foo_part2
437  * @tc.desc: get program fuction foo.
438  * @tc.type: FUNC
439  * @tc.require: issueI989S6
440  */
441 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_code_test_function_foo_part2, TestSize.Level1)
442 {
443     const pandasm::Function &function = *foo_function_;
444     size_t regs_num = function.regs_num;
445 
446     // check ins[15]
447     const pandasm::InsPtr &ins15 = function.ins[15];
448     std::string pa_ins_str15 = ins15->ToString("", true, regs_num);
449     EXPECT_TRUE(pa_ins_str15 == "label@12: ");
450     EXPECT_TRUE(ins15->Label() == "label@12");
451     EXPECT_TRUE(ins15->IsLabel());
452     // check ins[27]
453     const pandasm::InsPtr &ins27 = function.ins[27];
454     std::string pa_ins_str27 = ins27->ToString("", true, regs_num);
455     EXPECT_TRUE(pa_ins_str27 == "tryldglobalbyname 0x8, varA");
456     EXPECT_TRUE(ins27->Label() == "");
457     EXPECT_FALSE(ins27->IsLabel());
458     // check ins[31]
459     const pandasm::InsPtr &ins31 = function.ins[31];
460     std::string pa_ins_str31 = ins31->ToString("", true, regs_num);
461     EXPECT_TRUE(pa_ins_str31 == "jeqz label@29");
462     EXPECT_TRUE(ins31->Label() == "");
463     EXPECT_FALSE(ins31->IsLabel());
464     // check ins[34]
465     const pandasm::InsPtr &ins34 = function.ins[34];
466     std::string pa_ins_str34 = ins34->ToString("", true, regs_num);
467     EXPECT_TRUE(pa_ins_str34 == "label@29: ");
468     EXPECT_TRUE(ins34->Label() == "label@29");
469     EXPECT_TRUE(ins34->IsLabel());
470     // check ins[39]
471     const pandasm::InsPtr &ins39 = function.ins[39];
472     std::string pa_ins_str39 = ins39->ToString("", true, regs_num);
473     EXPECT_TRUE(pa_ins_str39 == "jeqz label@36");
474     EXPECT_TRUE(ins39->Label() == "");
475     EXPECT_FALSE(ins39->IsLabel());
476     // check ins[42]
477     const pandasm::InsPtr &ins42 = function.ins[42];
478     std::string pa_ins_str42 = ins42->ToString("", true, regs_num);
479     EXPECT_TRUE(pa_ins_str42 == "label@36: ");
480     EXPECT_TRUE(ins42->Label() == "label@36");
481     EXPECT_TRUE(ins42->IsLabel());
482 }
483 
484 /**
485  * @tc.name: abc2program_code_test_function_foo_part3
486  * @tc.desc: get program fuction foo.
487  * @tc.type: FUNC
488  * @tc.require: issueI989S6
489  */
490 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_code_test_function_foo_part3, TestSize.Level1)
491 {
492     const pandasm::Function &function = *foo_function_;
493     size_t regs_num = function.regs_num;
494     // check ins[45]
495     const pandasm::InsPtr &ins45 = function.ins[45];
496     std::string pa_ins_str45 = ins45->ToString("", true, regs_num);
497     EXPECT_TRUE(pa_ins_str45 == "label@38: ");
498     EXPECT_TRUE(ins45->Label() == "label@38");
499     EXPECT_TRUE(ins45->IsLabel());
500     // check ins[52]
501     const pandasm::InsPtr &ins52 = function.ins[52];
502     std::string pa_ins_str52 = ins52->ToString("", true, regs_num);
503     EXPECT_TRUE(pa_ins_str52 == "sta v4");
504     EXPECT_TRUE(ins52->Label() == "");
505     EXPECT_FALSE(ins52->IsLabel());
506     // check ins[55]
507     const pandasm::InsPtr &ins55 = function.ins[55];
508     std::string pa_ins_str55 = ins55->ToString("", true, regs_num);
509     EXPECT_TRUE(pa_ins_str55 == "label@47: ");
510     EXPECT_TRUE(ins55->Label() == "label@47");
511     EXPECT_TRUE(ins55->IsLabel());
512     // check ins[60]
513     const pandasm::InsPtr &ins60 = function.ins[60];
514     std::string pa_ins_str60 = ins60->ToString("", true, regs_num);
515     EXPECT_TRUE(pa_ins_str60 == "jmp label@53");
516     EXPECT_TRUE(ins60->Label() == "");
517     EXPECT_FALSE(ins60->IsLabel());
518     // check ins[61]
519     const pandasm::InsPtr &ins61 = function.ins[61];
520     std::string pa_ins_str61 = ins61->ToString("", true, regs_num);
521     EXPECT_TRUE(pa_ins_str61 == "label@52: ");
522     EXPECT_TRUE(ins61->Label() == "label@52");
523     EXPECT_TRUE(ins61->IsLabel());
524     // check ins[63]
525     const pandasm::InsPtr &ins63 = function.ins[63];
526     std::string pa_ins_str63 = ins63->ToString("", true, regs_num);
527     EXPECT_TRUE(pa_ins_str63 == "label@53: ");
528     EXPECT_TRUE(ins63->Label() == "label@53");
529     EXPECT_TRUE(ins63->IsLabel());
530     // check ins[66]
531     const pandasm::InsPtr &ins66 = function.ins[66];
532     std::string pa_ins_str66 = ins66->ToString("", true, regs_num);
533     EXPECT_TRUE(pa_ins_str66 == "jeqz label@64");
534     EXPECT_TRUE(ins66->Label() == "");
535     EXPECT_FALSE(ins66->IsLabel());
536     // check ins[75]
537     const pandasm::InsPtr &ins75 = function.ins[75];
538     std::string pa_ins_str75 = ins75->ToString("", true, regs_num);
539     EXPECT_TRUE(pa_ins_str75 == "label@64: ");
540     EXPECT_TRUE(ins75->Label() == "label@64");
541     EXPECT_TRUE(ins75->IsLabel());
542 }
543 
544 /**
545  * @tc.name: abc2program_code_test_function_foo_part4
546  * @tc.desc: get program fuction foo.
547  * @tc.type: FUNC
548  * @tc.require: issueI989S6
549  */
550 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_code_test_function_foo_part4, TestSize.Level1)
551 {
552     const pandasm::Function &function = *foo_function_;
553     size_t regs_num = function.regs_num;
554     // check ins[80]
555     const pandasm::InsPtr &ins80 = function.ins[80];
556     std::string pa_ins_str80 = ins80->ToString("", true, regs_num);
557     EXPECT_TRUE(pa_ins_str80 == "jeqz label@71");
558     EXPECT_TRUE(ins80->Label() == "");
559     EXPECT_FALSE(ins80->IsLabel());
560     // check ins[83]
561     const pandasm::InsPtr &ins83 = function.ins[83];
562     std::string pa_ins_str83 = ins83->ToString("", true, regs_num);
563     EXPECT_TRUE(pa_ins_str83 == "label@71: ");
564     EXPECT_TRUE(ins83->Label() == "label@71");
565     EXPECT_TRUE(ins83->IsLabel());
566     // check ins[84]
567     const pandasm::InsPtr &ins84 = function.ins[84];
568     std::string pa_ins_str84 = ins84->ToString("", true, regs_num);
569     EXPECT_TRUE(pa_ins_str84 == "returnundefined");
570     EXPECT_TRUE(ins84->Label() == "");
571     EXPECT_FALSE(ins84->IsLabel());
572     // check catch blocks
573     constexpr uint32_t NUM_OF_CODE_TEST_UT_FOO_METHOD_CATCH_BLOCKS = 3;
574     EXPECT_TRUE(function.catch_blocks.size() == NUM_OF_CODE_TEST_UT_FOO_METHOD_CATCH_BLOCKS);
575     // catch_blocks[0]
576     const pandasm::Function::CatchBlock &pa_catch_block0 = function.catch_blocks[0];
577     EXPECT_TRUE(pa_catch_block0.try_begin_label == "label@9");
578     EXPECT_TRUE(pa_catch_block0.try_end_label == "label@11");
579     EXPECT_TRUE(pa_catch_block0.catch_begin_label == "label@12");
580     EXPECT_TRUE(pa_catch_block0.catch_end_label == "label@12");
581     // catch_blocks[1]
582     const pandasm::Function::CatchBlock &pa_catch_block1 = function.catch_blocks[1];
583     EXPECT_TRUE(pa_catch_block1.try_begin_label == "label@3");
584     EXPECT_TRUE(pa_catch_block1.try_end_label == "label@38");
585     EXPECT_TRUE(pa_catch_block1.catch_begin_label == "label@38");
586     EXPECT_TRUE(pa_catch_block1.catch_end_label == "label@38");
587     // catch_blocks[2]
588     const pandasm::Function::CatchBlock &pa_catch_block2 = function.catch_blocks[2];
589     EXPECT_TRUE(pa_catch_block2.try_begin_label == "label@3");
590     EXPECT_TRUE(pa_catch_block2.try_end_label == "label@47");
591     EXPECT_TRUE(pa_catch_block2.catch_begin_label == "label@52");
592     EXPECT_TRUE(pa_catch_block2.catch_end_label == "label@52");
593 }
594 
595 /**
596  * @tc.name: abc2program_code_test_function_goo
597  * @tc.desc: get program fuction goo.
598  * @tc.type: FUNC
599  * @tc.require: issueI989S6
600  */
601 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_code_test_function_goo, TestSize.Level1)
602 {
603     const pandasm::Function &function = *goo_function_;
604     size_t regs_num = function.regs_num;
605     constexpr uint32_t NUM_OF_CODE_TEST_UT_GOO_METHOD_INS = 1;
606     EXPECT_TRUE(function.name == FUNC_NAME.goo);
607     EXPECT_TRUE(function.ins.size() == NUM_OF_CODE_TEST_UT_GOO_METHOD_INS);
608     // check ins[0]
609     constexpr uint32_t INDEX_OF_FUNC_RETURNUNDEFINED = 0;
610     const pandasm::InsPtr &ins1 = function.ins[INDEX_OF_FUNC_RETURNUNDEFINED];
611     std::string pa_ins_str1 = ins1->ToString("", true, regs_num);
612     EXPECT_TRUE(pa_ins_str1 == "returnundefined");
613     EXPECT_TRUE(ins1->Label() == "");
614     EXPECT_FALSE(ins1->IsLabel());
615     // check catch blocks
616     EXPECT_TRUE(function.catch_blocks.size() == 0);
617 }
618 
619 /**
620  * @tc.name: abc2program_code_imm_of_FLDAI
621  * @tc.desc: get and check immediate number of opcode FLDAI.
622  * @tc.type: FUNC
623  * @tc.require: issueI9E5ZM
624  */
625 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_code_imm_of_FLDAI, TestSize.Level1)
626 {
627     const pandasm::Function &hoo = *hoo_function_;
628     EXPECT_EQ(hoo.ins.size(), INS_SIZE_OF_FUNCTION_HOO);
629     pandasm::Ins *ins_fldai;
630     for (auto &ins : hoo.ins) {
631         if (ins->opcode == pandasm::Opcode::FLDAI) {
632             ins_fldai = ins.get();
633             break;
634         }
635     }
636     EXPECT_TRUE(ins_fldai->opcode == pandasm::Opcode::FLDAI);
637     // check imm of FLDAI
638     EXPECT_EQ(ins_fldai->Imms().size(), IMMS_SIZE_OF_OPCODE_FLDAI);
639     auto imm = ins_fldai->GetImm(0);
640     auto p = std::get_if<double>(&(imm));
641     EXPECT_NE(p, nullptr);
642     EXPECT_EQ(*p, 1.23);
643 }
644 
645 /**
646  * @tc.name: abc2program_module_literal_entry_test
647  * @tc.desc: get and check number of modules.
648  * @tc.type: FUNC
649  * @tc.require: issueI9E5ZM
650  */
651 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_module_literal_entry_test, TestSize.Level1)
652 {
653     auto &mod_table = prog_->literalarray_table;
654     EXPECT_EQ(mod_table.size(), SIZE_OF_LITERAL_ARRAY_TABLE);
655     auto &module_literals = mod_table.begin()->second.literals_;
656     EXPECT_EQ(module_literals.size(), TOTAL_NUM_OF_MODULE_LITERALS);
__anon3a331e0f0102(size_t idx, panda::panda_file::LiteralTag expect_tag, uint32_t expect_value) 657     auto check_entry = [&module_literals](size_t idx, panda::panda_file::LiteralTag expect_tag, uint32_t expect_value) {
658         auto *literal = &(module_literals[idx]);
659         EXPECT_EQ(literal->tag_, expect_tag);
660         auto p = std::get_if<uint32_t>(&literal->value_);
661         EXPECT_TRUE(p != nullptr && *p == expect_value);
662     };
663     size_t idx = 0;
664     // check ModuleRequests
665     check_entry(idx, panda::panda_file::LiteralTag::INTEGER, NUM_OF_MODULE_REQUESTS);
666     // Each constant value '1' below stands for each entry. Each entry is also in the literal vector and shall be
667     // considered while calculating the position (index) of next entry.
668     // check RegularImportEntry
669     idx += NUM_OF_MODULE_REQUESTS + 1;
670     check_entry(idx, panda::panda_file::LiteralTag::INTEGER, NUM_OF_REGULAR_IMPORTS);
671     // check NamespaceImportEntry
672     idx += NUM_OF_REGULAR_IMPORTS * LITERAL_NUM_OF_REGULAR_IMPORT + 1;
673     check_entry(idx, panda::panda_file::LiteralTag::INTEGER, NUM_OF_NAMESPACE_IMPORTS);
674     // check LocalExportEntry
675     idx += NUM_OF_NAMESPACE_IMPORTS * LITERAL_NUM_OF_NAMESPACE_IMPORT + 1;
676     check_entry(idx, panda::panda_file::LiteralTag::INTEGER, NUM_OF_LOCAL_EXPORTS);
677     // check IndirectExportEntry
678     idx += NUM_OF_LOCAL_EXPORTS * LITERAL_NUM_OF_LOCAL_EXPORT + 1;
679     check_entry(idx, panda::panda_file::LiteralTag::INTEGER, NUM_OF_INDIRECT_EXPORTS);
680     // check StarExportEntry
681     idx += NUM_OF_INDIRECT_EXPORTS * LITERAL_NUM_OF_INDIRECT_EXPORT + 1;
682     check_entry(idx, panda::panda_file::LiteralTag::INTEGER, NUM_OF_STAR_EXPORTS);
683     // check idx
684     idx += NUM_OF_STAR_EXPORTS * LITERAL_NUM_OF_STAR_EXPORT + 1;
685     EXPECT_EQ(idx, TOTAL_NUM_OF_MODULE_LITERALS);
686 }
687 
688 /**
689  * @tc.name: abc2program_hello_world_test_nested_literal_array
690  * @tc.desc: check contents of nested literal array
691  * @tc.type: FUNC
692  * @tc.require: issueIA7D9J
693  */
694 HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_nested_literal_array, TestSize.Level1)
695 {
696     auto &literal_array_table = prog_->literalarray_table;
697     EXPECT_EQ(literal_array_table.size(), SIZE_OF_LITERAL_ARRAY_TABLE);
698     /** current literal array table should be similar to below, each line indicates a literal array, which is
699      *  formated as 'id_name : { literals }':
700      *    _1 : { ... }                   // some other literal arrays
701      *    _2 : { ... }
702      *    _3 : { ... }                   // literal array that be nested, which id name is, for example, '_3'.
703      *    _4 : { ..., literal_array:_3}  // target literal array we are checking.
704      */
705     panda::pandasm::LiteralArray nested_literal_array;
706     for (auto &item : literal_array_table) {
707         for (auto &literal : item.second.literals_) {
708             if (literal.tag_ == panda_file::LiteralTag::LITERALARRAY) {
709                 nested_literal_array = item.second;
710                 break;
711             }
712         }
713         if (nested_literal_array.literals_.size() != 0) {
714             break;
715         }
716     }
717     EXPECT_EQ(nested_literal_array.literals_.size(), TOTAL_NUM_OF_NESTED_LITERALS);
718     auto it = nested_literal_array.literals_.begin();
719     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
720     ++it;
721     EXPECT_EQ(it->tag_, panda_file::LiteralTag::STRING);
722     ++it;
723     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
724     ++it;
725     EXPECT_EQ(it->tag_, panda_file::LiteralTag::METHOD);
726     EXPECT_EQ(std::get<std::string>(it->value_), FUNC_NAME.nested_literal_array);
727     ++it;
728     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
729     ++it;
730     EXPECT_EQ(it->tag_, panda_file::LiteralTag::METHODAFFILIATE);
731     ++it;
732     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
733     ++it;
734     EXPECT_EQ(it->tag_, panda_file::LiteralTag::INTEGER);
735     ++it;
736     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
737     ++it;
738     EXPECT_EQ(it->tag_, panda_file::LiteralTag::LITERALARRAY);
739     EXPECT_NE(literal_array_table.find(std::get<std::string>(it->value_)), literal_array_table.end());
740 }
741 
742 /*------------------------------------- Cases of release mode above -------------------------------------*/
743 /*-------------------------------------- Cases of debug mode below --------------------------------------*/
744 
745 /**
746  * @tc.name: abc2program_hello_world_debug_test_dump
747  * @tc.desc: check dump result in debug mode.
748  * @tc.type: FUNC
749  * @tc.require: IADG92
750  */
751 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_debug_test_dump, TestSize.Level1)
752 {
753     driver_.Dump(HELLO_WORLD_DEBUG_DUMP_RESULT_FILE_NAME);
754     EXPECT_TRUE(Abc2ProgramTestUtils::ValidateDumpResult(HELLO_WORLD_DEBUG_DUMP_RESULT_FILE_NAME,
755                                                          HELLO_WORLD_DEBUG_DUMP_EXPECTED_FILE_NAME));
756     if (REMOVE_DUMP_RESULT_FILES) {
757         Abc2ProgramTestUtils::RemoveDumpResultFile(HELLO_WORLD_DEBUG_DUMP_RESULT_FILE_NAME);
758     }
759 }
760 
761 /**
762  * @tc.name: abc2program_hello_world_test_source_file
763  * @tc.desc: Verify the source file.
764  * @tc.type: FUNC
765  * @tc.require: issueI9CL5Z
766  */
767 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_source_file, TestSize.Level1)
768 {
769     const pandasm::Function &function = *foo_function_;
770     std::string source_file = function.source_file;
771     EXPECT_TRUE(source_file.find("HelloWorld.ts") != std::string::npos);
772 }
773 
774 /**
775  * @tc.name: abc2program_hello_world_test_source_code
776  * @tc.desc: Verify the source code
777  * @tc.type: FUNC
778  * @tc.require: issueI9DT0V
779  */
780 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_source_code, TestSize.Level1)
781 {
782     const pandasm::Function &function = *main_function_;
783     std::string source_code = function.source_code;
784     EXPECT_TRUE(source_code.find("not supported") != std::string::npos);
785 }
786 
787 /**
788  * @tc.name: abc2program_hello_world_test_local_variable
789  * @tc.desc: get local variables
790  * @tc.type: FUNC
791  * @tc.require: issueI9DT0V
792  */
793 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_local_variable, TestSize.Level1)
794 {
795     const pandasm::Function &function = *foo_function_;
796     EXPECT_FALSE(function.local_variable_debug.empty());
797     EXPECT_TRUE(function.local_variable_debug[0].name.find("4funcObj") != std::string::npos);
798     EXPECT_TRUE(function.local_variable_debug[0].signature.find("any") != std::string::npos);
799     EXPECT_TRUE(function.local_variable_debug[0].signature_type.find("any") != std::string::npos);
800     EXPECT_TRUE(function.local_variable_debug[0].reg == 0);
801     EXPECT_TRUE(function.local_variable_debug[0].start == 3);
802     EXPECT_TRUE(function.local_variable_debug[0].length == 88);
803 }
804 
805 /**
806  * @tc.name: abc2program_hello_world_test_ins_debug
807  * @tc.desc: get ins_debug line number and column number
808  * @tc.type: FUNC
809  * @tc.require: issueI9DT0V
810  */
811 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_ins_debug, TestSize.Level1)
812 {
813     const pandasm::Function &function = *foo_function_;
814     size_t regs_num = function.regs_num;
815     EXPECT_FALSE(function.local_variable_debug.empty());
816 
817     const pandasm::InsPtr &ins0 = function.ins[0];
818     std::string pa_ins_str0 = ins0->ToString("", true, regs_num);
819     EXPECT_TRUE(pa_ins_str0 == "mov v0, a0");
820     EXPECT_TRUE(ins0->ins_debug.line_number == -1);
821     EXPECT_TRUE(ins0->ins_debug.column_number == -1);
822 
823     const pandasm::InsPtr &ins3 = function.ins[3];
824     std::string pa_ins_str3 = ins3->ToString("", true, regs_num);
825     EXPECT_TRUE(pa_ins_str3 == "ldundefined");
826     EXPECT_TRUE(ins3->ins_debug.line_number == 40);
827     EXPECT_TRUE(ins3->ins_debug.column_number == 2);
828 
829     const pandasm::InsPtr &ins6 = function.ins[6];
830     std::string pa_ins_str6 = ins6->ToString("", true, regs_num);
831     EXPECT_TRUE(pa_ins_str6 == "ldai 0xb");
832     EXPECT_TRUE(ins6->ins_debug.line_number == 41);
833     EXPECT_TRUE(ins6->ins_debug.column_number == 11);
834 }
835 
836 /**
837  * @tc.name: abc2program_hello_world_test_open_abc_file
838  * @tc.desc: open a non-existent abc file
839  * @tc.type: FUNC
840  * @tc.require: issueI9DT0V
841  */
842 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_open_abc_file, TestSize.Level1)
843 {
844     std::string file_path = "invalid_file_path";
845     EXPECT_FALSE(driver_.Compile(file_path));
846 }
847 
848 /**
849  * @tc.name: abc2program_hello_world_test_driver_run
850  * @tc.desc: driver run different parameters
851  * @tc.type: FUNC
852  * @tc.require: issueI9DT0V
853  */
854 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_driver_run, TestSize.Level1)
855 {
856     EXPECT_TRUE(driver_.Run(0, nullptr));
857     int argc1 = 2;
858     const char* args1[] = {"--param1", "--param2"};
859     EXPECT_TRUE(driver_.Run(argc1, args1));
860     int argc2 = 2;
861     const char* args2[] = {"abc2program_options", "input_file_path"};
862     EXPECT_TRUE(driver_.Run(argc2, args2));
863     int argc3 = 3;
864     const char* args3[] = {"abc2program_options", "input_file_path", "output_file_path"};
865     EXPECT_TRUE(driver_.Run(argc3, args3));
866     int argc4 = 2;
867     const char* args4[] = {"abc2program_options", "--debug"};
868     EXPECT_TRUE(driver_.Run(argc4, args4));
869     int argc5 = 4;
870     const char* args5[] = {"abc2program_options", "--debug", "--debug-file", "debug_file_path"};
871     EXPECT_TRUE(driver_.Run(argc5, args5));
872     int argc6 = 3;
873     const char* args6[] = {"abc2program_options", HELLO_WORLD_DEBUG_ABC_TEST_FILE_NAME.c_str(),
874                             HELLO_WORLD_DEBUG_DUMP_RESULT_FILE_NAME.c_str()};
875     EXPECT_FALSE(driver_.Run(argc6, args6));
876     if (REMOVE_DUMP_RESULT_FILES) {
877         Abc2ProgramTestUtils::RemoveDumpResultFile(HELLO_WORLD_DEBUG_DUMP_RESULT_FILE_NAME);
878     }
879 }
880 
881 /**
882  * @tc.name: abc2program_hello_world_test_Label
883  * @tc.desc: label found in the map
884  * @tc.type: FUNC
885  * @tc.require: issueI9DT0V
886  */
887 HWTEST_F(Abc2ProgramHelloWorldDebugTest, abc2program_hello_world_test_Label, TestSize.Level1)
888 {
889     LabelMap label_map = {{"first_label", "first_mapped_label"}, {"second_label", "second_mapped_label"}};
890     std::string label1 = "second_label";
891     std::string label2 = "third_label";
892     PandasmDumperUtils test = PandasmDumperUtils();
893     std::string result_found = test.GetMappedLabel(label1, label_map);
894     std::string result_null = test.GetMappedLabel(label2, label_map);
895     EXPECT_EQ(result_found, "second_mapped_label");
896     EXPECT_EQ(result_null, "");
897 }
898 
899 /*-------------------------------------- Cases of debug mode above --------------------------------------*/
900 /*-------------------------------------- Case of json file below ----------------------------------------*/
901 
902 /**
903  * @tc.name: abc2program_json_field_test
904  * @tc.desc: get json field metadata
905  * @tc.type: FUNC
906  * @tc.require: issueIAJKTS
907  */
908 HWTEST_F(Abc2ProgramJsonTest, abc2program_json_field_test, TestSize.Level1)
909 {
910     auto it = prog_->record_table.find(JSON_TEST_FILE_NAME);
911     ASSERT(it != prog_->record_table.end());
912     const pandasm::Record &record = it->second;
913     const std::vector<pandasm::Field> &field_list = record.field_list;
914     EXPECT_EQ(field_list.size(), 1);
915     const pandasm::Field &field = field_list[0];
916     EXPECT_EQ(field.name, JSON_FILE_CONTENT);
917     std::optional<pandasm::ScalarValue> val = field.metadata->GetValue();
918     EXPECT_TRUE(val.has_value());
919     auto content = val.value().GetValue<std::string>();
920     EXPECT_EQ(content, "{\n  \"name\" : \"Import json\"\n}");
921 }
922 
923 /**
924  * @tc.name: abc2program_annotations_test_Record
925  * @tc.desc: record fields compare
926  * @tc.type: FUNC
927  * @tc.require: IARNAU
928  */
929 HWTEST_F(Abc2ProgramAnnotationTest, abc2program_annotations_test_Record, TestSize.Level1)
930 {
931     const auto &fields = anno_record_->field_list;
932     for (auto& field : fields) {
933         EXPECT_TRUE(field.name == "a" || field.name == "b" || field.name == "c" || field.name == "d" ||
934                     field.name == "e" || field.name == "f");
935         if (field.name == "a") {
936             EXPECT_EQ(field.type.GetName(), "f64");
937             EXPECT_EQ(field.metadata->GetValue()->GetValue<double>(), 7);
938         }
939         if (field.name == "b") {
940             EXPECT_EQ(field.type.GetName(), "f64[]");
941             auto &litarr = prog_->literalarray_table.at(field.metadata->GetValue()->GetValue<std::string>());
942             EXPECT_EQ(litarr.literals_.size(), 4);
943         }
944         if (field.name == "c") {
945             EXPECT_EQ(field.type.GetName(), "panda.String");
946             EXPECT_EQ(field.metadata->GetValue()->GetValue<std::string>(), "abc");
947         }
948         if (field.name == "d") {
949             EXPECT_EQ(field.type.GetName(), "u1");
950             EXPECT_EQ(field.metadata->GetValue()->GetValue<bool>(), false);
951         }
952         if (field.name == "e") {
953             EXPECT_EQ(field.type.GetName(), "f64[]");
954             auto &litarr = prog_->literalarray_table.at(field.metadata->GetValue()->GetValue<std::string>());
955             EXPECT_EQ(litarr.literals_.size(), 6);
956         }
957         if (field.name == "f") {
958             EXPECT_EQ(field.type.GetName(), "f64");
959             EXPECT_EQ(field.metadata->GetValue()->GetValue<double>(), 2);
960         }
961     }
962 }
963 
964 /**
965  * @tc.name: abc2program_annotations_test_function_annotation
966  * @tc.desc: check if annotated function has annotation
967  * @tc.type: FUNC
968  * @tc.require: IARNAU
969  */
970 HWTEST_F(Abc2ProgramAnnotationTest, abc2program_annotations_test_function_annotation, TestSize.Level1)
971 {
972     auto &annotations = a_function_->metadata->GetAnnotations();
__anon3a331e0f0202(const pandasm::AnnotationData &anno) 973     auto iter = std::find_if(annotations.begin(), annotations.end(), [](const pandasm::AnnotationData &anno) {
974         return anno.GetName() == "Anno";
975     });
976     EXPECT_NE(iter, annotations.end());
977     EXPECT_EQ(iter->GetName(), "Anno");
978 }
979 
980 /**
981  * @tc.name: abc2program_annotations_test_function_annotation_fields
982  * @tc.desc: annotation of function fields comparison
983  * @tc.type: FUNC
984  * @tc.require: IARNAU
985  */
986 HWTEST_F(Abc2ProgramAnnotationTest, abc2program_annotations_test_function_annotation_fields, TestSize.Level1)
987 {
988     auto &annotations = b_function_->metadata->GetAnnotations();
__anon3a331e0f0302(const pandasm::AnnotationData &anno) 989     auto anno = std::find_if(annotations.begin(), annotations.end(), [](const pandasm::AnnotationData &anno) {
990         return anno.GetName() == "Anno";
991     });
992     EXPECT_NE(anno, annotations.end());
993     EXPECT_EQ(anno->GetName(), "Anno");
994     const auto &elements = anno->GetElements();
995     for (auto& elem : elements) {
996         EXPECT_TRUE(elem.GetName() == "a" || elem.GetName() == "b" || elem.GetName() == "c" || elem.GetName() == "d" ||
997                     elem.GetName() == "e" || elem.GetName() == "f");
998         if (elem.GetName() == "a") {
999             EXPECT_EQ(elem.GetValue()->GetType(), pandasm::Value::Type::F64);
1000             EXPECT_EQ(elem.GetValue()->GetAsScalar()->GetValue<double>(), 5);
1001         }
1002         if (elem.GetName() == "b") {
1003             EXPECT_EQ(elem.GetValue()->GetType(), pandasm::Value::Type::LITERALARRAY);
1004             auto &litarr = prog_->literalarray_table.at(elem.GetValue()->GetAsScalar()->GetValue<std::string>());
1005             EXPECT_EQ(litarr.literals_.size(), 6);
1006         }
1007         if (elem.GetName() == "c") {
1008             EXPECT_EQ(elem.GetValue()->GetType(), pandasm::Value::Type::STRING);
1009             EXPECT_EQ(elem.GetValue()->GetAsScalar()->GetValue<std::string>(), "def");
1010         }
1011         if (elem.GetName() == "d") {
1012             EXPECT_EQ(elem.GetValue()->GetType(), pandasm::Value::Type::U1);
1013             EXPECT_EQ(elem.GetValue()->GetAsScalar()->GetValue<bool>(), true);
1014         }
1015         if (elem.GetName() == "e") {
1016             EXPECT_EQ(elem.GetValue()->GetType(), pandasm::Value::Type::LITERALARRAY);
1017             auto &litarr = prog_->literalarray_table.at(elem.GetValue()->GetAsScalar()->GetValue<std::string>());
1018             EXPECT_EQ(litarr.literals_.size(), 4);
1019         }
1020         if (elem.GetName() == "f") {
1021             EXPECT_EQ(elem.GetValue()->GetType(), pandasm::Value::Type::F64);
1022             EXPECT_EQ(elem.GetValue()->GetAsScalar()->GetValue<double>(), 3);
1023         }
1024     }
1025 }
1026 
1027 };  // panda::abc2program