Enable run-libcore-tests.sh to test specific packages

Test: art/tools/run-libcore-tests.sh --mode=host -- libcore.java.lang
Change-Id: Iacb23abd4575b8c22fbc3119197bdda42a49e980
diff --git a/tools/run-libcore-tests.sh b/tools/run-libcore-tests.sh
index 9fa580b..7dea61e 100755
--- a/tools/run-libcore-tests.sh
+++ b/tools/run-libcore-tests.sh
@@ -59,7 +59,7 @@
   local me=$(basename "${BASH_SOURCE[0]}")
   (
     cat << EOF
-  Usage: ${me} --mode=<mode> [options]
+  Usage: ${me} --mode=<mode> [options] [-- <package_to_test> ...]
 
   Run libcore tests using the vogar testing tool.
 
@@ -74,6 +74,10 @@
 
   The script passes unrecognized options to the command-line created for vogar.
 
+  The script runs a hardcoded list of libcore test packages by default. The user
+  may run a subset of packages by appending '--' followed by a list of package
+  names.
+
   Examples:
 
     1. Run full test suite on host:
@@ -81,6 +85,9 @@
 
     2. Run full test suite on device:
       ${me} --mode=device
+
+    3. Run tests within libcore.java.lang package on device:
+      ${me} --mode=device -- libcore.java.lang
 EOF
   ) | sed -e 's/^  //' >&2 # Strip leading whitespace from heredoc.
 }
@@ -179,6 +186,12 @@
       vogar_args="$vogar_args $1"
       gcstress=true
       ;;
+    --)
+      shift
+      # Assume remaining elements are packages to test.
+      user_packages=("$@")
+      break
+      ;;
     --help)
       usage
       exit 1
@@ -260,7 +273,9 @@
     expectations="$expectations --expectations art/tools/libcore_gcstress_debug_failures.txt"
   fi
 else
-  # We only run this package when not under gcstress as it can cause timeouts. See b/78228743.
+  # We only run this package when user has not specified packages
+  # to run and not under gcstress as it can cause timeouts. See
+  # b/78228743.
   working_packages+=("libcore.libcore.icu")
 fi
 
@@ -276,6 +291,12 @@
   vogar_args="$vogar_args --no-color"
 fi
 
+# Override working_packages if user provided specific packages to
+# test.
+if [[ ${#user_packages[@]} != 0 ]] ; then
+  working_packages=("${user_packages[@]}")
+fi
+
 # Run the tests using vogar.
 echo "Running tests for the following test packages:"
 echo ${working_packages[@]} | tr " " "\n"