1
1
import sys
2
2
import os
3
+ from string import printable
4
+ from copy import deepcopy
5
+ from hypothesis import given
6
+ from hypothesis .strategies import text , lists , fixed_dictionaries
3
7
4
8
ROOT = os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." , ".." , ".." ))
5
9
sys .path .insert (0 , ROOT )
@@ -11,3 +15,71 @@ def test_instantiation():
11
15
for name , Class in TOOLCHAIN_CLASSES .items ():
12
16
CLS = Class (TARGET_MAP ["K64F" ])
13
17
assert name == CLS .name or name == LEGACY_TOOLCHAIN_NAMES [CLS .name ]
18
+
19
+ ALPHABET = [char for char in printable if char not in [u'.' , u'/' ]]
20
+
21
+ @given (fixed_dictionaries ({
22
+ 'common' : lists (text ()),
23
+ 'c' : lists (text ()),
24
+ 'cxx' : lists (text ()),
25
+ 'asm' : lists (text ()),
26
+ 'ld' : lists (text ())}),
27
+ lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 )
28
+ )
29
+ def test_toolchain_profile_c (profile , source_file ):
30
+ filename = deepcopy (source_file )
31
+ filename [- 1 ] += ".c"
32
+ 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 parameter in profile ['c' ] + profile ['common' ]:
39
+ assert any (parameter in cmd for cmd in compile_command ), \
40
+ "Toolchain %s did not propigate arg %s" % (CLS .name , parameter )
41
+
42
+ @given (fixed_dictionaries ({
43
+ 'common' : lists (text ()),
44
+ 'c' : lists (text ()),
45
+ 'cxx' : lists (text ()),
46
+ 'asm' : lists (text ()),
47
+ 'ld' : lists (text ())}),
48
+ lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 )
49
+ )
50
+ def test_toolchain_profile_cpp (profile , source_file ):
51
+ filename = deepcopy (source_file )
52
+ filename [- 1 ] += ".cpp"
53
+ 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" , [])
59
+ for parameter in profile ['cxx' ] + profile ['common' ]:
60
+ assert any (parameter in cmd for cmd in compile_command ), \
61
+ "Toolchain %s did not propigate arg %s" % (CLS .name , parameter )
62
+
63
+ @given (fixed_dictionaries ({
64
+ 'common' : lists (text ()),
65
+ 'c' : lists (text ()),
66
+ 'cxx' : lists (text ()),
67
+ 'asm' : lists (text ()),
68
+ 'ld' : lists (text ())}),
69
+ lists (text (min_size = 1 , alphabet = ALPHABET ), min_size = 1 )
70
+ )
71
+ def test_toolchain_profile_asm (profile , source_file ):
72
+ filename = deepcopy (source_file )
73
+ filename [- 1 ] += ".s"
74
+ 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" , [])
80
+ if not compile_command :
81
+ assert compile_command , to_compile
82
+ for parameter in profile ['asm' ]:
83
+ assert any (parameter in cmd for cmd in compile_command ), \
84
+ "Toolchain %s did not propigate arg %s" % (CLS .name , parameter )
85
+
0 commit comments