Skip to content

Commit e10adff

Browse files
committed
Test the Resources object
1 parent c27dabe commit e10adff

File tree

16 files changed

+104
-0
lines changed

16 files changed

+104
-0
lines changed

tools/test/resources/mbed-os.lib/TARGET_FRDM/main.cpp

Whitespace-only changes.

tools/test/resources/mbed-os.lib/TARGET_FRDM/not-main.cpp

Whitespace-only changes.

tools/test/resources/mbed-os.lib/TARGET_FRDM/pinmap.h

Whitespace-only changes.

tools/test/resources/mbed-os.lib/TARGET_K64F/hal_impl.c

Whitespace-only changes.

tools/test/resources/mbed-os.lib/platform/bm/mbed_lib.json

Whitespace-only changes.

tools/test/resources/mbed-os.lib/platform/mbed_lib.json

Whitespace-only changes.

tools/test/resources/resource_test.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# mbed SDK
2+
# Copyright (c) 2019 ARM Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import unittest
17+
from os.path import dirname, join
18+
from tools.resources import Resources, FileType
19+
from tools.notifier.mock import MockNotifier
20+
21+
SRC_PATHS = {
22+
'': join(dirname(__file__), 'source'),
23+
'mbed-os': join(dirname(__file__), 'mbed-os.lib'),
24+
}
25+
26+
27+
class ResourcesTest(unittest.TestCase):
28+
"""
29+
Tests for Resources objects
30+
"""
31+
32+
def setUp(self):
33+
"""
34+
Called before each test case
35+
36+
:return:
37+
"""
38+
def test_basic_scan(self):
39+
"""
40+
Verify that the ordering of Target info addition and directory addition
41+
does not matter, so long as all the Target info and all directories are
42+
added.
43+
"""
44+
first = Resources(MockNotifier())
45+
first._add_labels('TARGET', ['K64F'])
46+
first._add_labels('TARGET', ['FRDM'])
47+
for name, loc in SRC_PATHS.items():
48+
print(name, loc)
49+
first.add_directory(loc, into_path=name)
50+
assert("main.cpp" in first.get_file_names(FileType.CPP_SRC))
51+
52+
def test_add_target_info(self):
53+
"""
54+
Verify that the ordering of Target info addition and directory addition
55+
does not matter, so long as all the Target info and all directories are
56+
added.
57+
"""
58+
first = Resources(MockNotifier())
59+
middle = Resources(MockNotifier())
60+
last = Resources(MockNotifier())
61+
first._add_labels('TARGET', ['K64F'])
62+
first._add_labels('TARGET', ['FRDM'])
63+
middle._add_labels('TARGET', ['FRDM'])
64+
for name, loc in SRC_PATHS.items():
65+
first.add_directory(loc, into_path=name)
66+
middle.add_directory(loc, into_path=name)
67+
last.add_directory(loc, into_path=name)
68+
middle._add_labels('TARGET', ['K64F'])
69+
last._add_labels('TARGET', ['K64F'])
70+
last._add_labels('TARGET', ['FRDM'])
71+
for ftype in Resources.ALL_FILE_TYPES:
72+
assert(set(first.get_file_refs(ftype))
73+
== set(middle.get_file_refs(ftype)))
74+
assert(set(last.get_file_refs(ftype))
75+
== set(middle.get_file_refs(ftype)))
76+
77+
def test_detect_duplicates(self):
78+
"""
79+
Verify that detect_duplicates finds all off the duplicate object files
80+
in the scanned tree.
81+
"""
82+
notifier = MockNotifier()
83+
first = Resources(notifier)
84+
first._add_labels('TARGET', ['K64F'])
85+
for name, loc in SRC_PATHS.items():
86+
first.add_directory(loc, into_path=name)
87+
notifier.messages = []
88+
first.detect_duplicates()
89+
error_messages = "\n".join(
90+
m['message'] for m in notifier.messages if m['type'] == 'tool_error'
91+
)
92+
assert(" eggs.o " in error_messages)
93+
first._add_labels('TARGET', ['FRDM'])
94+
first.detect_duplicates()
95+
error_messages = "\n".join(
96+
m['message'] for m in notifier.messages if m['type'] == 'tool_error'
97+
)
98+
assert(" eggs.o " in error_messages)
99+
assert(" not-main.o " in error_messages)
100+
assert(" main.o " in error_messages)
101+
102+
103+
if __name__ == '__main__':
104+
unittest.main()

tools/test/resources/source/bl.bin

Whitespace-only changes.

tools/test/resources/source/bl.hex

Whitespace-only changes.

tools/test/resources/source/eggs.S

Whitespace-only changes.

0 commit comments

Comments
 (0)