1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14require 'test/unit'
15require_relative 'checker'
16
17class CheckerTest < Test::Unit::TestCase
18  def setup; end
19  def teardown; end
20
21  def test_disasm
22    disasm = %(
23    dummy
24METHOD_INFO:
25  name: _GLOBAL::main
26  frame_size: 12
27DISASSEMBLY:
28    asm ---
29    asm 000
30  # IR inst 1
31    asm 111
32      asm 222
33      # Tag
34        asm 333
35    # Tag
36      asm 444
37    asm 555
38  # IR inst 2
39    asm 666
40METHOD_INFO:
41  name: _GLOBAL::foo
42  frame_size: 0
43DISASSEMBLY:
44  asm 777
45)
46    # Checker will clear working directory, so create it before we create disasm.txt file
47    checker = $CheckerForTest.new(OpenStruct.new({arch: 'x64'}), "")
48
49    File.write('disasm.txt', disasm)
50    checker.ASM_METHOD(/main/)
51    checker.ASM(x64: '---')
52    checker.ASM(x64: '000')
53    checker.ASM(x64: '333')
54    checker.ASM(x64: '666')
55    checker.ASM_NOT(x64: '777')
56    checker.ASM_INST('IR inst 1')
57    checker.ASM(x64: '111')
58    checker.ASM_NOT(x64: '666')
59    checker.ASM_NEXT(x64: '222')
60    checker.ASM_NEXT_NOT(x64: '777')
61    checker.ASM_NEXT(x64: '333')
62    checker.ASM_NEXT(x64: '444')
63    checker.ASM_NEXT(x64: '555')
64    checker.ASM_NEXT_NOT(x64: '666')
65    checker.ASM_INST('IR inst 2')
66    checker.ASM_NEXT(x64: '666')
67    checker.ASM_NEXT_NOT(x64: /.*/)
68    checker.ASM_RESET
69    checker.ASM(x64: '666')
70    checker.ASM(x64: '---')
71    checker.ASM(x64: '333')
72    checker.ASM_METHOD('foo')
73    checker.ASM(x64: '777')
74    checker.ASM_NEXT_NOT(x64: /.*/)
75  end
76end
77