2018-04-17 22:57:45 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2024-01-10 04:18:02 -05:00
|
|
|
# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
2019-06-06 04:55:46 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-04-17 22:57:45 -04:00
|
|
|
#
|
2019-09-10 03:58:52 -04:00
|
|
|
import os
|
2018-04-17 22:57:45 -04:00
|
|
|
import sys
|
2019-09-10 03:58:52 -04:00
|
|
|
import tempfile
|
2021-01-25 21:49:01 -05:00
|
|
|
import unittest
|
2019-03-19 02:36:04 -04:00
|
|
|
from io import StringIO
|
2021-01-25 21:49:01 -05:00
|
|
|
|
2018-12-04 07:46:48 -05:00
|
|
|
try:
|
2021-12-23 20:41:47 -05:00
|
|
|
from ldgen.fragments import Align, Flag, Keep, Sort, Surround, parse_fragment_file
|
2021-12-23 20:43:06 -05:00
|
|
|
from ldgen.sdkconfig import SDKConfig
|
2018-12-04 07:46:48 -05:00
|
|
|
except ImportError:
|
2021-12-23 20:41:47 -05:00
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
from ldgen.fragments import Align, Flag, Keep, Sort, Surround, parse_fragment_file
|
2021-12-23 20:43:06 -05:00
|
|
|
from ldgen.sdkconfig import SDKConfig
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
from pyparsing import ParseException, ParseFatalException
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
class FragmentTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2019-09-10 03:58:52 -04:00
|
|
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
|
|
|
self.kconfigs_source_file = os.path.join(tempfile.gettempdir(), f.name)
|
|
|
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
|
|
|
self.kconfig_projbuilds_source_file = os.path.join(tempfile.gettempdir(), f.name)
|
|
|
|
|
|
|
|
os.environ['COMPONENT_KCONFIGS_SOURCE_FILE'] = self.kconfigs_source_file
|
|
|
|
os.environ['COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE'] = self.kconfig_projbuilds_source_file
|
|
|
|
os.environ['COMPONENT_KCONFIGS'] = ''
|
|
|
|
os.environ['COMPONENT_KCONFIGS_PROJBUILD'] = ''
|
|
|
|
|
2019-10-21 07:44:19 -04:00
|
|
|
# prepare_kconfig_files.py doesn't have to be called because COMPONENT_KCONFIGS and
|
|
|
|
# COMPONENT_KCONFIGS_PROJBUILD are empty
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
self.sdkconfig = SDKConfig('data/Kconfig', 'data/sdkconfig')
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2019-09-10 03:58:52 -04:00
|
|
|
def tearDown(self):
|
|
|
|
try:
|
|
|
|
os.remove(self.kconfigs_source_file)
|
|
|
|
os.remove(self.kconfig_projbuilds_source_file)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
@staticmethod
|
2021-01-25 21:49:01 -05:00
|
|
|
def create_fragment_file(contents, name='test_fragment.lf'):
|
2019-03-19 02:36:04 -04:00
|
|
|
f = StringIO(contents)
|
|
|
|
f.name = name
|
|
|
|
return f
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
value_2 # comments should be ignored
|
|
|
|
value_3
|
|
|
|
# this is a comment as well
|
2021-12-23 20:41:47 -05:00
|
|
|
value_a
|
2019-03-19 02:36:04 -04:00
|
|
|
# this is the last comment
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test')
|
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'value_1', 'value_2', 'value_3', 'value_a'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_conditional(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_2
|
|
|
|
value_3
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = n:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_4
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = n:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_5
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
|
|
|
|
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test')
|
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'value_1', 'value_2', 'value_3', 'value_5'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_2
|
2024-01-10 04:18:02 -05:00
|
|
|
elif PERFORMANCE_C = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_3
|
2024-01-10 04:18:02 -05:00
|
|
|
elif PERFORMANCE_A = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_4
|
|
|
|
else:
|
|
|
|
value_5
|
|
|
|
value_6
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test')
|
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'value_1', 'value_3', 'value_6'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_2
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_3
|
|
|
|
else:
|
|
|
|
value_4
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_C = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_5
|
|
|
|
value_6
|
|
|
|
value_7
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test')
|
|
|
|
self.assertEqual(fragment_file.fragments[0].entries,
|
|
|
|
{'value_1', 'value_2', 'value_4', 'value_5', 'value_6', 'value_7'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = n:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseFatalException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_empty_file(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
""")
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
self.assertEqual(len(fragment_file.fragments), 0)
|
|
|
|
|
|
|
|
def test_setting_indent(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
value_2
|
|
|
|
value_3
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test')
|
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'value_1', 'value_2', 'value_3'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
def test_settings_unmatch_indent(self):
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
value_2 # first element dictates indent
|
|
|
|
value_3
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_unsupported_key(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
2019-03-19 02:36:04 -04:00
|
|
|
key_1:
|
|
|
|
value_a
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_empty_fragment(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
2019-03-19 02:36:04 -04:00
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_empty_conditional(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
else:
|
|
|
|
value_1
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
2024-01-10 04:18:02 -05:00
|
|
|
else PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseFatalException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
2024-01-10 04:18:02 -05:00
|
|
|
elif PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
else:
|
|
|
|
value_2
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseFatalException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_out_of_order_conditional(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
elif PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
else:
|
|
|
|
value_2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
else:
|
|
|
|
value_2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_multiple_fragments(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test1]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
[scheme:test2]
|
|
|
|
entries:
|
|
|
|
section -> target
|
2019-03-19 02:36:04 -04:00
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test1')
|
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'value_1'})
|
|
|
|
self.assertEqual(fragment_file.fragments[1].name, 'test2')
|
|
|
|
self.assertEqual(fragment_file.fragments[1].entries, {('section', 'target')})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_whole_conditional_fragment(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test1]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
else:
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test2]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_2
|
|
|
|
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = y:
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test3]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_3
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_C = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_6
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test4]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_4
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test5]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_5
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
self.assertEqual(len(fragment_file.fragments), 4)
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].name, 'test2')
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'value_2'})
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[1].name, 'test3')
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[1].entries, {'value_3', 'value_6'})
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[2].name, 'test4')
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[2].entries, {'value_4'})
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[3].name, 'test5')
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[3].entries, {'value_5'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_equivalent_conditional_fragment(self):
|
|
|
|
test_fragment1 = self.create_fragment_file(u"""
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = y:
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test1]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
else:
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test2]
|
|
|
|
entries:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file1 = parse_fragment_file(test_fragment1, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file1.fragments[0].name, 'test1')
|
|
|
|
self.assertEqual(fragment_file1.fragments[0].entries, {'value_1'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment2 = self.create_fragment_file(u"""
|
2021-12-23 20:41:47 -05:00
|
|
|
[sections:test1]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_A = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
value_1
|
|
|
|
else:
|
|
|
|
value_2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file2 = parse_fragment_file(test_fragment2, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
self.assertEqual(fragment_file2.fragments[0].name, 'test1')
|
|
|
|
self.assertEqual(fragment_file2.fragments[0].entries, {'value_1'})
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
class SectionsTest(FragmentTest):
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_basic(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
.section1
|
|
|
|
.section2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'.section1', '.section2'})
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
def test_duplicate_entries(self):
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
.section1
|
|
|
|
.section2
|
|
|
|
.section3
|
|
|
|
.section2
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries, {'.section1', '.section2', '.section3'})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_empty_entries(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
.section1
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseFatalException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2020-10-22 06:51:03 -04:00
|
|
|
def test_entries_grammar(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
_valid1
|
|
|
|
valid2.
|
|
|
|
.valid3_-
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2020-10-22 06:51:03 -04:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries,
|
2021-01-25 21:49:01 -05:00
|
|
|
{'_valid1', 'valid2.', '.valid3_-'})
|
2020-10-22 06:51:03 -04:00
|
|
|
|
|
|
|
# invalid starting char
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
1invalid
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2020-10-22 06:51:03 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
-invalid
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2020-10-22 06:51:03 -04:00
|
|
|
|
|
|
|
# + notation
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
valid+
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2020-10-22 06:51:03 -04:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries,
|
2021-01-25 21:49:01 -05:00
|
|
|
{'valid+'})
|
2020-10-22 06:51:03 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[sections:test]
|
|
|
|
entries:
|
|
|
|
inva+lid+
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2020-10-22 06:51:03 -04:00
|
|
|
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2018-04-17 22:57:45 -04:00
|
|
|
class SchemeTest(FragmentTest):
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_basic(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[scheme:test]
|
|
|
|
entries:
|
|
|
|
sections1 -> target1
|
|
|
|
sections2 -> target2
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries,
|
2021-01-25 21:49:01 -05:00
|
|
|
{('sections1', 'target1'),
|
|
|
|
('sections2', 'target2')})
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_duplicate_entries(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[scheme:test]
|
|
|
|
entries:
|
|
|
|
sections1 -> target1
|
|
|
|
sections2 -> target2
|
|
|
|
sections2 -> target2
|
|
|
|
""")
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
self.assertEqual(fragment_file.fragments[0].entries,
|
2021-01-25 21:49:01 -05:00
|
|
|
{('sections1', 'target1'),
|
|
|
|
('sections2', 'target2')})
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
def test_empty_entries(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[scheme:test]
|
|
|
|
entries:
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[scheme:test]
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
sections1 -> target1
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseFatalException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_improper_grammar(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[scheme:test]
|
|
|
|
entries:
|
|
|
|
sections1, target1 # improper separator
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
class MappingTest(FragmentTest):
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_basic(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
obj:symbol (noflash)
|
|
|
|
obj (noflash)
|
|
|
|
obj:symbol_2 (noflash)
|
|
|
|
obj_2 (noflash)
|
|
|
|
* (noflash)
|
|
|
|
""")
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
expected = {('obj', 'symbol', 'noflash'),
|
|
|
|
('obj', None, 'noflash'),
|
|
|
|
('obj', 'symbol_2', 'noflash'),
|
|
|
|
('obj_2', None, 'noflash'),
|
|
|
|
('*', None, 'noflash')}
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
self.assertEqual(expected, fragment_file.fragments[0].entries)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_archive(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
entries:
|
|
|
|
* (default)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
lib1.a
|
|
|
|
lib2.a
|
|
|
|
entries:
|
|
|
|
* (default)
|
|
|
|
""")
|
|
|
|
with self.assertRaises(ParseFatalException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2019-06-06 04:55:46 -04:00
|
|
|
def test_archive_allowed_names(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
libstdc++.a
|
|
|
|
entries:
|
|
|
|
* (default)
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-06-06 04:55:46 -04:00
|
|
|
self.assertEqual('libstdc++.a', fragment_file.fragments[0].archive)
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_empty_entries(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
lib.a
|
|
|
|
entries:
|
2024-01-10 04:18:02 -05:00
|
|
|
if PERFORMANCE_B = y:
|
2019-03-19 02:36:04 -04:00
|
|
|
* (noflash) # if condition is false, then no 'entries' key value
|
|
|
|
""")
|
|
|
|
|
2019-04-14 07:34:27 -04:00
|
|
|
expected = set()
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-04-14 07:34:27 -04:00
|
|
|
self.assertEqual(expected, fragment_file.fragments[0].entries)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
lib.a
|
|
|
|
entries:
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_duplicate_entries(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
lib.a
|
|
|
|
entries:
|
|
|
|
obj:symbol (noflash)
|
|
|
|
obj:symbol (noflash)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
expected = {('obj', 'symbol', 'noflash')}
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
self.assertEqual(expected, fragment_file.fragments[0].entries)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_invalid_grammar(self):
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive:
|
|
|
|
lib.a
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
entries:
|
|
|
|
* (default)
|
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
obj: (noflash)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
obj: ()
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
obj:symbol
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
(noflash)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
obj:* (noflash)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
:symbol (noflash)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
*:symbol (noflash)
|
|
|
|
""")
|
2018-04-17 22:57:45 -04:00
|
|
|
with self.assertRaises(ParseException):
|
2021-12-23 20:41:47 -05:00
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2021-02-03 05:19:09 -05:00
|
|
|
def test_keep_flag(self):
|
|
|
|
# Test parsing combinations and orders of flags
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-03-02 04:37:31 -05:00
|
|
|
text->flash_text KEEP(),
|
|
|
|
rodata->flash_rodata KEEP() KEEP()
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
|
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Keep()]),
|
|
|
|
Flag('rodata', 'flash_rodata', [Keep(), Keep()])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_align_flag(self):
|
|
|
|
# Test parsing combinations and orders of flags
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-02-16 00:44:18 -05:00
|
|
|
text->flash_text ALIGN(8),
|
|
|
|
rodata->flash_rodata ALIGN(8, pre),
|
|
|
|
data->dram0_data ALIGN(8, pre, post),
|
|
|
|
bss->dram0_bss ALIGN(8, post),
|
|
|
|
common->dram0_bss ALIGN(8, pre, post) ALIGN(8)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Align(8, True, False)]),
|
|
|
|
Flag('rodata', 'flash_rodata', [Align(8, True, False)]),
|
|
|
|
Flag('data', 'dram0_data', [Align(8, True, True)]),
|
|
|
|
Flag('bss', 'dram0_bss', [Align(8, False, True)]),
|
|
|
|
Flag('common', 'dram0_bss', [Align(8, True, True), Align(8, True, False)])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
# Wrong post, pre order
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (noflash)
|
2021-02-16 00:44:18 -05:00
|
|
|
text->iram0_text ALIGN(8, post, pre)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
with self.assertRaises(ParseException):
|
|
|
|
parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
|
|
|
|
def test_sort_flag(self):
|
|
|
|
# Test parsing combinations and orders of flags
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-02-16 00:44:18 -05:00
|
|
|
text->flash_text SORT(name),
|
|
|
|
rodata->flash_rodata SORT(alignment),
|
|
|
|
data->dram0_data SORT(init_priority),
|
|
|
|
bss->dram0_bss SORT(name, alignment),
|
|
|
|
common->dram0_bss SORT(alignment, name),
|
|
|
|
iram->iram0_text SORT(name, name),
|
|
|
|
dram->dram0_data SORT(alignment, alignment)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Sort('name')]),
|
|
|
|
Flag('rodata', 'flash_rodata', [Sort('alignment')]),
|
|
|
|
Flag('data', 'dram0_data', [Sort('init_priority')]),
|
|
|
|
Flag('bss', 'dram0_bss', [Sort('name', 'alignment')]),
|
|
|
|
Flag('common', 'dram0_bss', [Sort('alignment', 'name')]),
|
|
|
|
Flag('iram', 'iram0_text', [Sort('name', 'name')]),
|
|
|
|
Flag('dram', 'dram0_data', [Sort('alignment', 'alignment')])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
2021-02-16 00:27:58 -05:00
|
|
|
def test_surround_flag(self):
|
2021-02-03 05:19:09 -05:00
|
|
|
# Test parsing combinations and orders of flags
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-02-16 00:44:18 -05:00
|
|
|
text->flash_text SURROUND(sym1)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Surround('sym1')])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_flag_order(self):
|
|
|
|
# Test that the order in which the flags are specified is retained
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-03-02 04:37:31 -05:00
|
|
|
text->flash_text ALIGN(4) KEEP() SURROUND(sym1) ALIGN(8) SORT(name),
|
|
|
|
rodata->flash_rodata KEEP() ALIGN(4) KEEP() SURROUND(sym1) ALIGN(8) ALIGN(4) SORT(name)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Align(4, True, False),
|
|
|
|
Keep(),
|
|
|
|
Surround('sym1'),
|
|
|
|
Align(8, True, False),
|
|
|
|
Sort('name')]),
|
|
|
|
Flag('rodata', 'flash_rodata', [Keep(),
|
|
|
|
Align(4, True, False),
|
|
|
|
Keep(),
|
|
|
|
Surround('sym1'),
|
|
|
|
Align(8, True, False),
|
|
|
|
Align(4, True, False),
|
|
|
|
Sort('name')])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_flags_entries_multiple_flags(self):
|
|
|
|
# Not an error, generation step handles this, since
|
|
|
|
# it that step has a more complete information
|
|
|
|
# about all mappings.
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-03-02 04:37:31 -05:00
|
|
|
text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name),
|
|
|
|
text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Align(4, True, False),
|
|
|
|
Keep(),
|
|
|
|
Surround('sym1'),
|
|
|
|
Sort('name')]),
|
|
|
|
Flag('text', 'flash_text', [Align(4, True, False),
|
|
|
|
Keep(),
|
|
|
|
Surround('sym1'),
|
|
|
|
Sort('name')])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_flags_entries_multiple_flags_and_entries(self):
|
|
|
|
# Not an error, generation step handles this, since
|
|
|
|
# it that step has a more complete information
|
|
|
|
# about all mappings. This can happen across multiple
|
|
|
|
# mapping fragments.
|
|
|
|
test_fragment = self.create_fragment_file(u"""
|
|
|
|
[mapping:map]
|
|
|
|
archive: libmain.a
|
|
|
|
entries:
|
|
|
|
obj1 (default);
|
2021-03-02 04:37:31 -05:00
|
|
|
text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name)
|
2021-02-03 05:19:09 -05:00
|
|
|
obj1 (default);
|
2021-03-02 04:37:31 -05:00
|
|
|
text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name)
|
2021-02-03 05:19:09 -05:00
|
|
|
""")
|
2021-12-23 20:41:47 -05:00
|
|
|
fragment_file = parse_fragment_file(test_fragment, self.sdkconfig)
|
2021-02-03 05:19:09 -05:00
|
|
|
fragment = fragment_file.fragments[0]
|
|
|
|
|
2021-12-23 20:41:47 -05:00
|
|
|
expected = [Flag('text', 'flash_text', [Align(4, True, False),
|
|
|
|
Keep(),
|
|
|
|
Surround('sym1'),
|
|
|
|
Sort('name')]),
|
|
|
|
Flag('text', 'flash_text', [Align(4, True, False),
|
|
|
|
Keep(),
|
|
|
|
Surround('sym1'),
|
|
|
|
Sort('name')])]
|
2021-02-03 05:19:09 -05:00
|
|
|
actual = fragment.flags[('obj1', None, 'default')]
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
if __name__ == '__main__':
|
2018-04-17 22:57:45 -04:00
|
|
|
unittest.main()
|