blob: c065f1246779720c7751d76de6e428f6888c72e9 [file] [log] [blame]
Ruben Brunk370e2432014-10-14 18:33:23 -07001# Copyright 2014 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import os.path
17import tempfile
18import subprocess
19import time
20import sys
Yin-Chia Yehab98ada2015-03-05 13:28:53 -080021import textwrap
Ruben Brunk370e2432014-10-14 18:33:23 -070022import its.device
23
24def main():
25 """Run all the automated tests, saving intermediate files, and producing
26 a summary/report of the results.
27
28 Script should be run from the top-level CameraITS directory.
29 """
30
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -070031 SKIP_RET_CODE = 101
32
Yin-Chia Yeh665dda42014-10-20 11:23:48 -070033 # Not yet mandated tests
34 NOT_YET_MANDATED = {
35 "scene0":[
36 "test_jitter"
37 ],
38 "scene1":[
39 "test_ae_precapture_trigger",
Yin-Chia Yeh665dda42014-10-20 11:23:48 -070040 "test_crop_region_raw",
Zhijun He6137f212014-11-20 13:47:11 -080041 "test_ev_compensation_advanced",
42 "test_ev_compensation_basic",
Yin-Chia Yeh3b1763a2014-10-22 10:59:13 -070043 "test_yuv_plus_jpeg"
Yin-Chia Yeh0e0276f2015-06-03 15:27:06 -070044 ],
45 "scene2":[]
Yin-Chia Yeh665dda42014-10-20 11:23:48 -070046 }
47
Ruben Brunk370e2432014-10-14 18:33:23 -070048 # Get all the scene0 and scene1 tests, which can be run using the same
49 # physical setup.
Yin-Chia Yeh0e0276f2015-06-03 15:27:06 -070050 scenes = ["scene0", "scene1", "scene2"]
51 scene_req = {
52 "scene0" : None,
53 "scene1" : "A grey card covering at least the middle 30% of the scene",
54 "scene2" : "A picture containing human faces"
55 }
Ruben Brunk370e2432014-10-14 18:33:23 -070056 tests = []
57 for d in scenes:
58 tests += [(d,s[:-3],os.path.join("tests", d, s))
59 for s in os.listdir(os.path.join("tests",d))
60 if s[-3:] == ".py"]
61 tests.sort()
62
63 # Make output directories to hold the generated files.
64 topdir = tempfile.mkdtemp()
Ruben Brunk370e2432014-10-14 18:33:23 -070065 print "Saving output files to:", topdir, "\n"
66
Yin-Chia Yehab98ada2015-03-05 13:28:53 -080067 camera_ids = []
Yin-Chia Yeha2277d02014-10-20 15:50:23 -070068 for s in sys.argv[1:]:
69 if s[:7] == "camera=" and len(s) > 7:
Yin-Chia Yehab98ada2015-03-05 13:28:53 -080070 camera_ids.append(s[7:])
Yin-Chia Yeha2277d02014-10-20 15:50:23 -070071
Yin-Chia Yehab98ada2015-03-05 13:28:53 -080072 # user doesn't specify camera id, run through all cameras
73 if not camera_ids:
74 camera_ids_path = os.path.join(topdir, "camera_ids.txt")
75 out_arg = "out=" + camera_ids_path
76 cmd = ['python',
77 os.path.join(os.getcwd(),"tools/get_camera_ids.py"), out_arg]
78 retcode = subprocess.call(cmd,cwd=topdir)
79 assert(retcode == 0)
80 with open(camera_ids_path, "r") as f:
81 for line in f:
82 camera_ids.append(line.replace('\n', ''))
Yin-Chia Yeh665dda42014-10-20 11:23:48 -070083
Yin-Chia Yehab98ada2015-03-05 13:28:53 -080084 print "Running ITS on the following cameras:", camera_ids
85
86 for camera_id in camera_ids:
87 # Loop capturing images until user confirm test scene is correct
88 camera_id_arg = "camera=" + camera_id
89 print "Preparing to run ITS on camera", camera_id
90
91 os.mkdir(os.path.join(topdir, camera_id))
92 for d in scenes:
93 os.mkdir(os.path.join(topdir, camera_id, d))
94
Yin-Chia Yehab98ada2015-03-05 13:28:53 -080095 print "Start running ITS on camera: ", camera_id
96 # Run each test, capturing stdout and stderr.
97 summary = "ITS test result summary for camera " + camera_id + "\n"
98 numpass = 0
99 numskip = 0
100 numnotmandatedfail = 0
101 numfail = 0
102
Yin-Chia Yeh0e0276f2015-06-03 15:27:06 -0700103 prev_scene = ""
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800104 for (scene,testname,testpath) in tests:
Yin-Chia Yeh0e0276f2015-06-03 15:27:06 -0700105 if scene != prev_scene and scene_req[scene] != None:
106 out_path = os.path.join(topdir, camera_id, scene+".jpg")
107 out_arg = "out=" + out_path
108 scene_arg = "scene=" + scene_req[scene]
109 cmd = ['python',
110 os.path.join(os.getcwd(),"tools/validate_scene.py"),
111 camera_id_arg, out_arg, scene_arg]
112 retcode = subprocess.call(cmd,cwd=topdir)
113 assert(retcode == 0)
114 print "Start running tests for", scene
115 prev_scene = scene
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800116 cmd = ['python', os.path.join(os.getcwd(),testpath)] + \
117 sys.argv[1:] + [camera_id_arg]
118 outdir = os.path.join(topdir,camera_id,scene)
119 outpath = os.path.join(outdir,testname+"_stdout.txt")
120 errpath = os.path.join(outdir,testname+"_stderr.txt")
121 t0 = time.time()
122 with open(outpath,"w") as fout, open(errpath,"w") as ferr:
123 retcode = subprocess.call(cmd,stderr=ferr,stdout=fout,cwd=outdir)
124 t1 = time.time()
125
126 if retcode == 0:
127 retstr = "PASS "
128 numpass += 1
129 elif retcode == SKIP_RET_CODE:
130 retstr = "SKIP "
131 numskip += 1
132 elif retcode != 0 and testname in NOT_YET_MANDATED[scene]:
133 retstr = "FAIL*"
134 numnotmandatedfail += 1
135 else:
136 retstr = "FAIL "
137 numfail += 1
138
139 msg = "%s %s/%s [%.1fs]" % (retstr, scene, testname, t1-t0)
140 print msg
141 summary += msg + "\n"
142 if retcode != 0 and retcode != SKIP_RET_CODE:
143 # Dump the stderr if the test fails
144 with open (errpath, "r") as error_file:
145 errors = error_file.read()
146 summary += errors + "\n"
147
148 if numskip > 0:
149 skipstr = ", %d test%s skipped" % (numskip, "s" if numskip > 1 else "")
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -0700150 else:
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800151 skipstr = ""
Yin-Chia Yeh665dda42014-10-20 11:23:48 -0700152
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800153 test_result = "\n%d / %d tests passed (%.1f%%)%s" % (
154 numpass + numnotmandatedfail, len(tests) - numskip,
155 100.0 * float(numpass + numnotmandatedfail) / (len(tests) - numskip)
156 if len(tests) != numskip else 100.0,
157 skipstr)
158 print test_result
159 summary += test_result + "\n"
Ruben Brunk370e2432014-10-14 18:33:23 -0700160
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800161 if numnotmandatedfail > 0:
162 msg = "(*) tests are not yet mandated"
163 print msg
164 summary += msg + "\n"
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -0700165
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800166 result = numfail == 0
167 print "Reporting ITS result to CtsVerifier"
168 summary_path = os.path.join(topdir, camera_id, "summary.txt")
169 with open(summary_path, "w") as f:
170 f.write(summary)
171 its.device.report_result(camera_id, result, summary_path)
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -0700172
Yin-Chia Yehab98ada2015-03-05 13:28:53 -0800173 print "ITS tests finished. Please go back to CtsVerifier and proceed"
Ruben Brunk370e2432014-10-14 18:33:23 -0700174
175if __name__ == '__main__':
176 main()