Add test example
Change-Id: I6e6f37c8eeb21bc3d7280fd8023cfb75ce1cbfd7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/quickstart/bazel/+/210631
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Keir Mierle <keir@google.com>
diff --git a/src/BUILD.bazel b/src/BUILD.bazel
index 0f3e201..aee40f8 100644
--- a/src/BUILD.bazel
+++ b/src/BUILD.bazel
@@ -13,6 +13,11 @@
# the License.
load("//:echo.bzl", "stm32_cc_binary")
+load(
+ "@pigweed//pw_build:pigweed.bzl",
+ "pw_cc_test",
+)
+
package(default_visibility = ["//visibility:public"])
cc_binary(
@@ -40,3 +45,25 @@
name = "echo.elf",
binary = ":echo",
)
+
+cc_library(
+ name = "multiply",
+ hdrs = ["multiply.h"],
+ srcs = ["multiply.cc"],
+)
+
+# Note: Must use pw_cc_test instead of cc_test to enable on-device execution.
+# See http://pigweed.dev/bazel#pw_cc_test for more details.
+pw_cc_test(
+ name = "multiply_test",
+ srcs = ["multiply_test.cc"],
+ deps = [
+ ":multiply",
+ ]
+)
+
+stm32_cc_binary(
+ name = "multiply_test.elf",
+ binary = ":multiply_test",
+ testonly = True,
+)
diff --git a/src/multiply.cc b/src/multiply.cc
new file mode 100644
index 0000000..b1f6871
--- /dev/null
+++ b/src/multiply.cc
@@ -0,0 +1,17 @@
+// Copyright 2024 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+int Multiply(int a, int b) {
+ return a * b;
+}
diff --git a/src/multiply.h b/src/multiply.h
new file mode 100644
index 0000000..3a7115a
--- /dev/null
+++ b/src/multiply.h
@@ -0,0 +1,16 @@
+// Copyright 2024 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// Demonstration function; multiplies a and b, returns result.
+int Multiply(int a, int b);
diff --git a/src/multiply_test.cc b/src/multiply_test.cc
new file mode 100644
index 0000000..81a548b
--- /dev/null
+++ b/src/multiply_test.cc
@@ -0,0 +1,26 @@
+// Copyright 2024 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// Note: Bazel/monorepo style include path, not Pigweed style.
+#include "src/multiply.h"
+
+#include "pw_unit_test/framework.h"
+
+namespace {
+
+TEST(Multiply, TwoTimesThreeIsSix) {
+ ASSERT_EQ(Multiply(2, 3), 6);
+}
+
+} // namespace