pw_unit_test: Create test running groups

Have pw_test_group create a *_run test group that runs all of the tests
in that group and dependent groups. This allows, for example, using
pw_module_tests_run to run all tests without rebuilding the docs.

Change-Id: I5b37129e94c1cc0f44085e02b0093848f1f8d249
diff --git a/BUILD.gn b/BUILD.gn
index e1c19e6..3543b67 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -12,6 +12,8 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+import("$dir_pw_unit_test/test.gni")
+
 # All Pigweed modules that can be built using gn.
 group("pw_modules") {
   deps = [
@@ -28,8 +30,8 @@
 }
 
 # Targets for all module unit test groups.
-group("pw_module_tests") {
-  deps = [
+pw_test_group("pw_module_tests") {
+  group_deps = [
     "$dir_pw_preprocessor:tests",
     "$dir_pw_span:tests",
     "$dir_pw_status:tests",
diff --git a/pw_unit_test/test.gni b/pw_unit_test/test.gni
index d40b97c..b55c22b 100644
--- a/pw_unit_test/test.gni
+++ b/pw_unit_test/test.gni
@@ -80,7 +80,11 @@
 template("pw_test_group") {
   _group_target = target_name
   _group_deps_metadata = []
-  _deps = invoker.tests
+  if (defined(invoker.tests)) {
+    _deps = invoker.tests
+  } else {
+    _deps = []
+  }
 
   if (defined(invoker.group_deps)) {
     # If the group specified any other group dependencies, create a metadata
@@ -113,7 +117,9 @@
       # the group dependencies group. This entry is listed as a "walk_key" in
       # the generated file so that only test targets' metadata (not group
       # targets) appear in the output.
-      propagate_metadata_from = invoker.tests
+      if (defined(invoker.tests)) {
+        propagate_metadata_from = invoker.tests
+      }
     }
     deps = _deps
   }
@@ -133,4 +139,17 @@
     output_conversion = "json"
     deps = _test_group_deps
   }
+
+  # If automatic test running is enabled, create a *_run group that collects all
+  # of the individual *_run targets and groups.
+  if (pw_automatic_test_runner != "") {
+    group(_group_target + "_run") {
+      deps = [
+        ":$_group_target",
+      ]
+      foreach(_target, _deps) {
+        deps += [ "${_target}_run" ]
+      }
+    }
+  }
 }