forked from realsenseai/realsense_mipi_platform_driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_ci.py
More file actions
executable file
·86 lines (67 loc) · 2.23 KB
/
Copy pathrun_ci.py
File metadata and controls
executable file
·86 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
'''
This script helps running the tests using pytest.
'''
import sys, os, subprocess, re, getopt, time
start_time = time.time()
running_on_ci = False
if 'WORKSPACE' in os.environ:
running_on_ci = True
#logs are stored @ ./realsense_mipi_driver_platform/test/logs
logdir = os.path.join( '/'.join(os.path.abspath( __file__ ).split( os.path.sep )[0:-1]), 'logs')
dir_live_tests = os.path.dirname(__file__)
regex = None
handle = None
test_ran = False
def usage():
ourname = os.path.basename( sys.argv[0] )
print( 'Syntax: ' + ourname + ' [options] ' )
print( 'Options:' )
print( ' -h, --help Usage help' )
print( ' -r, --regex Run all tests whose name matches the following regular expression' )
print( ' e.g.: --regex test_fw_version; -r test_fw_version')
sys.exit( 0 )
def command(dev_name, test=None):
cmd = ['pytest']
cmd += ['-vs']
cmd += ['-m', ''.join(dev_name)]
if test:
cmd += ['-k', f'{test}']
cmd += [''.join(dir_live_tests)]
cmd += ['--debug']
cmd += [f'--junit-xml={logdir}/{dev_name.upper()}_pytest.xml']
return cmd
def run_test(cmd):
try:
subprocess.run( cmd,
timeout=200,
check=True )
except Exception as e:
print("Exception occurred: {}".format( e ))
def run_tests_on_d457():
global logdir
try:
os.makedirs( logdir, exist_ok=True )
device = "D457"
testname = regex if regex else None
cmd = command(device.lower(), testname)
run_test(cmd)
finally:
if running_on_ci:
print("Log path- \"Build Artifacts\":/realsense_mipi_driver_platform/test/logs ")
run_time = time.time() - start_time
print( "server took", run_time, "seconds" )
if __name__ == '__main__':
try:
opts, args = getopt.getopt( sys.argv[1:], 'hr:', longopts=['help', 'regex=' ] )
except getopt.GetoptError as err:
print( err )
usage()
sys.exit ( 1 )
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
elif opt in ('-r', '--regex'):
regex = arg
run_tests_on_d457()
sys.exit( 0 )