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_avm_api.c File Reference

This file contains unit tests for the AVM API. More...

#include "anc_payloads.h"
#include "cdi_avm_api.h"
#include "cdi_avm_payloads_api.h"
#include "cdi_baseline_profile_02_00_api.h"
#include "cdi_core_api.h"
#include "cdi_logger_api.h"
#include "utilities_api.h"
#include <assert.h>
#include <arpa/inet.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>

Data Structures

struct  GenPacketControl
 Control structure for PacketizeAncCb and UnpacketizeAncCb callbacks. More...
 
struct  GenPacketControl2
 Control structure for UnpacketizeAncCb2 callback. More...
 

Macros

#define CHECK(condition)
 Helper macro.
 
#define CHECK_PAYLOAD_ERRORS(ERRORS, EXPECTED_CHECKSUM_ERRORS, EXPECTED_DATA_COUNT_ERRORS)
 Helper macro: check error counts.
 
#define CHECK_NO_PAYLOAD_ERRORS(errors)
 Helper macro: check that error counts are zero and reset them.
 
#define CHECK_EQUAL_OBJECTS(OBJ1, OBJ2)   CHECK(CheckEqualObjects(&(OBJ1), &(OBJ2), sizeof(OBJ1), 10))
 Helper macro: check that two objects are equal.
 
#define RUN_TEST(test_func)
 Helper macro.
 

Functions

static const CdiSgListMakeAncillaryDataPayload (int which)
 
static const char * WordBits (uint32_t word_)
 
static bool CheckPayloadErrors (const struct AncillaryDataPayloadErrors *errors_ptr, int expected_checksum_errors, int expected_parity_errors, int line_number)
 
static bool CheckEqualObjects (const void *obj1_ptr, const void *obj2_ptr, size_t n, int max_lines)
 
static bool TestGetBaselineUnitSize ()
 Test for CdiAvmGetBaselineUnitSize.
 
static bool TestValidateBaselineVersion ()
 Test for CdiAvmValidateBaselineVersionString.
 
static bool TestRegisterBaselineProfile ()
 Test for CdiAvmRegisterBaselineProfile.
 
static bool TestParseAncillaryDataPayloadHeader ()
 Test ParseAncillaryDataPayloadHeader.
 
static bool TestParseAncillaryDataPacketHeader ()
 Test ParseAncillaryDataPacketHeader.
 
static bool ReferenceParity8 (uint8_t value)
 Parity8 reference implementation.
 
static bool TestParityBits (void)
 Test the parity-bit checking logic.
 
static bool TestParseAncillaryDataPacket (void)
 Test parsing full ancillary data packets.
 
static bool TestPacketChecksum (void)
 Test the checksum calculating logic.
 
static bool TestWriteAncillaryDataPayloadHeader (void)
 Test function.
 
static struct AncillaryDataPacket MakePacket (bool c, uint16_t ln, uint16_t ho, bool s, uint8_t ssrc, uint16_t did, uint16_t sdid, uint8_t dc)
 Helper for some test functions.
 
static bool TestWriteAncillaryDataPacketHeader (void)
 Test WriteAncillaryDataPacketHeader.
 
static bool TestWriteAncillaryDataPacket (void)
 Test WriteAncillaryDataPacket.
 
static bool TestGetAncPayloadSize (void)
 Test CdiAvmGetAncillaryDataPayloadSize.
 
const CdiAvmAncillaryDataPacketGenerateAncDataPacket (int packet_num)
 Helper for Packetize/Unpacketize tests.
 
static bool CheckEqualAncPackets (const CdiAvmAncillaryDataPacket *p1, const CdiAvmAncillaryDataPacket *p2)
 Helper for Packetize and Unpacketize tests.
 
static const CdiAvmAncillaryDataPacketPacketizeAncCb (void *user_data_ptr)
 Callback used by TestPacketizeAnc. Generates four different ANC packets.
 
static void UnpacketizeAncCb (void *user_data_ptr, CdiFieldKind field_kind, const CdiAvmAncillaryDataPacket *packet_ptr, bool has_parity_error, bool has_checksum_error)
 Callback used by TestUnpacketizeAncillaryData. Compares decoded with expected packets.
 
