CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
|
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 [] |
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.
enum PortNumLimits |
Enum for max and min IP port numbers.
|
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.
stream_settings_ptr | Pointer to the stream settings array. |
avm_data_type | The AVM data type chosen by the user. |
avm_types_ptr | Pointer to the AVM types counter. |
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.
argc | The system command line argument count variable. |
argv_ptr | The pointer to the system command line arguments array. |
test_settings_ptr | Pointer to an array of test settings data structures we will modify. |
num_connections_found | Pointer to the number of connections found. |
|
static |
This function parses the command-line test arguments for the log components and inserts the valid components into the GlobalTestSettings structure.
component_str | Pointer to the log component that is to be searched in the log_component array. |
log_component_array_ptr | Pointer to the log component array maintained in global_test_settings. |
|
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.
str | The pointer to the string to be evaluated. |
num_ptr | The pointer to the integer location we will store the result of the conversion. |
end_str | The pointer to the remaining string after the converted number has been removed from the beginning. |
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.
str | The 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_ptr | The 64 bit integer representation of the number string in str. May be NULL when the return number is not needed. |
base | The numerical base (N) to use for the compare. |
|
static |
Check a string to see if it is a base-10 number.
str | The string we are checking to see if it represents a base-10 number. |
base10_num_ptr | The integer representation of the number string in str. Maye be NULL when the return number is not needed. |
|
static |
Check a string to see if it is a 32 bit base-N number.
str | The 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_ptr | The integer representation of the number string in str. Set to NULL if the return number is not needed. |
base | The numerical base (N) to use for the compare. |
|
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.
bool_str | The string to be evaluated. |
result | The boolean result after attempting to interpret the input string as a boolean. |
|
static |
Check a string provided to see if the entire thing can be converted to an int.
int_str | The string to be evaluated. |
result_ptr | The integer result after attempting to interpret the input string. |
|
static |
Check a string provided to see if it is a valid ip address string of the form: ip.ip.ip.ip.
ip_addr_str | The string to be evaluated. |
|
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.
rate_str | Pointer to the string to be evaluated. |
rate_numerator_ptr | The pointer to where we should store the numerator integer. |
rate_denominator_ptr | The 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. |
|
static |
Verify that stream identifiers are unique. Helper for VerifyTestSettings.
test_settings_ptr | A pointer to the test settings data structure for the current connection to be evaluated. |
|
static |
This function searches the log_component array for a matching CdiLogComponent.
log_component_array_ptr | A Pointer to the log component array maintained in global_test_settings. |
component_ptr | Pointer to the log component that is to be searched in the log_component array. |
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.
key_array | Array of log component (enum, string) items. |
log_component_str | A pointer to the buffer that the resulting log component string will be held. |
log_component_ptr | A pointer to the array of selected log components; this is held in the global_test_settings structure. |
|
static |
Use GetOpt to parse through the command line options looking for global options, and assign them to global data structures when found.
argc | The system command line argument count variable. |
argv_ptr | The pointer to the system command line arguments array. |
opt_ptr | The pointer to the options structure that contains the available options. |
|
static |
Use GetOpt to parse through the command line options looking for help commands, and run them if they are found.
argc | The system command line argument count variable. |
argv_ptr | The pointer to the system command line arguments array. |
opt_ptr | The pointer to the options structure that contains the available options. |
|
static |
Prints help on RIFF format and usage in cdi_test.
opt_ptr | Pointer to option argument. |
void PrintTestSettings | ( | const TestSettings *const | test_settings_ptr, |
const int | num_connections ) |
Pretty-print the test settings.
test_settings_ptr | Pointer to the test settings struct. |
num_connections | The number of connections in the test_settings array. |
Prints the audio usage message.
opt_array_ptr | Pointer to the options array, where all usage information is stored. |
opt_ptr | Pointer to option argument. |
Prints the main usage message.
opt_array_ptr | Pointer to the options array, where all usage information is stored. |
opt_ptr | Pointer to optional argument. |
|
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.
is_single_file | true if using the "--log" command line option (single log file), otherwise use false. |
filename_str | Pointer to log filename string to save. |
Return true if success, otherwise the log filename has already been set and false is returned.
|
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.
test_settings_ptr | Pointer to the TestSettings structure for each connection. |
|
static |
Function used to convert a test pattern enum value to a string.
enum_value | Value to convert to a string. |
|
static |
Function used to convert a test pattern string to a matching enum value.
name_str | Pointer to string name of enumerated value. |
|
static |
Function used to convert a test protocol enum value to a string.
enum_value | Value to convert to a string. |
|
static |
Function used to convert a test protocol string to a matching enum value.
name_str | Pointer to string name of enumerated value. |
|
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.
test_settings_ptr | A pointer to the test settings data structure for the current connection to be evaluated. |
|
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.
|
static |
Enum/String array that contains valid test pattern modes.