Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 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 | |
| 15 | import os |
| 16 | import os.path |
| 17 | import tempfile |
| 18 | import subprocess |
| 19 | import time |
| 20 | import sys |
| 21 | import its.device |
| 22 | |
| 23 | def main(): |
| 24 | """Run all the automated tests, saving intermediate files, and producing |
| 25 | a summary/report of the results. |
| 26 | |
| 27 | Script should be run from the top-level CameraITS directory. |
| 28 | """ |
| 29 | |
Yin-Chia Yeh | 665dda4 | 2014-10-20 11:23:48 -0700 | [diff] [blame^] | 30 | # Not yet mandated tests |
| 31 | NOT_YET_MANDATED = { |
| 32 | "scene0":[ |
| 33 | "test_jitter" |
| 34 | ], |
| 35 | "scene1":[ |
| 36 | "test_ae_precapture_trigger", |
| 37 | "test_black_white", |
| 38 | "test_burst_sameness_manual", |
| 39 | "test_crop_region_raw", |
| 40 | "test_crop_regions", |
| 41 | "test_exposure", |
| 42 | "test_locked_burst", |
| 43 | "test_param_exposure_time", |
| 44 | "test_param_flash_mode", |
| 45 | "test_yuv_plus_jpeg", |
| 46 | "test_yuv_plus_raw", |
| 47 | "test_yuv_plus_raw10" |
| 48 | ] |
| 49 | } |
| 50 | |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 51 | # Get all the scene0 and scene1 tests, which can be run using the same |
| 52 | # physical setup. |
| 53 | scenes = ["scene0", "scene1"] |
| 54 | tests = [] |
| 55 | for d in scenes: |
| 56 | tests += [(d,s[:-3],os.path.join("tests", d, s)) |
| 57 | for s in os.listdir(os.path.join("tests",d)) |
| 58 | if s[-3:] == ".py"] |
| 59 | tests.sort() |
| 60 | |
| 61 | # Make output directories to hold the generated files. |
| 62 | topdir = tempfile.mkdtemp() |
| 63 | for d in scenes: |
| 64 | os.mkdir(os.path.join(topdir, d)) |
| 65 | print "Saving output files to:", topdir, "\n" |
| 66 | |
| 67 | # Run each test, capturing stdout and stderr. |
| 68 | numpass = 0 |
Yin-Chia Yeh | 665dda4 | 2014-10-20 11:23:48 -0700 | [diff] [blame^] | 69 | numnotmandatedfail = 0 |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 70 | for (scene,testname,testpath) in tests: |
| 71 | cmd = ['python', os.path.join(os.getcwd(),testpath)] + sys.argv[1:] |
| 72 | outdir = os.path.join(topdir,scene) |
| 73 | outpath = os.path.join(outdir,testname+"_stdout.txt") |
| 74 | errpath = os.path.join(outdir,testname+"_stderr.txt") |
| 75 | t0 = time.time() |
| 76 | with open(outpath,"w") as fout, open(errpath,"w") as ferr: |
| 77 | retcode = subprocess.call(cmd,stderr=ferr,stdout=fout,cwd=outdir) |
| 78 | t1 = time.time() |
Yin-Chia Yeh | 665dda4 | 2014-10-20 11:23:48 -0700 | [diff] [blame^] | 79 | retstr = "PASS " |
| 80 | if retcode != 0: |
| 81 | retstr = "FAIL*" if testname in NOT_YET_MANDATED[scene] else "FAIL " |
| 82 | |
| 83 | if retstr == "FAIL*": |
| 84 | numnotmandatedfail += 1 |
| 85 | |
| 86 | print "%s %s/%s [%.1fs]" % (retstr, scene, testname, t1-t0) |
| 87 | if retcode == 0 or testname in NOT_YET_MANDATED[scene]: |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 88 | numpass += 1 |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 89 | |
| 90 | print "\n%d / %d tests passed (%.1f%%)" % ( |
| 91 | numpass, len(tests), 100.0*float(numpass)/len(tests)) |
Yin-Chia Yeh | 665dda4 | 2014-10-20 11:23:48 -0700 | [diff] [blame^] | 92 | if numnotmandatedfail > 0: |
| 93 | print "(*) tests are not yet mandated" |
| 94 | its.device.ItsSession.report_result(numpass == len(tests)) |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 95 | |
| 96 | if __name__ == '__main__': |
| 97 | main() |
| 98 | |