24
24
#
25
25
26
26
27
-
28
- import os
29
- import subprocess
30
- import sys
27
+ import datetime
31
28
import getopt
32
29
import glob
30
+ import os
33
31
import re
34
- import datetime
32
+ import subprocess
35
33
import sys
36
34
37
35
build_sub_dir = "build_tests"
38
36
39
- def build_cmake_tests (cmake_files , executable_pattern ) :
37
+
38
+ def build_cmake_tests (cmake_files , executable_pattern ):
40
39
global build_sub_dir
41
40
run_files = []
42
41
43
- if len (cmake_files ) == 0 :
42
+ if len (cmake_files ) == 0 :
44
43
return [1 , []]
45
44
46
45
has_error = False
@@ -53,36 +52,39 @@ def build_cmake_tests(cmake_files, executable_pattern) :
53
52
54
53
parallel_build = os .getenv ("PARALLEL_BUILD" )
55
54
56
- for cmake_file in cmake_files :
55
+ for cmake_file in cmake_files :
57
56
source_dir = os .path .dirname (cmake_file )
58
57
module_build_dir = os .path .join (build_dir , source_dir )
59
58
os .makedirs (name = module_build_dir , exist_ok = True )
60
59
os .chdir (module_build_dir )
61
60
62
- cmake_command = [' cmake' ]
61
+ cmake_command = [" cmake" ]
63
62
if cmake_args is not None :
64
63
cmake_command .append (cmake_args )
65
64
cmake_command .append (os .path .join (base_dir , source_dir ))
66
65
67
66
if sys .platform == "win32" :
68
- cmake_command .append (' -DBIN_SUB_DIR=/Debug' )
67
+ cmake_command .append (" -DBIN_SUB_DIR=/Debug" )
69
68
70
69
result_code = subprocess .call (cmake_command , shell = False )
71
- if result_code != 0 :
70
+ if result_code != 0 :
72
71
print (f"Error with cmake for { source_dir } " )
73
72
has_error = True
74
73
continue
75
74
76
75
if parallel_build is not None :
77
76
print ("building parallel" )
78
- result_code = subprocess .call (['cmake' , '--build' , '.' , '--parallel' , f'{ parallel_build } ' ], shell = False )
77
+ result_code = subprocess .call (
78
+ ["cmake" , "--build" , "." , "--parallel" , f"{ parallel_build } " ],
79
+ shell = False ,
80
+ )
79
81
else :
80
- result_code = subprocess .call ([' cmake' , ' --build' , '.' ], shell = False )
82
+ result_code = subprocess .call ([" cmake" , " --build" , "." ], shell = False )
81
83
82
- if result_code != 0 :
84
+ if result_code != 0 :
83
85
has_error = True
84
86
continue
85
- for executable in executable_pattern :
87
+ for executable in executable_pattern :
86
88
run_files .extend (glob .glob (f"{ module_build_dir } { executable } " ))
87
89
88
90
if has_error :
@@ -92,25 +94,25 @@ def build_cmake_tests(cmake_files, executable_pattern) :
92
94
93
95
94
96
def build_tests (service = "*" ):
95
- cmake_files = glob .glob ( f"example_code/{ service } /tests/CMakeLists.txt" )
96
- cmake_files .extend (glob .glob ( f"example_code/{ service } /gtests/CMakeLists.txt" ))
97
+ cmake_files = glob .glob (f"example_code/{ service } /tests/CMakeLists.txt" )
98
+ cmake_files .extend (glob .glob (f"example_code/{ service } /gtests/CMakeLists.txt" ))
97
99
98
100
executable_pattern = ["/*_gtest" , "/Debug/*_gtest.exe" ]
99
101
100
102
return build_cmake_tests (cmake_files , executable_pattern )
101
103
102
104
103
- def run_tests (run_files = [], type1 = False , type2 = False , type3 = False ):
105
+ def run_tests (run_files = [], type1 = False , type2 = False , type3 = False ):
104
106
global build_sub_dir
105
107
has_error = False
106
108
filters = []
107
- if type1 :
109
+ if type1 :
108
110
filters .append ("*_1_" )
109
111
110
- if type2 :
112
+ if type2 :
111
113
filters .append ("*_2_" )
112
114
113
- if type3 :
115
+ if type3 :
114
116
filters .append ("*_3_" )
115
117
116
118
filter_arg = ""
@@ -123,9 +125,11 @@ def run_tests(run_files = [], type1=False, type2=False, type3=False):
123
125
run_dir = os .path .join (build_sub_dir , "integration_tests_run" )
124
126
os .makedirs (name = run_dir , exist_ok = True )
125
127
os .chdir (run_dir )
126
- for run_file in run_files :
128
+ for run_file in run_files :
127
129
print (f"Calling '{ run_file } { filter_arg } '." )
128
- proc = subprocess .Popen ([run_file , filter_arg ], stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
130
+ proc = subprocess .Popen (
131
+ [run_file , filter_arg ], stdout = subprocess .PIPE , stderr = subprocess .STDOUT
132
+ )
129
133
for line in proc .stdout :
130
134
line = line .decode ("utf-8" )
131
135
sys .stdout .write (line )
@@ -141,29 +145,32 @@ def run_tests(run_files = [], type1=False, type2=False, type3=False):
141
145
142
146
proc .wait ()
143
147
144
- if proc .returncode != 0 :
148
+ if proc .returncode != 0 :
145
149
has_error = True
146
150
147
- print ('-' * 88 )
151
+ print ("-" * 88 )
148
152
print (f"{ passed_tests } tests passed." )
149
153
print (f"{ failed_tests } tests failed." )
150
154
151
155
os .chdir (old_dir )
152
156
if has_error :
153
157
return [1 , passed_tests , failed_tests ]
154
- else :
158
+ else :
155
159
return [0 , passed_tests , failed_tests ]
156
160
161
+
157
162
def test_hello_service (service = "*" ):
158
- print ('-' * 88 )
163
+ print ("-" * 88 )
159
164
print (f"Running hello tests for { service } ." )
160
165
161
166
print (os .getcwd ())
162
167
cmake_files = glob .glob (f"example_code/{ service } /hello_{ service } /CMakeLists.txt" )
163
168
164
- (err_code , run_files ) = build_cmake_tests (cmake_files , ['/hello_*' , '/Debug/hello_*.exe' ])
169
+ (err_code , run_files ) = build_cmake_tests (
170
+ cmake_files , ["/hello_*" , "/Debug/hello_*.exe" ]
171
+ )
165
172
166
- if err_code != 0 :
173
+ if err_code != 0 :
167
174
print ("Build hello tests failed." )
168
175
return [err_code , 0 , 0 ]
169
176
@@ -175,45 +182,49 @@ def test_hello_service(service="*"):
175
182
passed_count = 0
176
183
failed_count = 0
177
184
has_error = False
178
- for run_file in run_files :
185
+ for run_file in run_files :
179
186
path_split = os .path .splitext (run_file )
180
- if (path_split [1 ] == ' .exe' ) or (path_split [1 ] == '' ):
187
+ if (path_split [1 ] == " .exe" ) or (path_split [1 ] == "" ):
181
188
print (f"Calling '{ run_file } '." )
182
189
completedProcess = subprocess .run ([run_file ], stdout = subprocess .DEVNULL )
183
- if completedProcess .returncode != 0 :
190
+ if completedProcess .returncode != 0 :
184
191
print (f"Error with { run_file } " )
185
192
has_error = True
186
193
failed_count = failed_count + 1
187
194
else :
188
195
passed_count = passed_count + 1
189
196
190
- print ('-' * 88 )
197
+ print ("-" * 88 )
191
198
print (f"{ passed_count } tests passed." )
192
199
print (f"{ failed_count } tests failed." )
193
200
print (f"Total cmake files - { len (cmake_files )} " )
194
201
195
202
os .chdir (old_dir )
196
203
197
204
if has_error :
198
- return [1 , passed_count , failed_count ]
199
- else :
200
- return [0 , passed_count , failed_count ]
205
+ return [1 , passed_count , failed_count ]
206
+ else :
207
+ return [0 , passed_count , failed_count ]
208
+
201
209
202
210
def main (argv ):
203
211
type1 = False
204
212
type2 = False
205
213
type3 = False
206
214
service = "*"
215
+ run_dir = os .path .dirname (os .path .realpath (__file__ ))
216
+ print (f"Running script from directory { run_dir } " )
217
+ os .chdir (run_dir )
207
218
208
219
opts , args = getopt .getopt (argv , "h123s:" )
209
220
for opt , arg in opts :
210
- if opt == '-h' :
211
- print (' run_automated_tests.py -1 -2 -3 -s <service>' )
212
- print (' Where:' )
213
- print (' 1. Requires credentials and pre-configured resources.' )
214
- print (' 2. Requires credentials.' )
215
- print (' 3. Does not require credentials.' )
216
- print (' s. Test this service (regular expression).' )
221
+ if opt == "-h" :
222
+ print (" run_automated_tests.py -1 -2 -3 -s <service>" )
223
+ print (" Where:" )
224
+ print (" 1. Requires credentials and pre-configured resources." )
225
+ print (" 2. Requires credentials." )
226
+ print (" 3. Does not require credentials." )
227
+ print (" s. Test this service (regular expression)." )
217
228
sys .exit ()
218
229
elif opt in ("-1" ):
219
230
type1 = True
@@ -230,16 +241,20 @@ def main(argv):
230
241
231
242
[err_code , run_files ] = build_tests (service = service )
232
243
233
- if err_code == 0 :
234
- [err_code , passed_count , failed_count ]= run_tests (run_files = run_files , type1 = type1 , type2 = type2 , type3 = type3 )
244
+ if err_code == 0 :
245
+ [err_code , passed_count , failed_count ] = run_tests (
246
+ run_files = run_files , type1 = type1 , type2 = type2 , type3 = type3
247
+ )
235
248
236
249
os .chdir (base_dir )
237
250
if err_code == 0 :
238
- [err_code , hello_passed_count , hello_failed_count ] = test_hello_service (service = service )
251
+ [err_code , hello_passed_count , hello_failed_count ] = test_hello_service (
252
+ service = service
253
+ )
239
254
passed_count = passed_count + hello_passed_count
240
255
failed_count = failed_count + hello_failed_count
241
256
242
- print ('-' * 88 )
257
+ print ("-" * 88 )
243
258
print (f"{ passed_count } tests passed." )
244
259
print (f"{ failed_count } tests failed." )
245
260
@@ -249,8 +264,6 @@ def main(argv):
249
264
250
265
251
266
if __name__ == "__main__" :
252
- result = main (sys .argv [1 :])
253
-
254
- exit (result )
255
-
267
+ result = main (sys .argv [1 :])
256
268
269
+ exit (result )
0 commit comments