pw_perf_test: Support overloaded functions in the simple macro

Switch to using a lambda for the PW_PERF_TEST_SIMPLE macro. That makes
it possible for the compiler to disambiguate between overloads of the
function under test, since it is called in the lambda.

Change-Id: Ifcc33708a1e3a7810ed95ef908991cbe7a94e3eb
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/125150
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Erik Gilling <konkers@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
diff --git a/pw_checksum/crc16_ccitt_perf_test.cc b/pw_checksum/crc16_ccitt_perf_test.cc
index c506ab4..0c6a01c 100644
--- a/pw_checksum/crc16_ccitt_perf_test.cc
+++ b/pw_checksum/crc16_ccitt_perf_test.cc
@@ -27,13 +27,10 @@
     "people very angry and been widely regarded as a bad move.";
 constexpr auto kBytes = bytes::Initialized<1000>([](size_t i) { return i; });
 
-void CcittCalculationTest(span<const std::byte> input) {
-  Crc16Ccitt::Calculate(input);
-}
+PW_PERF_TEST_SIMPLE(CcittCalculationBytes, Crc16Ccitt::Calculate, kBytes);
 
-PW_PERF_TEST_SIMPLE(CcittCalculationBytes, CcittCalculationTest, kBytes);
 PW_PERF_TEST_SIMPLE(CcittCalculationString,
-                    CcittCalculationTest,
+                    Crc16Ccitt::Calculate,
                     as_bytes(span(kString)));
 
 }  // namespace
diff --git a/pw_perf_test/perf_test_test.cc b/pw_perf_test/perf_test_test.cc
index 6c74e36..68bb10e 100644
--- a/pw_perf_test/perf_test_test.cc
+++ b/pw_perf_test/perf_test_test.cc
@@ -26,13 +26,19 @@
 // This function is intentionally left blank
 void SimpleFunction() {}
 
+void SimpleFunctionWithArgs(int, bool) {}
+
 namespace pw::perf_test {
 namespace {
 
-TEST(MacroTesting, RegisterTest) {
-  PW_PERF_TEST(TestingComponentRegistration, TestingFunction);
-  PW_PERF_TEST_SIMPLE(TestingSimpleRegistration, SimpleFunction);
-}
+PW_PERF_TEST(TestingComponentRegistration, TestingFunction);
+
+PW_PERF_TEST_SIMPLE(TestingSimpleRegistration, SimpleFunction);
+
+PW_PERF_TEST_SIMPLE(TestingSimpleRegistrationArgs,
+                    SimpleFunctionWithArgs,
+                    123,
+                    false);
 
 }  // namespace
 }  // namespace pw::perf_test
diff --git a/pw_perf_test/public/pw_perf_test/perf_test.h b/pw_perf_test/public/pw_perf_test/perf_test.h
index 1fff326..64f6e64 100644
--- a/pw_perf_test/public/pw_perf_test/perf_test.h
+++ b/pw_perf_test/public/pw_perf_test/perf_test.h
@@ -20,16 +20,25 @@
 #include "pw_perf_test/event_handler.h"
 #include "pw_perf_test/internal/duration_unit.h"
 #include "pw_perf_test/internal/timer.h"
+#include "pw_preprocessor/arguments.h"
 
-#define PW_PERF_TEST(Name, Function, ...)                  \
-  ::pw::perf_test::internal::TestInfo PwPerfTest_##Name(   \
-      #Name, [](::pw::perf_test::State& state) {           \
-        static_cast<void>(Function(state, ##__VA_ARGS__)); \
-      });                                                  \
-  static_assert(true, "Perftest calls must end with a semicolon")
+#define PW_PERF_TEST(name, function, ...)                             \
+  ::pw::perf_test::internal::TestInfo PwPerfTest_##name(              \
+      #name, [](::pw::perf_test::State& pw_perf_test_state) {         \
+        static_cast<void>(                                            \
+            function(pw_perf_test_state PW_COMMA_ARGS(__VA_ARGS__))); \
+      })
 
-#define PW_PERF_TEST_SIMPLE(name, /*function,*/...) \
-  PW_PERF_TEST(name, ::pw::perf_test::internal::RunSimpleFunction, __VA_ARGS__)
+#define PW_PERF_TEST_SIMPLE(name, function, ...)            \
+  PW_PERF_TEST(                                             \
+      name,                                                 \
+      [](::pw::perf_test::State& pw_perf_test_simple_state, \
+         const auto&... args) {                             \
+        while (pw_perf_test_simple_state.KeepRunning()) {   \
+          function(args...);                                \
+        }                                                   \
+      },                                                    \
+      __VA_ARGS__)
 
 namespace pw::perf_test {
 
@@ -163,19 +172,6 @@
   TestCase test_info;
 };
 
-namespace internal {
-
-template <typename Function, typename... Args>
-void RunSimpleFunction(::pw::perf_test::State& state,
-                       Function function,
-                       const Args&... args) {
-  while (state.KeepRunning()) {
-    static_cast<void>(function(args...));
-  }
-}
-
-}  // namespace internal
-
 void RunAllTests(pw::perf_test::EventHandler& handler);
 
 }  // namespace pw::perf_test