cros_run_unit_tests: Option to filter input packages.

Add an option to skip testing on input packages which do not inherit
from cros-workon. If opts.installed will also skip tests on packages
which are not installed.

BUG=b:187795989
TEST=./run_tests
TEST=./cros_run_unit_tests --board eve --pretend --no-testable-packages-ok --packages 'sys-apps/keyutils' --filter-only-cros-workon

Change-Id: Iaa4cf049ae97478def42e579c3afcef29e101adc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2893696
Tested-by: Navil Perez <navil@google.com>
Commit-Queue: Navil Perez <navil@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_run_unit_tests.py b/scripts/cros_run_unit_tests.py
index 16bd61e..67a5d21 100644
--- a/scripts/cros_run_unit_tests.py
+++ b/scripts/cros_run_unit_tests.py
@@ -83,7 +83,13 @@
       default=False,
       action='store_true',
       dest='testable_packages_optional',
-      help="If specified, don't fail if no testable packages are found.")
+      help='If specified, do not fail if no testable packages are found.')
+  parser.add_argument(
+      '--filter-only-cros-workon',
+      default=False,
+      action='store_true',
+      help='If specified and packages are given, filters out non-cros_workon '
+      'packages.')
 
   options = parser.parse_args(argv)
   options.Freeze()
@@ -135,7 +141,8 @@
     logging.info('Skipping package %s.', cp)
 
   packages = packages - skipped_packages
-  pkg_with_test = portage_util.PackagesWithTest(sysroot, packages)
+  pkg_with_test = portage_util.PackagesWithTest(sysroot, packages,
+                                                opts.filter_only_cros_workon)
 
   if packages - pkg_with_test:
     logging.warning('The following packages do not have tests:\n  %s',