OSDN Git Service

Host test script should return 1 when build fails or test is missing
authorJack He <siyuanh@google.com>
Wed, 25 Oct 2017 17:14:53 +0000 (10:14 -0700)
committerJack He <siyuanh@google.com>
Wed, 25 Oct 2017 17:27:40 +0000 (10:27 -0700)
* test/run_host_unit_tests.py returns 1 when
  - Build environement could not be setup
  - Build fails
  - Test could not be found
* It returns 0 when
  - Test exists, but failed
  - All tests pass

Bug: 64687730
Test: ./test/run_host_unit_tests.py -j40
Change-Id: Idbff0c73a219b5ce7b640f44f41caf43030e2b51

test/run_host_unit_tests.py

index 536ad21..e5e392c 100755 (executable)
@@ -77,7 +77,7 @@ def get_android_root_or_die():
         current_path = parent_path
     if not value:
       print 'Cannot determine ANDROID_BUILD_TOP'
-      sys.exit(0)
+      sys.exit(1)
   check_dir_exists(value, '$ANDROID_BUILD_TOP')
   return value
 
@@ -93,7 +93,7 @@ def get_android_host_out_or_die():
                                      'HOST_OUT'))
     if not value:
       print 'Cannot determine ANDROID_HOST_OUT'
-      sys.exit(0)
+      sys.exit(1)
   check_dir_exists(value, '$ANDROID_HOST_OUT')
   return value
 
@@ -108,7 +108,7 @@ def get_android_dist_dir_or_die():
   if not os.path.isdir(value):
     if os.path.exists(value):
       print '%s is not a directory!' % (value)
-      sys.exit(0)
+      sys.exit(1)
     os.makedirs(value)
   return value
 
@@ -121,7 +121,7 @@ def get_native_test_root_or_die():
     if not os.path.isdir(test_root):
       print 'Neither nativetest64 nor nativetest directory exist,' \
             ' please compile first'
-      sys.exit(0)
+      sys.exit(1)
   return test_root
 
 
@@ -129,7 +129,7 @@ def get_test_cmd_or_die(test_root, test_name, enable_xml, test_filter):
   test_path = os.path.join(os.path.join(test_root, test_name), test_name)
   if not os.path.isfile(test_path):
     print 'Cannot find: ' + test_path
-    return None
+    sys.exit(1)
   cmd = [test_path]
   if enable_xml:
     dist_dir = get_android_dist_dir_or_die()
@@ -149,9 +149,10 @@ def build_target(target, num_tasks):
     build_cmd.append('-j' + str(num_tasks))
   build_cmd.append(target)
   p = subprocess.Popen(build_cmd, cwd=ANDROID_BUILD_TOP, env=os.environ.copy())
-  if p.wait() != 0:
-    print 'BUILD FAILED'
-    sys.exit(0)
+  return_code = p.wait()
+  if return_code != 0:
+    print 'BUILD FAILED, return code: {0}'.format(str(return_code))
+    sys.exit(1)
   return
 
 
@@ -187,9 +188,6 @@ def main():
   test_results = []
   for test in HOST_TESTS:
     test_cmd = get_test_cmd_or_die(TEST_ROOT, test, args.enable_xml, args.rest)
-    if not test_cmd:
-      test_results.append(False)
-      continue
     if subprocess.call(test_cmd) != 0:
       test_results.append(False)
     else: