1*288bf522SAndroid Build Coastguard Worker# Copyright (C) 2020 The Android Open Source Project 2*288bf522SAndroid Build Coastguard Worker# 3*288bf522SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*288bf522SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*288bf522SAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*288bf522SAndroid Build Coastguard Worker# 7*288bf522SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*288bf522SAndroid Build Coastguard Worker# 9*288bf522SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*288bf522SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*288bf522SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*288bf522SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*288bf522SAndroid Build Coastguard Worker# limitations under the License. 14*288bf522SAndroid Build Coastguard Workerimport unittest 15*288bf522SAndroid Build Coastguard Worker 16*288bf522SAndroid Build Coastguard Workerfrom perf2cfg import exceptions 17*288bf522SAndroid Build Coastguard Workerfrom perf2cfg import parse 18*288bf522SAndroid Build Coastguard Worker 19*288bf522SAndroid Build Coastguard Worker 20*288bf522SAndroid Build Coastguard Workerclass TestParse(unittest.TestCase): 21*288bf522SAndroid Build Coastguard Worker 22*288bf522SAndroid Build Coastguard Worker def test_build_flags_without_arguments(self): 23*288bf522SAndroid Build Coastguard Worker got = parse.build_flags([]) 24*288bf522SAndroid Build Coastguard Worker self.assertEqual(got.strip(), 'flags') 25*288bf522SAndroid Build Coastguard Worker 26*288bf522SAndroid Build Coastguard Worker def test_build_flags_with_arguments(self): 27*288bf522SAndroid Build Coastguard Worker got = parse.build_flags(['catch_block', 'critical']) 28*288bf522SAndroid Build Coastguard Worker self.assertEqual(got.strip(), 'flags "catch_block" "critical"') 29*288bf522SAndroid Build Coastguard Worker 30*288bf522SAndroid Build Coastguard Worker def test_build_name(self): 31*288bf522SAndroid Build Coastguard Worker got = parse.build_name('void hcf()') 32*288bf522SAndroid Build Coastguard Worker self.assertEqual(got.strip(), 'name "void hcf()"') 33*288bf522SAndroid Build Coastguard Worker 34*288bf522SAndroid Build Coastguard Worker def test_parse_invalid_address_line(self): 35*288bf522SAndroid Build Coastguard Worker with self.assertRaises(exceptions.ParseError) as ctx: 36*288bf522SAndroid Build Coastguard Worker parse.parse_address(':)') 37*288bf522SAndroid Build Coastguard Worker 38*288bf522SAndroid Build Coastguard Worker self.assertEqual(str(ctx.exception), 'Expected an address') 39*288bf522SAndroid Build Coastguard Worker 40*288bf522SAndroid Build Coastguard Worker def test_parse_valid_address_line(self): 41*288bf522SAndroid Build Coastguard Worker got = parse.parse_address('0x0000001c: d503201f nop') 42*288bf522SAndroid Build Coastguard Worker self.assertEqual(got, 0x1c) 43*288bf522SAndroid Build Coastguard Worker 44*288bf522SAndroid Build Coastguard Worker def test_parse_flags_wrong_directive(self): 45*288bf522SAndroid Build Coastguard Worker with self.assertRaises(exceptions.ParseError) as ctx: 46*288bf522SAndroid Build Coastguard Worker parse.parse_flags('name "void hcf()"') 47*288bf522SAndroid Build Coastguard Worker 48*288bf522SAndroid Build Coastguard Worker self.assertEqual(str(ctx.exception), 'Expected a `flags` directive') 49*288bf522SAndroid Build Coastguard Worker 50*288bf522SAndroid Build Coastguard Worker def test_parse_flags_without_arguments(self): 51*288bf522SAndroid Build Coastguard Worker got = parse.parse_flags('flags') 52*288bf522SAndroid Build Coastguard Worker self.assertEqual(got, []) 53*288bf522SAndroid Build Coastguard Worker 54*288bf522SAndroid Build Coastguard Worker def test_parse_flags_with_arguments(self): 55*288bf522SAndroid Build Coastguard Worker got = parse.parse_flags('flags "catch_block" "critical"') 56*288bf522SAndroid Build Coastguard Worker self.assertEqual(got, ['catch_block', 'critical']) 57*288bf522SAndroid Build Coastguard Worker 58*288bf522SAndroid Build Coastguard Worker def test_parse_name_wrong_directive(self): 59*288bf522SAndroid Build Coastguard Worker with self.assertRaises(exceptions.ParseError) as ctx: 60*288bf522SAndroid Build Coastguard Worker parse.parse_name('flags "catch_block" "critical"') 61*288bf522SAndroid Build Coastguard Worker 62*288bf522SAndroid Build Coastguard Worker self.assertEqual(str(ctx.exception), 'Expected a `name` directive') 63*288bf522SAndroid Build Coastguard Worker 64*288bf522SAndroid Build Coastguard Worker def test_parse_name_without_argument(self): 65*288bf522SAndroid Build Coastguard Worker with self.assertRaises(exceptions.ParseError) as ctx: 66*288bf522SAndroid Build Coastguard Worker parse.parse_name('name') 67*288bf522SAndroid Build Coastguard Worker 68*288bf522SAndroid Build Coastguard Worker self.assertEqual(str(ctx.exception), 69*288bf522SAndroid Build Coastguard Worker 'Expected an argument to the `name` directive') 70*288bf522SAndroid Build Coastguard Worker 71*288bf522SAndroid Build Coastguard Worker def test_parse_name_with_argument(self): 72*288bf522SAndroid Build Coastguard Worker got = parse.parse_name('name "void hcf()"') 73*288bf522SAndroid Build Coastguard Worker self.assertEqual(got, 'void hcf()') 74