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

This file contains the definitions of the functions used for capturing command line arguments and sanitizing them and converting them to cdi_test program test settings. More...

#include "test_args.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "configuration.h"
#include "cdi_log_enums.h"
#include "cdi_logger_api.h"
#include "cdi_os_api.h"
#include "cdi_test.h"
#include "cdi_utility_api.h"
#include "optarg.h"
#include "riff.h"
#include "test_common.h"
#include "test_console.h"
#include "utilities_api.h"

Enumerations

enum  PortNumLimits { kPortNumMin = 1 , kPortNumMax = UINT16_MAX }
 

Functions

static const char * TestPatternEnumToString (TestPatternType enum_value)
 Function used to convert a test pattern enum value to a string.
 
static const char * TestProtocolEnumToString (CdiConnectionProtocolType enum_value)
 Function used to convert a test protocol enum value to a string.
 
static TestPatternType TestPatternStringToEnum (const char *name_str)
 Function used to convert a test pattern string to a matching enum value.
 
static CdiConnectionProtocolType TestProtocolStringToEnum (const char *name_str)
 Function used to convert a test protocol string to a matching enum value.
 
static void PrintUsageVideo (const OptDef *opt_array_ptr, const OptArg *opt_ptr)
 Prints the main usage message.
 
static void PrintUsageAudio (const OptDef *opt_array_ptr, const OptArg *opt_ptr)
 Prints the audio usage message.
 
static void PrintRiffHelp (const OptArg *opt_ptr)
 Prints help on RIFF format and usage in cdi_test.
 
static void PrintStatsHelp (const OptDef *opt_array_ptr)
 Prints the statistics help message.
 
static void InitOptionsTable (void)
 Initialize the options table with choice string arrays for the arg_choices_array_ptr fields.
 
static bool IsBaseNNumber (const char *str, int *base_n_num_ptr, const int base)
 
static bool IsBase10Number (const char *str, int *base10_num_ptr)
 
bool Is64BitBaseNNumber (const char *str, uint64_t *base_n_num_ptr, const int base)
 
static bool IntStringToInt (const char *str, int *num_ptr, char **end_str)
 Converts a string to a base-10 number if it can be found at the start of the string. If a number is found, then the end_str pointer points to the character after the number and the number is stored in the num_ptr. If a number is not found, then end_str pointer points to the start of the string, and the number returned is 0.
 
static bool IsIntStringValid (const char *int_str, int *result_ptr)
 Check a string provided to see if the entire thing can be converted to an int.
 
static bool IsBoolStringValid (const char *bool_str, bool *result)
 Check a string provided to see if the entire thing can be converted to a bool. Check for 'true' and 'false' as well as '0' and '1' as valid strings.
 
static bool IsIPAddrValid (const char *ip_addr_str)
 Check a string provided to see if it is a valid ip address string of the form: ip.ip.ip.ip.
 
static bool IsRateValid (const char *rate_str, int *rate_numerator_ptr, int *rate_denominator_ptr)
 Check a string provided by the –rate option to see if it is a valid rate string of either the form rate_numerator/rate_denominator or simply rate_numerator if rate_numerator is an integer value. Converts the numerator and denominator to integers and stores them at the provided pointer locations.
 
static void SetConnectionRatePeriods (TestSettings *test_settings_ptr)
 Calculates the frame rate period and RTP video/ancillary timestamp periods for this connection and assigns to the TestSettings for each connection. This function is called only if the rate settings have been verified.
 
static bool LogComponentExists (CdiLogComponent *log_component_array_ptr, CdiLogComponent *component_ptr)
 This function searches the log_component array for a matching CdiLogComponent.
 
static bool GetLogComponents (const char *component_str, CdiLogComponent *log_component_array_ptr)
 This function parses the command-line test arguments for the log components and inserts the valid components into the GlobalTestSettings structure.
 
static bool AvmTypeSetAndIncrement (StreamSettings *const stream_settings_ptr, const CdiBaselineAvmPayloadType avm_data_type, int *avm_types_ptr)
 A helper function that takes in an AVM type setting chosen by the user via –avm_video/audio/anc/raw and sets the avm_data_type field in the test settings array, and also increments the number of types chosen. If the total types is greater than 1, then error out since we only allow one AVM type for now.
 
static bool IsUniqueStreamIdentifiers (TestSettings *const test_settings_ptr)
 Verify that stream identifiers are unique. Helper for VerifyTestSettings.
 
static bool VerifyTestSettings (TestSettings *const test_settings_ptr)
 After all settings for a given connection have been collected by the options parser, this function will check that they are all legal, and error out if they are not.
 
