2020-06-23 00:10:31 +02:00
|
|
|
#
|
|
|
|
# Copyright (C) 2016 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
"""Tests for symbolfile."""
|
|
|
|
import io
|
|
|
|
import textwrap
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import symbolfile
|
2022-07-16 16:30:09 +02:00
|
|
|
from symbolfile import Arch, Tag, Tags, Version, Symbol, Filter
|
|
|
|
from copy import copy
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
# pylint: disable=missing-docstring
|
|
|
|
|
|
|
|
|
|
|
|
class DecodeApiLevelTest(unittest.TestCase):
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_decode_api_level(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
self.assertEqual(9, symbolfile.decode_api_level('9', {}))
|
|
|
|
self.assertEqual(9000, symbolfile.decode_api_level('O', {'O': 9000}))
|
|
|
|
|
|
|
|
with self.assertRaises(KeyError):
|
|
|
|
symbolfile.decode_api_level('O', {})
|
|
|
|
|
|
|
|
|
|
|
|
class TagsTest(unittest.TestCase):
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_get_tags_no_tags(self) -> None:
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertEqual(Tags(), symbolfile.get_tags('', {}))
|
|
|
|
self.assertEqual(Tags(), symbolfile.get_tags('foo bar baz', {}))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_get_tags(self) -> None:
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertEqual(Tags.from_strs(['foo', 'bar']),
|
|
|
|
symbolfile.get_tags('# foo bar', {}))
|
|
|
|
self.assertEqual(Tags.from_strs(['bar', 'baz']),
|
|
|
|
symbolfile.get_tags('foo # bar baz', {}))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_split_tag(self) -> None:
|
|
|
|
self.assertTupleEqual(('foo', 'bar'),
|
|
|
|
symbolfile.split_tag(Tag('foo=bar')))
|
|
|
|
self.assertTupleEqual(('foo', 'bar=baz'),
|
|
|
|
symbolfile.split_tag(Tag('foo=bar=baz')))
|
2020-06-23 00:10:31 +02:00
|
|
|
with self.assertRaises(ValueError):
|
2020-06-23 20:21:21 +02:00
|
|
|
symbolfile.split_tag(Tag('foo'))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_get_tag_value(self) -> None:
|
|
|
|
self.assertEqual('bar', symbolfile.get_tag_value(Tag('foo=bar')))
|
|
|
|
self.assertEqual('bar=baz',
|
|
|
|
symbolfile.get_tag_value(Tag('foo=bar=baz')))
|
2020-06-23 00:10:31 +02:00
|
|
|
with self.assertRaises(ValueError):
|
2020-06-23 20:21:21 +02:00
|
|
|
symbolfile.get_tag_value(Tag('foo'))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_is_api_level_tag(self) -> None:
|
|
|
|
self.assertTrue(symbolfile.is_api_level_tag(Tag('introduced=24')))
|
|
|
|
self.assertTrue(symbolfile.is_api_level_tag(Tag('introduced-arm=24')))
|
|
|
|
self.assertTrue(symbolfile.is_api_level_tag(Tag('versioned=24')))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
# Shouldn't try to process things that aren't a key/value tag.
|
2020-06-23 20:21:21 +02:00
|
|
|
self.assertFalse(symbolfile.is_api_level_tag(Tag('arm')))
|
|
|
|
self.assertFalse(symbolfile.is_api_level_tag(Tag('introduced')))
|
|
|
|
self.assertFalse(symbolfile.is_api_level_tag(Tag('versioned')))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
# We don't support arch specific `versioned` tags.
|
2020-06-23 20:21:21 +02:00
|
|
|
self.assertFalse(symbolfile.is_api_level_tag(Tag('versioned-arm=24')))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_decode_api_level_tags(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
api_map = {
|
|
|
|
'O': 9000,
|
|
|
|
'P': 9001,
|
|
|
|
}
|
|
|
|
|
|
|
|
tags = [
|
2021-06-04 23:30:40 +02:00
|
|
|
symbolfile.decode_api_level_tag(t, api_map) for t in (
|
|
|
|
Tag('introduced=9'),
|
|
|
|
Tag('introduced-arm=14'),
|
|
|
|
Tag('versioned=16'),
|
|
|
|
Tag('arm'),
|
|
|
|
Tag('introduced=O'),
|
|
|
|
Tag('introduced=P'),
|
|
|
|
)
|
2020-06-23 00:10:31 +02:00
|
|
|
]
|
|
|
|
expected_tags = [
|
2020-06-23 20:21:21 +02:00
|
|
|
Tag('introduced=9'),
|
|
|
|
Tag('introduced-arm=14'),
|
|
|
|
Tag('versioned=16'),
|
|
|
|
Tag('arm'),
|
|
|
|
Tag('introduced=9000'),
|
|
|
|
Tag('introduced=9001'),
|
2020-06-23 00:10:31 +02:00
|
|
|
]
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertListEqual(expected_tags, tags)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
with self.assertRaises(symbolfile.ParseError):
|
2021-06-04 23:30:40 +02:00
|
|
|
symbolfile.decode_api_level_tag(Tag('introduced=O'), {})
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PrivateVersionTest(unittest.TestCase):
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_version_is_private(self) -> None:
|
2021-06-04 23:30:40 +02:00
|
|
|
def mock_version(name: str) -> Version:
|
|
|
|
return Version(name, base=None, tags=Tags(), symbols=[])
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertFalse(mock_version('foo').is_private)
|
|
|
|
self.assertFalse(mock_version('PRIVATE').is_private)
|
|
|
|
self.assertFalse(mock_version('PLATFORM').is_private)
|
|
|
|
self.assertFalse(mock_version('foo_private').is_private)
|
|
|
|
self.assertFalse(mock_version('foo_platform').is_private)
|
|
|
|
self.assertFalse(mock_version('foo_PRIVATE_').is_private)
|
|
|
|
self.assertFalse(mock_version('foo_PLATFORM_').is_private)
|
|
|
|
|
|
|
|
self.assertTrue(mock_version('foo_PRIVATE').is_private)
|
|
|
|
self.assertTrue(mock_version('foo_PLATFORM').is_private)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SymbolPresenceTest(unittest.TestCase):
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_symbol_in_arch(self) -> None:
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertTrue(symbolfile.symbol_in_arch(Tags(), Arch('arm')))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_arch(Tags.from_strs(['arm']), Arch('arm')))
|
2020-06-23 20:21:21 +02:00
|
|
|
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_arch(Tags.from_strs(['x86']), Arch('arm')))
|
2020-06-23 20:21:21 +02:00
|
|
|
|
|
|
|
def test_symbol_in_api(self) -> None:
|
|
|
|
self.assertTrue(symbolfile.symbol_in_api([], Arch('arm'), 9))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced=9')], Arch('arm'), 9))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced=9')], Arch('arm'), 14))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced-arm=9')], Arch('arm'),
|
|
|
|
14))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced-arm=9')], Arch('arm'),
|
|
|
|
14))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced-x86=14')], Arch('arm'),
|
|
|
|
9))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced-arm=9'),
|
|
|
|
Tag('introduced-x86=21')], Arch('arm'), 14))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced=9'),
|
|
|
|
Tag('introduced-x86=21')], Arch('arm'), 14))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced=21'),
|
|
|
|
Tag('introduced-arm=9')], Arch('arm'), 14))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_in_api([Tag('future')], Arch('arm'),
|
|
|
|
symbolfile.FUTURE_API_LEVEL))
|
|
|
|
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced=14')], Arch('arm'), 9))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced-arm=14')], Arch('arm'),
|
|
|
|
9))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api([Tag('future')], Arch('arm'), 9))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced=9'), Tag('future')], Arch('arm'), 14))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api([Tag('introduced-arm=9'),
|
|
|
|
Tag('future')], Arch('arm'), 14))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced-arm=21'),
|
|
|
|
Tag('introduced-x86=9')], Arch('arm'), 14))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced=9'),
|
|
|
|
Tag('introduced-arm=21')], Arch('arm'), 14))
|
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_in_api(
|
|
|
|
[Tag('introduced=21'),
|
|
|
|
Tag('introduced-x86=9')], Arch('arm'), 14))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
# Interesting edge case: this symbol should be omitted from the
|
|
|
|
# library, but this call should still return true because none of the
|
|
|
|
# tags indiciate that it's not present in this API level.
|
2020-06-23 20:21:21 +02:00
|
|
|
self.assertTrue(symbolfile.symbol_in_api([Tag('x86')], Arch('arm'), 9))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_verioned_in_api(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
self.assertTrue(symbolfile.symbol_versioned_in_api([], 9))
|
2020-06-23 20:21:21 +02:00
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_versioned_in_api([Tag('versioned=9')], 9))
|
|
|
|
self.assertTrue(
|
|
|
|
symbolfile.symbol_versioned_in_api([Tag('versioned=9')], 14))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
self.assertFalse(
|
|
|
|
symbolfile.symbol_versioned_in_api([Tag('versioned=14')], 9))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class OmitVersionTest(unittest.TestCase):
|
2022-07-16 16:30:09 +02:00
|
|
|
def setUp(self) -> None:
|
|
|
|
self.filter = Filter(arch = Arch('arm'), api = 9)
|
|
|
|
self.version = Version('foo', None, Tags(), [])
|
|
|
|
|
|
|
|
def assertOmit(self, f: Filter, v: Version) -> None:
|
|
|
|
self.assertTrue(f.should_omit_version(v))
|
|
|
|
|
|
|
|
def assertInclude(self, f: Filter, v: Version) -> None:
|
|
|
|
self.assertFalse(f.should_omit_version(v))
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_private(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f = self.filter
|
|
|
|
v = self.version
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertInclude(f, v)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
v.name = 'foo_PRIVATE'
|
|
|
|
self.assertOmit(f, v)
|
|
|
|
|
|
|
|
v.name = 'foo_PLATFORM'
|
|
|
|
self.assertOmit(f, v)
|
|
|
|
|
|
|
|
v.name = 'foo'
|
|
|
|
v.tags = Tags.from_strs(['platform-only'])
|
|
|
|
self.assertOmit(f, v)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_llndk(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f = self.filter
|
|
|
|
v = self.version
|
|
|
|
v_llndk = copy(v)
|
|
|
|
v_llndk.tags = Tags.from_strs(['llndk'])
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertOmit(f, v_llndk)
|
|
|
|
|
|
|
|
f.llndk = True
|
|
|
|
self.assertInclude(f, v)
|
|
|
|
self.assertInclude(f, v_llndk)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_apex(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f = self.filter
|
|
|
|
v = self.version
|
|
|
|
v_apex = copy(v)
|
|
|
|
v_apex.tags = Tags.from_strs(['apex'])
|
2022-07-17 04:30:47 +02:00
|
|
|
v_systemapi = copy(v)
|
|
|
|
v_systemapi.tags = Tags.from_strs(['systemapi'])
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertOmit(f, v_apex)
|
|
|
|
|
|
|
|
f.apex = True
|
|
|
|
self.assertInclude(f, v)
|
|
|
|
self.assertInclude(f, v_apex)
|
2022-07-17 04:30:47 +02:00
|
|
|
self.assertOmit(f, v_systemapi)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2021-06-04 23:31:58 +02:00
|
|
|
def test_omit_systemapi(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f = self.filter
|
|
|
|
v = self.version
|
2022-07-17 04:30:47 +02:00
|
|
|
v_apex = copy(v)
|
|
|
|
v_apex.tags = Tags.from_strs(['apex'])
|
2022-07-16 16:30:09 +02:00
|
|
|
v_systemapi = copy(v)
|
|
|
|
v_systemapi.tags = Tags.from_strs(['systemapi'])
|
2021-06-04 23:31:58 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertOmit(f, v_systemapi)
|
|
|
|
|
2022-07-17 04:30:47 +02:00
|
|
|
f.systemapi = True
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertInclude(f, v)
|
|
|
|
self.assertInclude(f, v_systemapi)
|
2022-07-17 04:30:47 +02:00
|
|
|
self.assertOmit(f, v_apex)
|
2021-06-04 23:31:58 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_arch(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_arm = self.filter
|
|
|
|
v_none = self.version
|
|
|
|
self.assertInclude(f_arm, v_none)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
v_arm = copy(v_none)
|
|
|
|
v_arm.tags = Tags.from_strs(['arm'])
|
|
|
|
self.assertInclude(f_arm, v_arm)
|
|
|
|
|
|
|
|
v_x86 = copy(v_none)
|
|
|
|
v_x86.tags = Tags.from_strs(['x86'])
|
|
|
|
self.assertOmit(f_arm, v_x86)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_api(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_api9 = self.filter
|
|
|
|
v_none = self.version
|
|
|
|
self.assertInclude(f_api9, v_none)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
v_api9 = copy(v_none)
|
|
|
|
v_api9.tags = Tags.from_strs(['introduced=9'])
|
|
|
|
self.assertInclude(f_api9, v_api9)
|
|
|
|
|
|
|
|
v_api14 = copy(v_none)
|
|
|
|
v_api14.tags = Tags.from_strs(['introduced=14'])
|
|
|
|
self.assertOmit(f_api9, v_api14)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class OmitSymbolTest(unittest.TestCase):
|
2022-07-16 16:30:09 +02:00
|
|
|
def setUp(self) -> None:
|
|
|
|
self.filter = Filter(arch = Arch('arm'), api = 9)
|
|
|
|
|
|
|
|
def assertOmit(self, f: Filter, s: Symbol) -> None:
|
|
|
|
self.assertTrue(f.should_omit_symbol(s))
|
|
|
|
|
|
|
|
def assertInclude(self, f: Filter, s: Symbol) -> None:
|
|
|
|
self.assertFalse(f.should_omit_symbol(s))
|
|
|
|
|
2022-09-26 13:58:27 +02:00
|
|
|
def test_omit_ndk(self) -> None:
|
|
|
|
f_ndk = self.filter
|
|
|
|
f_nondk = copy(f_ndk)
|
|
|
|
f_nondk.ndk = False
|
|
|
|
f_nondk.apex = True
|
|
|
|
|
|
|
|
s_ndk = Symbol('foo', Tags())
|
|
|
|
s_nonndk = Symbol('foo', Tags.from_strs(['apex']))
|
|
|
|
|
|
|
|
self.assertInclude(f_ndk, s_ndk)
|
|
|
|
self.assertOmit(f_ndk, s_nonndk)
|
|
|
|
self.assertOmit(f_nondk, s_ndk)
|
|
|
|
self.assertInclude(f_nondk, s_nonndk)
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_llndk(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_none = self.filter
|
|
|
|
f_llndk = copy(f_none)
|
|
|
|
f_llndk.llndk = True
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
s_none = Symbol('foo', Tags())
|
|
|
|
s_llndk = Symbol('foo', Tags.from_strs(['llndk']))
|
|
|
|
|
|
|
|
self.assertOmit(f_none, s_llndk)
|
|
|
|
self.assertInclude(f_llndk, s_none)
|
|
|
|
self.assertInclude(f_llndk, s_llndk)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_apex(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_none = self.filter
|
|
|
|
f_apex = copy(f_none)
|
|
|
|
f_apex.apex = True
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
s_none = Symbol('foo', Tags())
|
|
|
|
s_apex = Symbol('foo', Tags.from_strs(['apex']))
|
2022-07-17 04:30:47 +02:00
|
|
|
s_systemapi = Symbol('foo', Tags.from_strs(['systemapi']))
|
2022-07-16 16:30:09 +02:00
|
|
|
|
|
|
|
self.assertOmit(f_none, s_apex)
|
|
|
|
self.assertInclude(f_apex, s_none)
|
|
|
|
self.assertInclude(f_apex, s_apex)
|
2022-07-17 04:30:47 +02:00
|
|
|
self.assertOmit(f_apex, s_systemapi)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2021-06-04 23:31:58 +02:00
|
|
|
def test_omit_systemapi(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_none = self.filter
|
|
|
|
f_systemapi = copy(f_none)
|
2022-07-17 04:30:47 +02:00
|
|
|
f_systemapi.systemapi = True
|
2021-06-04 23:31:58 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
s_none = Symbol('foo', Tags())
|
2022-07-17 04:30:47 +02:00
|
|
|
s_apex = Symbol('foo', Tags.from_strs(['apex']))
|
2022-07-16 16:30:09 +02:00
|
|
|
s_systemapi = Symbol('foo', Tags.from_strs(['systemapi']))
|
|
|
|
|
|
|
|
self.assertOmit(f_none, s_systemapi)
|
|
|
|
self.assertInclude(f_systemapi, s_none)
|
|
|
|
self.assertInclude(f_systemapi, s_systemapi)
|
2022-07-17 04:30:47 +02:00
|
|
|
self.assertOmit(f_systemapi, s_apex)
|
|
|
|
|
|
|
|
def test_omit_apex_and_systemapi(self) -> None:
|
|
|
|
f = self.filter
|
|
|
|
f.systemapi = True
|
|
|
|
f.apex = True
|
|
|
|
|
|
|
|
s_none = Symbol('foo', Tags())
|
|
|
|
s_apex = Symbol('foo', Tags.from_strs(['apex']))
|
|
|
|
s_systemapi = Symbol('foo', Tags.from_strs(['systemapi']))
|
|
|
|
self.assertInclude(f, s_none)
|
|
|
|
self.assertInclude(f, s_apex)
|
|
|
|
self.assertInclude(f, s_systemapi)
|
2021-06-04 23:31:58 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_arch(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_arm = self.filter
|
|
|
|
s_none = Symbol('foo', Tags())
|
|
|
|
s_arm = Symbol('foo', Tags.from_strs(['arm']))
|
|
|
|
s_x86 = Symbol('foo', Tags.from_strs(['x86']))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertInclude(f_arm, s_none)
|
|
|
|
self.assertInclude(f_arm, s_arm)
|
|
|
|
self.assertOmit(f_arm, s_x86)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_omit_api(self) -> None:
|
2022-07-16 16:30:09 +02:00
|
|
|
f_api9 = self.filter
|
|
|
|
s_none = Symbol('foo', Tags())
|
|
|
|
s_api9 = Symbol('foo', Tags.from_strs(['introduced=9']))
|
|
|
|
s_api14 = Symbol('foo', Tags.from_strs(['introduced=14']))
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2022-07-16 16:30:09 +02:00
|
|
|
self.assertInclude(f_api9, s_none)
|
|
|
|
self.assertInclude(f_api9, s_api9)
|
|
|
|
self.assertOmit(f_api9, s_api14)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SymbolFileParseTest(unittest.TestCase):
|
2022-07-16 16:30:09 +02:00
|
|
|
def setUp(self) -> None:
|
|
|
|
self.filter = Filter(arch = Arch('arm'), api = 16)
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_next_line(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
foo
|
|
|
|
|
|
|
|
bar
|
|
|
|
# baz
|
|
|
|
qux
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
self.assertIsNone(parser.current_line)
|
|
|
|
|
|
|
|
self.assertEqual('foo', parser.next_line().strip())
|
2020-06-23 20:21:21 +02:00
|
|
|
assert parser.current_line is not None
|
2020-06-23 00:10:31 +02:00
|
|
|
self.assertEqual('foo', parser.current_line.strip())
|
|
|
|
|
|
|
|
self.assertEqual('bar', parser.next_line().strip())
|
|
|
|
self.assertEqual('bar', parser.current_line.strip())
|
|
|
|
|
|
|
|
self.assertEqual('qux', parser.next_line().strip())
|
|
|
|
self.assertEqual('qux', parser.current_line.strip())
|
|
|
|
|
|
|
|
self.assertEqual('', parser.next_line())
|
|
|
|
self.assertEqual('', parser.current_line)
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_parse_version(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 { # foo bar
|
|
|
|
baz;
|
|
|
|
qux; # woodly doodly
|
|
|
|
};
|
|
|
|
|
|
|
|
VERSION_2 {
|
|
|
|
} VERSION_1; # asdf
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
parser.next_line()
|
|
|
|
version = parser.parse_version()
|
|
|
|
self.assertEqual('VERSION_1', version.name)
|
|
|
|
self.assertIsNone(version.base)
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertEqual(Tags.from_strs(['foo', 'bar']), version.tags)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
expected_symbols = [
|
2022-07-16 16:30:09 +02:00
|
|
|
Symbol('baz', Tags()),
|
|
|
|
Symbol('qux', Tags.from_strs(['woodly', 'doodly'])),
|
2020-06-23 00:10:31 +02:00
|
|
|
]
|
|
|
|
self.assertEqual(expected_symbols, version.symbols)
|
|
|
|
|
|
|
|
parser.next_line()
|
|
|
|
version = parser.parse_version()
|
|
|
|
self.assertEqual('VERSION_2', version.name)
|
|
|
|
self.assertEqual('VERSION_1', version.base)
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertEqual(Tags(), version.tags)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_parse_version_eof(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
parser.next_line()
|
|
|
|
with self.assertRaises(symbolfile.ParseError):
|
|
|
|
parser.parse_version()
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_unknown_scope_label(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
foo:
|
|
|
|
}
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
parser.next_line()
|
|
|
|
with self.assertRaises(symbolfile.ParseError):
|
|
|
|
parser.parse_version()
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_parse_symbol(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
foo;
|
|
|
|
bar; # baz qux
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
parser.next_line()
|
|
|
|
symbol = parser.parse_symbol()
|
|
|
|
self.assertEqual('foo', symbol.name)
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertEqual(Tags(), symbol.tags)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
parser.next_line()
|
|
|
|
symbol = parser.parse_symbol()
|
|
|
|
self.assertEqual('bar', symbol.name)
|
2021-06-04 23:30:40 +02:00
|
|
|
self.assertEqual(Tags.from_strs(['baz', 'qux']), symbol.tags)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_wildcard_symbol_global(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
*;
|
|
|
|
};
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
parser.next_line()
|
|
|
|
with self.assertRaises(symbolfile.ParseError):
|
|
|
|
parser.parse_version()
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_wildcard_symbol_local(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
local:
|
|
|
|
*;
|
|
|
|
};
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
parser.next_line()
|
|
|
|
version = parser.parse_version()
|
|
|
|
self.assertEqual([], version.symbols)
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_missing_semicolon(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
foo
|
|
|
|
};
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
parser.next_line()
|
|
|
|
with self.assertRaises(symbolfile.ParseError):
|
|
|
|
parser.parse_version()
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_parse_fails_invalid_input(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
with self.assertRaises(symbolfile.ParseError):
|
|
|
|
input_file = io.StringIO('foo')
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
parser.parse()
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_parse(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
local:
|
|
|
|
hidden1;
|
|
|
|
global:
|
|
|
|
foo;
|
|
|
|
bar; # baz
|
|
|
|
};
|
|
|
|
|
|
|
|
VERSION_2 { # wasd
|
|
|
|
# Implicit global scope.
|
|
|
|
woodly;
|
|
|
|
doodly; # asdf
|
|
|
|
local:
|
|
|
|
qwerty;
|
|
|
|
} VERSION_1;
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, self.filter)
|
2020-06-23 00:10:31 +02:00
|
|
|
versions = parser.parse()
|
|
|
|
|
|
|
|
expected = [
|
2021-06-04 23:30:40 +02:00
|
|
|
symbolfile.Version('VERSION_1', None, Tags(), [
|
2022-07-16 16:30:09 +02:00
|
|
|
Symbol('foo', Tags()),
|
|
|
|
Symbol('bar', Tags.from_strs(['baz'])),
|
2020-06-23 00:10:31 +02:00
|
|
|
]),
|
2021-06-04 23:30:40 +02:00
|
|
|
symbolfile.Version(
|
|
|
|
'VERSION_2', 'VERSION_1', Tags.from_strs(['wasd']), [
|
2022-07-16 16:30:09 +02:00
|
|
|
Symbol('woodly', Tags()),
|
|
|
|
Symbol('doodly', Tags.from_strs(['asdf'])),
|
2021-06-04 23:30:40 +02:00
|
|
|
]),
|
2020-06-23 00:10:31 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(expected, versions)
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def test_parse_llndk_apex_symbol(self) -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
input_file = io.StringIO(textwrap.dedent("""\
|
|
|
|
VERSION_1 {
|
|
|
|
foo;
|
|
|
|
bar; # llndk
|
|
|
|
baz; # llndk apex
|
|
|
|
qux; # apex
|
|
|
|
};
|
|
|
|
"""))
|
2022-07-16 16:30:09 +02:00
|
|
|
f = copy(self.filter)
|
|
|
|
f.llndk = True
|
|
|
|
parser = symbolfile.SymbolFileParser(input_file, {}, f)
|
2020-06-23 00:10:31 +02:00
|
|
|
|
|
|
|
parser.next_line()
|
|
|
|
version = parser.parse_version()
|
|
|
|
self.assertEqual('VERSION_1', version.name)
|
|
|
|
self.assertIsNone(version.base)
|
|
|
|
|
|
|
|
expected_symbols = [
|
2022-07-16 16:30:09 +02:00
|
|
|
Symbol('foo', Tags()),
|
|
|
|
Symbol('bar', Tags.from_strs(['llndk'])),
|
|
|
|
Symbol('baz', Tags.from_strs(['llndk', 'apex'])),
|
|
|
|
Symbol('qux', Tags.from_strs(['apex'])),
|
2020-06-23 00:10:31 +02:00
|
|
|
]
|
|
|
|
self.assertEqual(expected_symbols, version.symbols)
|
|
|
|
|
|
|
|
|
2020-06-23 20:21:21 +02:00
|
|
|
def main() -> None:
|
2020-06-23 00:10:31 +02:00
|
|
|
suite = unittest.TestLoader().loadTestsFromName(__name__)
|
|
|
|
unittest.TextTestRunner(verbosity=3).run(suite)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|