BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/test/memap/parse_test.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | import sys |
borlanic | 0:02dd72d1d465 | 2 | from io import open |
borlanic | 0:02dd72d1d465 | 3 | from os.path import isfile, join, dirname |
borlanic | 0:02dd72d1d465 | 4 | import json |
borlanic | 0:02dd72d1d465 | 5 | |
borlanic | 0:02dd72d1d465 | 6 | import pytest |
borlanic | 0:02dd72d1d465 | 7 | |
borlanic | 0:02dd72d1d465 | 8 | from tools.memap import MemapParser, _ArmccParser |
borlanic | 0:02dd72d1d465 | 9 | from copy import deepcopy |
borlanic | 0:02dd72d1d465 | 10 | |
borlanic | 0:02dd72d1d465 | 11 | |
borlanic | 0:02dd72d1d465 | 12 | PARSED_ARM_DATA = { |
borlanic | 0:02dd72d1d465 | 13 | "startup/startup.o": {".text": 0xc0}, |
borlanic | 0:02dd72d1d465 | 14 | "[lib]/c_p.l/__main.o": {".text": 8}, |
borlanic | 0:02dd72d1d465 | 15 | "irqs/irqs.o": {".text": 0x98}, |
borlanic | 0:02dd72d1d465 | 16 | "data/data.o": {".data": 0x18, ".bss": 0x198}, |
borlanic | 0:02dd72d1d465 | 17 | "main.o": {".text": 0x36}, |
borlanic | 0:02dd72d1d465 | 18 | } |
borlanic | 0:02dd72d1d465 | 19 | |
borlanic | 0:02dd72d1d465 | 20 | def test_parse_armcc(): |
borlanic | 0:02dd72d1d465 | 21 | memap = MemapParser() |
borlanic | 0:02dd72d1d465 | 22 | memap.parse(join(dirname(__file__), "arm.map"), "ARM") |
borlanic | 0:02dd72d1d465 | 23 | assert memap.modules == PARSED_ARM_DATA |
borlanic | 0:02dd72d1d465 | 24 | memap.parse(join(dirname(__file__), "arm.map"), "UARM") |
borlanic | 0:02dd72d1d465 | 25 | assert memap.modules == PARSED_ARM_DATA |
borlanic | 0:02dd72d1d465 | 26 | |
borlanic | 0:02dd72d1d465 | 27 | PARSED_IAR_DATA = { |
borlanic | 0:02dd72d1d465 | 28 | "startup/startup.o": {".text": 0xc0}, |
borlanic | 0:02dd72d1d465 | 29 | "[lib]/d16M_tlf.a/__main.o": {".text": 8}, |
borlanic | 0:02dd72d1d465 | 30 | "irqs/irqs.o": {".text": 0x98}, |
borlanic | 0:02dd72d1d465 | 31 | "data/data.o": {".data": 0x18, ".bss": 0x198}, |
borlanic | 0:02dd72d1d465 | 32 | "main.o": {".text": 0x36}, |
borlanic | 0:02dd72d1d465 | 33 | } |
borlanic | 0:02dd72d1d465 | 34 | |
borlanic | 0:02dd72d1d465 | 35 | def test_parse_iar(): |
borlanic | 0:02dd72d1d465 | 36 | memap = MemapParser() |
borlanic | 0:02dd72d1d465 | 37 | memap.parse(join(dirname(__file__), "iar.map"), "IAR") |
borlanic | 0:02dd72d1d465 | 38 | assert memap.modules == PARSED_IAR_DATA |
borlanic | 0:02dd72d1d465 | 39 | |
borlanic | 0:02dd72d1d465 | 40 | PARSED_GCC_DATA = { |
borlanic | 0:02dd72d1d465 | 41 | "startup/startup.o": {".text": 0xc0}, |
borlanic | 0:02dd72d1d465 | 42 | "[lib]/d16M_tlf.a/__main.o": {".text": 8}, |
borlanic | 0:02dd72d1d465 | 43 | "[lib]/misc/foo.o": {".text": 8}, |
borlanic | 0:02dd72d1d465 | 44 | "irqs/irqs.o": {".text": 0x98}, |
borlanic | 0:02dd72d1d465 | 45 | "data/data.o": {".data": 0x18, ".bss": 0x198}, |
borlanic | 0:02dd72d1d465 | 46 | "main.o": {".text": 0x36}, |
borlanic | 0:02dd72d1d465 | 47 | } |
borlanic | 0:02dd72d1d465 | 48 | |
borlanic | 0:02dd72d1d465 | 49 | def test_parse_gcc(): |
borlanic | 0:02dd72d1d465 | 50 | memap = MemapParser() |
borlanic | 0:02dd72d1d465 | 51 | memap.parse(join(dirname(__file__), "gcc.map"), "GCC_ARM") |
borlanic | 0:02dd72d1d465 | 52 | assert memap.modules == PARSED_GCC_DATA |
borlanic | 0:02dd72d1d465 | 53 | memap.parse(join(dirname(__file__), "gcc.map"), "GCC_CR") |
borlanic | 0:02dd72d1d465 | 54 | assert memap.modules == PARSED_GCC_DATA |
borlanic | 0:02dd72d1d465 | 55 | |
borlanic | 0:02dd72d1d465 | 56 | |
borlanic | 0:02dd72d1d465 | 57 | def test_add_empty_module(): |
borlanic | 0:02dd72d1d465 | 58 | memap = _ArmccParser() |
borlanic | 0:02dd72d1d465 | 59 | old_modules = deepcopy(memap.modules) |
borlanic | 0:02dd72d1d465 | 60 | memap.module_add("", 8, ".data") |
borlanic | 0:02dd72d1d465 | 61 | assert(old_modules == memap.modules) |
borlanic | 0:02dd72d1d465 | 62 | memap.module_add("main.o", 0, ".text") |
borlanic | 0:02dd72d1d465 | 63 | assert(old_modules == memap.modules) |
borlanic | 0:02dd72d1d465 | 64 | memap.module_add("main.o", 8, "") |
borlanic | 0:02dd72d1d465 | 65 | assert(old_modules == memap.modules) |
borlanic | 0:02dd72d1d465 | 66 | |
borlanic | 0:02dd72d1d465 | 67 | def test_add_full_module(): |
borlanic | 0:02dd72d1d465 | 68 | memap = _ArmccParser() |
borlanic | 0:02dd72d1d465 | 69 | old_modules = deepcopy(memap.modules) |
borlanic | 0:02dd72d1d465 | 70 | memap.module_add("main.o", 8, ".data") |
borlanic | 0:02dd72d1d465 | 71 | assert(old_modules != memap.modules) |
borlanic | 0:02dd72d1d465 | 72 | assert("main.o" in memap.modules) |
borlanic | 0:02dd72d1d465 | 73 | assert(".data" in memap.modules["main.o"]) |
borlanic | 0:02dd72d1d465 | 74 | assert(memap.modules["main.o"][".data"] == 8) |