static ProgramExecutionStatus ParseHelpOptions (int argc, const char **argv_ptr, OptArg *opt_ptr)
 
static bool ProcessLogFilenameOption (bool is_single_file, const char *filename_str)
 
static bool ParseGlobalOptions (int argc, const char **argv_ptr, OptArg *opt_ptr)
 
void LogComponentToString (const CdiEnumStringKey *key_array, char *log_component_str, CdiLogComponent *log_component_ptr)
 A function that turns selected log components into a string of log components delimited by the '|' character.
 
void PrintTestSettings (const TestSettings *const test_settings_ptr, const int num_connections)
 
ProgramExecutionStatus GetArgs (int argc, const char **argv_ptr, TestSettings *test_settings_ptr, int *num_connections_found)
 

Variables

static const CdiEnumStringKey patterns_key_array []
 
static OptDef my_options []
 

Detailed Description

This file contains the definitions of the functions used for capturing command line arguments and sanitizing them and converting them to cdi_test program test settings.

Enumeration Type Documentation

◆ PortNumLimits

Enum for max and min IP port numbers.

Function Documentation

◆ AvmTypeSetAndIncrement()

static bool AvmTypeSetAndIncrement ( StreamSettings *const stream_settings_ptr,
const CdiBaselineAvmPayloadType avm_data_type,
int * avm_types_ptr )
static

A helper function that takes in an AVM type setting chosen by the user via –avm_video/audio/anc/raw and sets the avm_data_type field in the test settings array, and also increments the number of types chosen. If the total types is greater than 1, then error out since we only allow one AVM type for now.

Parameters
stream_settings_ptrPointer to the stream settings array.
avm_data_typeThe AVM data type chosen by the user.
avm_types_ptrPointer to the AVM types counter.
Returns
True if only one AVM type has been chosen, false if more than one has been chosen.

◆ GetArgs()

ProgramExecutionStatus GetArgs ( int argc,
const char ** argv_ptr,
TestSettings * test_settings_ptr,
int * num_connections_found )

A helper function that takes in command-line arguments, sanitizes them for syntax and correctness, and then assigns them to the test_settings data structure.

Parameters
argcThe system command line argument count variable.
argv_ptrThe pointer to the system command line arguments array.
test_settings_ptrPointer to an array of test settings data structures we will modify.
num_connections_foundPointer to the number of connections found.
Returns
ProgramExecutionStatus to indicate whether the program should continue and if not, what exit status to have.

◆ GetLogComponents()

static bool GetLogComponents ( const char * component_str,
CdiLogComponent * log_component_array_ptr )
static

This function parses the command-line test arguments for the log components and inserts the valid components into the GlobalTestSettings structure.

Parameters
component_strPointer to the log component that is to be searched in the log_component array.
log_component_array_ptrPointer to the log component array maintained in global_test_settings.
Returns
bool True if found in the array, false if not found in array.

◆ IntStringToInt()

static bool IntStringToInt ( const char * str,
int * num_ptr,
char ** end_str )
static

Converts a string to a base-10 number if it can be found at the start of the string. If a number is found, then the end_str pointer points to the character after the number and the number is stored in the num_ptr. If a number is not found, then end_str pointer points to the start of the string, and the number returned is 0.

Parameters
strThe pointer to the string to be evaluated.
num_ptrThe pointer to the integer location we will store the result of the conversion.
end_strThe pointer to the remaining string after the converted number has been removed from the beginning.
Returns
True if a number conversion was successful; false if no base-10 number was found.

◆ Is64BitBaseNNumber()

bool Is64BitBaseNNumber ( const char * str,
uint64_t * base_n_num_ptr,
const int base )

Check a string to see if it is a 64 bit base-N number.

Parameters
strThe string we are checking to see if it represents a base-N number.The integer representation of the number string in str. Set to NULL if the return number in num_ptr is not needed.
base_n_num_ptrThe 64 bit integer representation of the number string in str. May be NULL when the return number is not needed.
baseThe numerical base (N) to use for the compare.
Returns
True if string represents a base-N number; false if string does not

◆ IsBase10Number()

static bool IsBase10Number ( const char * str,
int * base10_num_ptr )
static

Check a string to see if it is a base-10 number.

Parameters
strThe string we are checking to see if it represents a base-10 number.
base10_num_ptrThe integer representation of the number string in str. Maye be NULL when the return number is not needed.
Returns
True if string represents a base-10 number; false if string does not

