• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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
14definitions:
15  - name: java
16    template: |
17      .language Java
18
19      .record java.lang.Object <external>
20      .record java.lang.String <external>
21  - name: pandasm
22    template: |
23      .record panda.String <external>
24      .record panda.Object <external>
25
26tests:
27  - file-name: "lda.str"
28    isa:
29      title: Load accumulator from string constant pool
30      description: Load string specified by id into accumulator.
31      exceptions:
32        - x_none
33      verification:
34        - constant_string_id
35      instructions:
36        - sig: lda.str string_id
37          acc: out:ref
38          format: [op_id_32]
39    commands:
40
41
42      - file-name: "string_invalid"
43        isa:
44          description: Load string specified by id into accumulator.
45        runner-options: [compile-failure]
46        description: Check 'lda.str' instruction with invalid string.
47        code-template: |
48          #
49              lda.str %s
50        check-type: exit-positive
51        cases:
52          - values:
53            - ""
54          - values:
55            - "label:"
56          - values:
57            - "{}"
58          - values:
59            - "}"
60          - values:
61            - "# \"comment\""
62          - values:
63            - "null"
64          - values:
65            - "0"
66          - values:
67            - "v0"
68          - values:
69            - "\"test\", v0"
70          - values:
71            - "\"test\", \"string\""
72          - values:
73            - "test\"a\"string"
74          - values:
75            - "test'a'string"
76          # unknown escape sequence
77          - values:
78            - "\"test \\c string\""
79          - values:
80            - "\"test \\y string\""
81          - values:
82            - "\"123 = \\X31\\X32\\X33\""
83          # pandasm expects strings in mutf8 format, not \u or \U
84          - values:
85            - "\"utf-16: \\u018a\""
86          - values:
87            - "\"surrogate: \\U0001303F\""
88          # invalid mutf8 sequence
89          - values:
90            - "\"\\x32\\x00\\x33\""
91            bugid: ['3407']
92            ignore: true
93          - values:
94            - "\"\\xfd\\xa1\\xbe\\xed\""
95            bugid: ['3407']
96            ignore: true
97          - values:
98            - "\"\\x0\""
99          - values:
100            - "\"\\x 31\""
101          - values:
102            - "\"\\x3_1\""
103          - values:
104            - "\"\\xed\\xb0\""
105            bugid: ['3407']
106            ignore: true
107          - values:
108            - "\"\\xdf\\xdf\\xdf\""
109            bugid: ['3407']
110            ignore: true
111
112
113      - file-name: "string_valid"
114        isa:
115          description: Load string specified by id into accumulator.
116        runner-options: ['verifier-only', 'verifier-debug-config']
117        tags: [verifier]
118        description: Check 'lda.str' instruction with valid string.
119        code-template: |
120          #
121              lda.str %s
122        check-type: exit-positive
123        cases:
124          - values:
125            - "\"\""
126          - values:
127            - "\"   \""
128          - values:
129            - "\"\\\\\\\\\\\"\\\\\\\"\""
130          - values:
131            - "\" ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
132          - values:
133            - "\"\\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
134          - values:
135            - "\"\\a \\b \\t \\n \\f \\r \\' \\\" \\\\ \""
136          - values:
137            - "\" ~`\\t!@#$%^&*()_-+={[}]|\\x22.,<>/?|01234567\\x389@\\x41BCDEFGHIJKLMNOPQRSTUVWXYZ\\x61bc\\x64efghijklmnopqrstuvwxyz\""
138          - values:
139            - "#{'\"' + '~`\\t!@#$%^&*()_-+={[}]|\\x22.,<>/?|01234567\\x389@\\x41BCDEFGHIJKLMNOPQRSTUVWXYZ\\x61bc\\x64efghijklmnopqrstuvwxyz' * 50 + '\"'}"
140
141
142      - file-name: "string_type_p"
143        isa:
144          description: Load string specified by id into accumulator.
145        description: Check type of object created by 'lda.str' instruction with valid string in PandaAssembly context.
146        header-template: [pandasm, main]
147        code-template: |
148          #
149              lda.null
150              lda.str %s
151              isinstance panda.String
152              subi 1
153        check-type: no-check
154        cases:
155          - values:
156            - "\"\""
157          - values:
158            - "\"   \""
159          - values:
160            - "\"ascii: ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
161            tags: ['tsan']
162          - values:
163            - "\"mutf8: \\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
164            tags: ['tsan']
165          - values:
166            - "\"escaped: \\a \\b \\t \\n \\f \\r \\' \\\" \\\\ \""
167          - values:
168            - "\"\\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc\""
169          - values:
170            - "#{'\"<<' + 'aAbBcCdDeE' * 300 + '>>\"'}"
171
172
173      - file-name: "string_value_p"
174        isa:
175          description: Load string specified by id into accumulator.
176        description: Check value of object created by 'lda.str' instruction with valid string in PandaAssembly context.
177        header-template: []
178        code-template: |
179          .record panda.String <external>
180          .record Convert {} <external>
181          .function i32 Convert.stringToI32(panda.String a0) <external>
182          .function i32 main() {
183              movi v1, %s
184              lda.null
185              lda.str %s
186              sta.obj v0
187              call.short Convert.stringToI32, v0
188              jne v1, exit_failure
189              ldai 0
190              return
191          exit_failure:
192              ldai 1
193        check-type: no-check
194        cases:
195          # ascii
196          - values:
197            - 0
198            - "\"0\""
199          - values:
200            - 12345
201            - "\"12345\""
202            tags: ['tsan']
203          - values:
204            - -123
205            - "\"-123\""
206          - values:
207            - 0xffffffff
208            - "\"-1\""
209          - values:
210            - 0x7fffffff
211            - "\"2147483647\""
212          - values:
213            - 0x80000000
214            - "\"-2147483648\""
215          # mutf8 encoded
216          - values:
217            - 6789
218            - "\"\\x36\\x37\\x38\\x39\""
219          # mix of ascii and mutf8 encoded
220          - values:
221            - 31579
222            - "\"3\\x315\\x379\""
223
224
225      - file-name: "strings_eq"
226        isa:
227          description: Load string specified by id into accumulator.
228        description: Check that two strings created by 'lda.str' instructions are the same in the string constant pool.
229        code-template: |
230          #
231              lda.str %s
232              sta.obj v1
233              lda.null
234              lda.str %s
235              jeq.obj v1, ok
236              ldai 1
237              return
238          ok:
239        check-type: exit-positive
240        cases:
241          # empty strings
242          - values:
243            - "\"\""
244            - "\"\""
245          # ascii
246          - values:
247            - "\"abcdef\""
248            - "\"abcdef\""
249          - values:
250            - "\"abcdef\""
251            - "\"\\x61\\x62\\x63\\x64\\x65\\x66\""
252          - values:
253            - "\"abcdef\""
254            - "\"a\\x62\\x63\\x64e\\x66\""
255          - values:
256            - "\" ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
257            - "\" ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
258            tags: ['tsan']
259          - values:
260            - "\"\\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
261            - "\"\\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
262          - values:
263            - "\"I \\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc!\""
264            - "\"I \\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc\\x21\""
265          # escaping
266          - values:
267            - "\"\\b\\t\\n\\f\\r\\\"\\'\\\\\""
268            - "\"\\b\\t\\n\\f\\r\\\"\\'\\\\\""
269          - values:
270            - "\"\\b\\t\\n\\f\\r\\\"\\'\\\\\""
271            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
272            tags: ['tsan']
273          - values:
274            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
275            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
276
277
278      - file-name: "strings_ne"
279        isa:
280          description: Load string specified by id into accumulator.
281        description: Check that two strings created by 'lda.str' instructions are different in the string constant pool.
282        code-template: |
283          #
284              lda.str %s
285              sta.obj v1
286              lda.null
287              lda.str %s
288              jne.obj v1, ok
289              ldai 1
290              return
291          ok:
292        check-type: exit-positive
293        cases:
294          - values:
295            - "\"\""
296            - "\" \""
297          - values:
298            - "\" \""
299            - "\"  \""
300          - values:
301            - "\"a\""
302            - "\"a \""
303          - values:
304            - "\"a\""
305            - "\"b\""
306            tags: ['tsan']
307          - values:
308            - "\"a\""
309            - "\"A\""
310          - values:
311            - "\"1\\x33\\x324\""
312            - "\"1234\""
313          - values:
314            - "\"\\x08\\x09\\x0a\\x0d\\x0c\\x22\\x27\\x5c\""
315            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
316            tags: ['tsan']
317
318
319