forked from Archive/PX4-Autopilot
added unit test directive to switch out parameter storage
This commit is contained in:
parent
13039f9e69
commit
5cccc01cd4
|
@ -70,9 +70,16 @@
|
|||
/**
|
||||
* Array of static parameter info.
|
||||
*/
|
||||
struct param_info_s param_array[2];
|
||||
static const struct param_info_s *param_info_base = (struct param_info_s *) ¶m_array[0];
|
||||
static const struct param_info_s *param_info_limit = (struct param_info_s *) ¶m_array[1];
|
||||
#ifdef _UNIT_TEST
|
||||
extern struct param_info_s param_array[];
|
||||
extern struct param_info_s *param_info_base;
|
||||
extern struct param_info_s *param_info_limit;
|
||||
#else
|
||||
extern char __param_start, __param_end;
|
||||
static const struct param_info_s *param_info_base = (struct param_info_s *) &__param_start;
|
||||
static const struct param_info_s *param_info_limit = (struct param_info_s *) &__param_end;
|
||||
#endif
|
||||
|
||||
#define param_info_count ((unsigned)(param_info_limit - param_info_base))
|
||||
|
||||
/**
|
||||
|
@ -200,14 +207,10 @@ 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;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ add_definitions(-Dnoreturn_function=)
|
|||
add_definitions(-Dmain_t=int)
|
||||
add_definitions(-DERROR=-1)
|
||||
add_definitions(-DOK=0)
|
||||
add_definitions(-D_UNIT_TEST=)
|
||||
|
||||
# check
|
||||
add_custom_target(unittests COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
|
||||
|
@ -81,10 +82,8 @@ add_gtest(sf0x_test)
|
|||
# param_test
|
||||
add_executable(param_test param_test.cpp
|
||||
hrt.cpp
|
||||
stubs.cpp
|
||||
${PX_SRC}/modules/systemlib/visibility.h
|
||||
uorb_stub.cpp
|
||||
${PX_SRC}/modules/systemlib/param/param.c
|
||||
${PX_SRC}/modules/systemlib/bson/tinybson.c
|
||||
${PX_SRC}/drivers/drv_hrt.h
|
||||
)
|
||||
add_gtest(param_test)
|
||||
|
|
|
@ -3,33 +3,28 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
//#PARAM_DEFINE_INT32(TEST_A, 5);
|
||||
|
||||
|
||||
static const struct param_info_s testparam = {
|
||||
"test",
|
||||
static const struct param_info_s test_1 = {
|
||||
"TEST_1",
|
||||
PARAM_TYPE_INT32,
|
||||
.val.i = 2
|
||||
};
|
||||
|
||||
|
||||
extern param_info_s *__param_start, *__param_end;
|
||||
extern struct param_info_s param_array[];
|
||||
const struct param_info_s *ib = __param_start;
|
||||
const struct param_info_s *il = __param_end;
|
||||
struct param_info_s param_array[256];
|
||||
struct param_info_s *param_info_base;
|
||||
struct param_info_s *param_info_limit;
|
||||
|
||||
TEST(ParamTest, ResetAll) {
|
||||
param_array[0] = testparam;
|
||||
param_array[0] = test_1;
|
||||
param_info_base = (struct param_info_s *) ¶m_array[0];
|
||||
param_info_limit = (struct param_info_s *) ¶m_array[1];
|
||||
|
||||
printf("diff: %i\n", (unsigned)(il - ib));
|
||||
printf("start: %i\n", __param_start);
|
||||
printf("end: %i\n", __param_end);
|
||||
printf("diff: %i\n", (unsigned)(param_info_limit - param_info_base));
|
||||
|
||||
param_t testparam = param_find("test");
|
||||
ASSERT_NE(PARAM_INVALID, testparam) << "param_find failed";
|
||||
param_t test_1 = param_find("TEST_1");
|
||||
ASSERT_NE(PARAM_INVALID, test_1) << "param_find failed";
|
||||
|
||||
int32_t value;
|
||||
int result = param_get(testparam, &value);
|
||||
int result = param_get(test_1, &value);
|
||||
ASSERT_EQ(0, result) << "param_get failed";
|
||||
ASSERT_EQ(2, value) << "wrong param value";
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
//#include "gmock/gmock.h"
|
||||
|
||||
#include "uORB/uORB.h"
|
||||
|
||||
/******************************************
|
||||
* uORB stubs (incomplete)
|
||||
*
|
||||
* TODO: use googlemock
|
||||
******************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue