2018-04-17 22:57:45 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2021-01-27 03:03:24 -05:00
|
|
|
# Copyright 2021 Espressif Systems (Shanghai) CO LTD
|
2018-04-17 22:57:45 -04:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
import collections
|
|
|
|
import fnmatch
|
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
|
|
|
|
import unittest
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2018-12-04 07:46:48 -05:00
|
|
|
try:
|
2021-01-27 03:03:24 -05:00
|
|
|
from generation import Generation, GenerationException
|
2018-12-04 07:46:48 -05:00
|
|
|
except ImportError:
|
|
|
|
sys.path.append('../')
|
2021-01-27 03:03:24 -05:00
|
|
|
from generation import Generation, GenerationException
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
from io import StringIO
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
from entity import Entity, EntityDB
|
2019-03-19 02:36:04 -04:00
|
|
|
from fragments import FragmentFile
|
2021-01-27 03:03:24 -05:00
|
|
|
from linker_script import LinkerScript
|
|
|
|
from output_commands import InputSectionDesc
|
2018-12-04 07:46:48 -05:00
|
|
|
from sdkconfig import SDKConfig
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
ROOT = Entity('*')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
FREERTOS = Entity('libfreertos.a')
|
|
|
|
CROUTINE = Entity('libfreertos.a', 'croutine')
|
|
|
|
TIMERS = Entity('libfreertos.a', 'timers')
|
|
|
|
|
|
|
|
FREERTOS2 = Entity('libfreertos2.a')
|
|
|
|
|
|
|
|
|
|
|
|
class GenerationTest(unittest.TestCase):
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2021-01-27 03:03:24 -05:00
|
|
|
self.generation = Generation()
|
|
|
|
self.entities = None
|
|
|
|
self.linker_script = None
|
2018-04-17 22:57:45 -04:00
|
|
|
|
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)
|
|
|
|
self.addCleanup(os.remove, self.kconfigs_source_file)
|
|
|
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
|
|
|
self.kconfig_projbuilds_source_file = os.path.join(tempfile.gettempdir(), f.name)
|
|
|
|
self.addCleanup(os.remove, self.kconfig_projbuilds_source_file)
|
|
|
|
|
|
|
|
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')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
with open('data/base.lf') as fragment_file_obj:
|
2019-03-19 02:36:04 -04:00
|
|
|
fragment_file = FragmentFile(fragment_file_obj, self.sdkconfig)
|
2021-01-27 03:03:24 -05:00
|
|
|
self.generation.add_fragments_from_file(fragment_file)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.entities = EntityDB()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
with open('data/libfreertos.a.txt') as objdump:
|
|
|
|
self.entities.add_sections_info(objdump)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
with open('data/linker_script.ld') as linker_script:
|
|
|
|
self.linker_script = LinkerScript(linker_script)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
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
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def add_fragments(self, text):
|
|
|
|
fragment_file = self.create_fragment_file(text)
|
|
|
|
fragment_file = FragmentFile(fragment_file, self.sdkconfig)
|
2021-01-27 03:03:24 -05:00
|
|
|
self.generation.add_fragments_from_file(fragment_file)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def write(self, expected, actual):
|
2021-01-27 03:03:24 -05:00
|
|
|
self.linker_script.fill(expected)
|
|
|
|
self.linker_script.write(open('expected.ld', 'w'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.linker_script.fill(actual)
|
|
|
|
self.linker_script.write(open('actual.ld', 'w'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def generate_default_rules(self):
|
2021-01-27 03:03:24 -05:00
|
|
|
rules = collections.defaultdict(list)
|
|
|
|
|
|
|
|
rules['flash_text'].append(InputSectionDesc(ROOT, ['.literal', '.literal.*', '.text', '.text.*'], []))
|
|
|
|
rules['flash_rodata'].append(InputSectionDesc(ROOT, ['.rodata', '.rodata.*'], []))
|
|
|
|
rules['dram0_data'].append(InputSectionDesc(ROOT, ['.data', '.data.*'], []))
|
|
|
|
rules['dram0_data'].append(InputSectionDesc(ROOT, ['.dram', '.dram.*'], []))
|
|
|
|
rules['dram0_bss'].append(InputSectionDesc(ROOT, ['.bss', '.bss.*'], []))
|
|
|
|
rules['dram0_bss'].append(InputSectionDesc(ROOT, ['COMMON'], []))
|
|
|
|
rules['iram0_text'].append(InputSectionDesc(ROOT, ['.iram', '.iram.*'], []))
|
|
|
|
rules['rtc_text'].append(InputSectionDesc(ROOT, ['.rtc.text', '.rtc.literal'], []))
|
|
|
|
rules['rtc_data'].append(InputSectionDesc(ROOT, ['.rtc.data'], []))
|
|
|
|
rules['rtc_data'].append(InputSectionDesc(ROOT, ['.rtc.rodata'], []))
|
|
|
|
rules['rtc_bss'].append(InputSectionDesc(ROOT, ['.rtc.bss'], []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
return rules
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def compare_rules(self, expected, actual):
|
2018-04-17 22:57:45 -04:00
|
|
|
self.assertEqual(set(expected.keys()), set(actual.keys()))
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
for target in sorted(actual.keys()):
|
|
|
|
a_cmds = actual[target]
|
|
|
|
e_cmds = expected[target]
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.assertEqual(len(a_cmds), len(e_cmds))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
for a, e in zip(a_cmds, e_cmds):
|
|
|
|
self.assertEqual(a, e)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def get_default(self, target, rules):
|
2018-04-17 22:57:45 -04:00
|
|
|
return rules[target][0]
|
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
def test_rule_generation_default(self):
|
2021-01-27 03:03:24 -05:00
|
|
|
# Checks that default rules are generated from
|
|
|
|
# the default scheme properly and even if no mappings
|
|
|
|
# are defined.
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
|
|
|
expected = self.generate_default_rules()
|
|
|
|
|
|
|
|
self.compare_rules(expected, actual)
|
|
|
|
|
|
|
|
|
|
|
|
class DefaultMappingTest(GenerationTest):
|
|
|
|
|
|
|
|
def test_default_mapping_lib(self):
|
|
|
|
# Mapping a library with default mapping. This should not emit additional rules,
|
|
|
|
# other than the default ones.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
* (default)
|
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
self.test_rule_generation_default()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_default_mapping_obj(self):
|
|
|
|
# Mapping an object with default mapping. This should not emit additional rules,
|
|
|
|
# other than the default ones.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (default)
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
self.test_rule_generation_default()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_default_mapping_symbol(self):
|
|
|
|
# Mapping a symbol with default mapping. This should not emit additional rules,
|
|
|
|
# other than the default ones.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine:prvCheckPendingReadyList (default) #1
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
self.test_rule_generation_default()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_default_mapping_all(self):
|
|
|
|
# Mapping a library, object, and symbol with default mapping. This should not emit additional rules,
|
|
|
|
# other than the default ones.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
* (default) #1
|
|
|
|
croutine (default) #2
|
|
|
|
croutine:prvCheckPendingReadyList (default) #3
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
self.test_rule_generation_default()
|
|
|
|
|
|
|
|
def test_default_mapping_lib_symbol(self):
|
|
|
|
# Mapping a library, and symbol with default mapping. This should not emit additional rules,
|
|
|
|
# other than the default ones.
|
|
|
|
#
|
|
|
|
# This is a check needed to make sure generation does not generate
|
|
|
|
# intermediate commands due to presence of symbol mapping.
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
* (default) #1
|
|
|
|
croutine:prvCheckPendingReadyList (default) #2
|
|
|
|
"""
|
|
|
|
self.add_fragments(mapping)
|
|
|
|
self.test_rule_generation_default()
|
|
|
|
|
|
|
|
def test_default_mapping_obj_symbol(self):
|
|
|
|
# Mapping a library, and symbol with default mapping. This should not emit additional rules,
|
|
|
|
# other than the default ones.
|
|
|
|
#
|
|
|
|
# This is a check needed to make sure generation does not generate
|
|
|
|
# intermediate commands due to presence of symbol mapping.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (default) #1
|
|
|
|
croutine:prvCheckPendingReadyList (default) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
self.test_rule_generation_default()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
class BasicTest(GenerationTest):
|
|
|
|
# Test basic and fundamental interactions between typical
|
|
|
|
# entries.
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_nondefault_mapping_lib(self, alt=None):
|
|
|
|
# Test mapping entry different from default for a library.
|
|
|
|
# There should be exclusions in the default commands for flash_text and flash_rodata:
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *((EXCLUDE_FILE(libfreertos.a)) .literal ...) A
|
|
|
|
#
|
|
|
|
# Commands placing the entire library in iram, dram should be generated:
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *(.iram ...)
|
|
|
|
# *libfreertos.a(.literal ...) B
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
* (noflash) #1
|
|
|
|
"""
|
|
|
|
self.add_fragments(alt if alt else mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Generate exclusions in flash_text and flash_rodata A
|
|
|
|
flash_text[0].exclusions.add(FREERTOS)
|
|
|
|
flash_rodata[0].exclusions.add(FREERTOS)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Input section commands in iram_text and dram0_data for #1 B
|
|
|
|
iram0_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, []))
|
|
|
|
dram0_data.append(InputSectionDesc(FREERTOS, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_nondefault_mapping_obj(self, alt=None):
|
|
|
|
# Test mapping entry different from default for an object.
|
|
|
|
# There should be exclusions in the default commands for flash_text and flash_rodata:
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *((EXCLUDE_FILE(libfreertos.a:croutine)) .literal ...) A
|
|
|
|
#
|
|
|
|
# Commands placing the entire library in iram, dram should be generated:
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *(.iram ...)
|
|
|
|
# *libfreertos.a:croutine(.literal ...) B
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (noflash) #1
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(alt if alt else mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Generate exclusions in flash_text and flash_rodata A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
|
|
|
flash_rodata[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Input section commands in iram_text and dram0_data for #1 B
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, flash_text[0].sections, []))
|
|
|
|
dram0_data.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_nondefault_mapping_symbol(self):
|
|
|
|
# Test mapping entry different from default for symbol.
|
|
|
|
# There should be exclusions in the default commands for flash_text, as well as the implicit intermediate object command
|
|
|
|
# with an exclusion from default:
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *((EXCLUDE_FILE(libfreertos.a:croutine)) .literal ...) A
|
|
|
|
# *libfreertos.a:croutine(.literal .literal.prvCheckDelayedList ...) B
|
|
|
|
#
|
|
|
|
# Commands placing the entire library in iram should be generated:
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *(.iram ...)
|
|
|
|
# *libfreertos.a:croutine(.text.prvCheckPendingReadyList .literal.prvCheckPendingReadyList) C
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine:prvCheckPendingReadyList (noflash) #1
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
iram0_text = expected['iram0_text']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Generate exclusion in flash_text A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Generate intermediate command B
|
|
|
|
# List all relevant sections except the symbol
|
|
|
|
# being mapped
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections.append('.text')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Input section commands in iram_text for #1 C
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_default_symbol_nondefault_lib(self):
|
|
|
|
# Test default symbol mapping with different lib mapping. This should create an implicit intermediate object command.
|
|
|
|
# The significant targets are flash_text, flash_rodata, iram0_text, dram0_data.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a) .text ...) A
|
|
|
|
# libfreertos.a:croutine (.text.prvCheckPendingReadyList .literal.prvCheckPendingReadyList) B
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a) .rodata ...) A
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# * ( .iram ...)
|
|
|
|
# libfreertos.a (EXCLUDE_FILE(libfreertos:croutine) .text ...) C.1
|
|
|
|
# *libfreertos.a:croutine(.literal .literal.prvCheckDelayedList ...) D
|
|
|
|
#
|
|
|
|
# dram0_data
|
|
|
|
# * ( .dram ...)
|
|
|
|
# libfreertos.a ( .rodata ...) C.2
|
|
|
|
#
|
|
|
|
# Only default commands are in the other targets.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
* (noflash) #1
|
|
|
|
croutine:prvCheckPendingReadyList (default) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(FREERTOS)
|
|
|
|
flash_rodata[0].exclusions.add(FREERTOS)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Commands for #1 C.1 & C.2
|
|
|
|
# C.1 excludes intermediate command for #2
|
|
|
|
iram0_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, [CROUTINE]))
|
|
|
|
dram0_data.append(InputSectionDesc(FREERTOS, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Intermediate command for excluding #2 D
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections.append('.text')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #2 B
|
|
|
|
flash_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_default_symbol_nondefault_obj(self):
|
|
|
|
# Test default symbol mapping with different obj mapping. Since there is an explicit entry for the object,
|
|
|
|
# the sections for that object should just be expanded and the symbol section subtracted, to be placed
|
|
|
|
# using another command.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine) .text ...) A
|
|
|
|
# libfreertos.a:croutine (.text.prvCheckPendingReadyList .literal.prvCheckPendingReadyList) B
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine) .rodata ...) A
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *( .iram ...)
|
|
|
|
# *libfreertos.a:croutine(.literal .literal.prvCheckDelayedList ...) C.1
|
|
|
|
#
|
|
|
|
# dram0_data
|
|
|
|
# *(.data ..)
|
|
|
|
# *libfreertos.a:croutine(.rodata ....) C.2
|
|
|
|
#
|
|
|
|
# Only default commands are in the other targets
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (noflash) #1
|
|
|
|
croutine:prvCheckPendingReadyList (default) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
|
|
|
flash_rodata[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Commands for #1 C.1 & C.2
|
|
|
|
# C.1 list relevant sections for libfreertos.a:croutine to
|
|
|
|
# exclude symbol to map
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections.append('.text')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
|
|
|
dram0_data.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #2 B
|
|
|
|
flash_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_default_nondefault_alternating(self):
|
|
|
|
# Here, each of the entries map sections to something different
|
|
|
|
# than its one-level-up entry.
|
|
|
|
#
|
|
|
|
# * text -> flash, rodata -> flash
|
|
|
|
# libfreertos.a text -> iram, rodata -> dram
|
|
|
|
# libfreertos.a:croutine text -> flash, rodata -> flash
|
|
|
|
# croutine:prvCheckPendingReadyList text -> iram
|
|
|
|
#
|
|
|
|
# The significant targets are flash_text, flash_rodata, iram0_text, and dram0_data.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a) .text ...) A
|
|
|
|
# *libfreertos.a:croutine(.literal .literal.prvCheckDelayedList ...) B.1
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a) .rodata ...) A
|
|
|
|
# *libfreertos.a:croutine(.rodata .rodata.*) B.2
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# * ( .iram ...)
|
|
|
|
# libfreertos.a (EXCLUDE_FILE(libfreertos:croutine) .text ...) C
|
|
|
|
# libfreertos.a:croutine (.text.prvCheckPendingReadyList .literal.prvCheckPendingReadyList) D
|
|
|
|
#
|
|
|
|
# dram0_data
|
|
|
|
# * ( .dram ...)
|
|
|
|
# libfreertos.a (EXCLUDE_FILE(libfreertos:croutine) .rodata ...) C
|
|
|
|
#
|
|
|
|
# For the other targets only the default commands should be present.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
* (noflash) #1
|
|
|
|
croutine (default) #2
|
|
|
|
croutine:prvCheckPendingReadyList (noflash) #3
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
# Only for flash_text and flash_rodata
|
|
|
|
flash_text[0].exclusions.add(FREERTOS)
|
|
|
|
flash_rodata[0].exclusions.add(FREERTOS)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Commands for #1 C
|
|
|
|
# with exclusions for #2
|
|
|
|
iram0_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, [CROUTINE]))
|
|
|
|
dram0_data.append(InputSectionDesc(FREERTOS, flash_rodata[0].sections, [CROUTINE]))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Commands for #2 B.1
|
|
|
|
flash_rodata.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# List all relevant sections in case of flash_text B.2
|
|
|
|
# as exclusion for #3
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections.append('.text')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #3 D
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_nondefault_but_same_lib_and_obj(self):
|
|
|
|
# Extension of DefaultMappingTest. Commands should not be generated for #2, since it does similar mapping
|
|
|
|
# to #1. Output is similar to test_different_mapping_lib.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
* (noflash) #1
|
|
|
|
croutine (noflash) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.test_nondefault_mapping_lib(mapping)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_nondefault_but_same_lib_and_sym(self):
|
|
|
|
# Extension of DefaultMappingTest. Commands should not be generated for #2, since it does similar mapping
|
|
|
|
# to #1. Output is similar to test_different_mapping_lib.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
* (noflash) #1
|
|
|
|
croutine:prvCheckPendingReadyList (noflash) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.test_nondefault_mapping_lib(mapping)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_nondefault_but_same_obj_and_sym(self):
|
|
|
|
# Commands should not be generated for #2, since it does similar mapping
|
|
|
|
# to #1. Output is similar to test_different_mapping_obj.
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
croutine (noflash) #1
|
|
|
|
croutine:prvCheckPendingReadyList (noflash) #2
|
|
|
|
"""
|
|
|
|
self.test_nondefault_mapping_obj(mapping)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_multiple_symbols_excluded_from_intermediate_command(self):
|
|
|
|
# Test mapping multiple symbols from the same object.
|
|
|
|
# All these symbols must be succesfully excluded from
|
|
|
|
# the intermediate command.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# * (EXCLUDE_FILE(libfreertos.a:croutine) .text ...) A
|
|
|
|
# libfreertos:croutine(.text ...) B
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
#
|
|
|
|
#
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
croutine:prvCheckPendingReadyList (noflash) #1
|
|
|
|
croutine:prvCheckDelayedList (noflash) #2
|
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
iram0_text = expected['iram0_text']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 & #2 intermediate command A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Intermediate command for #1 & #2 which lists B
|
|
|
|
# all relevant sections in croutine except prvCheckPendingReadyList
|
|
|
|
# and prvCheckDelayedList
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckDelayedList')]
|
|
|
|
filtered_sections.append('.text')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Commands for #1 & 2
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckDelayedList', '.literal.prvCheckDelayedList']), []))
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
class AdvancedTest(GenerationTest):
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Test valid but quirky cases, corner cases, failure cases, and
|
|
|
|
# cases involving interaction between schemes, other mapping
|
|
|
|
# fragments.
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_same_entity_no_scheme_common(self):
|
|
|
|
# Test same entity being mapped by schemes that have nothing in common.
|
|
|
|
#
|
|
|
|
# noflash_data: rodata -> dram0_data
|
|
|
|
# noflash_text: text -> iram0_text
|
|
|
|
#
|
|
|
|
# This operation should succeed with the following commands:
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine) .text ...) A
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine) .rodata ...) B
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *(.iram ...)
|
|
|
|
# *libfreertos.a:croutine(.text .text.* ...) C
|
|
|
|
#
|
|
|
|
# dram0_data
|
|
|
|
# *(.data ..)
|
|
|
|
# *(.dram ...)
|
|
|
|
# *libfreertos.a:croutine(.rodata .rodata.*) D
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (noflash_text) #1
|
|
|
|
croutine (noflash_data) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #2 B
|
|
|
|
flash_rodata[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #1 C
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, flash_text[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #2 D
|
|
|
|
dram0_data.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_same_entity_sub_scheme(self):
|
|
|
|
# Test same entity being mapped by scheme that is a subset of the other.
|
|
|
|
#
|
|
|
|
# noflash: text -> iram0_text, rodata -> dram0_data
|
|
|
|
# noflash_text: text -> iram0_text
|
|
|
|
#
|
|
|
|
# `text -> iram0_text` is common between the two schemes.
|
|
|
|
#
|
|
|
|
# This operation should succeed with the following commands:
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine) .text ...) A
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine) .rodata ...) B
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *(.iram ...)
|
|
|
|
# *libfreertos.a:croutine(.text .text.* ...) C
|
|
|
|
#
|
|
|
|
# dram0_data
|
|
|
|
# *(.data ..)
|
|
|
|
# *(.dram ...)
|
|
|
|
# *libfreertos.a:croutine(.rodata .rodata.*) D
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (noflash) #1
|
|
|
|
croutine (noflash_data) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 & #2 B
|
|
|
|
flash_rodata[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #1 C
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, flash_text[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #1 & #2 D
|
|
|
|
dram0_data.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_same_entity_conflicting_scheme(self, alt=None):
|
|
|
|
# Test same entity being mapped by scheme conflicting with another.
|
|
|
|
#
|
|
|
|
# rtc = text -> rtc_text, rodata -> rtc_data
|
|
|
|
# noflash = text -> iram0_text, rodata -> dram0_data
|
|
|
|
#
|
|
|
|
# This operation should fail.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (noflash) #1
|
|
|
|
croutine (rtc) #2
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(alt if alt else mapping)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
with self.assertRaises(GenerationException):
|
|
|
|
self.generation.generate_rules(self.entities)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_complex_mapping_case(self, alt=None):
|
|
|
|
# Test a complex case where an object is mapped using
|
|
|
|
# one scheme, but a specific symbol in that object is mapped
|
|
|
|
# using another. Another object and symbol is mapped the other way around.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine libfreertos.a:timers) .text ...) A, B
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:croutine libfreertos.a:timers) .rodata ...) A, B
|
|
|
|
#
|
|
|
|
# dram0_data
|
|
|
|
# *(EXCLUDE_FILES(libfreertos.a:timers) .data ..) B
|
|
|
|
# *(.dram ...)
|
|
|
|
# *libfreertos.a:croutine(.rodata .rodata.*) C
|
|
|
|
# *libfreertos.a:timers(.rodata.prvProcessReceivedCommands ...) E
|
|
|
|
#
|
|
|
|
# dram0_bss
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:timers) .bss .bss.* ...) B
|
|
|
|
# *(EXCLUDE_FILE(libfreertos.a:timers) COMMON) B
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
# *(.iram ...)
|
|
|
|
# *libfreertos.a:croutine(.literal .literal.prvCheckDelayedList ...) C
|
|
|
|
# *libfreertos.a:timers(.literal .literal.prvProcessReceivedCommands ...) E
|
|
|
|
#
|
|
|
|
# rtc_text
|
|
|
|
# *(rtc.text .rtc.literal)
|
|
|
|
# libfreertos.a:croutine (.text.prvCheckPendingReadyList .literal.prvCheckPendingReadyList) F
|
|
|
|
# libfreertos.a:timers (.text .text.prvCheckForValidListAndQueue ...) D.2
|
|
|
|
#
|
|
|
|
# rtc_data
|
|
|
|
# *(rtc.data)
|
|
|
|
# *(rtc.rodata)
|
|
|
|
# libfreertos.a:timers (.data .data.*) D
|
|
|
|
# libfreertos.a:timers (.rodata ...) D.2
|
|
|
|
#
|
|
|
|
# rtc_bss
|
|
|
|
# *(rtc.bss .rtc.bss)
|
|
|
|
# libfreertos.a:timers (.bss .bss.*) D
|
|
|
|
# libfreertos.a:timers (COMMON) D
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
croutine (noflash) #1
|
|
|
|
timers (rtc) #2
|
|
|
|
timers:prvProcessReceivedCommands (noflash) #3
|
|
|
|
croutine:prvCheckPendingReadyList (rtc) #4
|
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(alt if alt else mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
dram0_data = expected['dram0_data']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_bss = expected['dram0_bss']
|
|
|
|
rtc_text = expected['rtc_text']
|
|
|
|
rtc_data = expected['rtc_data']
|
|
|
|
rtc_bss = expected['rtc_bss']
|
|
|
|
|
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
|
|
|
flash_rodata[0].exclusions.add(CROUTINE)
|
|
|
|
|
|
|
|
# Exclusions for #2 B
|
|
|
|
flash_text[0].exclusions.add(TIMERS)
|
|
|
|
flash_rodata[0].exclusions.add(TIMERS)
|
|
|
|
dram0_data[0].exclusions.add(TIMERS)
|
|
|
|
dram0_bss[0].exclusions.add(TIMERS)
|
|
|
|
dram0_bss[1].exclusions.add(TIMERS)
|
|
|
|
|
|
|
|
# Commands for #1 C
|
|
|
|
# List all relevant sections excluding #4 for text -> iram0_text
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
|
|
|
|
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections.append('.text')
|
|
|
|
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
|
|
|
dram0_data.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
|
|
|
|
|
|
|
# Commands for #4 F
|
|
|
|
# Processed first due to alphabetical ordering
|
|
|
|
rtc_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
|
|
|
|
|
|
|
# Commands for #2 D
|
|
|
|
# List all relevant sections excluding #3 for text -> rtc_text and D.2
|
|
|
|
# rodata -> rtc_data
|
|
|
|
timers_sections = self.entities.get_sections('libfreertos.a', 'timers')
|
|
|
|
filtered_sections = fnmatch.filter(timers_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(timers_sections, '.text.*'))
|
|
|
|
|
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvProcessReceivedCommands')]
|
|
|
|
filtered_sections.append('.text')
|
|
|
|
rtc_text.append(InputSectionDesc(TIMERS, set(filtered_sections), []))
|
|
|
|
|
|
|
|
rtc_data.append(InputSectionDesc(TIMERS, dram0_data[0].sections, []))
|
|
|
|
filtered_sections = fnmatch.filter(timers_sections, '.rodata.*')
|
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvProcessReceivedCommands')]
|
|
|
|
rtc_data.append(InputSectionDesc(TIMERS, set(filtered_sections), []))
|
|
|
|
|
|
|
|
rtc_bss.append(InputSectionDesc(TIMERS, dram0_bss[0].sections, []))
|
|
|
|
rtc_bss.append(InputSectionDesc(TIMERS, dram0_bss[1].sections, []))
|
|
|
|
|
|
|
|
# Commands for #3 E
|
|
|
|
iram0_text.append(InputSectionDesc(TIMERS, set(['.text.prvProcessReceivedCommands', '.literal.prvProcessReceivedCommands']), []))
|
|
|
|
dram0_data.append(InputSectionDesc(TIMERS, set(['.rodata.prvProcessReceivedCommands']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_multiple_mapping_fragments(self):
|
|
|
|
# Test mapping multiple fragments succeeds, particularly
|
|
|
|
# generating exclusions from the default command of archive
|
|
|
|
# and object specificity.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# * (EXCLUDE_FILE(libfreertos.a libfreertos.a:croutine) .text ...)
|
|
|
|
#
|
|
|
|
# flash_rodata
|
|
|
|
# * (EXCLUDE_FILE(libfreertos.a libfreertos.a:croutine) .text ...)
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test_1]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
croutine (noflash) #1
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
[mapping:test_2]
|
|
|
|
archive: libfreertos2.a
|
|
|
|
entries:
|
|
|
|
* (noflash) #2
|
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
|
|
|
flash_rodata[0].exclusions.add(CROUTINE)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 & #2 B
|
|
|
|
flash_text[0].exclusions.add(FREERTOS2)
|
|
|
|
flash_rodata[0].exclusions.add(FREERTOS2)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #1 C
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, flash_text[0].sections, []))
|
|
|
|
dram0_data.append(InputSectionDesc(CROUTINE, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for #1 & #2 D
|
|
|
|
iram0_text.append(InputSectionDesc(FREERTOS2, flash_text[0].sections, []))
|
|
|
|
dram0_data.append(InputSectionDesc(FREERTOS2, flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_mapping_same_lib_in_multiple_fragments_no_conflict(self):
|
|
|
|
# Test mapping fragments operating on the same archive.
|
|
|
|
# In these cases, the entries are taken together.
|
|
|
|
#
|
|
|
|
# Uses the same entries as C_05 but spreads them across
|
|
|
|
# two fragments. The output should still be the same.
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test_1]
|
2019-03-19 02:36:04 -04:00
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine (noflash) #1
|
|
|
|
timers:prvProcessReceivedCommands (noflash) #3
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
[mapping:test_2]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
timers (rtc) #2
|
|
|
|
croutine:prvCheckPendingReadyList (rtc) #4
|
|
|
|
"""
|
|
|
|
self.test_complex_mapping_case(mapping)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_mapping_same_lib_in_multiple_fragments_conflict(self):
|
|
|
|
# Test mapping fragments operating on the same archive
|
|
|
|
# with conflicting mappings.
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:test_1]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
croutine (noflash) #1
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
[mapping:test_2]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
|
|
|
croutine (rtc) #2
|
|
|
|
"""
|
|
|
|
self.test_same_entity_conflicting_scheme(mapping)
|
|
|
|
|
|
|
|
def test_command_order(self):
|
|
|
|
# Test command order sorting: the commands should be sorted by specificity, then
|
|
|
|
# alphabetically. This contributes to deterministic output given
|
|
|
|
# the same input mapping entries.
|
|
|
|
#
|
|
|
|
# This ordering is also tested in other tests as a side-effect.
|
|
|
|
#
|
|
|
|
# flash_text
|
|
|
|
# * (EXCLUDE_FILE(libfreertos.a:croutine libfreertos.a:croutine2)) A
|
|
|
|
# libfreertos.a:croutine(.text ....) B
|
|
|
|
#
|
|
|
|
# iram0_text
|
|
|
|
#
|
|
|
|
# * (.iram .iram.*)
|
|
|
|
# libfreertos:croutine(.text .literal ...) C
|
|
|
|
# libfreertos:croutine(.text.prvCheckDelayedList .literal.prvCheckDelayedList) F
|
|
|
|
# libfreertos:croutine(.text.prvCheckPendingReadyList .literal.prvCheckPendingReadyList) G
|
|
|
|
# libfreertos2:croutine(.text .literal ...) D
|
|
|
|
# libfreertos2:croutine2(.text .literal ...) E
|
|
|
|
mapping = u"""
|
|
|
|
[mapping:freertos2]
|
|
|
|
archive: libfreertos2.a
|
|
|
|
entries:
|
|
|
|
croutine2 (noflash_text) #1
|
|
|
|
croutine (noflash_text) #2
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
[mapping:freertos]
|
2019-03-19 02:36:04 -04:00
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
croutine:prvCheckPendingReadyList (noflash_text) #3
|
|
|
|
croutine:prvCheckDelayedList (noflash_text) #4
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
iram0_text = expected['iram0_text']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Exclusions for #1 A
|
|
|
|
flash_text[0].exclusions.add(CROUTINE)
|
|
|
|
flash_text[0].exclusions.add(Entity(FREERTOS2.archive, 'croutine2'))
|
|
|
|
flash_text[0].exclusions.add(Entity(FREERTOS2.archive, 'croutine'))
|
|
|
|
|
|
|
|
# Intermediate command for #3 and #4 B
|
|
|
|
croutine_sections = self.entities.get_sections('libfreertos.a', 'croutine')
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = fnmatch.filter(croutine_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(croutine_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckPendingReadyList')]
|
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('prvCheckDelayedList')]
|
|
|
|
filtered_sections.append('.text')
|
|
|
|
flash_text.append(InputSectionDesc(CROUTINE, set(filtered_sections), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Command for
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckDelayedList', '.literal.prvCheckDelayedList']), []))
|
|
|
|
iram0_text.append(InputSectionDesc(CROUTINE, set(['.text.prvCheckPendingReadyList', '.literal.prvCheckPendingReadyList']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
iram0_text.append(InputSectionDesc(Entity(FREERTOS2.archive, 'croutine'), flash_text[0].sections, []))
|
|
|
|
iram0_text.append(InputSectionDesc(Entity(FREERTOS2.archive, 'croutine2'), flash_text[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2019-03-19 02:36:04 -04:00
|
|
|
self.compare_rules(expected, actual)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_ambigious_obj(self):
|
|
|
|
# Command generation for ambiguous entry should fail.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: libfreertos.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
port:xPortGetTickRateHz (noflash) #1
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.add_fragments(mapping)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
|
|
|
with self.assertRaises(GenerationException):
|
2021-01-27 03:03:24 -05:00
|
|
|
self.generation.generate_rules(self.entities)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_disambiguated_obj(self):
|
|
|
|
# Test command generation for disambiguated entry. Should produce similar
|
|
|
|
# results to test_nondefault_mapping_symbol.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
2021-01-27 03:03:24 -05:00
|
|
|
archive: libfreertos.a
|
2019-03-19 02:36:04 -04:00
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
port.c:xPortGetTickRateHz (noflash) #1
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
port = Entity('libfreertos.a', 'port.c')
|
|
|
|
self.add_fragments(mapping)
|
|
|
|
actual = self.generation.generate_rules(self.entities)
|
|
|
|
expected = self.generate_default_rules()
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text = expected['flash_text']
|
|
|
|
iram0_text = expected['iram0_text']
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Generate exclusion in flash_text A
|
|
|
|
flash_text[0].exclusions.add(port)
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Generate intermediate command B
|
|
|
|
# List all relevant sections except the symbol
|
|
|
|
# being mapped
|
|
|
|
port_sections = self.entities.get_sections('libfreertos.a', 'port.c')
|
|
|
|
filtered_sections = fnmatch.filter(port_sections, '.literal.*')
|
|
|
|
filtered_sections.extend(fnmatch.filter(port_sections, '.text.*'))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
filtered_sections = [s for s in filtered_sections if not s.endswith('xPortGetTickRateHz')]
|
|
|
|
filtered_sections.append('.text')
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text.append(InputSectionDesc(port, set(filtered_sections), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
# Input section commands in iram_text for #1 C
|
|
|
|
iram0_text.append(InputSectionDesc(port, set(['.text.xPortGetTickRateHz', '.literal.xPortGetTickRateHz']), []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.compare_rules(expected, actual)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2019-04-14 07:34:27 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
class ConfigTest(GenerationTest):
|
|
|
|
# Test command generation with conditions
|
2019-04-14 07:34:27 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def _test_conditional_on_scheme(self, perf, alt=None):
|
|
|
|
# Test that proper commands are generated if using
|
|
|
|
# schemes with conditional entries.
|
|
|
|
scheme = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[sections:cond_text_data]
|
|
|
|
entries:
|
|
|
|
if PERFORMANCE_LEVEL >= 1:
|
|
|
|
.text+
|
|
|
|
.literal+
|
|
|
|
else:
|
2021-01-27 03:03:24 -05:00
|
|
|
.rodata+
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
[scheme:cond_noflash]
|
|
|
|
entries:
|
|
|
|
if PERFORMANCE_LEVEL >= 1:
|
|
|
|
cond_text_data -> iram0_text
|
|
|
|
else:
|
|
|
|
cond_text_data -> dram0_data
|
2021-01-27 03:03:24 -05:00
|
|
|
"""
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
* (cond_noflash)
|
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.sdkconfig.config.syms['PERFORMANCE_LEVEL'].set_value(str(perf))
|
|
|
|
self.add_fragments(scheme)
|
|
|
|
self.add_fragments(alt if alt else mapping)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
actual = self.generation.generate_rules(self.entities)
|
2019-03-19 02:36:04 -04:00
|
|
|
expected = self.generate_default_rules()
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
if perf >= 1:
|
|
|
|
flash_text = expected['flash_text']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
flash_text[0].exclusions.add(Entity('lib.a'))
|
|
|
|
iram0_text.append(InputSectionDesc(Entity('lib.a'), flash_text[0].sections, []))
|
|
|
|
else:
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
dram0_data = expected['dram0_data']
|
|
|
|
flash_rodata[0].exclusions.add(Entity('lib.a'))
|
|
|
|
dram0_data.append(InputSectionDesc(Entity('lib.a'), flash_rodata[0].sections, []))
|
2019-03-19 02:36:04 -04:00
|
|
|
|
|
|
|
self.compare_rules(expected, actual)
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_conditional_on_scheme_00(self):
|
|
|
|
self._test_conditional_on_scheme(0)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_conditional_on_scheme_01(self):
|
|
|
|
self._test_conditional_on_scheme(1)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_conditional_mapping(self, alt=None):
|
|
|
|
# Test that proper commands are generated
|
|
|
|
# in conditional mapping entries.
|
|
|
|
mapping = u"""
|
2019-03-19 02:36:04 -04:00
|
|
|
[mapping:test]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
2021-01-27 03:03:24 -05:00
|
|
|
if PERFORMANCE_LEVEL = 1:
|
|
|
|
obj1 (noflash)
|
|
|
|
elif PERFORMANCE_LEVEL = 2:
|
|
|
|
obj1 (noflash)
|
|
|
|
obj2 (noflash)
|
|
|
|
elif PERFORMANCE_LEVEL = 3:
|
|
|
|
obj1 (noflash)
|
|
|
|
obj2 (noflash)
|
|
|
|
obj3 (noflash)
|
2019-03-19 02:36:04 -04:00
|
|
|
"""
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
for perf_level in range(0, 4):
|
|
|
|
self.sdkconfig.config.syms['PERFORMANCE_LEVEL'].set_value(str(perf_level))
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.generation.mappings = {}
|
|
|
|
self.add_fragments(alt if alt else mapping)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
actual = self.generation.generate_rules(self.entities)
|
|
|
|
expected = self.generate_default_rules()
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
if perf_level < 4 and perf_level > 0:
|
|
|
|
for append_no in range(1, perf_level + 1):
|
|
|
|
flash_text = expected['flash_text']
|
|
|
|
flash_rodata = expected['flash_rodata']
|
|
|
|
iram0_text = expected['iram0_text']
|
|
|
|
dram0_data = expected['dram0_data']
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
obj_str = 'obj' + str(append_no)
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
flash_text[0].exclusions.add(Entity('lib.a', obj_str))
|
|
|
|
flash_rodata[0].exclusions.add(Entity('lib.a', obj_str))
|
2019-03-19 02:36:04 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
iram0_text.append(InputSectionDesc(Entity('lib.a', obj_str), flash_text[0].sections, []))
|
|
|
|
dram0_data.append(InputSectionDesc(Entity('lib.a', obj_str), flash_rodata[0].sections, []))
|
2018-04-17 22:57:45 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.compare_rules(expected, actual)
|
|
|
|
|
|
|
|
def test_conditional_on_scheme_legacy_mapping_00(self):
|
|
|
|
# Test use of conditional scheme on legacy mapping fragment grammar.
|
|
|
|
mapping = u"""
|
|
|
|
[mapping]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
* (cond_noflash)
|
|
|
|
"""
|
|
|
|
self._test_conditional_on_scheme(0, mapping)
|
|
|
|
|
|
|
|
def test_conditional_on_scheme_legacy_mapping_01(self):
|
|
|
|
# Test use of conditional scheme on legacy mapping fragment grammar.
|
|
|
|
mapping = u"""
|
|
|
|
[mapping]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
* (cond_noflash)
|
|
|
|
"""
|
|
|
|
self._test_conditional_on_scheme(0, mapping)
|
|
|
|
|
|
|
|
def test_conditional_entries_legacy_mapping_fragment(self):
|
|
|
|
# Test conditional entries on legacy mapping fragment grammar.
|
|
|
|
mapping = u"""
|
2019-04-02 04:40:43 -04:00
|
|
|
[mapping]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
: PERFORMANCE_LEVEL = 0
|
|
|
|
: PERFORMANCE_LEVEL = 1
|
|
|
|
obj1 (noflash)
|
|
|
|
: PERFORMANCE_LEVEL = 2
|
|
|
|
obj1 (noflash)
|
|
|
|
obj2 (noflash)
|
|
|
|
: PERFORMANCE_LEVEL = 3
|
|
|
|
obj1 (noflash)
|
|
|
|
obj2 (noflash)
|
|
|
|
obj3 (noflash)
|
|
|
|
"""
|
2021-01-27 03:03:24 -05:00
|
|
|
self.test_conditional_mapping(mapping)
|
2019-04-02 04:40:43 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_multiple_fragment_same_lib_conditional_legacy(self):
|
|
|
|
# Test conditional entries on legacy mapping fragment grammar
|
|
|
|
# across multiple fragments.
|
|
|
|
mapping = u"""
|
2019-04-05 02:32:21 -04:00
|
|
|
[mapping]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
: PERFORMANCE_LEVEL = 0
|
|
|
|
: PERFORMANCE_LEVEL = 1
|
|
|
|
obj1 (noflash)
|
|
|
|
: PERFORMANCE_LEVEL = 2
|
|
|
|
obj1 (noflash)
|
|
|
|
: PERFORMANCE_LEVEL = 3
|
|
|
|
obj1 (noflash)
|
|
|
|
|
|
|
|
[mapping]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
: PERFORMANCE_LEVEL = 1
|
|
|
|
obj1 (noflash) # ignore duplicate definition
|
|
|
|
: PERFORMANCE_LEVEL = 2
|
|
|
|
obj2 (noflash)
|
|
|
|
: PERFORMANCE_LEVEL = 3
|
|
|
|
obj2 (noflash)
|
|
|
|
obj3 (noflash)
|
|
|
|
"""
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.test_conditional_mapping(mapping)
|
2019-04-05 02:32:21 -04:00
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
def test_multiple_fragment_same_lib_conditional(self):
|
|
|
|
# Test conditional entries on new mapping fragment grammar.
|
|
|
|
# across multiple fragments.
|
|
|
|
mapping = u"""
|
2019-04-05 02:32:21 -04:00
|
|
|
[mapping:base]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
if PERFORMANCE_LEVEL = 1:
|
|
|
|
obj1 (noflash)
|
|
|
|
elif PERFORMANCE_LEVEL = 2:
|
|
|
|
obj1 (noflash)
|
|
|
|
elif PERFORMANCE_LEVEL = 3:
|
|
|
|
obj1 (noflash)
|
|
|
|
|
|
|
|
[mapping:extra]
|
|
|
|
archive: lib.a
|
|
|
|
entries:
|
|
|
|
if PERFORMANCE_LEVEL = 1:
|
|
|
|
obj1 (noflash) # ignore duplicate definition
|
|
|
|
elif PERFORMANCE_LEVEL = 2:
|
|
|
|
obj2 (noflash)
|
|
|
|
elif PERFORMANCE_LEVEL = 3:
|
|
|
|
obj2 (noflash)
|
|
|
|
obj3 (noflash)
|
|
|
|
"""
|
|
|
|
|
2021-01-27 03:03:24 -05:00
|
|
|
self.test_conditional_mapping(mapping)
|
2020-11-16 00:55:22 -05:00
|
|
|
|
2018-12-04 07:46:48 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
if __name__ == '__main__':
|
2018-12-04 07:46:48 -05:00
|
|
|
unittest.main()
|