static void UnpacketizeAncCb2 (void *user_data_ptr, CdiFieldKind field_kind, const CdiAvmAncillaryDataPacket *packet_ptr, bool has_parity_error, bool has_checksum_error)
 Callback used by TestAncillaryDataPayloadChunks. Copies data to a buffer.
 
static int ComputeRequiredBufferSize (const struct GenPacketControl *control)
 Helper for serialize/deserialize test.
 
static bool TestAncillaryInternalToExternalCopying (void)
 Test the copy functions between public and internal AncillaryDataPacket structs.
 
static bool TestPacketizeAncillaryData (void)
 Test CdiAvmPacketizeAncillaryData.
 
static bool TestUnpacketizeAncillaryData (void)
 Test CdiAvmUnpacketizeAncillaryData.
 
static bool TestAncillaryDataPayloadChunks (void)
 Test packet_offset and packet_size.
 
CdiReturnStatus TestUnitAvmApi (void)
 External declarations.
 

Variables

static char anc_payload []
 Packetized Anc payload with seven Anc packets generated with GenerateAncDataPacket.
 

Detailed Description

This file contains unit tests for the AVM API.

Macro Definition Documentation

◆ CHECK

#define CHECK ( condition)
Value:
do { \
if (!(condition)) { \
CDI_LOG_THREAD(kLogError, "%s at line [%d] failed", #condition, __LINE__); \
pass = false; \
} \
} while (false);
@ kLogError
Errors to the user.
Definition cdi_log_enums.h:53

Helper macro.

◆ CHECK_NO_PAYLOAD_ERRORS

#define CHECK_NO_PAYLOAD_ERRORS ( errors)
Value:
do { \
CHECK_PAYLOAD_ERRORS(errors, 0, 0); \
memset(&errors, 0, sizeof(errors)); \
} while (false)

Helper macro: check that error counts are zero and reset them.

◆ CHECK_PAYLOAD_ERRORS

#define CHECK_PAYLOAD_ERRORS ( ERRORS,
EXPECTED_CHECKSUM_ERRORS,
EXPECTED_DATA_COUNT_ERRORS )
Value:
do { \
if (!CheckPayloadErrors(&(ERRORS), EXPECTED_CHECKSUM_ERRORS, EXPECTED_DATA_COUNT_ERRORS, __LINE__)) { \
pass = false; \
} \
} while (false)
static bool CheckPayloadErrors(const struct AncillaryDataPayloadErrors *errors_ptr, int expected_checksum_errors, int expected_parity_errors, int line_number)
Definition test_unit_avm_api.c:228

Helper macro: check error counts.

◆ RUN_TEST

#define RUN_TEST ( test_func)
Value:
do { if (!test_func()) { \
CDI_LOG_THREAD(kLogError, "AVM test "#test_func" failed."); \
} } while (false)
@ kCdiStatusFatal
An unspecified, unrecoverable error occurred.
Definition cdi_core_api.h:194

Helper macro.

Function Documentation

◆ CheckEqualObjects()

static bool CheckEqualObjects ( const void * obj1_ptr,
const void * obj2_ptr,
size_t n,
int max_lines )
static

Helper for CHECK_EQUAL_OBJECTS macro: Bit-compare to objects of same size and print their bits if different.

Parameters
obj1_ptrPointer to first object.
obj2_ptrPointer to second object.
nSize in bytes of object.
max_linesMaximum number of lines to print.

◆ CheckPayloadErrors()

static bool CheckPayloadErrors ( const struct AncillaryDataPayloadErrors * errors_ptr,
int expected_checksum_errors,
int expected_parity_errors,
int line_number )
static

Check function used by macro CHECK_PAYLOAD_ERRORS.

Parameters
errors_ptrPointer to error counters.
expected_checksum_errorsNumber of expected checksum errors.
expected_parity_errorsNumber of expected parity errors.
line_numberSource line number to print in an error message.
Returns
True if and only if error counts match expected error counts.

◆ MakeAncillaryDataPayload()

static const CdiSgList * MakeAncillaryDataPayload ( int which)
static

Helper for TestUnpacketizeAncillaryData: wrap payload in an SGL.

Parameters
whichChooses a case.
Returns
Pointer to an SGL.

◆ WordBits()

static const char * WordBits ( uint32_t word_)
static

Debug helper: Print a word's bit representation.

Parameters
word_The 32-bit word to print.