+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* |
| 2 | * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0 |
| 3 | * Copyright (c) 2026 Saif Mukhtar |
| 4 | * |
| 5 | * OpenAVX - Open Audio-Video eXchange |
| 6 | * test/oavx_telemetry_test.c - Unit test suite for Full Stream Observability Telemetry Engine |
| 7 | */ |
| 8 | |
| 9 | #define _DEFAULT_SOURCE |
| 10 | #define _POSIX_C_SOURCE 200809L |
| 11 | #include "openavx.h" |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | #include <assert.h> |
| 16 | #include <unistd.h> |
| 17 | |
| 18 | int main(void) { |
| 19 | printf("=== OpenAVX Stream Telemetry Tests ===\n\n"); |
| 20 | |
| 21 | /* --------------------------------------------------------------------- */ |
| 22 | /* 1. Defensive Input Validation */ |
| 23 | /* --------------------------------------------------------------------- */ |
| 24 | printf("[*] 1. Testing defensive parameter validation...\n"); |
| 25 | assert(!oavx_stream_get_telemetry(NULL, NULL)); |
| 26 | oavx_telemetry_t dummy; |
| 27 | assert(!oavx_stream_get_telemetry(NULL, &dummy)); |
| 28 | assert(oavx_telemetry_to_json(NULL, NULL, 0) == 0); |
| 29 | assert(oavx_telemetry_to_json(&dummy, NULL, 0) == 0); |
| 30 | char tiny_buf[8]; |
| 31 | assert(oavx_telemetry_to_json(NULL, tiny_buf, sizeof(tiny_buf)) == 0); |
| 32 | printf(" [+] Defensive NULL and boundary validations passed.\n"); |
| 33 | |
| 34 | /* --------------------------------------------------------------------- */ |
| 35 | /* 2. Context Engine and Stream Setup */ |
| 36 | /* --------------------------------------------------------------------- */ |
| 37 | printf("[*] 2. Initializing Context and Transmitter Stream...\n"); |
| 38 | oavx_context_t *ctx = oavx_context_create(); |
| 39 | assert(ctx != NULL); |
| 40 | |
| 41 | oavx_stream_config_t tx_cfg = { |
| 42 | .name = "TELEMETRY_TX_PROD", |
| 43 | .direction = OAVX_DIR_TRANSMIT, |
| 44 | .clock_sync = false |
| 45 | }; |
| 46 | oavx_stream_t *tx_stream = oavx_stream_open(ctx, &tx_cfg); |
| 47 | assert(tx_stream != NULL); |
| 48 | |
| 49 | const oavx_endpoint_t *tx_ep = oavx_stream_get_endpoint(tx_stream); |
| 50 | assert(tx_ep != NULL); |
| 51 | assert(tx_ep->address != NULL && tx_ep->address[0] != '\0'); |
| 52 | printf(" [+] Transmitter bound to endpoint: %s\n", tx_ep->address); |
| 53 | |
| 54 | oavx_telemetry_t tx_telem; |
| 55 | bool ok = oavx_stream_get_telemetry(tx_stream, &tx_telem); |
| 56 | assert(ok); |
| 57 | assert(!tx_telem.is_connected); |
| 58 | assert(tx_telem.video_frames_total == 0); |
| 59 | assert(tx_telem.total_wire_bytes == 0); |
| 60 | printf(" [+] Initial pre-connection TX telemetry verified (0 frames, not connected).\n"); |
| 61 | |
| 62 | /* --------------------------------------------------------------------- */ |
| 63 | /* 3. Connecting Receiver Stream */ |
| 64 | /* --------------------------------------------------------------------- */ |
| 65 | printf("[*] 3. Connecting Receiver Stream to %s...\n", tx_ep->address); |
| 66 | oavx_stream_config_t rx_cfg = { |
| 67 | .name = "TELEMETRY_RX_PROD", |
| 68 | .endpoint = tx_ep->address, |
| 69 | .direction = OAVX_DIR_RECEIVE, |
| 70 | .color_format = OAVX_COLOR_FORMAT_FASTEST, |
| 71 | .bandwidth = OAVX_BANDWIDTH_HIGHEST |
| 72 | }; |
| 73 | oavx_stream_t *rx_stream = oavx_stream_open(ctx, &rx_cfg); |
| 74 | assert(rx_stream != NULL); |
| 75 | |
| 76 | /* Allow TCP handshake to establish */ |
| 77 | usleep(60000); |
| 78 | |
| 79 | oavx_telemetry_t rx_telem; |
| 80 | ok = oavx_stream_get_telemetry(rx_stream, &rx_telem); |
| 81 | assert(ok); |
| 82 | printf(" [+] Post-handshake RX telemetry: connected=%s, endpoint=%s\n", |
| 83 | rx_telem.is_connected ? "true" : "false", rx_telem.remote_endpoint); |
| 84 | assert(rx_telem.is_connected); |
| 85 | |
| 86 | /* --------------------------------------------------------------------- */ |
| 87 | /* 4. Video & Audio Transmission Under Observability Monitoring */ |
| 88 | /* --------------------------------------------------------------------- */ |
| 89 | printf("[*] 4. Transmitting 30 test video frames and audio chunks...\n"); |
| 90 | const uint32_t width = 320; |
| 91 | const uint32_t height = 240; |
| 92 | size_t frame_bytes = (size_t)width * height * 2; /* UYVY */ |
| 93 | uint8_t *yuv_buf = (uint8_t*)calloc(1, frame_bytes); |
| 94 | assert(yuv_buf != NULL); |
| 95 | |
| 96 | for (int i = 0; i < 30; ++i) { |
| 97 | oavx_video_frame_t vframe = { |
| 98 | .width = width, |
| 99 | .height = height, |
| 100 | .fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY, |
| 101 | .planes = { yuv_buf, NULL, NULL, NULL }, |
| 102 | .strides = { width * 2, 0, 0, 0 }, |
| 103 | .pts_ns = (int64_t)i * 33333333LL, |
| 104 | .dts_ns = (int64_t)i * 33333333LL, |
| 105 | .framerate = { .num = 30, .den = 1 }, |
| 106 | .scan_type = OAVX_SCAN_PROGRESSIVE |
| 107 | }; |
| 108 | oavx_status_t st = oavx_stream_send_video(tx_stream, &vframe); |
| 109 | assert(st == OAVX_SUCCESS); |
| 110 | |
| 111 | /* Receive frame on receiver */ |
| 112 | oavx_video_frame_t recv_v = {0}; |
| 113 | oavx_frame_type_t ft = oavx_stream_receive(rx_stream, &recv_v, NULL, NULL, 50); |
| 114 | if (ft == OAVX_FRAME_TYPE_VIDEO) { |
| 115 | oavx_stream_release_video(rx_stream, &recv_v); |
| 116 | } |
| 117 | usleep(1000); |
| 118 | } |
| 119 | free(yuv_buf); |
| 120 | |
| 121 | /* --------------------------------------------------------------------- */ |
| 122 | /* 5. Deep Telemetry Layer Verification (Media, Transport, Kernel) */ |
| 123 | /* --------------------------------------------------------------------- */ |
| 124 | printf("[*] 5. Querying and verifying full multi-layer telemetry...\n"); |
| 125 | memset(&rx_telem, 0, sizeof(rx_telem)); |
| 126 | ok = oavx_stream_get_telemetry(rx_stream, &rx_telem); |
| 127 | assert(ok); |
| 128 | |
| 129 | printf(" --> Media Layer:\n"); |
| 130 | printf(" Delivered Video Frames: %lld\n", (long long)rx_telem.video_frames_total); |
| 131 | printf(" Dropped Video Frames: %lld\n", (long long)rx_telem.dropped_frames_total); |
| 132 | printf(" Instantaneous FPS: %.2f\n", (double)rx_telem.fps); |
| 133 | assert(rx_telem.video_frames_total > 0); |
| 134 | assert(rx_telem.width == width); |
| 135 | assert(rx_telem.height == height); |
| 136 | assert(rx_telem.fourcc == OAVX_FOURCC_VIDEO_TYPE_UYVY); |
| 137 | |
| 138 | printf(" --> Transport Dynamics Layer:\n"); |
| 139 | printf(" Total Wire Bytes: %llu bytes\n", (unsigned long long)rx_telem.total_wire_bytes); |
| 140 | printf(" Instant Bitrate: %.2f Mbps\n", (double)rx_telem.bitrate_mbps); |
| 141 | printf(" Inter-frame Jitter: %.3f ms\n", (double)rx_telem.inter_frame_jitter_ms); |
| 142 | assert(rx_telem.total_wire_bytes > 0); |
| 143 | assert(rx_telem.inter_frame_jitter_ms >= 0.0f); |
| 144 | |
| 145 | printf(" --> OS Kernel Diagnostics Layer:\n"); |
| 146 | printf(" Kernel TCP RTT: %.3f ms\n", (double)rx_telem.kernel_rtt_ms); |
| 147 | printf(" TCP Retransmissions: %u\n", rx_telem.tcp_retransmissions); |
| 148 | printf(" Socket Send Queue: %u bytes\n", rx_telem.socket_send_q_bytes); |
| 149 | printf(" Socket Recv Queue: %u bytes\n", rx_telem.socket_recv_q_bytes); |
| 150 | assert(rx_telem.kernel_rtt_ms >= 0.0f); |
| 151 | |
| 152 | /* --------------------------------------------------------------------- */ |
| 153 | /* 6. JSON Telemetry Export & Formatting Verification */ |
| 154 | /* --------------------------------------------------------------------- */ |
| 155 | printf("[*] 6. Testing oavx_telemetry_to_json() export format...\n"); |
| 156 | char json_buf[2048]; |
| 157 | size_t json_len = oavx_telemetry_to_json(&rx_telem, json_buf, sizeof(json_buf)); |
| 158 | assert(json_len > 0); |
| 159 | assert(json_len < sizeof(json_buf)); |
| 160 | |
| 161 | printf(" [+] Generated JSON Telemetry:\n%s\n", json_buf); |
| 162 | |
| 163 | /* Validate mandatory JSON fields */ |
| 164 | assert(strstr(json_buf, "\"connected\": true") != NULL); |
| 165 | assert(strstr(json_buf, "\"fourcc\": \"UYVY\"") != NULL); |
| 166 | assert(strstr(json_buf, "\"width\": 320") != NULL); |
| 167 | assert(strstr(json_buf, "\"height\": 240") != NULL); |
| 168 | assert(strstr(json_buf, "\"video_frames\":") != NULL); |
| 169 | assert(strstr(json_buf, "\"bitrate_mbps\":") != NULL); |
| 170 | assert(strstr(json_buf, "\"jitter_ms\":") != NULL); |
| 171 | assert(strstr(json_buf, "\"rtt_ms\":") != NULL); |
| 172 | assert(strstr(json_buf, "\"send_queue_bytes\":") != NULL); |
| 173 | assert(strstr(json_buf, "\"recv_queue_bytes\":") != NULL); |
| 174 | |
| 175 | /* Truncation boundary test */ |
| 176 | char tiny_out[16]; |
| 177 | size_t trunc_len = oavx_telemetry_to_json(&rx_telem, tiny_out, sizeof(tiny_out)); |
| 178 | assert(trunc_len == sizeof(tiny_out) - 1); |
| 179 | assert(tiny_out[sizeof(tiny_out) - 1] == '\0'); |
| 180 | printf(" [+] Buffer boundary safety and truncation verified.\n"); |
| 181 | |
| 182 | /* --------------------------------------------------------------------- */ |
| 183 | /* 7. Clean Teardown */ |
| 184 | /* --------------------------------------------------------------------- */ |
| 185 | printf("[*] 7. Closing streams and destroying context...\n"); |
| 186 | oavx_stream_close(rx_stream); |
| 187 | oavx_stream_close(tx_stream); |
| 188 | oavx_context_destroy(ctx); |
| 189 | |
| 190 | printf("\n[PASS] oavx_telemetry_test\n"); |
| 191 | return 0; |
| 192 | } |