From c459054007dee9478bf8f1c127975926ffc98caf Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=82=A8=EA=B6=81=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Mon, 30 Jul 2018 13:27:49 +0900 Subject: [PATCH] Add python script of run_unittest (#2050) Parent Issue : #1896 Working Issue : #1019 This commit will add python script of run_unittest Signed-off-by: Seok NamKoong --- tools/test_driver/py/run_unittest.py | 136 +++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 tools/test_driver/py/run_unittest.py diff --git a/tools/test_driver/py/run_unittest.py b/tools/test_driver/py/run_unittest.py new file mode 100755 index 0000000..625dd35 --- /dev/null +++ b/tools/test_driver/py/run_unittest.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python + +# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse + + +def get_parsed_options(): + parser = argparse.ArgumentParser(prog='run_unittest.py', usage='%(prog)s [options]') + + parser.add_argument( + "--reportdir", + action="store", + type=str, + dest="reportdir", + default="report", + help="(default=report) directory that each test result will be stored") + + parser.add_argument( + "--unittestdir", + action="store", + type=str, + dest="unittestdir", + required=True, + help="directory that unittests are included") + + parser.add_argument( + "--ldlibrarypath", + action="store", + type=str, + dest="ldlibrarypath", + help= + "(usually : ARTIFACT_PATH/Product/out/lib) path that you want to include libraries" + ) + + options = parser.parse_args() + return options + + +def get_gtest_option(report_dir, test_bin, unittest_dir): + # Set path to save test result + output_option = "--gtest_output=xml:{report_dir}/{test_bin}.xml".format( + report_dir=report_dir, test_bin=test_bin) + + # Set filter not to run *.skip unit tests + filter_option = "" + skiplist_path = "{unittest_dir}/{test_bin}.skip".format( + unittest_dir=unittest_dir, test_bin=test_bin) + if os.path.exists(skiplist_path): + filter_option = "--gtest_filter=-" + skiplist_file = open(skiplist_path, "r") + filter_option = filter_option + ':'.join(line[:-1] for line in skiplist_file + if line[0] != '#') + skiplist_file.close() + + return output_option + " " + filter_option + + +# Just call this function when running unit test in test_driver.py +def run_unittest(unittest_dir, report_dir, ldlibrary_path): + if unittest_dir == "" or unittest_dir == None: + print("Fail : unittestdir is not given") + print("(Usually unit test directory is Product/out/unittest)") + sys.exit(1) + + if report_dir == "" or report_dir == None: + print("Info : 'report' folder of current path will be used as report directory") + report_dir = "report" + + if type(ldlibrary_path) is str and ldlibrary_path != "": + os.environ["LD_LIBRARY_PATH"] = ldlibrary_path + + print("") + print("============================================") + print("Unittest start") + print("============================================") + + # Run all unit tests in unittest_dir except *.skip test bin + unittest_result = 0 + all_test_bin = (t for t in os.listdir(unittest_dir) + if len(t) < 5 or t[-5:] != ".skip") + for idx, test_bin in enumerate(all_test_bin): + num_unittest = idx + 1 + print("============================================") + print("Starting set {num_unittest}: {test_bin}...".format( + num_unittest=num_unittest, test_bin=test_bin)) + print("============================================") + + cmd = "{unittest_dir}/{test_bin} {gtest_option}".format( + unittest_dir=unittest_dir, + test_bin=test_bin, + gtest_option=get_gtest_option(report_dir, test_bin, unittest_dir)) + ret = os.system(cmd) + + if ret != 0: + unittest_result = ret + print("{test_bin} failed... return code: {unittest_result}".format( + test_bin=test_bin, unittest_result=unittest_result)) + + print("============================================") + print("Finishing set {num_unittest}: {test_bin}...".format( + num_unittest=num_unittest, test_bin=test_bin)) + print("============================================") + + if unittest_result != 0: + print("============================================") + print("Failed unit test... exit code: {unittest_result}".format( + unittest_result=unittest_result)) + print("============================================") + sys.exit(1) + + print("============================================") + print("Completed total {num_unittest} set of unittest".format( + num_unittest=num_unittest)) + print("Unittest end") + print("============================================") + sys.exit(0) + + +if __name__ == "__main__": + options = get_parsed_options() + sys.exit(run_unittest(options.unittestdir, options.reportdir, options.ldlibrarypath)) -- 2.7.4