41 #include <px4_platform_common/defines.h> 94 ut_compare(
"param_get did not return parameter", 0, result);
95 ut_compare(
"value for param doesn't match default value", expected, value);
104 ut_compare(
"param_get did not return parameter", 0, result);
105 ut_compare_float(
"value for param doesn't match default value", expected, value, 0.001);
136 ut_compare(
"param_get did not return parameter", 0, result);
137 ut_compare(
"value of returned parameter does not match", 4, value);
162 const char *excludes[] = {
"TEST_RC_X"};
179 const char *excludes[] = {
"TEST_RC_X",
"TEST_1"};
196 const char *excludes[] = {
"TEST_RC_X",
"TEST_1"};
213 const char *excludes[] = {
"TEST_RC*"};
228 static constexpr
float MAGIC_FLOAT_VAL = 0.314159f;
235 for (
auto p : test_params) {
237 const int32_t set_val = p;
240 PX4_ERR(
"param_set_no_notification failed for: %d", p);
241 ut_assert(
"param_set_no_notification failed",
false);
247 PX4_ERR(
"param_get failed for: %d", p);
248 ut_assert(
"param_set_no_notification failed",
false);
251 ut_compare(
"value for param doesn't match default value", p, get_val);
255 const float set_val = (float)p + MAGIC_FLOAT_VAL;
258 PX4_ERR(
"param_set_no_notification failed for: %d", p);
259 ut_assert(
"param_set_no_notification failed",
false);
262 float get_val = 0.0f;
265 PX4_ERR(
"param_get failed for: %d", p);
266 ut_assert(
"param_set_no_notification failed",
false);
269 ut_compare(
"value for param doesn't match default value", p, (
float)p + MAGIC_FLOAT_VAL);
275 PX4_ERR(
"param_save_default failed");
280 for (
auto p : test_params) {
282 const int32_t set_val = 0;
285 PX4_ERR(
"param_set_no_notification failed for: %d", p);
286 ut_assert(
"param_set_no_notification failed",
false);
289 int32_t get_val = -1;
292 PX4_ERR(
"param_get failed for: %d", p);
293 ut_assert(
"param_set_no_notification failed",
false);
296 ut_compare(
"value for param doesn't match default value", set_val, get_val);
300 const float set_val = 0.0f;
303 PX4_ERR(
"param_set_no_notification failed for: %d", p);
304 ut_assert(
"param_set_no_notification failed",
false);
307 float get_val = -1.0f;
310 PX4_ERR(
"param_get failed for: %d", p);
311 ut_assert(
"param_set_no_notification failed",
false);
314 ut_compare_float(
"value for param doesn't match default value", set_val, get_val, 0.001
f);
320 PX4_ERR(
"param_save_default failed");
325 for (
auto p : test_params) {
328 int32_t get_val = 0.0f;
331 PX4_ERR(
"param_get failed for: %d", p);
332 ut_assert(
"param_set_no_notification failed",
false);
335 ut_compare(
"value for param doesn't match default value", p, get_val);
339 float get_val = 0.0f;
342 PX4_ERR(
"param_get failed for: %d", p);
343 ut_assert(
"param_set_no_notification failed",
false);
346 ut_compare_float(
"value for param doesn't match default value", p, (
float)p + MAGIC_FLOAT_VAL, 0.001
f);
355 static constexpr
float MAGIC_FLOAT_VAL = 0.217828f;
358 const char *param_file_name = PX4_STORAGEDIR
"/param_backup";
359 int fd = open(param_file_name, O_WRONLY | O_CREAT, PX4_O_MODE_666);
362 PX4_ERR(
"open '%s' failed (%i)", param_file_name, errno);
368 if (result != PX4_OK) {
369 PX4_ERR(
"param_export failed");
381 for (
unsigned i = 0; i < N; i++) {
386 PX4_ERR(
"param invalid: %d(%d)", p, i);
391 const int32_t set_val = p;
394 PX4_ERR(
"param_set_no_notification failed for: %d", p);
395 ut_assert(
"param_set_no_notification failed",
false);
401 PX4_ERR(
"param_get failed for: %d", p);
402 ut_assert(
"param_set_no_notification failed",
false);
405 ut_compare(
"value for param doesn't match default value", p, get_val);
409 const float set_val = (float)p + MAGIC_FLOAT_VAL;
412 PX4_ERR(
"param_set_no_notification failed for: %d", p);
413 ut_assert(
"param_set_no_notification failed",
false);
416 float get_val = 0.0f;
419 PX4_ERR(
"param_get failed for: %d", p);
420 ut_assert(
"param_set_no_notification failed",
false);
423 ut_compare(
"value for param doesn't match default value", p, (
float)p + MAGIC_FLOAT_VAL);
429 PX4_ERR(
"param_save_default failed");
434 for (
unsigned i = 0; i < N; i++) {
439 const int32_t set_val = 0;
442 PX4_ERR(
"param set failed: %d", p);
443 ut_assert(
"param_set_no_notification failed",
false);
446 int32_t get_val = -1;
449 PX4_ERR(
"param_get failed for: %d", p);
450 ut_assert(
"param_set_no_notification failed",
false);
453 ut_compare(
"value for param doesn't match default value", set_val, get_val);
457 float set_val = 0.0f;
460 PX4_ERR(
"param set failed: %d", p);
461 ut_assert(
"param_set_no_notification failed",
false);
464 float get_val = -1.0f;
467 PX4_ERR(
"param_get failed for: %d", p);
468 ut_assert(
"param_set_no_notification failed",
false);
471 ut_compare(
"value for param doesn't match default value", set_val, get_val);
477 PX4_ERR(
"param_save_default failed");
482 for (
unsigned i = 0; i < N; i++) {
490 PX4_ERR(
"param_get failed for: %d", p);
491 ut_assert(
"param_set_no_notification failed",
false);
494 ut_compare(
"value for param doesn't match default value", p, get_val);
498 float get_val = 0.0f;
501 PX4_ERR(
"param_get failed for: %d", p);
502 ut_assert(
"param_set_no_notification failed",
false);
505 ut_compare(
"value for param doesn't match default value", p, (
float)p + MAGIC_FLOAT_VAL);
512 fd = open(param_file_name, O_RDONLY);
515 PX4_ERR(
"open '%s' failed (%i)", param_file_name, errno);
523 PX4_ERR(
"importing from '%s' failed (%i)", param_file_name, result);
529 PX4_ERR(
"param_save_default failed");
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
bool _assert_parameter_int_value(param_t param, int32_t expected)
__EXPORT int param_import(int fd)
Import parameters from a file, discarding any unrecognized parameters.
#define PARAM_TYPE_INT32
Parameter types.
#define ut_declare_test_c(test_function, test_class)
bool ResetAllExcludesOne()
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
__EXPORT int param_set_no_notification(param_t param, const void *val)
Set the value of a parameter, but do not notify the system about the change.
bool _assert_parameter_float_value(param_t param, float expected)
__EXPORT int param_set(param_t param, const void *val)
Set the value of a parameter.
__EXPORT param_t param_for_index(unsigned index)
Look up a parameter by index.
Base class to be used for unit tests.
__EXPORT unsigned param_count(void)
Return the total number of parameters.
bool ResetAllExcludesTwo()
Global flash based parameter store.
int _tests_failed
The number of unit tests which failed.
__EXPORT void param_reset_excludes(const char *excludes[], int num_excludes)
Reset all parameters to their default values except for excluded parameters.
__EXPORT int param_export(int fd, bool only_unsaved)
Export changed parameters to a file.
#define ut_assert(message, test)
Used to assert a value within a unit test.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
__EXPORT param_type_t param_type(param_t param)
Obtain the type of a parameter.
__EXPORT int param_save_default(void)
Save parameters to the default file.
#define ut_assert_true(test)
To assert specifically to true.
virtual bool run_tests()
Override to run your unit tests.
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
bool ResetAllExcludesBoundaryCheck()
__EXPORT void param_control_autosave(bool enable)
Enable/disable the param autosaving.
__EXPORT void param_reset_all(void)
Reset all parameters to their default values.
#define ut_compare(message, v1, v2)
Used to compare two integer values within a unit test.
#define ut_run_test(test)
Runs a single unit test.
#define ut_compare_float(message, v1, v2, precision)
Used to compare two float values within a unit test.
int test_parameters(int argc, char *argv[])
bool ResetAllExcludesWildcard()
__EXPORT int param_load_default(void)
Load parameters from the default parameter file.
bool _set_all_int_parameters_to(int32_t value)
uint32_t param_t
Parameter handle.