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

This file contains definitions and functions that are common to test applications. More...

#include "test_common.h"
#include "cdi_baseline_profile_01_00_api.h"
#include "cdi_baseline_profile_02_00_api.h"
#include <assert.h>
#include <stdlib.h>

Data Structures

struct  CommandLineState
 

Macros

#define MAX_CMD_TOKENS_IN_FILE   (10000)
 The maximum number of command line tokens allowed in a text file when using the @ command line option.
 
#define TestConsoleLog   SimpleConsoleLog
 Define TestConsoleLog.
 

Functions

static int FormatFileString (char *file_buffer_str, const char **cmd_array)
 A helper function that takes in a string of command-line tokens derived from a file. It will parse the string and store the token substrings into an array of the format identical to the command-line parameter, argv_ptr.
 
static bool FileToString (const char *file_name_str, CdiFileID file_handle, char **file_buffer_str)
 A helper function that reads the contents of a file into a buffer.
 
static bool CopyFileContentsToBuffer (const char *file_name_str, char **file_buffer_str)
 This function attempts to take the file buffer and create and array of command strings. If successful, it will substitute the command-line parameters, argc and argv_ptr.
 
static bool CommandsFromFile (char **file_buffer_str, const char **cmd_array_ptr, int *argc, const char ***argv_ptr)
 This function attempts to open and read file into a buffer. If the buffer contains valid command parameters, it will substitute the command-line parameters, argc and argv_ptr.
 
void SimpleConsoleLog (CdiLogLevel log_level, const char *format_str,...)
 
bool TestStringToInt (const char *str, int *num_ptr, char **ret_end_str)
 
bool TestCommandLineParserCreate (int *argc_ptr, const char ***argv_ptr, CommandLineHandle *ret_handle)
 
void TestCommandLineParserDestroy (CommandLineHandle handle)
 
void TestLogAVMChanges (uint16_t stream_identifier, int payload_size, CdiAvmConfig *config_ptr, const CdiAvmBaselineConfig *baseline_config_ptr, CdiAvmBaselineConfig *last_baseline_config_ptr)
 

Detailed Description

This file contains definitions and functions that are common to test applications.

Function Documentation

◆ CommandsFromFile()

static bool CommandsFromFile ( char ** file_buffer_str,
const char ** cmd_array_ptr,
int * argc,
const char *** argv_ptr )
static

This function attempts to open and read file into a buffer. If the buffer contains valid command parameters, it will substitute the command-line parameters, argc and argv_ptr.

Parameters
file_buffer_strPointer to a string that will hold the file contents.
argcPointer to the number of command-line arguments.
argv_ptrPointer to the array of string from the command-line arguments.
cmd_array_ptrPointer to the array of strings that will be used in place of the arguments in argv_ptr.
Returns
true if successful, false if unsuccessful.

◆ CopyFileContentsToBuffer()

static bool CopyFileContentsToBuffer ( const char * file_name_str,
char ** file_buffer_str )
static

This function attempts to take the file buffer and create and array of command strings. If successful, it will substitute the command-line parameters, argc and argv_ptr.

Parameters
file_name_strA string that represents the file name.
file_buffer_strPointer to a string that holds the file contents.
Returns
True if successful, false if unsuccessful.

◆ FileToString()

static bool FileToString ( const char * file_name_str,
CdiFileID file_handle,
char ** file_buffer_str )
static

A helper function that reads the contents of a file into a buffer.

Parameters
file_name_strA string that represents the file name.
file_handleThe handle of the file to open/read.
file_buffer_strPointer to a string that will hold the file contents.
Returns
True if successful, false if unsuccessful.

◆ FormatFileString()

static int FormatFileString ( char * file_buffer_str,
const char ** cmd_array )
static

A helper function that takes in a string of command-line tokens derived from a file. It will parse the string and store the token substrings into an array of the format identical to the command-line parameter, argv_ptr.

Parameters
file_buffer_strThe string of command-line tokens.
cmd_arrayPointer to the resulting array of strings.
Returns
The number of elements in the resulting cmd_array.

◆ SimpleConsoleLog()

void SimpleConsoleLog ( CdiLogLevel log_level,
const char * format_str,
... )

Not using the console logger, so implement this API here so it can be used from within test_common.c and test applications that use this file.

Parameters
log_levelThe log level for this message.
format_strFormat string specifier.
...The remaining parameters contain a variable length list of arguments.

◆ TestCommandLineParserCreate()

bool TestCommandLineParserCreate ( int * argc_ptr,
const char *** argv_ptr,
CommandLineHandle * ret_handle )

Create an instance of a command line parser.

Parameters
argc_ptrPointer to number of command line arguments.
argv_ptrPointer pointer to array of pointers to command line arguments.
ret_handleAddress where to write returned handle of parser.
Returns
true if successful, otherwise false.

◆ TestCommandLineParserDestroy()

void TestCommandLineParserDestroy ( CommandLineHandle handle)

Destroy an instance of the command line parser.

Parameters
handleInstance handle returned from TestCommandLineParserCreate().

◆ TestLogAVMChanges()

void TestLogAVMChanges ( uint16_t stream_identifier,
int payload_size,
CdiAvmConfig * config_ptr,
const CdiAvmBaselineConfig * baseline_config_ptr,
CdiAvmBaselineConfig * last_baseline_config_ptr )
Parameters
stream_identifier
payload_size
config_ptr
baseline_config_ptr
last_baseline_config_ptr

◆ TestStringToInt()

bool TestStringToInt ( const char * str,
int * num_ptr,
char ** ret_end_str )

Convert a string to an integer.

Parameters
strPointer to string to convert.
num_ptrAddress where to write converted integer value.
ret_end_strOptional address where to write pointer to string after last character parsed.
Returns
true if successful, otherwise false.