• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14definitions:
15  - name: PandaAssembly
16    template: |
17      .language PandaAssembly
18
19      .record panda.Object <external>
20      .record panda.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      verification:
32        - constant_string_id
33      instructions:
34        - sig: lda.str string_id
35          acc: out:ref
36          format: [op_id_32]
37    commands:
38
39
40      - file-name: "string_invalid"
41        isa:
42          description: Load string specified by id into accumulator.
43        runner-options: [compile-failure]
44        description: Check 'lda.str' instruction with invalid string.
45        code-template: |
46          #
47              lda.str %s
48        check-type: exit-positive
49        cases:
50          - values:
51            - ""
52          - values:
53            - "label:"
54          - values:
55            - "{}"
56          - values:
57            - "}"
58          - values:
59            - "# \"comment\""
60          - values:
61            - "null"
62          - values:
63            - "0"
64          - values:
65            - "v0"
66          - values:
67            - "\"test\", v0"
68          - values:
69            - "\"test\", \"string\""
70          - values:
71            - "test\"a\"string"
72          - values:
73            - "test'a'string"
74          # unknown escape sequence
75          - values:
76            - "\"test \\c string\""
77          - values:
78            - "\"test \\y string\""
79          - values:
80            - "\"123 = \\X31\\X32\\X33\""
81          # pandasm expects strings in mutf8 format, not \u or \U
82          - values:
83            - "\"utf-16: \\u018a\""
84          - values:
85            - "\"surrogate: \\U0001303F\""
86          # invalid mutf8 sequence
87          - values:
88            - "\"\\x32\\x00\\x33\""
89            bugid: ['3407']
90            ignore: true
91          - values:
92            - "\"\\xfd\\xa1\\xbe\\xed\""
93            bugid: ['3407']
94            ignore: true
95          - values:
96            - "\"\\x0\""
97          - values:
98            - "\"\\x 31\""
99          - values:
100            - "\"\\x3_1\""
101          - values:
102            - "\"\\xed\\xb0\""
103            bugid: ['3407']
104            ignore: true
105          - values:
106            - "\"\\xdf\\xdf\\xdf\""
107            bugid: ['3407']
108            ignore: true
109
110
111      - file-name: "string_valid"
112        isa:
113          description: Load string specified by id into accumulator.
114        runner-options: ['verifier-only', 'verifier-config']
115        tags: [verifier]
116        description: Check 'lda.str' instruction with valid string.
117        code-template: |
118          #
119              lda.str %s
120        check-type: exit-positive
121        cases:
122          - values:
123            - "\"\""
124          - values:
125            - "\"   \""
126          - values:
127            - "\"\\\\\\\\\\\"\\\\\\\"\""
128          - values:
129            - "\" ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
130          - values:
131            - "\"\\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
132          - values:
133            - "\"\\a \\b \\t \\n \\f \\r \\' \\\" \\\\ \""
134          - values:
135            - "\" ~`\\t!@#$%^&*()_-+={[}]|\\x22.,<>/?|01234567\\x389@\\x41BCDEFGHIJKLMNOPQRSTUVWXYZ\\x61bc\\x64efghijklmnopqrstuvwxyz\""
136          - values:
137            - "#{'\"' + '~`\\t!@#$%^&*()_-+={[}]|\\x22.,<>/?|01234567\\x389@\\x41BCDEFGHIJKLMNOPQRSTUVWXYZ\\x61bc\\x64efghijklmnopqrstuvwxyz' * 50 + '\"'}"
138
139
140      - file-name: "string_type_p"
141        isa:
142          description: Load string specified by id into accumulator.
143        description: Check type of object created by 'lda.str' instruction with valid string in PandaAssembly context.
144        header-template: [pandasm, main]
145        code-template: |
146          #
147              lda.str %s
148              sta.obj v1
149              isinstance panda.String
150              jeqz set_failure
151              lda.obj v1
152              isinstance panda.Object
153              jeqz set_failure
154              ldai 0
155              return
156          set_failure:
157              ldai 1
158              return
159        check-type: none
160        cases:
161          - values:
162            - "\"\""
163          - values:
164            - "\"   \""
165          - values:
166            - "\"ascii: ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
167            tags: ['tsan']
168          - values:
169            - "\"mutf8: \\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
170            tags: ['tsan']
171          - values:
172            - "\"escaped: \\a \\b \\t \\n \\f \\r \\' \\\" \\\\ \""
173          - values:
174            - "\"\\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc\""
175          - values:
176            - "#{'\"<<' + 'aAbBcCdDeE' * 300 + '>>\"'}"
177
178
179      - file-name: "string_type_j"
180        isa:
181          description: Load string specified by id into accumulator.
182        description: Check type of object created by 'lda.str' instruction with valid string in PandaAssembly context.
183        runner-options: [use-pa]
184        header-template: [PandaAssembly, main]
185        code-template: |
186          #
187              lda.str %s
188              sta.obj v1
189              isinstance panda.String
190              jeqz set_failure
191              lda.obj v1
192              isinstance panda.Object
193              jeqz set_failure
194              ldai 0
195              return
196          set_failure:
197              ldai 1
198              return
199        check-type: none
200        cases:
201          - values:
202            - "\"\""
203          - values:
204            - "\"   \""
205          - values:
206            - "\"ascii: ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
207            tags: ['tsan']
208          - values:
209            - "\"mutf8: \\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
210            tags: ['tsan']
211          - values:
212            - "\"escaped: \\a \\b \\t \\n \\f \\r \\' \\\" \\\\ \""
213          - values:
214            - "\"\\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc\""
215          - values:
216            - "#{'\"<<' + 'aAbBcCdDeE' * 300 + '>>\"'}"
217
218
219      - file-name: "string_value_p"
220        isa:
221          description: Load string specified by id into accumulator.
222        description: Check value of object created by 'lda.str' instruction with valid string in PandaAssembly context.
223        header-template: []
224        code-template: |
225          .record panda.String <external>
226          .record Convert {} <external>
227          .function i32 Convert.stringToI32(panda.String a0) <external>
228          .function i32 main() {
229              movi v1, %s
230              lda.null
231              lda.str %s
232              sta.obj v0
233              call.short Convert.stringToI32, v0
234              jne v1, exit_failure
235              ldai 0
236              return
237          exit_failure:
238              ldai 1
239        check-type: no-check
240        cases:
241          # ascii
242          - values:
243            - 0
244            - "\"0\""
245          - values:
246            - 12345
247            - "\"12345\""
248            tags: ['tsan']
249          - values:
250            - -123
251            - "\"-123\""
252          - values:
253            - 0xffffffff
254            - "\"-1\""
255          - values:
256            - 0x7fffffff
257            - "\"2147483647\""
258          - values:
259            - 0x80000000
260            - "\"-2147483648\""
261          # mutf8 encoded
262          - values:
263            - 6789
264            - "\"\\x36\\x37\\x38\\x39\""
265          # mix of ascii and mutf8 encoded
266          - values:
267            - 31579
268            - "\"3\\x315\\x379\""
269
270
271      - file-name: "string_value_j"
272        isa:
273          description: Load string specified by id into accumulator.
274        description: Check value of object created by 'lda.str' instruction with valid string in PandaAssembly context.
275        runner-options: [use-pa]
276        tags: ['irtoc_ignore']
277        header-template: []
278        code-template: |
279          .language PandaAssembly
280          .record panda.String <external>
281          .record panda.Integer <external>
282          .function void panda.Integer.ctor(panda.Integer a0, panda.String a1) <external, ctor>
283          .function i32 panda.Integer.intValue(panda.Integer a0) <external>
284          .function i32 main() {
285              movi v1, %s
286              lda.null
287              lda.str %s
288              sta.obj v0
289              initobj panda.Integer.ctor, v0
290              sta.obj v0
291              call.short panda.Integer.intValue, v0
292              jne v1, set_failure
293              ldai 0
294              return
295          set_failure:
296              ldai 1
297        check-type: no-check
298        cases:
299          # ascii
300          - values:
301            - 0
302            - "\"0\""
303          - values:
304            - 12345
305            - "\"12345\""
306          - values:
307            - -123
308            - "\"-123\""
309          - values:
310            - 0xffffffff
311            - "\"-1\""
312          - values:
313            - 0x7fffffff
314            - "\"2147483647\""
315          - values:
316            - 0x80000000
317            - "\"-2147483648\""
318          # mutf8 encoded
319          - values:
320            - 6789
321            - "\"\\x36\\x37\\x38\\x39\""
322            tags: ['tsan']
323            bugid: ['3859']
324          # mix of ascii and mutf8 encoded
325          - values:
326            - 31579
327            - "\"3\\x315\\x379\""
328
329
330      - file-name: "strings_eq"
331        isa:
332          description: Load string specified by id into accumulator.
333        description: Check that two strings created by 'lda.str' instructions are the same in the string constant pool.
334        code-template: |
335          #
336              lda.str %s
337              sta.obj v1
338              lda.null
339              lda.str %s
340              jeq.obj v1, ok
341              ldai 1
342              return
343          ok:
344        check-type: exit-positive
345        cases:
346          # empty strings
347          - values:
348            - "\"\""
349            - "\"\""
350          # ascii
351          - values:
352            - "\"abcdef\""
353            - "\"abcdef\""
354          - values:
355            - "\"abcdef\""
356            - "\"\\x61\\x62\\x63\\x64\\x65\\x66\""
357          - values:
358            - "\"abcdef\""
359            - "\"a\\x62\\x63\\x64e\\x66\""
360          - values:
361            - "\" ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
362            - "\" ~`!@#$%^&*()_-+={[}]|.,<>/?|0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\""
363            tags: ['tsan']
364          - values:
365            - "\"\\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
366            - "\"\\xe6\\x96\\x87\\xe5\\xad\\x97\\xe8\\x8c\\x83\\xe4\\xbe\\x8b\""
367          - values:
368            - "\"I \\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc!\""
369            - "\"I \\xed\\xa1\\xbe\\xed\\xb7\\xa1\\xed\\xa1\\xbd\\xed\\xb0\\xbc\\x21\""
370          # escaping
371          - values:
372            - "\"\\b\\t\\n\\f\\r\\\"\\'\\\\\""
373            - "\"\\b\\t\\n\\f\\r\\\"\\'\\\\\""
374          - values:
375            - "\"\\b\\t\\n\\f\\r\\\"\\'\\\\\""
376            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
377            tags: ['tsan']
378          - values:
379            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
380            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
381
382
383      - file-name: "strings_ne"
384        isa:
385          description: Load string specified by id into accumulator.
386        description: Check that two strings created by 'lda.str' instructions are different in the string constant pool.
387        code-template: |
388          #
389              lda.str %s
390              sta.obj v1
391              lda.null
392              lda.str %s
393              jne.obj v1, ok
394              ldai 1
395              return
396          ok:
397        check-type: exit-positive
398        cases:
399          - values:
400            - "\"\""
401            - "\" \""
402          - values:
403            - "\" \""
404            - "\"  \""
405          - values:
406            - "\"a\""
407            - "\"a \""
408          - values:
409            - "\"a\""
410            - "\"b\""
411            tags: ['tsan']
412          - values:
413            - "\"a\""
414            - "\"A\""
415          - values:
416            - "\"1\\x33\\x324\""
417            - "\"1234\""
418          - values:
419            - "\"\\x08\\x09\\x0a\\x0d\\x0c\\x22\\x27\\x5c\""
420            - "\"\\x08\\x09\\x0a\\x0c\\x0d\\x22\\x27\\x5c\""
421            tags: ['tsan']
422
423
424      - file-name: "string_content_eq"
425        isa:
426          description: Load string specified by id into accumulator.
427        description: Check that a string created by 'lda.str' instruction has the expected content.
428        runner-options: [use-pa]
429        header-template: []
430        code-template: |
431            .language PandaAssembly
432            .record panda.StringFactory <external>
433            .record panda.String <external>
434            .function panda.String panda.StringFactory.newStringFromChars(u16[] a0) <external, static>
435            .function i32 panda.String.compareTo(panda.String a0, panda.String a1) <external>
436            .function i32 main() {
437                movi v0, 3
438                newarr v1, v0, u16[]        # 3-char array
439
440                ldai %s           # 1-st char
441                movi v2, 0        # index
442                starr.16 v1, v2
443
444                ldai %s           # 2-nd char
445                movi v2, 1        # index
446                starr.16 v1, v2
447
448                ldai %s           # 3-rd char
449                movi v2, 2        # index
450                starr.16 v1, v2
451
452                call panda.StringFactory.newStringFromChars, v1
453                sta.obj v7
454
455                lda.str %s
456                sta.obj v8
457
458                call.virt panda.String.compareTo, v8, v7
459                jeqz equal_strings
460                ldai 1
461            equal_strings:
462                movi v0, %s
463                jeq v0, ok
464                ldai 1
465                return
466            ok:
467        check-type: exit-positive
468        cases:
469          - values: [0x0020, 0x0020, 0x0020, "\"   \"", 0]
470          - values: [0x0020, 0x0020, 0x0020, "\"    \"", 1]
471          - values: [0x0041, 0x0042, 0x0043, "\"ABC\"", 0]
472          - values: [0x0041, 0x0042, 0x0043, "\"ABCDE\"", 1]
473          - values: [0x0041, 0x0042, 0x0043, "\"AB\"", 1]
474          - values: [0x5927, 0x91cd, 0x7f6e, "\"\\xe5\\xa4\\xa7\\xe9\\x87\\x8d\\xe7\\xbd\\xae\"", 0]
475          - values: [0x5927, 0x4e16, 0x754c, "\"\\xe5\\xa4\\xa7\\xe9\\x87\\x8d\\xe7\\xbd\\xae\"", 1]
476          - values: [0x5927, 0x4e16, 0x754c, "\"\\xe5\\xa4\\xa7\\xe4\\xb8\\x96\\xe7\\x95\\x8c\"", 0]
477          - values: [0x0009, 0x000d, 0x000a, "\"\\t\\r\\n\"", 0]
478          - values: [0x0009, 0x000d, 0x000a, "\"\\a\\r\\n\"", 1]
479
480