diff options
author | Andreas Antener <antener_a@gmx.ch> | 2015-02-02 16:53:12 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2015-02-10 08:39:46 +0100 |
commit | a73a095c1d6aba53edb47cbb7375c81261772e43 (patch) | |
tree | 981039688f28f7325021b48105b58a6ac29e377e | |
parent | f8ff5b617b75f74481ef8631205a51d62c971c34 (diff) | |
download | px4-firmware-a73a095c1d6aba53edb47cbb7375c81261772e43.tar.gz px4-firmware-a73a095c1d6aba53edb47cbb7375c81261772e43.tar.bz2 px4-firmware-a73a095c1d6aba53edb47cbb7375c81261772e43.zip |
added test and stub
-rw-r--r-- | src/modules/systemlib/param/param.c | 4 | ||||
-rw-r--r-- | unittests/CMakeLists.txt | 11 | ||||
-rw-r--r-- | unittests/param_test.cpp | 34 | ||||
-rw-r--r-- | unittests/stubs.cpp | 37 |
4 files changed, 86 insertions, 0 deletions
diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c index 94935d9c3..66dfed55c 100644 --- a/src/modules/systemlib/param/param.c +++ b/src/modules/systemlib/param/param.c @@ -200,10 +200,14 @@ param_notify_changes(void) param_t param_find(const char *name) { + warn("debug info count %i\n", param_count()); + warn("start: %i\n", __param_start); + param_t param; /* perform a linear search of the known parameters */ for (param = 0; handle_in_range(param); param++) { + warn("param find: %s", param_info_base[param].name); if (!strcmp(param_info_base[param].name, name)) return param; } diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index a87c23be2..3c5920738 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -77,3 +77,14 @@ add_gtest(st24_test) # sf0x_test add_executable(sf0x_test sf0x_test.cpp ${PX_SRC}/drivers/sf0x/sf0x_parser.cpp) add_gtest(sf0x_test) + +# param_test +add_executable(param_test param_test.cpp + hrt.cpp + stubs.cpp + ${PX_SRC}/modules/systemlib/visibility.h + ${PX_SRC}/modules/systemlib/param/param.c + ${PX_SRC}/modules/systemlib/bson/tinybson.c + ${PX_SRC}/drivers/drv_hrt.h + ) +add_gtest(param_test) diff --git a/unittests/param_test.cpp b/unittests/param_test.cpp new file mode 100644 index 000000000..d4c10acaf --- /dev/null +++ b/unittests/param_test.cpp @@ -0,0 +1,34 @@ +#include <systemlib/visibility.h> +#include <systemlib/param/param.h> + +#include "gtest/gtest.h" + +//#PARAM_DEFINE_INT32(TEST_A, 5); + +struct param_info_s test = { + "test", + PARAM_TYPE_INT32, + .val.i = 2 +}; + + + +extern param_info_s *__param_start, *__param_end; +const struct param_info_s *ib = __param_start; +const struct param_info_s *il = __param_end; + +TEST(ParamTest, ResetAll) { + printf("diff: %i\n", (unsigned)(il - ib)); + printf("start: %i\n", __param_start); + printf("end: %i\n", __param_end); + + param_t testparam = param_find("test"); + ASSERT_NE(PARAM_INVALID, testparam) << "param_find failed"; + + int32_t value; + int result = param_get(testparam, &value); + ASSERT_EQ(0, result) << "param_get failed"; + ASSERT_EQ(2, value) << "wrong param value"; + + ASSERT_TRUE(false) << "fail"; +} diff --git a/unittests/stubs.cpp b/unittests/stubs.cpp new file mode 100644 index 000000000..19415a83f --- /dev/null +++ b/unittests/stubs.cpp @@ -0,0 +1,37 @@ +#include <stdint.h> +#include <sys/types.h> +//#include "gmock/gmock.h" + +#include "uORB/uORB.h" +#include <systemlib/param/param.h> + +/****************************************** + * uORB stubs +******************************************/ + +/* +struct orb_metadata { + const char *o_name; + const size_t o_size; +}; +typedef intptr_t orb_advert_t; +extern orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data); +extern int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data); +*/ + +orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) { + return (orb_advert_t)0; +} + +int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) { + return 0; +} + +/****************************************** + * param stubs +******************************************/ + +//extern param_info_s * __param_start, __param_end; +struct param_info_s param_info_base[5]; +param_info_s *__param_start = ¶m_info_base[0]; +param_info_s *__param_end = ¶m_info_base[4]; |