◆ IsBaseNNumber()

static bool IsBaseNNumber ( const char * str,
int * base_n_num_ptr,
const int base )
static

Check a string to see if it is a 32 bit base-N number.

Parameters
strThe string we are checking to see if it represents a base-N number. The integer representation of the number string in str. Set to NULL if the return number in num_ptr is not needed.
base_n_num_ptrThe integer representation of the number string in str. Set to NULL if the return number is not needed.
baseThe numerical base (N) to use for the compare.
Returns
True if string represents a base-N number; false if string does not

◆ IsBoolStringValid()

static bool IsBoolStringValid ( const char * bool_str,
bool * result )
static

Check a string provided to see if the entire thing can be converted to a bool. Check for 'true' and 'false' as well as '0' and '1' as valid strings.

Parameters
bool_strThe string to be evaluated.
resultThe boolean result after attempting to interpret the input string as a boolean.
Returns
True if success, false if the bool_str can not be interpreted as a bool.

◆ IsIntStringValid()

static bool IsIntStringValid ( const char * int_str,
int * result_ptr )
static

Check a string provided to see if the entire thing can be converted to an int.

Parameters
int_strThe string to be evaluated.
result_ptrThe integer result after attempting to interpret the input string.
Returns
True if success, false if the int_str can not be interpreted as a int.

◆ IsIPAddrValid()

static bool IsIPAddrValid ( const char * ip_addr_str)
static

Check a string provided to see if it is a valid ip address string of the form: ip.ip.ip.ip.

Parameters
ip_addr_strThe string to be evaluated.
Returns
True if success, false if the ip_addr_str is not of the proper syntax or if it does not contain integers.

◆ IsRateValid()

static bool IsRateValid ( const char * rate_str,
int * rate_numerator_ptr,
int * rate_denominator_ptr )
static

Check a string provided by the –rate option to see if it is a valid rate string of either the form rate_numerator/rate_denominator or simply rate_numerator if rate_numerator is an integer value. Converts the numerator and denominator to integers and stores them at the provided pointer locations.

Parameters
rate_strPointer to the string to be evaluated.
rate_numerator_ptrThe pointer to where we should store the numerator integer.
rate_denominator_ptrThe pointer to where we should store the denominator integer. If only rate numerator was provided (rate numerator is an integer value), then this value will be set to 1.
Returns
True if success, false if the rate_str is not of the proper syntax or if it does not contain integers for the numerator and denominator (if a denominator is provided).

◆ IsUniqueStreamIdentifiers()

static bool IsUniqueStreamIdentifiers ( TestSettings *const test_settings_ptr)
static

Verify that stream identifiers are unique. Helper for VerifyTestSettings.

Parameters
test_settings_ptrA pointer to the test settings data structure for the current connection to be evaluated.
Returns
true if stream identifiers are unique, false otherwise.

◆ LogComponentExists()

static bool LogComponentExists ( CdiLogComponent * log_component_array_ptr,
CdiLogComponent * component_ptr )
static

This function searches the log_component array for a matching CdiLogComponent.

Parameters
log_component_array_ptrA Pointer to the log component array maintained in global_test_settings.
component_ptrPointer to the log component that is to be searched in the log_component array.
Returns
bool True if found in the array, false if not found in array.

◆ LogComponentToString()

void LogComponentToString ( const CdiEnumStringKey * key_array,
char * log_component_str,
CdiLogComponent * log_component_ptr )

A function that turns selected log components into a string of log components delimited by the '|' character.

Parameters
key_arrayArray of log component (enum, string) items.
log_component_strA pointer to the buffer that the resulting log component string will be held.
log_component_ptrA pointer to the array of selected log components; this is held in the global_test_settings structure.

◆ ParseGlobalOptions()

static bool ParseGlobalOptions ( int argc,
const char ** argv_ptr,
OptArg * opt_ptr )
static

Use GetOpt to parse through the command line options looking for global options, and assign them to global data structures when found.

Parameters
argcThe system command line argument count variable.
argv_ptrThe pointer to the system command line arguments array.
opt_ptrThe pointer to the options structure that contains the available options.
Returns
False if any help options are found, or if errors are encountered. True if no help options are found.

◆ ParseHelpOptions()

static ProgramExecutionStatus ParseHelpOptions ( int argc,
const char ** argv_ptr,
OptArg * opt_ptr )
static

Use GetOpt to parse through the command line options looking for help commands, and run them if they are found.

