1# 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 21 22def main(): 23 """Run all the automated tests, saving intermediate files, and producing 24 a summary/report of the results. 25 26 Script should be run from the top-level CameraITS directory. 27 """ 28 29 # Get all the scene0 and scene1 tests, which can be run using the same 30 # physical setup. 31 scenes = ["scene0", "scene1"] 32 tests = [] 33 for d in scenes: 34 tests += [(d,s[:-3],os.path.join("tests", d, s)) 35 for s in os.listdir(os.path.join("tests",d)) 36 if s[-3:] == ".py"] 37 tests.sort() 38 39 # Make output directories to hold the generated files. 40 topdir = tempfile.mkdtemp() 41 for d in scenes: 42 os.mkdir(os.path.join(topdir, d)) 43 print "Saving output files to:", topdir, "\n" 44 45 # Run each test, capturing stdout and stderr. 46 numpass = 0 47 for (scene,testname,testpath) in tests: 48 cmd = ['python', os.path.join(os.getcwd(),testpath)] + sys.argv[1:] 49 outdir = os.path.join(topdir,scene) 50 outpath = os.path.join(outdir,testname+"_stdout.txt") 51 errpath = os.path.join(outdir,testname+"_stderr.txt") 52 t0 = time.time() 53 with open(outpath,"w") as fout, open(errpath,"w") as ferr: 54 retcode = subprocess.call(cmd,stderr=ferr,stdout=fout,cwd=outdir) 55 t1 = time.time() 56 print "%s %s/%s [%.1fs]" % ( 57 "PASS" if retcode==0 else "FAIL", scene, testname, t1-t0) 58 if retcode == 0: 59 numpass += 1 60 61 print "\n%d / %d tests passed (%.1f%%)" % ( 62 numpass, len(tests), 100.0*float(numpass)/len(tests)) 63 64if __name__ == '__main__': 65 main() 66 67