pw_unit_test: Support target specified main()

In particular, this allows implementing main() in the test itself.

Change-Id: Id65975880ce0084f0b1954de7dfde3e2cee0151d
diff --git a/pw_unit_test/docs.rst b/pw_unit_test/docs.rst
index 01632e7..a5c93b5 100644
--- a/pw_unit_test/docs.rst
+++ b/pw_unit_test/docs.rst
@@ -150,6 +150,9 @@
   ``pw_executable``.
 * ``enable_if``: Boolean indicating whether the test should be built. If false,
   replaces the test with an empty target. Default true.
+* ``test_main``: Target label to add to the tests's dependencies to provide the
+  ``main()`` function. Defaults to ``pw_unit_test_MAIN``. Set to ``""`` if
+  ``main()`` is implemented in the test's ``sources``.
 
 **Example**
 
diff --git a/pw_unit_test/test.gni b/pw_unit_test/test.gni
index d4d1e31..22e9e40 100644
--- a/pw_unit_test/test.gni
+++ b/pw_unit_test/test.gni
@@ -102,6 +102,11 @@
     _test_output_dir = invoker.output_dir
   }
 
+  _test_main = pw_unit_test_MAIN
+  if (defined(invoker.test_main)) {
+    _test_main = invoker.test_main
+  }
+
   _pw_disableable_target(_test_target_name) {
     target_type = "pw_executable"
     enable_if = _test_is_enabled
@@ -122,7 +127,9 @@
     if (!defined(deps)) {
       deps = []
     }
-    deps += [ pw_unit_test_MAIN ]
+    if (_test_main != "") {
+      deps += [ _test_main ]
+    }
 
     output_dir = _test_output_dir
   }