Name | Updated at | |
---|---|---|
common | ||
simulation | ||
README.md | ||
test.mk |
The framework aims to provide an environment to test CHRE (and its users) code on-device, using Pigweed's Unit Test Framework. Test instantiations are syntactically identical to Googletest, so modifications to on-host unit tests to run on-device are easier.
CHRE recommends running the same host-side gtests on-device using this framework, to catch subtle bugs. For example, the target CPU may raise an exception on unaligned access, when the same code would run without any problems on a local x86-based machine.
One key difference is to run the tests via a call to chre::runAllTests
in
chre/test/common/unit_test.h, which basically wraps the gtest RUN_ALL_TESTS
macro, and implements CHRE specific event handlers for Pigweed's UT Framework.
Under the current incarnation of the CHRE Unit Test Framework, the following steps need to be taken to run the on-device tests:
CHRE_ON_DEVICE_TESTS_ENABLED
from your Makefile invocation before CHRE is built.COMMON_SRCS
either in test/test.mk or in
your own Makefile.chre::runAllTests
from somewhere in your code.In math_test.cc
#include <gtest/gtest.h>
TEST(MyMath, Add) {
int x = 1, y = 2;
int result = myAdd(x, y);
EXPECT_EQ(result, 3);
}
In some_source.cc
#include "chre/test/common/unit_test.h"
void utEntryFunc() {
chre::runAllTests();
}
Some advanced features of gtest (SCOPED_TRACE, etc.) are unsupported by Pigweed.
The framework has been tested with Pigweed's git revision ee460238