Esempio n. 1
0
    def test_equivalent_conditional_fragment(self):
        test_fragment1 = self.create_fragment_file(u"""
if A = y:
    [test:test1]
    key_1:
        value_1
else:
    [test:test2]
    key_1:
        value_2
""")

        fragment_file1 = FragmentFile(test_fragment1, self.sdkconfig)
        self.assertEqual(len(fragment_file1.fragments), 1)
        self.assertEqual(fragment_file1.fragments[0].key_1[0], 'value_1')

        test_fragment2 = self.create_fragment_file(u"""
[test:test1]
key_1:
    if A = y:
        value_1
    else:
        value_2
""")

        fragment_file2 = FragmentFile(test_fragment2, self.sdkconfig)
        self.assertEqual(len(fragment_file2.fragments), 1)
        self.assertEqual(fragment_file2.fragments[0].key_1[0], 'value_1')
Esempio n. 2
0
    def test_empty_conditional(self):
        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1:
    if B = y:
    else:
        value_1
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)

        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1:
    if B = y:
        value_1
    else B = y:
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)

        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1:
    if B = y:
        value_1
    elif B = y:
    else:
        value_2
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 3
0
    def test_entries_grammar(self):

        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    _valid1
    valid2.
    .valid3_-
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(fragment_file.fragments[0].entries,
                         {'_valid1', 'valid2.', '.valid3_-'})

        # invalid starting char
        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    1invalid
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)

        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    -invalid
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)

        # + notation
        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    valid+
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(fragment_file.fragments[0].entries,
                         {'valid+'})

        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    inva+lid+
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 4
0
    def test_valid_grammar(self):
        test_fragment = self.create_fragment_file(u"""
[mapping]
archive: lib.a
entries:
    obj:symbol (noflash)
    # Comments should not matter
    obj (noflash)
    # Nor should whitespace
                    obj  :     symbol_2 (    noflash )
        obj_2  (    noflash )
    * (noflash)
""")
        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual('lib.a', fragment_file.fragments[0].archive)
        self.assertEqual('lib_a', fragment_file.fragments[0].name)

        expected = {('obj', 'symbol', 'noflash'),
                    ('obj', None, 'noflash'),
                    ('obj', 'symbol_2', 'noflash'),
                    ('obj_2', None, 'noflash'),
                    ('*', None, 'noflash')
                    }

        self.assertEqual(expected, fragment_file.fragments[0].entries)
Esempio n. 5
0
    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);
        text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name)
    obj1 (default);
        text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name)
""")
        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        fragment = fragment_file.fragments[0]

        expected = [('text', 'flash_text', [
            Mapping.Align(4, True, False),
            Mapping.Keep(),
            Mapping.Surround('sym1'),
            Mapping.Sort('name')
        ]),
                    ('text', 'flash_text', [
                        Mapping.Align(4, True, False),
                        Mapping.Keep(),
                        Mapping.Surround('sym1'),
                        Mapping.Sort('name')
                    ])]
        actual = fragment.flags[('obj1', None, 'default')]
        self.assertEqual(expected, actual)
Esempio n. 6
0
    def test_mixed_deprecated_mapping(self):
        test_fragment = self.create_fragment_file(u"""
[mapping]
archive: lib.a
entries:
    : A = n
    obj_A (noflash)
    : default
    obj_B (noflash)


[mapping:test]
archive: lib.a
entries:
    if A = n:
        obj_A (noflash)
    else:
        obj_B (noflash)
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(2, len(fragment_file.fragments))

        self.assertEqual(fragment_file.fragments[0].entries,
                         fragment_file.fragments[1].entries)
Esempio n. 7
0
    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);
        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)
