1
+ """Tests for the toolchain sub-system"""
1
2
import sys
2
3
import os
3
4
from string import printable
4
5
from copy import deepcopy
5
6
from hypothesis import given
6
7
from hypothesis .strategies import text , lists , fixed_dictionaries
7
8
8
- ROOT = os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." , ".." , ".." ))
9
+ ROOT = os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." , ".." ,
10
+ ".." ))
9
11
sys .path .insert (0 , ROOT )
10
12
11
13
from tools .toolchains import TOOLCHAIN_CLASSES , LEGACY_TOOLCHAIN_NAMES
12
14
from tools .targets import TARGET_MAP
13
15
14
16
def test_instantiation ():
15
- for name , Class in TOOLCHAIN_CLASSES .items ():
16
- CLS = Class (TARGET_MAP ["K64F" ])
17
- assert name == CLS .name or name == LEGACY_TOOLCHAIN_NAMES [CLS .name ]
17
+ """Test that all exported toolchain may be instantiated"""
18
+ for name , tc_class in TOOLCHAIN_CLASSES .items ():
19
+ cls = tc_class (TARGET_MAP ["K64F" ])
20
+ assert name == cls .name or \
21
+ name == LEGACY_TOOLCHAIN_NAMES [cls .name ]
18
22
19
23
ALPHABET = [char for char in printable if char not in [u'.' , u'/' ]]
20
24
@@ -24,62 +28,71 @@ def test_instantiation():
24
28
'cxx' : lists (text ()),
25
29
'asm' : lists (text ()),
26
30
'ld' : lists (text ())}),
27
- lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 )
28
- )
31
+ lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 ))
29
32
def test_toolchain_profile_c (profile , source_file ):
33
+ """Test that the appropriate profile parameters are passed to the
34
+ C compiler"""
30
35
filename = deepcopy (source_file )
31
36
filename [- 1 ] += ".c"
32
37
to_compile = os .path .join (* filename )
33
- for name , Class in TOOLCHAIN_CLASSES .items ():
34
- CLS = Class (TARGET_MAP ["K64F" ], build_profile = profile )
35
- CLS .inc_md5 = ""
36
- CLS .build_dir = ""
37
- compile_command = CLS .compile_command (to_compile , to_compile + ".o" , [])
38
+ for _ , tc_class in TOOLCHAIN_CLASSES .items ():
39
+ toolchain = tc_class (TARGET_MAP ["K64F" ], build_profile = profile )
40
+ toolchain .inc_md5 = ""
41
+ toolchain .build_dir = ""
42
+ compile_command = toolchain .compile_command (to_compile ,
43
+ to_compile + ".o" , [])
38
44
for parameter in profile ['c' ] + profile ['common' ]:
39
45
assert any (parameter in cmd for cmd in compile_command ), \
40
- "Toolchain %s did not propigate arg %s" % (CLS .name , parameter )
46
+ "Toolchain %s did not propigate arg %s" % (toolchain .name ,
47
+ parameter )
41
48
42
49
@given (fixed_dictionaries ({
43
50
'common' : lists (text ()),
44
51
'c' : lists (text ()),
45
52
'cxx' : lists (text ()),
46
53
'asm' : lists (text ()),
47
54
'ld' : lists (text ())}),
48
- lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 )
49
- )
55
+ lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 ))
50
56
def test_toolchain_profile_cpp (profile , source_file ):
57
+ """Test that the appropriate profile parameters are passed to the
58
+ C++ compiler"""
51
59
filename = deepcopy (source_file )
52
60
filename [- 1 ] += ".cpp"
53
61
to_compile = os .path .join (* filename )
54
- for name , Class in TOOLCHAIN_CLASSES .items ():
55
- CLS = Class (TARGET_MAP ["K64F" ], build_profile = profile )
56
- CLS .inc_md5 = ""
57
- CLS .build_dir = ""
58
- compile_command = CLS .compile_command (to_compile , to_compile + ".o" , [])
62
+ for _ , tc_class in TOOLCHAIN_CLASSES .items ():
63
+ toolchain = tc_class (TARGET_MAP ["K64F" ], build_profile = profile )
64
+ toolchain .inc_md5 = ""
65
+ toolchain .build_dir = ""
66
+ compile_command = toolchain .compile_command (to_compile ,
67
+ to_compile + ".o" , [])
59
68
for parameter in profile ['cxx' ] + profile ['common' ]:
60
69
assert any (parameter in cmd for cmd in compile_command ), \
61
- "Toolchain %s did not propigate arg %s" % (CLS .name , parameter )
70
+ "Toolchain %s did not propigate arg %s" % (toolchain .name ,
71
+ parameter )
62
72
63
73
@given (fixed_dictionaries ({
64
74
'common' : lists (text ()),
65
75
'c' : lists (text ()),
66
76
'cxx' : lists (text ()),
67
77
'asm' : lists (text ()),
68
78
'ld' : lists (text ())}),
69
- lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 )
70
- )
79
+ lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 ))
71
80
def test_toolchain_profile_asm (profile , source_file ):
81
+ """Test that the appropriate profile parameters are passed to the
82
+ Assembler"""
72
83
filename = deepcopy (source_file )
73
84
filename [- 1 ] += ".s"
74
85
to_compile = os .path .join (* filename )
75
- for name , Class in TOOLCHAIN_CLASSES .items ():
76
- CLS = Class (TARGET_MAP ["K64F" ], build_profile = profile )
77
- CLS .inc_md5 = ""
78
- CLS .build_dir = ""
79
- compile_command = CLS .compile_command (to_compile , to_compile + ".o" , [])
86
+ for _ , tc_class in TOOLCHAIN_CLASSES .items ():
87
+ toolchain = tc_class (TARGET_MAP ["K64F" ], build_profile = profile )
88
+ toolchain .inc_md5 = ""
89
+ toolchain .build_dir = ""
90
+ compile_command = toolchain .compile_command (to_compile ,
91
+ to_compile + ".o" , [])
80
92
if not compile_command :
81
93
assert compile_command , to_compile
82
94
for parameter in profile ['asm' ]:
83
95
assert any (parameter in cmd for cmd in compile_command ), \
84
- "Toolchain %s did not propigate arg %s" % (CLS .name , parameter )
96
+ "Toolchain %s did not propigate arg %s" % (toolchain .name ,
97
+ parameter )
85
98
0 commit comments