David Srbecky | 0adf4d8 | 2018-10-01 18:17:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2018 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import unittest |
| 18 | import make_header |
| 19 | |
| 20 | test_input = r''' |
| 21 | // Check that the various other assembly lines are ignored. |
| 22 | .globl _Z49AsmDefineHelperFor_MIRROR_OBJECT_LOCK_WORD_OFFSETv |
| 23 | .type _Z49AsmDefineHelperFor_MIRROR_OBJECT_LOCK_WORD_OFFSETv,%function |
| 24 | .ascii ">>MIRROR_OBJECT_LOCK_WORD_OFFSET #4 #0<<" |
| 25 | bx lr |
| 26 | |
| 27 | // Check large positive 32-bit constant. |
| 28 | .ascii ">>OBJECT_ALIGNMENT_MASK_TOGGLED #4294967288 #0<<" |
| 29 | |
| 30 | // Check large positive 64-bit constant (it overflows into negative value). |
| 31 | .ascii ">>OBJECT_ALIGNMENT_MASK_TOGGLED64 #-8 #0<<" |
| 32 | |
| 33 | // Check negative constant. |
| 34 | .ascii ">>JIT_CHECK_OSR #-1 #1<<" |
| 35 | ''' |
| 36 | |
| 37 | test_output = r''' |
| 38 | #define JIT_CHECK_OSR -0x1 |
David Srbecky | 0adf4d8 | 2018-10-01 18:17:45 +0100 | [diff] [blame] | 39 | #define MIRROR_OBJECT_LOCK_WORD_OFFSET 0x4 |
| 40 | #define OBJECT_ALIGNMENT_MASK_TOGGLED 0xfffffff8 |
David Srbecky | 0adf4d8 | 2018-10-01 18:17:45 +0100 | [diff] [blame] | 41 | #define OBJECT_ALIGNMENT_MASK_TOGGLED64 0xfffffffffffffff8 |
| 42 | ''' |
| 43 | |
| 44 | class CppDefineGeneratorTest(unittest.TestCase): |
| 45 | def test_convert(self): |
| 46 | self.assertEqual(test_output.strip(), make_header.convert(test_input)) |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | unittest.main() |