import os
import sys
import argparse
+import subprocess
def get_parsed_options():
parser.add_argument(
"--runall",
action="store_true",
- type=str,
dest="runall",
+ default=False,
help="run all unittest and ignore skiplist")
options = parser.parse_args()
return options
-def get_gtest_option(report_dir, test_bin, unittest_dir):
+def get_gtest_option(report_dir, test_bin, unittest_dir=None):
# 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 to run only one unit test, for runall unittest
+ if '.' in test_bin:
+ return output_option + " " + "--gtest_filter={test_list_item}".format(
+ test_list_item=test_bin)
+
# Set filter not to run *.skip unit tests
filter_option = ""
skiplist_path = "{unittest_dir}/{test_bin}.skip".format(
return output_option + " " + filter_option
+def get_test_list_items(unittest_dir, test_bin):
+ cmd_output = subprocess.check_output(
+ "{unittestdir}/{testbin} --gtest_list_tests".format(
+ unittestdir=unittest_dir, testbin=test_bin),
+ shell=True)
+ all_test_list = str(cmd_output).replace('\\n', ' ').split()
+ all_test_list[0] = all_test_list[0][2:]
+
+ category = ""
+ item = ""
+ test_list_items = []
+ for verbose_line in all_test_list:
+ if verbose_line[-1] == '.':
+ category = verbose_line
+ else:
+ item = "{category}{verbose_line}".format(
+ category=category, verbose_line=verbose_line)
+ test_list_items.append(item)
+
+ return test_list_items
+
+
# Just call this function when running unit test in test_driver.py
def run_unittest(unittest_dir, report_dir, ldlibrary_path, runall):
if unittest_dir == "" or unittest_dir == None:
print("Unittest start")
print("============================================")
- # Run all unit tests in unittest_dir except *.skip test bin
+ # Run all unit tests in unittest_dir
unittest_result = 0
all_test_bin = (t for t in os.listdir(unittest_dir)
if len(t) < 5 or t[-5:] != ".skip")
- if runall:
- # TODO: run all unittest using --gtest_list_tests option
- sys.exit(0)
-
for idx, test_bin in enumerate(all_test_bin):
num_unittest = idx + 1
print("============================================")
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)
+ ret = 0
+
+ # Run all unit tests ignoring skip list
+ if runall:
+ test_list_items = get_test_list_items(unittest_dir, test_bin)
+ for test_item in test_list_items:
+ cmd = "{unittest_dir}/{test_bin} {gtest_option}".format(
+ unittest_dir=unittest_dir,
+ test_bin=test_bin,
+ gtest_option=get_gtest_option(report_dir, test_item))
+ result = os.system(cmd)
+ if result != 0:
+ ret = result
+ # Run all unit tests except skip list
+ else:
+ 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
echo "============================================"
num_unittest=0
+for TEST_BIN in `ls $UNITTEST_TEST_DIR --hide=*.skip`; do
+ num_unittest=$((num_unittest+1))
+ echo "============================================"
+ echo "Starting set $num_unittest: $TEST_BIN..."
+ echo "============================================"
+ TEMP_UNITTEST_RESULT=0
-if [ "$UNITTEST_RUN_ALL" == "true" ]; then
-
- TEST_LIST_CATEGORY=""
- TEST_LIST_ITEM=""
-
- for TEST_BIN in `ls $UNITTEST_TEST_DIR --hide=*.skip`; do
+ if [ "$UNITTEST_RUN_ALL" == "true" ]; then
for TEST_LIST_VERBOSE_LINE in $($UNITTEST_TEST_DIR/$TEST_BIN --gtest_list_tests); do
if [[ $TEST_LIST_VERBOSE_LINE == *\. ]]; then
TEST_LIST_CATEGORY=$TEST_LIST_VERBOSE_LINE
else
TEST_LIST_ITEM="$TEST_LIST_CATEGORY""$TEST_LIST_VERBOSE_LINE"
$UNITTEST_TEST_DIR/$TEST_BIN --gtest_filter=$TEST_LIST_ITEM --gtest_output="xml:$UNITTEST_REPORT_DIR/$TEST_LIST_ITEM.xml"
+ ONE_UNITTEST_RESULT=$?
+ if [[ $ONE_UNITTEST_RESULT -ne 0 ]]; then
+ TEMP_UNITTEST_RESULT=$ONE_UNITTEST_RESULT
+ fi
fi
done
- done
-
- exit 0
-fi
-
-for TEST_BIN in `ls $UNITTEST_TEST_DIR --hide=*.skip`; do
- num_unittest=$((num_unittest+1))
- echo "============================================"
- echo "Starting set $num_unittest: $TEST_BIN..."
- echo "============================================"
- $UNITTEST_TEST_DIR/$TEST_BIN $(get_gtest_option)
- TEMP_UNITTEST_RESULT=$?
+ else
+ $UNITTEST_TEST_DIR/$TEST_BIN $(get_gtest_option)
+ TEMP_UNITTEST_RESULT=$?
+ fi
+
if [[ $TEMP_UNITTEST_RESULT -ne 0 ]]; then
UNITTEST_RESULT=$TEMP_UNITTEST_RESULT
- echo "$TEST_BIN failed... return code: $UNITTEST_RESULT"
+ echo "$TEST_BIN failed... return code: $TEMP_UNITTEST_RESULT"
fi
echo "============================================"
echo "Finishing set $num_unittest: $TEST_BIN..."