move parameter unittest into systemcmds

This commit is contained in:
Daniel Agar
2017-06-12 12:18:53 -04:00
parent f26cd01d16
commit 4937449890
22 changed files with 210 additions and 388 deletions
-3
View File
@@ -569,7 +569,6 @@ void VDev::showDevices()
pthread_mutex_unlock(&devmutex);
#ifndef __PX4_UNIT_TESTS
PX4_INFO("DF Devices:");
const char *dev_path;
unsigned int index = 0;
@@ -583,8 +582,6 @@ void VDev::showDevices()
PX4_INFO(" %s", dev_path);
}
} while (i == 0);
#endif
}
void VDev::showTopics()
+1
View File
@@ -22,6 +22,7 @@ set(tests
mc_pos_control
mixer
param
parameters
perf
rc
servo
+1 -9
View File
@@ -84,7 +84,6 @@
static const char *param_default_file = PX4_ROOTFSDIR"/eeprom/parameters";
static char *param_user_file = NULL;
#if 0
# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0)
#else
@@ -111,15 +110,8 @@ static bool autosave_disabled = false;
/**
* Array of static parameter info.
*/
#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;
#define param_info_count (param_info_limit - param_info_base)
#else
static const struct param_info_s *param_info_base = (const struct param_info_s *) &px4_parameters;
#define param_info_count px4_parameters.param_count
#endif /* _UNIT_TEST */
#define param_info_count px4_parameters.param_count
/**
* Storage for modified parameters.
@@ -96,15 +96,8 @@ static bool autosave_disabled = false;
/**
* Array of static parameter info.
*/
#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;
#define param_info_count (param_info_limit - param_info_base)
#else
static struct param_info_s *param_info_base = (struct param_info_s *) &px4_parameters;
#define param_info_count px4_parameters.param_count
#endif /* _UNIT_TEST */
/**
* Storage for modified parameters.
+1 -3
View File
@@ -47,7 +47,5 @@
#include <board_config.h>
#elif defined (__PX4_POSIX)
# if !defined(__PX4_UNIT_TESTS)
# include <board_config.h>
# endif
# include <board_config.h>
#endif
+3 -2
View File
@@ -34,16 +34,16 @@
set(srcs
test_adc.c
test_autodeclination.cpp
test_dataman.c
test_hysteresis.cpp
test_bson.c
test_conv.cpp
test_dataman.c
test_file.c
test_file2.c
test_float.cpp
test_gpio.c
test_hott_telemetry.c
test_hrt.c
test_hysteresis.cpp
test_int.cpp
test_jig_voltages.c
test_led.c
@@ -52,6 +52,7 @@ set(srcs
test_mixer.cpp
test_mount.c
test_param.c
test_parameters.cpp
test_perf.c
test_ppm_loopback.c
test_rc.c
+24
View File
@@ -0,0 +1,24 @@
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_1, 2);
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_2, 4);
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_RC_X, 8);
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_RC2_X, 16);
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_PARAMS, 12345678);
-5
View File
@@ -46,11 +46,6 @@
#define PARAM_MAGIC1 12345678
#define PARAM_MAGIC2 0xa5a5a5a5
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_PARAMS, 12345678);
int
test_param(int argc, char *argv[])
{
+172
View File
@@ -0,0 +1,172 @@
#include <unit_test/unit_test.h>
class ParameterTest : public UnitTest
{
public:
virtual bool run_tests();
ParameterTest()
{
p0 = param_find("TEST_RC_X");
p1 = param_find("TEST_RC2_X");
p2 = param_find("TEST_1");
p3 = param_find("TEST_2");
}
private:
param_t p0{PARAM_INVALID};
param_t p1{PARAM_INVALID};
param_t p2{PARAM_INVALID};
param_t p3{PARAM_INVALID};
bool _assert_parameter_int_value(param_t param, int32_t expected);
bool _set_all_int_parameters_to(int32_t value);
bool SimpleFind();
bool ResetAll();
bool ResetAllExcludesOne();
bool ResetAllExcludesTwo();
bool ResetAllExcludesBoundaryCheck();
bool ResetAllExcludesWildcard();
};
bool ParameterTest::_assert_parameter_int_value(param_t param, int32_t expected)
{
int32_t value;
int result = param_get(param, &value);
ut_compare("param_get did not return parameter", 0, result);
ut_compare("value for param doesn't match default value", expected, value);
return true;
}
bool ParameterTest::_set_all_int_parameters_to(int32_t value)
{
param_set(p0, &value);
param_set(p1, &value);
param_set(p2, &value);
param_set(p3, &value);
bool ret = false;
ret = ret || _assert_parameter_int_value(p0, value);
ret = ret || _assert_parameter_int_value(p1, value);
ret = ret || _assert_parameter_int_value(p2, value);
ret = ret || _assert_parameter_int_value(p3, value);
return ret;
}
bool ParameterTest::SimpleFind()
{
param_t param = param_find("TEST_2");
ut_assert_true(PARAM_INVALID != param);
int32_t value;
int result = param_get(param, &value);
ut_compare("param_get did not return parameter", 0, result);
ut_compare("value of returned parameter does not match", 4, value);
return true;
}
bool ParameterTest::ResetAll()
{
_set_all_int_parameters_to(50);
param_reset_all();
bool ret = false;
ret = ret || _assert_parameter_int_value(p0, 8);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);
return ret;
}
bool ParameterTest::ResetAllExcludesOne()
{
_set_all_int_parameters_to(50);
const char *excludes[] = {"TEST_RC_X"};
param_reset_excludes(excludes, 1);
bool ret = false;
ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);
return ret;
}
bool ParameterTest::ResetAllExcludesTwo()
{
_set_all_int_parameters_to(50);
const char *excludes[] = {"TEST_RC_X", "TEST_1"};
param_reset_excludes(excludes, 2);
bool ret = false;
ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 50);
ret = ret || _assert_parameter_int_value(p3, 4);
return ret;
}
bool ParameterTest::ResetAllExcludesBoundaryCheck()
{
_set_all_int_parameters_to(50);
const char *excludes[] = {"TEST_RC_X", "TEST_1"};
param_reset_excludes(excludes, 1);
bool ret = false;
ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);
return ret;
}
bool ParameterTest::ResetAllExcludesWildcard()
{
_set_all_int_parameters_to(50);
const char *excludes[] = {"TEST_RC*"};
param_reset_excludes(excludes, 1);
bool ret = false;
ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 50);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);
return ret;
}
bool ParameterTest::run_tests()
{
ut_run_test(SimpleFind);
ut_run_test(ResetAll);
ut_run_test(ResetAllExcludesOne);
ut_run_test(ResetAllExcludesTwo);
ut_run_test(ResetAllExcludesBoundaryCheck);
ut_run_test(ResetAllExcludesWildcard);
return (_tests_failed == 0);
}
ut_declare_test_c(test_parameters, ParameterTest)
+1
View File
@@ -116,6 +116,7 @@ const struct {
{"matrix", test_matrix, 0},
{"mount", test_mount, OPT_NOJIGTEST | OPT_NOALLTEST},
{"param", test_param, 0},
{"parameters", test_parameters, 0},
{"perf", test_perf, OPT_NOJIGTEST},
{"ppm", test_ppm, OPT_NOJIGTEST | OPT_NOALLTEST},
{"ppm_loopback", test_ppm_loopback, OPT_NOALLTEST},
+1
View File
@@ -86,6 +86,7 @@ extern int test_uart_break(int argc, char *argv[]);
extern int test_uart_console(int argc, char *argv[]);
extern int test_uart_loopback(int argc, char *argv[]);
extern int test_uart_send(int argc, char *argv[]);
extern int test_parameters(int argc, char *argv[]);
/* external */
extern int commander_tests_main(int argc, char *argv[]);