""")
        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        fragment = fragment_file.fragments[0]

        expected = [('text', 'flash_text', [
            Mapping.Align(4, True, False),
            Mapping.Keep(),
            Mapping.Surround('sym1'),
            Mapping.Align(8, True, False),
            Mapping.Sort('name')
        ]),
                    ('rodata', 'flash_rodata', [
                        Mapping.Keep(),
                        Mapping.Align(4, True, False),
                        Mapping.Keep(),
                        Mapping.Surround('sym1'),
                        Mapping.Align(8, True, False),
                        Mapping.Align(4, True, False),
                        Mapping.Sort('name')
                    ])]
        actual = fragment.flags[('obj1', None, 'default')]
        self.assertEqual(expected, actual)
Esempio n. 8
0
    def test_empty_fragment(self):
        test_fragment = self.create_fragment_file(u"""
[test:test]
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 9
0
    def test_whole_conditional_fragment(self):
        test_fragment = self.create_fragment_file(u"""
if B = y:
    [test:test1]
    key_1:
        value_1
else:
    [test:test2]
    key_1:
        value_2

    if A = y:
        [test:test3]
        key_1:
            value_3
            if C = y:
                value_6

    [test:test4]
    key_1:
        value_4

[test:test5]
key_1:
    value_5
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(len(fragment_file.fragments), 4)
        self.assertEqual(fragment_file.fragments[0].name, 'test2')
        self.assertEqual(fragment_file.fragments[1].name, 'test3')
        self.assertEqual(fragment_file.fragments[1].key_1[1], 'value_6')
        self.assertEqual(fragment_file.fragments[2].name, 'test4')
        self.assertEqual(fragment_file.fragments[3].name, 'test5')
Esempio n. 10
0
    def test_duplicate_keys(self):
        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1: value_1
key_1: value_a
""")
        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 11
