mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-20 20:03:54 +08:00
added actual tests and fixed reset-exclude funtction
This commit is contained in:
committed by
Lorenz Meier
parent
28e943ca28
commit
a7580a1eae
@@ -504,15 +504,22 @@ param_reset_excludes(const char* excludes[], int num_excludes)
|
||||
|
||||
for (param = 0; handle_in_range(param); param++) {
|
||||
const char* name = param_name(param);
|
||||
bool exclude = false;
|
||||
|
||||
for (int index = 0; index < num_excludes; index ++) {
|
||||
int len = strlen(excludes[index]);
|
||||
|
||||
for (int index = 0, len = strlen(excludes[index]); index < num_excludes; index ++) {
|
||||
if((excludes[index][len - 1] == '*'
|
||||
&& strncmp(name, excludes[index], len - 1)) == 0
|
||||
&& strncmp(name, excludes[index], len - 1) == 0)
|
||||
|| strcmp(name, excludes[index]) == 0) {
|
||||
|
||||
param_reset(param);
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!exclude) {
|
||||
param_reset(param);
|
||||
}
|
||||
}
|
||||
|
||||
param_unlock();
|
||||
|
||||
+100
-4
@@ -3,7 +3,9 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
/*
|
||||
* These will be used in param.c if compiling for unit tests
|
||||
*/
|
||||
struct param_info_s param_array[256];
|
||||
struct param_info_s *param_info_base;
|
||||
struct param_info_s *param_info_limit;
|
||||
@@ -24,16 +26,48 @@ void _add_parameters() {
|
||||
};
|
||||
test_2.val.i = 4;
|
||||
|
||||
struct param_info_s rc_x = {
|
||||
"RC_X",
|
||||
PARAM_TYPE_INT32
|
||||
};
|
||||
rc_x.val.i = 8;
|
||||
|
||||
struct param_info_s rc2_x = {
|
||||
"RC2_X",
|
||||
PARAM_TYPE_INT32
|
||||
};
|
||||
rc2_x.val.i = 16;
|
||||
|
||||
param_array[0] = test_1;
|
||||
param_array[1] = test_2;
|
||||
param_array[2] = rc_x;
|
||||
param_array[3] = rc2_x;
|
||||
param_info_base = (struct param_info_s *) ¶m_array[0];
|
||||
param_info_limit = (struct param_info_s *) ¶m_array[2];
|
||||
param_info_limit = (struct param_info_s *) ¶m_array[4]; // needs to point at the end of the data,
|
||||
// therefore number of params + 1
|
||||
}
|
||||
|
||||
void _assert_parameter_int_value(param_t param, int32_t expected) {
|
||||
int32_t value;
|
||||
int result = param_get(param, &value);
|
||||
ASSERT_EQ(0, result) << printf("param_get (%i) did not return parameter\n", param);
|
||||
ASSERT_EQ(expected, value) << printf("value for param (%i) doesn't match default value\n", param);
|
||||
}
|
||||
|
||||
void _set_all_int_parameters_to(int32_t value) {
|
||||
param_set((param_t)0, &value);
|
||||
param_set((param_t)1, &value);
|
||||
param_set((param_t)2, &value);
|
||||
param_set((param_t)3, &value);
|
||||
|
||||
_assert_parameter_int_value((param_t)0, value);
|
||||
_assert_parameter_int_value((param_t)1, value);
|
||||
_assert_parameter_int_value((param_t)2, value);
|
||||
_assert_parameter_int_value((param_t)3, value);
|
||||
}
|
||||
|
||||
TEST(ParamTest, SimpleFind) {
|
||||
_add_parameters();
|
||||
|
||||
printf("diff: %i\n", (unsigned)(param_info_limit - param_info_base));
|
||||
|
||||
param_t param = param_find("TEST_2");
|
||||
ASSERT_NE(PARAM_INVALID, param) << "param_find did not find parameter";
|
||||
@@ -44,4 +78,66 @@ TEST(ParamTest, SimpleFind) {
|
||||
ASSERT_EQ(4, value) << "value of returned parameter does not match";
|
||||
}
|
||||
|
||||
TEST(ParamTest, ResetAll) {
|
||||
_add_parameters();
|
||||
_set_all_int_parameters_to(50);
|
||||
|
||||
param_reset_all();
|
||||
|
||||
_assert_parameter_int_value((param_t)0, 2);
|
||||
_assert_parameter_int_value((param_t)1, 4);
|
||||
_assert_parameter_int_value((param_t)2, 8);
|
||||
_assert_parameter_int_value((param_t)3, 16);
|
||||
}
|
||||
|
||||
TEST(ParamTest, ResetAllExcludesOne) {
|
||||
_add_parameters();
|
||||
_set_all_int_parameters_to(50);
|
||||
|
||||
const char* excludes[] = {"RC_X"};
|
||||
param_reset_excludes(excludes, 1);
|
||||
|
||||
_assert_parameter_int_value((param_t)0, 2);
|
||||
_assert_parameter_int_value((param_t)1, 4);
|
||||
_assert_parameter_int_value((param_t)2, 50);
|
||||
_assert_parameter_int_value((param_t)3, 16);
|
||||
}
|
||||
|
||||
TEST(ParamTest, ResetAllExcludesTwo) {
|
||||
_add_parameters();
|
||||
_set_all_int_parameters_to(50);
|
||||
|
||||
const char* excludes[] = {"RC_X", "TEST_1"};
|
||||
param_reset_excludes(excludes, 2);
|
||||
|
||||
_assert_parameter_int_value((param_t)0, 50);
|
||||
_assert_parameter_int_value((param_t)1, 4);
|
||||
_assert_parameter_int_value((param_t)2, 50);
|
||||
_assert_parameter_int_value((param_t)3, 16);
|
||||
}
|
||||
|
||||
TEST(ParamTest, ResetAllExcludesBoundaryCheck) {
|
||||
_add_parameters();
|
||||
_set_all_int_parameters_to(50);
|
||||
|
||||
const char* excludes[] = {"RC_X", "TEST_1"};
|
||||
param_reset_excludes(excludes, 1);
|
||||
|
||||
_assert_parameter_int_value((param_t)0, 2);
|
||||
_assert_parameter_int_value((param_t)1, 4);
|
||||
_assert_parameter_int_value((param_t)2, 50);
|
||||
_assert_parameter_int_value((param_t)3, 16);
|
||||
}
|
||||
|
||||
TEST(ParamTest, ResetAllExcludesWildcard) {
|
||||
_add_parameters();
|
||||
_set_all_int_parameters_to(50);
|
||||
|
||||
const char* excludes[] = {"RC*"};
|
||||
param_reset_excludes(excludes, 1);
|
||||
|
||||
_assert_parameter_int_value((param_t)0, 2);
|
||||
_assert_parameter_int_value((param_t)1, 4);
|
||||
_assert_parameter_int_value((param_t)2, 50);
|
||||
_assert_parameter_int_value((param_t)3, 50);
|
||||
}
|
||||
Reference in New Issue
Block a user