CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
test_unit_t_digest.c File Reference

This file contains definitions and implementation of various unit tests for checking the functionality of the t_digest.c module. More...

#include <float.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "configuration.h"
#include "cdi_logger_api.h"
#include "cdi_os_api.h"
#include "t_digest.h"
#include "utilities_api.h"

Macros

#define TEST_URAND_SAMPLES   (300000)
 Define for the number of samples to run in the TestUniformRand test.
 
#define TEST_SRAND_SAMPLES   (300)
 Define for the number of samples to run in the TestSkewedRand test.
 
#define TEST_RUNTIME_SAMPLES   (200000000)
 Define for the number of samples to run in the TestRunTime test.
 
#define TEST_NUM_PERCENTILES   (14)
 Define for the number of percentiles to check in this test.
 
#define COMPARE_RETURN_MSG(message, test)   do { if (!(test)) return message; } while (0)
 Macro used to do a boolean test and return a message if the test fails.
 
#define RUN_TEST(test, run_flag)
 Macro used to run a test function that returns a message; this macro returns that message if it is not NULL.
 
#define MAX_FILE_LINES   (10000)
 Define to limit the number of lines of an input data file to read.
 
#define USEC_PER_SEC   (1000000)
 Define for the number of microseconds in a second.
 

Functions

static int SortComp (const void *c1_ptr, const void *c2_ptr)
 Function used by qsort to make decisions about how to sort.
 
static uint32_t GetRandFromToSkewed (uint32_t min, uint32_t max)
 Function to get a random number within the range min to max, but to distribute the samples more closely around the 30% and 70% positions in that range as follows: 40% of samples are within 10% of the 30% point in the range. 40% of samples are within 10% of the 70% point in the range. 20% of the samples are randomly distributed across the entire range.
 
static uint32_t GetRandFromTo (uint32_t min, uint32_t max)
 Function to get a random number within the range min to max.
 
static char * TestGenericArray (TDigestHandle td_handle, uint32_t *data_array, int num_entries)
 This is a generic function that takes in a digest and an array of input samples and then adds all the samples to the digest and then checks some main percentile values for correctness.
 
static char * TestSimple3 ()
 Simple test that adds 3 samples to the digest and then checks the percentile values.
 
static char * TestSimple100 ()
 Simple test that adds 100 samples to the digest and then checks the percentile values.
 
static char * TestRunTime ()
 Simple test that adds TEST_RUNTIME_SAMPLES uniform random samples to the digest and measures the amount of time it takes.
 
static char * TestUniformRand ()
 Simple test that adds TEST_URAND_SAMPLES uniform random samples to the digest and then checks for percentile values.
 
static char * TestSkewedRand ()
 Simple test that adds TEST_SRAND_SAMPLES skewed random samples to the digest and then checks for percentile values. "Skewed random samples" are samples that tend to be random within a certain range, with few outside that range. In this case, the function GetRandFromToSkewed() is used to generate a distribution with two main focal ranges and a lighter random distribution outside of those focal ranges.
 
static char * TestRealDataFromFile ()
 This test reads input samples from a file and feeds them into the digest and then checks for expected percentile values. This is intended to allow users to collect their own data from an actual cdi_test test run and feed it in. The file must be in a format where each line is a sample.
 
static char * TestInvalidPercentiles ()
 This test verifies that the value NaN is returned under certain known circumstances, such as when the digest is empty, or when a percentile outside of 0-100, inclusive, is requested.
 
static char * AllTests ()
 Runs all tests. Use the boolean parameter after the test name to enable or disable tests.
 
bool TestUnitTDigest (void)
 Public wrapper for AllTests() above.
 

Variables

static int tests_run
 Variable used to count the number of tests that have been run.
 

Detailed Description

This file contains definitions and implementation of various unit tests for checking the functionality of the t_digest.c module.

Macro Definition Documentation

◆ RUN_TEST

#define RUN_TEST ( test,
run_flag )
Value:
do { if (run_flag) { char* message = test(); tests_run++; \
if (message) { return message; } } } while (0)
static int tests_run
Variable used to count the number of tests that have been run.
Definition test_unit_t_digest.c:53

