PX4 Firmware
PX4 Autopilot Software http://px4.io
|
Testing the DataValidatorGroup class. More...
#include <stdint.h>
#include <cassert>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include <validation/data_validator.h>
#include <validation/data_validator_group.h>
#include <validation/tests/tests_common.h>
Go to the source code of this file.
Functions | |
DataValidatorGroup * | setup_base_group (unsigned *sibling_count) |
Initialize a DataValidatorGroup with some common settings;. More... | |
void | fill_one_with_valid_data (DataValidatorGroup *group, int val1_idx, uint32_t num_samples) |
Fill one DataValidator with samples, by index. More... | |
void | fill_two_with_valid_data (DataValidatorGroup *group, int val1_idx, int val2_idx, uint32_t num_samples) |
Fill two validators in the group with samples, by index. More... | |
DataValidator * | add_validator_to_group (DataValidatorGroup *group) |
Dynamically add a validator to the group after construction. More... | |
DataValidatorGroup * | setup_group_with_two_validator_handles (DataValidator **validator1_handle, DataValidator **validator2_handle, unsigned *sibling_count) |
Create a DataValidatorGroup and tack on two additional DataValidators. More... | |
void | test_init () |
void | test_put () |
Happy path test of put method – ensure the "best" sensor selected is the one with highest priority. More... | |
void | test_priority_switch () |
Verify that the DataValidatorGroup will select the sensor with the latest higher priority as "best". More... | |
void | test_simple_failover () |
Verify that the DataGroupValidator will prefer a sensor with no errors over a sensor with high errors. More... | |
void | test_vibration () |
Verify that we get expected vibration values after injecting samples. More... | |
void | test_sensor_failure () |
Force once sensor to fail and ensure that we detect it. More... | |
int | main (int argc, char *argv[]) |
Variables | |
const uint32_t | base_timeout_usec = 2000 |
const int | equal_value_count = 100 |
const uint64_t | base_timestamp = 666 |
const unsigned | base_num_siblings = 4 |
Testing the DataValidatorGroup class.
Definition in file test_data_validator_group.cpp.
DataValidator* add_validator_to_group | ( | DataValidatorGroup * | group | ) |
Dynamically add a validator to the group after construction.
group |
Definition at line 162 of file test_data_validator_group.cpp.
References DataValidatorGroup::add_new_validator(), base_timeout_usec, equal_value_count, DataValidator::get_timeout(), and DataValidator::set_equal_value_threshold().
Referenced by setup_group_with_two_validator_handles(), test_sensor_failure(), and test_vibration().
void fill_one_with_valid_data | ( | DataValidatorGroup * | group, |
int | val1_idx, | ||
uint32_t | num_samples | ||
) |
Fill one DataValidator with samples, by index.
group | |
val1_idx | Index of the validator to fill with samples |
num_samples |
Definition at line 104 of file test_data_validator_group.cpp.
References base_timestamp, data, DataValidator::dimensions, DataValidatorGroup::get_best(), and DataValidatorGroup::put().
void fill_two_with_valid_data | ( | DataValidatorGroup * | group, |
int | val1_idx, | ||
int | val2_idx, | ||
uint32_t | num_samples | ||
) |
Fill two validators in the group with samples, by index.
Both validators will be filled with the same data, but the priority of the first validator will be higher than the second.
group | |
val1_idx | index of the first validator to fill |
val2_idx | index of the second validator to fill |
num_samples |
Definition at line 135 of file test_data_validator_group.cpp.
References base_timestamp, data, DataValidator::dimensions, DataValidatorGroup::get_best(), and DataValidatorGroup::put().
Referenced by test_priority_switch(), test_put(), and test_simple_failover().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 428 of file test_data_validator_group.cpp.
References test_init(), test_priority_switch(), test_put(), test_sensor_failure(), test_simple_failover(), and test_vibration().
DataValidatorGroup* setup_base_group | ( | unsigned * | sibling_count | ) |
Initialize a DataValidatorGroup with some common settings;.
sibling_count | (out) the number of siblings initialized |
Definition at line 60 of file test_data_validator_group.cpp.
References base_num_siblings, base_timeout_usec, base_timestamp, equal_value_count, DataValidator::ERROR_FLAG_NO_ERROR, f(), DataValidatorGroup::failover_count(), DataValidatorGroup::failover_index(), DataValidatorGroup::failover_state(), DataValidatorGroup::get_vibration_factor(), DataValidatorGroup::get_vibration_offset(), DataValidatorGroup::print(), DataValidatorGroup::set_equal_value_threshold(), and DataValidatorGroup::set_timeout().
Referenced by setup_group_with_two_validator_handles(), test_init(), test_sensor_failure(), and test_vibration().
DataValidatorGroup* setup_group_with_two_validator_handles | ( | DataValidator ** | validator1_handle, |
DataValidator ** | validator2_handle, | ||
unsigned * | sibling_count | ||
) |
Create a DataValidatorGroup and tack on two additional DataValidators.
validator1_handle | (out) first DataValidator added to the group |
validator2_handle | (out) second DataValidator added to the group |
sibling_count | (in/out) in: number of initial siblings to create, out: total |
Definition at line 182 of file test_data_validator_group.cpp.
References add_validator_to_group(), and setup_base_group().
Referenced by test_priority_switch(), test_put(), and test_simple_failover().
void test_init | ( | ) |
Definition at line 198 of file test_data_validator_group.cpp.
References base_timestamp, DataValidatorGroup::get_best(), and setup_base_group().
Referenced by main().
void test_priority_switch | ( | ) |
Verify that the DataValidatorGroup will select the sensor with the latest higher priority as "best".
Definition at line 251 of file test_data_validator_group.cpp.
References base_timestamp, data, DataValidator::dimensions, DataValidatorGroup::failover_count(), fill_two_with_valid_data(), DataValidatorGroup::get_best(), DataValidatorGroup::put(), and setup_group_with_two_validator_handles().
Referenced by main().
void test_put | ( | ) |
Happy path test of put method – ensure the "best" sensor selected is the one with highest priority.
Definition at line 215 of file test_data_validator_group.cpp.
References base_timestamp, fill_two_with_valid_data(), DataValidatorGroup::get_best(), setup_group_with_two_validator_handles(), and DataValidator::value().
Referenced by main().
void test_sensor_failure | ( | ) |
Force once sensor to fail and ensure that we detect it.
Definition at line 391 of file test_data_validator_group.cpp.
References add_validator_to_group(), base_timestamp, DataValidator::confidence(), DataValidator::ERROR_FLAG_TIMEOUT, f(), DataValidatorGroup::failover_index(), fill_validator_with_samples(), DataValidatorGroup::get_best(), setup_base_group(), and DataValidator::state().
Referenced by main().
void test_simple_failover | ( | ) |
Verify that the DataGroupValidator will prefer a sensor with no errors over a sensor with high errors.
Definition at line 288 of file test_data_validator_group.cpp.
References base_timestamp, data, DataValidator::dimensions, DataValidator::error_count(), DataValidator::ERROR_FLAG_NO_ERROR, DataValidatorGroup::failover_count(), DataValidatorGroup::failover_index(), DataValidatorGroup::failover_state(), fill_two_with_valid_data(), DataValidatorGroup::get_best(), DataValidatorGroup::put(), setup_group_with_two_validator_handles(), and DataValidator::state().
Referenced by main().
void test_vibration | ( | ) |
Verify that we get expected vibration values after injecting samples.
Definition at line 346 of file test_data_validator_group.cpp.
References add_validator_to_group(), base_timestamp, f(), DataValidatorGroup::get_vibration_factor(), DataValidatorGroup::get_vibration_offset(), insert_values_around_mean(), DataValidator::rms(), setup_base_group(), and DataValidator::vibration_offset().
Referenced by main().
const unsigned base_num_siblings = 4 |
Definition at line 53 of file test_data_validator_group.cpp.
Referenced by setup_base_group().
const uint32_t base_timeout_usec = 2000 |
Definition at line 50 of file test_data_validator_group.cpp.
Referenced by add_validator_to_group(), and setup_base_group().
const uint64_t base_timestamp = 666 |
Definition at line 52 of file test_data_validator_group.cpp.
Referenced by fill_one_with_valid_data(), fill_two_with_valid_data(), setup_base_group(), test_init(), test_priority_switch(), test_put(), test_sensor_failure(), test_simple_failover(), and test_vibration().
const int equal_value_count = 100 |
Definition at line 51 of file test_data_validator_group.cpp.
Referenced by add_validator_to_group(), fill_validator_with_samples(), setup_base_group(), test_error_tracking(), and test_rms_calculation().