@@ -17,11 +17,6 @@ def get_full_path(command):
1717
1818
1919def build ():
20- build_dir = Path (build_dir_name )
21- build_dir .parents
22- if build_dir .exists ():
23- shutil .rmtree (build_dir )
24-
2520 env = dict (os .environ )
2621
2722 threads = os .cpu_count () - 1
@@ -33,81 +28,78 @@ def build():
3328 env ["CC" ] = get_full_path ("gcc-11" )
3429 env ["CXX" ] = get_full_path ("g++-11" )
3530
36- subprocess .run (
37- [
38- "cmake" ,
39- "--preset" ,
40- "tests-posix-debug" ,
41- "-B" ,
42- f"{ build_dir_name } " ,
43- "-DCMAKE_C_COMPILER_LAUNCHER=sccache" ,
44- "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache" ,
45- ],
46- check = True ,
47- env = env ,
48- )
49-
50- subprocess .run (
51- ["cmake" , "--build" , f"{ build_dir_name } " , "--config" , "Debug" , "--verbose" ],
52- check = True ,
53- env = env ,
54- )
55-
56- subprocess .run (
57- ["ctest" , "--test-dir" , f"{ build_dir_name } " , "--output-on-failure" ],
58- check = True ,
59- env = env ,
60- )
61-
62-
63- def generate_coverage ():
64- # Capture coverage data
65- subprocess .run (
66- [
67- "lcov" ,
68- "--capture" ,
69- "--directory" ,
70- f"{ build_dir_name } " ,
71- "--no-external" ,
72- "--base-directory" ,
73- "." ,
74- "--output-file" ,
75- f"{ build_dir_name } /coverage_unfiltered.info" ,
76- ],
77- check = True ,
78- )
79-
80- # Remove unwanted paths from coverage
81-
82- subprocess .run (
83- [
84- "lcov" ,
85- "--remove" ,
86- f"{ build_dir_name } /coverage_unfiltered.info" ,
87- "*/3rdparty/*" ,
88- "*/mock/*" ,
89- "*/gmock/*" ,
90- "*/gtest/*" ,
91- "*/test/*" ,
92- "--output-file" ,
93- f"{ build_dir_name } /coverage.info" ,
94- ],
95- check = True ,
96- )
97-
98- # Generate HTML report
99- subprocess .run (
100- [
101- "genhtml" ,
102- f"{ build_dir_name } /coverage.info" ,
103- "--output-directory" ,
104- f"{ build_dir_name } /coverage" ,
105- "--prefix" ,
106- "/home/jenkins/" ,
107- ],
108- check = True ,
109- )
110-
31+ build_dir1 = Path (build_dir_name ) / "s32k1xx"
32+ build_dir2 = Path (build_dir_name ) / "posix"
33+
34+ for d in [build_dir1 , build_dir2 ]:
35+ if d .exists ():
36+ shutil .rmtree (d )
37+
38+ subprocess .run ([
39+ "cmake" , "--preset" , "tests-s32k1xx-debug" ,
40+ "-B" , str (build_dir1 ),
41+ "-DCMAKE_C_COMPILER_LAUNCHER=sccache" ,
42+ "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
43+ ], check = True , env = env )
44+
45+ subprocess .run (["cmake" , "--build" , str (build_dir1 ), "--config" , "Debug" ], check = True , env = env )
46+
47+ subprocess .run (["ctest" , "--test-dir" , str (build_dir1 ), "--output-on-failure" ], check = True , env = env )
48+
49+ subprocess .run ([
50+ "cmake" , "--preset" , "tests-posix-debug" ,
51+ "-B" , str (build_dir2 ),
52+ "-DCMAKE_C_COMPILER_LAUNCHER=sccache" ,
53+ "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
54+ ], check = True , env = env )
55+
56+ subprocess .run (["cmake" , "--build" , str (build_dir2 ), "--config" , "Debug" ], check = True , env = env )
57+
58+ subprocess .run (["ctest" , "--test-dir" , str (build_dir2 ), "--output-on-failure" ], check = True , env = env )
59+
60+ def generate_combined_coverage ():
61+ subprocess .run ([
62+ "lcov" , "--capture" , "--directory" , "code_coverage/s32k1xx" ,
63+ "--no-external" , "--base-directory" , "." , "--output-file" ,
64+ "code_coverage/coverage_s32k1xx_unfiltered.info"
65+ ], check = True )
66+
67+ subprocess .run ([
68+ "lcov" , "--capture" , "--directory" , "code_coverage/posix" ,
69+ "--no-external" , "--base-directory" , "." , "--output-file" ,
70+ "code_coverage/coverage_posix_unfiltered.info"
71+ ], check = True )
72+
73+ exclude_patterns = [
74+ "*/mock/*" ,
75+ "*/gmock/*" ,
76+ "*/gtest/*" ,
77+ "*/test/*" ,
78+ "*/3rdparty/*"
79+ ]
80+
81+ subprocess .run ([
82+ "lcov" , "--remove" , "code_coverage/coverage_s32k1xx_unfiltered.info" , * exclude_patterns ,
83+ "--output-file" , "code_coverage/coverage_s32k1xx.info"
84+ ], check = True )
85+
86+ subprocess .run ([
87+ "lcov" , "--remove" , "code_coverage/coverage_posix_unfiltered.info" , * exclude_patterns ,
88+ "--output-file" , "code_coverage/coverage_posix.info"
89+ ], check = True )
90+
91+ subprocess .run ([
92+ "lcov" , "--add-tracefile" , "code_coverage/coverage_s32k1xx.info" ,
93+ "--add-tracefile" , "code_coverage/coverage_posix.info" ,
94+ "--output-file" , f"{ build_dir_name } /coverage.info"
95+ ], check = True )
96+
97+ repo_root = Path (__file__ ).resolve ().parents [1 ]
98+ subprocess .run ([
99+ "genhtml" , f"{ build_dir_name } /coverage.info" ,
100+ "--prefix" , str (repo_root ),
101+ "--output-directory" , f"{ build_dir_name } /coverage"
102+ ], check = True )
111103
112104def generate_badges ():
113105 result = subprocess .run (
@@ -127,36 +119,35 @@ def generate_badges():
127119
128120 if line_percentage :
129121 line_value = line_percentage .group (1 )
130- print (f"Line Percentage : { line_value } %" )
122+ print (f"Line Coverage : { line_value } %" )
131123 subprocess .run (
132124 [
133125 "wget" ,
134- f"https://img.shields.io/badge/coverage -{ line_value } %25-brightgreen.svg" ,
126+ f"https://img.shields.io/badge/lines -{ line_value } %25-brightgreen.svg" ,
135127 "-O" ,
136- " line_coverage_badge.svg" ,
128+ f" { build_dir_name } / line_coverage_badge.svg" ,
137129 ],
138130 check = True ,
139131 )
140132
141133 if function_percentage :
142134 function_value = function_percentage .group (1 )
143- print (f"Function Percentage : { function_value } %" )
135+ print (f"Function Coverage : { function_value } %" )
144136 subprocess .run (
145137 [
146138 "wget" ,
147- f"https://img.shields.io/badge/coverage -{ function_value } %25-brightgreen.svg" ,
139+ f"https://img.shields.io/badge/functions -{ function_value } %25-brightgreen.svg" ,
148140 "-O" ,
149- " function_coverage_badge.svg" ,
141+ f" { build_dir_name } / function_coverage_badge.svg" ,
150142 ],
151143 check = True ,
152144 )
153145
154-
155146if __name__ == "__main__" :
156147 try :
157148 build ()
158- generate_coverage ()
149+ generate_combined_coverage ()
159150 generate_badges ()
160151 except subprocess .CalledProcessError as e :
161152 print (f"Command failed with exit code { e .returncode } " )
162- sys .exit (e .returncode )
153+ sys .exit (e .returncode )
0 commit comments