-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-test.py
117 lines (94 loc) · 3.63 KB
/
run-test.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Setup:
#
# Change "Exposure, Auto" to "Manual Mode"
# (Default value: 3)
# $ v4l2-ctl -d /dev/video2 --set-ctrl=exposure_auto=1
# To confirm:
# $ v4l2-ctl -d /dev/video2 --get-ctrl=exposure_auto
# exposure_auto: 1
import time
import datetime
import argparse
import importlib
from robot import Robot
from vision import Vision
def parse_arguments():
parser = argparse.ArgumentParser(description='Tapster Robot - App Launch Test')
parser.add_argument('-p', '--port', action='store', dest='port',
required=True,
help='Serial port of robot')
parser.add_argument('-c', '--camera', action='store', dest='camera',
required=True,
type=int,
help='Integer index of camera capture device')
parser.add_argument('-n', '--name', action='store', dest='name',
default = "iphone_6s",
help='Phone module name: (e.g. iphone_6s, iphone_xs_max) Default: iphone_6s')
parser.add_argument('-i', '--iterations', action='store', dest='iterations',
default=1,
type=int,
help='Integer number of test iterations to run. Default: 1')
parser.add_argument('-t', '--type', action='store', dest='type',
default = "warm",
help='Launch type: {warm, cold} Default: warm')
parser.add_argument('-r', '--results', action='store', dest='results',
default="results",
help='Name of directory to store results data. Default: results')
parser.add_argument('--save', action='store_true', dest='save',
default = False,
help='Save test data in RESULTS directory. Will only save results if this flag is set.')
arguments = parser.parse_args()
return arguments
if __name__ == '__main__':
args = parse_arguments()
#Initialize
robot = Robot(args.port)
camera = Vision(args.camera)
# Dynamically import the phone module based on the --name command line flag
phone_module = importlib.import_module(args.name)
phone = phone_module.Phone(robot)
print("-------------------")
print("Tapster - App Launch Test")
print("-------------------")
print()
print(" Phone name: " + args.name)
print(" Launch type: " + args.type)
print(" Number of iterations: " + str(args.iterations))
print(" Save results: " + str(args.save))
if args.results:
print(" Results directory: " + args.results)
print()
if args.save:
file_timestamp = datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S")
# Open results file
results = open(args.results + "/" + phone.name + "--" + args.type + "-start--" + file_timestamp + ".txt", "w")
results.write("Iteration, Duration\n")
phone.go_to_start_position()
# Start main timer
main_timer_start = time.perf_counter()
for i in range(args.iterations):
print(f"Iteration #{i+1}")
camera.clear_image_buffer()
phone.open_app()
camera.look_for_image()
elapsed_time = camera.timestamp - phone.start_timestamp
print(" Elapsed time:", elapsed_time)
if args.save:
results.write(f"{i+1}, {elapsed_time}\n")
time.sleep(0.5)
if args.type == "warm":
print(" Closing app\n")
phone.close_app()
else:
print(" Quitting app\n")
phone.quit_app()
# Stop main timer
main_timer_stop = time.perf_counter()
main_timer_duration = main_timer_stop - main_timer_start
print("Total time:", str(datetime.timedelta(seconds=main_timer_duration)))
# Close results file
if args.save:
results.close()
# When done, return to starting position
phone.go_to_start_position()
camera.clean_up()