Macro used to run a test function that returns a message; this macro returns that message if it is not NULL.

Function Documentation

◆ AllTests()

static char * AllTests ( )
static

Runs all tests. Use the boolean parameter after the test name to enable or disable tests.

Returns
Message for a failure; NULL if no errors.

◆ GetRandFromTo()

static uint32_t GetRandFromTo ( uint32_t min,
uint32_t max )
static

Function to get a random number within the range min to max.

Parameters
minThe minimum allowable number.
maxThe maximum allowable number.
Returns
A random float number within the desired range.

◆ GetRandFromToSkewed()

static uint32_t GetRandFromToSkewed ( uint32_t min,
uint32_t max )
static

Function to get a random number within the range min to max, but to distribute the samples more closely around the 30% and 70% positions in that range as follows: 40% of samples are within 10% of the 30% point in the range. 40% of samples are within 10% of the 70% point in the range. 20% of the samples are randomly distributed across the entire range.

Parameters
minThe minimum allowable number.
maxThe maximum allowable number.
Returns
A random float number with the desired distribution within the specified range.

◆ SortComp()

static int SortComp ( const void * c1_ptr,
const void * c2_ptr )
static

Function used by qsort to make decisions about how to sort.

Parameters
c1_ptrPointer to the first value to sort.
c2_ptrPointer to the second value to sort.
Returns
-1 if c1 < c2, 1 if c1 > c2, and 0 if they are equal.

◆ TestGenericArray()

static char * TestGenericArray ( TDigestHandle td_handle,
uint32_t * data_array,
int num_entries )
static

This is a generic function that takes in a digest and an array of input samples and then adds all the samples to the digest and then checks some main percentile values for correctness.

Parameters
td_handlePointer to the t-Digest instance to use for this test.
data_arrayThe array of input samples.
num_entriesThe number of input samples in the data_array.
Returns
Message for a failure; NULL if no errors.

◆ TestInvalidPercentiles()

static char * TestInvalidPercentiles ( )
static

This test verifies that the value NaN is returned under certain known circumstances, such as when the digest is empty, or when a percentile outside of 0-100, inclusive, is requested.

Returns
Message for a failure; NULL if no errors.

◆ TestRealDataFromFile()

static char * TestRealDataFromFile ( )
static

This test reads input samples from a file and feeds them into the digest and then checks for expected percentile values. This is intended to allow users to collect their own data from an actual cdi_test test run and feed it in. The file must be in a format where each line is a sample.

Returns
Message for a failure; NULL if no errors.

◆ TestRunTime()

static char * TestRunTime ( )
static

Simple test that adds TEST_RUNTIME_SAMPLES uniform random samples to the digest and measures the amount of time it takes.

Returns
Message for a failure; NULL if no errors.

◆ TestSimple100()

static char * TestSimple100 ( )
static

Simple test that adds 100 samples to the digest and then checks the percentile values.

Returns
Message for a failure; NULL if no errors.

◆ TestSimple3()

static char * TestSimple3 ( )
static

Simple test that adds 3 samples to the digest and then checks the percentile values.

Returns
Message for a failure; NULL if no errors.

◆ TestSkewedRand()

static char * TestSkewedRand ( )
static

Simple test that adds TEST_SRAND_SAMPLES skewed random samples to the digest and then checks for percentile values. "Skewed random samples" are samples that tend to be random within a certain range, with few outside that range. In this case, the function GetRandFromToSkewed() is used to generate a distribution with two main focal ranges and a lighter random distribution outside of those focal ranges.

Returns
Message for a failure; NULL if no errors.

◆ TestUniformRand()

static char * TestUniformRand ( )
static

Simple test that adds TEST_URAND_SAMPLES uniform random samples to the digest and then checks for percentile values.

Returns
Message for a failure; NULL if no errors.

◆ TestUnitTDigest()

bool TestUnitTDigest ( void )

Public wrapper for AllTests() above.

External declarations.

Returns
Status code.