0
    def test_required_keys(self):
        test_fragment = self.create_fragment_file(u"""
[test:test]
key_2:
    value_1
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 12
0
    def test_empty_entries(self):
        test_fragment = self.create_fragment_file(u"""
[scheme:test]
entries:
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)

        test_fragment = self.create_fragment_file(u"""
[scheme:test]
entries:
    if B = y:
        sections1 -> target1
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 13
0
    def test_improper_grammar(self):
        test_fragment = self.create_fragment_file(u"""
[scheme:test]
entries:
    sections1, target1 # improper separator
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 14
0
    def test_empty_file(self):
        test_fragment = self.create_fragment_file(u"""




""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(len(fragment_file.fragments), 0)
Esempio n. 15
0
    def test_basic(self):
        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    .section1
    .section2
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(fragment_file.fragments[0].entries, {'.section1', '.section2'})
Esempio n. 16
0
    def test_implicit_blank_default(self):
        test_fragment = self.create_fragment_file(u"""
[mapping]
archive: lib.a
entries:
    : default
""")
        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        expected = {('*', None, 'default')}

        self.assertEqual(expected, fragment_file.fragments[0].entries)
Esempio n. 17
0
    def test_basic(self):
        test_fragment = self.create_fragment_file(u"""
[scheme:test]
entries:
    sections1 -> target1
    sections2 -> target2
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(fragment_file.fragments[0].entries,
                         {('sections1', 'target1'), ('sections2', 'target2')})
Esempio n. 18
0
    def test_archive_allowed_names(self):
        test_fragment = self.create_fragment_file(u"""
[mapping:test]
archive:
    libstdc++.a
entries:
    * (default)
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual('libstdc++.a', fragment_file.fragments[0].archive)
Esempio n. 19
0
    def test_unsupported_key(self):
        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1:
    value_a
key_4:
    value_1
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 20
0
    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);
        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)
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        fragment = fragment_file.fragments[0]

        expected = [
            ('text', 'flash_text', [Mapping.Align(8, True, False)]),
            ('rodata', 'flash_rodata', [Mapping.Align(8, True, False)]),
            ('data', 'dram0_data', [Mapping.Align(8, True, True)]),
            ('bss', 'dram0_bss', [Mapping.Align(8, False, True)]),
            ('common', 'dram0_bss',
             [Mapping.Align(8, True, True),
              Mapping.Align(8, True, False)])
        ]
        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)
        text->iram0_text ALIGN(8, post, pre)
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 21
0
    def test_blank_first_condition(self):
        test_fragment = self.create_fragment_file(u"""
[mapping]
archive: lib.a
entries:
    obj_a (noflash)
    : CONFIG_B = y
    obj_b (noflash)
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 22
0
    def test_duplicate_entries(self):
        test_fragment = self.create_fragment_file(u"""
[scheme:test]
entries:
    sections1 -> target1
    sections2 -> target2
    sections2 -> target2
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(fragment_file.fragments[0].entries,
                         {("sections1", "target1"), ("sections2", "target2")})
Esempio n. 23
0
    def test_implicit_blank_default_w_others(self):
        test_fragment = self.create_fragment_file(u"""
[mapping]
archive: lib.a
entries:
    : A = n
    obj_a (noflash)
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        expected = {("*", None, "default")}

        self.assertEqual(expected, fragment_file.fragments[0].entries)
Esempio n. 24
0
    def test_archive(self):
        test_fragment = self.create_fragment_file(u"""
[mapping:test]
archive:
entries:
    * (default)
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)

        test_fragment = self.create_fragment_file(u"""
[mapping:test]
archive:
    lib1.a
    lib2.a
entries:
    * (default)
""")

        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 25
0
    def test_nonlast_default_1(self):
        test_fragment = self.create_fragment_file(u"""
[mapping]
archive: lib.a
entries:
    : default
    obj_a (noflash)
    : CONFIG_A = y
    obj_A (noflash)
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 26
0
    def test_duplicate_entries(self):
        test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
    .section1
    .section2
    .section3
    .section2
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(fragment_file.fragments[0].entries,
                         {".section1", ".section2", ".section3"})
Esempio n. 27
0
    def test_duplicate_entries(self):
        test_fragment = self.create_fragment_file(u"""
[mapping:test]
archive:
    lib.a
entries:
    obj:symbol (noflash)
    obj:symbol (noflash)
""")

        expected = {('obj', 'symbol', 'noflash')}

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(expected, fragment_file.fragments[0].entries)
Esempio n. 28
0
    def test_empty_entries(self):
        test_fragment = self.create_fragment_file(u"""
[mapping:test]
archive:
    lib.a
entries:
    if B = y:
        * (noflash) # if condition is false, then no 'entries' key value
""")

        expected = set()

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        self.assertEqual(expected, fragment_file.fragments[0].entries)

        test_fragment = self.create_fragment_file(u"""
[mapping:test]
archive:
    lib.a
entries:
""")

        with self.assertRaises(ParseException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 29
0
    def test_setting_indent(self):
        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1:
 value_1
 value_2
 value_3
""")
        fragment_file = FragmentFile(test_fragment, self.sdkconfig)

        self.assertEqual(len(fragment_file.fragments[0].key_1), 3)
        self.assertEqual(fragment_file.fragments[0].key_1[0], 'value_1')
        self.assertEqual(fragment_file.fragments[0].key_1[1], 'value_2')
        self.assertEqual(fragment_file.fragments[0].key_1[2], 'value_3')

        test_fragment = self.create_fragment_file(u"""
[test:test]
key_1:
 value_1
  value_2 # first element dictates indent
  value_3
""")
        with self.assertRaises(ParseFatalException):
            FragmentFile(test_fragment, self.sdkconfig)
Esempio n. 30
0
    def test_surround_flag(self):
        # Test parsing combinations and orders of flags
        test_fragment = self.create_fragment_file(u"""
[mapping:map]
archive: libmain.a
entries:
    obj1 (default);
        text->flash_text SURROUND(sym1)
""")

        fragment_file = FragmentFile(test_fragment, self.sdkconfig)
        fragment = fragment_file.fragments[0]

        expected = [('text', 'flash_text', [Mapping.Surround('sym1')])]
        actual = fragment.flags[('obj1', None, 'default')]
        self.assertEqual(expected, actual)