PX4 Firmware
PX4 Autopilot Software http://px4.io
test_data_validator_group.cpp File Reference

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>
Include dependency graph for test_data_validator_group.cpp:

Go to the source code of this file.

Functions

DataValidatorGroupsetup_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...
 
DataValidatoradd_validator_to_group (DataValidatorGroup *group)
 Dynamically add a validator to the group after construction. More...
 
DataValidatorGroupsetup_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
 

Detailed Description

Testing the DataValidatorGroup class.

Author
Todd Stellanova

Definition in file test_data_validator_group.cpp.

Function Documentation

◆ add_validator_to_group()

DataValidator* add_validator_to_group ( DataValidatorGroup group)

Dynamically add a validator to the group after construction.

Parameters
group
Returns

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_one_with_valid_data()

void fill_one_with_valid_data ( DataValidatorGroup group,
int  val1_idx,
uint32_t  num_samples 
)

Fill one DataValidator with samples, by index.

Parameters
group
val1_idxIndex 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().

Here is the call graph for this function:

◆ fill_two_with_valid_data()

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.

Parameters
group
val1_idxindex of the first validator to fill
val2_idxindex 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

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().

Here is the call graph for this function:

◆ setup_base_group()

DataValidatorGroup* setup_base_group ( unsigned *  sibling_count)

Initialize a DataValidatorGroup with some common settings;.

Parameters
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_group_with_two_validator_handles()

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.

Parameters
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
Returns

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_init()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_priority_switch()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_put()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_sensor_failure()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_simple_failover()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_vibration()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ base_num_siblings

const unsigned base_num_siblings = 4

Definition at line 53 of file test_data_validator_group.cpp.

Referenced by setup_base_group().

◆ base_timeout_usec

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().

◆ base_timestamp

◆ equal_value_count