test: Add unit tests for native_sim
Run the tests by going into the hello_dtsexample directory, then running
the bazel test command.
BUG=b/346596832
Change-Id: I13a481ade6526b1085e01b8a5e8358c76e70836d
Reviewed-on: https://pigweed-review.googlesource.com/c/zephyr/zephyr-bazel/+/223459
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Yuval Peress <peress@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Pigweed-Auto-Submit: Yuval Peress <peress@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Sergio Soares <sergiosoares@google.com>
diff --git a/README.md b/README.md
index dddbd08..356c1a1 100644
--- a/README.md
+++ b/README.md
@@ -106,3 +106,19 @@
}),
)
```
+
+Examples
+========
+There is currently just 1 example, you can run it via:
+
+```
+$ cd examples/hello_dts
+$ bazel run :app
+```
+
+Or, you can run the tests via:
+
+```
+$ cd examples/hello_dts
+$ bazel test //...
+```
diff --git a/examples/hello_dts/BUILD.bazel b/examples/hello_dts/BUILD.bazel
index 2807542..277b90a 100644
--- a/examples/hello_dts/BUILD.bazel
+++ b/examples/hello_dts/BUILD.bazel
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations under
# the License.
+load("@pigweed//pw_build:pigweed.bzl", "pw_cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@zephyr//:defs.bzl", "dts_cc_library")
@@ -41,11 +42,11 @@
"@platforms//cpu:x86_64": "@bazel_tools//tools/cpp:malloc",
}),
deps = [
- "@pigweed//pw_log",
- "@pigweed//pw_sys_io",
"@pigweed//pw_assert:backend_impl",
+ "@pigweed//pw_log",
"@pigweed//pw_log:backend_impl",
- "@zephyr//:zephyr",
+ "@pigweed//pw_sys_io",
+ "@zephyr",
] + select({
"@platforms//cpu:armv7e-m": [
"@pigweed//pw_toolchain/arm_gcc:arm_none_eabi_gcc_support",
@@ -53,8 +54,23 @@
"@pigweed//targets/stm32f429i_disc1:pre_init",
],
"@platforms//cpu:x86_64": [
- "@zephyr//include:posix",
":app_host_dts",
+ "@zephyr//include:posix",
],
}),
)
+
+pw_cc_test(
+ name = "test",
+ srcs = [
+ "native_sim_test.cc",
+ ],
+ deps = [
+ ":app_host_dts",
+ "@zephyr",
+ "@zephyr//include:posix",
+ ],
+ copts = [
+ "-DCONFIG_ARCH_POSIX=1",
+ ],
+)
diff --git a/examples/hello_dts/native_sim_test.cc b/examples/hello_dts/native_sim_test.cc
new file mode 100644
index 0000000..f40b4a8
--- /dev/null
+++ b/examples/hello_dts/native_sim_test.cc
@@ -0,0 +1,18 @@
+#include <cstring>
+
+#include "pw_unit_test/framework.h"
+#include "zephyr/devicetree.h"
+
+namespace {
+
+TEST(Dts, RootCompatibleIsZephyrPosix) {
+ const char *compatible = DT_PROP(DT_ROOT, compatible);
+ EXPECT_STREQ("zephyr,posix", compatible);
+}
+
+TEST(Dts, Cpu0IsNativePosix) {
+ const char *compatible = DT_PROP(DT_NODELABEL(cpu0), compatible);
+ EXPECT_STREQ("zephyr,native-posix-cpu", compatible);
+}
+
+} // namespace
\ No newline at end of file