Parameters
argcThe system command line argument count variable.
argv_ptrThe pointer to the system command line arguments array.
opt_ptrThe pointer to the options structure that contains the available options.
Returns
ProgramExecutionStatus to indicate whether the program should continue and if not, what exit status to have.

◆ PrintRiffHelp()

static void PrintRiffHelp ( const OptArg * opt_ptr)
static

Prints help on RIFF format and usage in cdi_test.

Parameters
opt_ptrPointer to option argument.

◆ PrintTestSettings()

void PrintTestSettings ( const TestSettings *const test_settings_ptr,
const int num_connections )

Pretty-print the test settings.

Parameters
test_settings_ptrPointer to the test settings struct.
num_connectionsThe number of connections in the test_settings array.

◆ PrintUsageAudio()

static void PrintUsageAudio ( const OptDef * opt_array_ptr,
const OptArg * opt_ptr )
static

Prints the audio usage message.

Parameters
opt_array_ptrPointer to the options array, where all usage information is stored.
opt_ptrPointer to option argument.

◆ PrintUsageVideo()

static void PrintUsageVideo ( const OptDef * opt_array_ptr,
const OptArg * opt_ptr )
static

Prints the main usage message.

Parameters
opt_array_ptrPointer to the options array, where all usage information is stored.
opt_ptrPointer to optional argument.

◆ ProcessLogFilenameOption()

static bool ProcessLogFilenameOption ( bool is_single_file,
const char * filename_str )
static

Process a "--log" or a "--logs" command line option, setting the single connection log file flag and make a copy of the log filename in the global test settings.

Parameters
is_single_filetrue if using the "--log" command line option (single log file), otherwise use false.
filename_strPointer to log filename string to save.

Return true if success, otherwise the log filename has already been set and false is returned.

◆ SetConnectionRatePeriods()

static void SetConnectionRatePeriods ( TestSettings * test_settings_ptr)
static

Calculates the frame rate period and RTP video/ancillary timestamp periods for this connection and assigns to the TestSettings for each connection. This function is called only if the rate settings have been verified.

Parameters
test_settings_ptrPointer to the TestSettings structure for each connection.

◆ TestPatternEnumToString()

static const char * TestPatternEnumToString ( TestPatternType enum_value)
static

Function used to convert a test pattern enum value to a string.

Parameters
enum_valueValue to convert to a string.
Returns
Pointer to returned string. If no match was found, NULL is returned.

◆ TestPatternStringToEnum()

static TestPatternType TestPatternStringToEnum ( const char * name_str)
static

Function used to convert a test pattern string to a matching enum value.

Parameters
name_strPointer to string name of enumerated value.
Returns
Returned enumerated value. If no match was found, CDI_INVALID_ENUM_VALUE is returned.

◆ TestProtocolEnumToString()

static const char * TestProtocolEnumToString ( CdiConnectionProtocolType enum_value)
static

Function used to convert a test protocol enum value to a string.

Parameters
enum_valueValue to convert to a string.
Returns
Pointer to returned string. If no match was found, NULL is returned.

◆ TestProtocolStringToEnum()

static CdiConnectionProtocolType TestProtocolStringToEnum ( const char * name_str)
static

Function used to convert a test protocol string to a matching enum value.

Parameters
name_strPointer to string name of enumerated value.
Returns
Returned enumerated value. If no match was found, CDI_INVALID_ENUM_VALUE is returned.

◆ VerifyTestSettings()

static bool VerifyTestSettings ( TestSettings *const test_settings_ptr)
static

After all settings for a given connection have been collected by the options parser, this function will check that they are all legal, and error out if they are not.

Parameters
test_settings_ptrA pointer to the test settings data structure for the current connection to be evaluated.
Returns
true if all test settings are valid and complete; false if there are argument errors.

Variable Documentation

◆ my_options

OptDef my_options[]
static

User-defined command-line options. These are the short options and the long options for our command line arguments. Keep these organized, so they're easy to change and also easy to debug. The last element is required to be 0's.

NOTE: Must keep this table in sync with typedef enum TestOptionNames in test_args.h.

◆ patterns_key_array

const CdiEnumStringKey patterns_key_array[]
static
Initial value:
= {
{ kTestPatternSame, "SAME" },
{ kTestPatternInc, "INC" },
{ kTestPatternSHR, "SHR" },
{ kTestPatternSHL, "SHL" },
{ kTestPatternNone, "NONE" },
{ kTestPatternIgnore, "IGNORE" },
}
#define CDI_INVALID_ENUM_VALUE
Used to define an invalid enum found.
Definition cdi_utility_api.h:38

Enum/String array that contains valid test pattern modes.