+ +
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/openavx_gateway_test.c - Automated Verification of Unified CLI Suite and Gateway Bridge |
| 7 | */ |
| 8 | |
| 9 | #define _GNU_SOURCE |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <assert.h> |
| 14 | #include <unistd.h> |
| 15 | #include <sys/wait.h> |
| 16 | #include "avx_platform.h" |
| 17 | #include "openavx.h" |
| 18 | |
| 19 | static int run_cli(const char* bin_rel, const char* args) { |
| 20 | char cmd[512]; |
| 21 | /* Try 1: direct relative path as given, e.g. ./bin/openavx */ |
| 22 | snprintf(cmd, sizeof(cmd), "%s %s > /dev/null 2>&1", bin_rel, args); |
| 23 | int ret = system(cmd); |
| 24 | if (WIFEXITED(ret) && WEXITSTATUS(ret) == 0) return 0; |
| 25 | |
| 26 | /* Try 2: prefix with ./build, e.g. ./build/bin/openavx */ |
| 27 | snprintf(cmd, sizeof(cmd), "./build%s %s > /dev/null 2>&1", bin_rel + 1, args); |
| 28 | ret = system(cmd); |
| 29 | if (WIFEXITED(ret) && WEXITSTATUS(ret) == 0) return 0; |
| 30 | |
| 31 | /* Try 3: basename in current dir, e.g. ./openavx */ |
| 32 | const char* base = strrchr(bin_rel, '/'); |
| 33 | if (base) { |
| 34 | snprintf(cmd, sizeof(cmd), ".%s %s > /dev/null 2>&1", base, args); |
| 35 | ret = system(cmd); |
| 36 | if (WIFEXITED(ret) && WEXITSTATUS(ret) == 0) return 0; |
| 37 | } |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | int main(void) { |
| 42 | printf("\n=== OpenAVX CLI & Gateway Integration Tests ===\n\n"); |
| 43 | |
| 44 | /* 1. Test Master CLI Help Banner */ |
| 45 | printf("[*] 1. Testing Master CLI Help Banner (openavx --help)...\n"); |
| 46 | int ret_help = run_cli("./bin/openavx", "--help"); |
| 47 | assert(ret_help == 0); |
| 48 | printf(" [+] openavx --help returned exit code 0.\n"); |
| 49 | |
| 50 | /* 2. Test Master CLI Version Output */ |
| 51 | printf("[*] 2. Testing Version Flag (openavx --version)...\n"); |
| 52 | int ret_ver = run_cli("./bin/openavx", "--version"); |
| 53 | assert(ret_ver == 0); |
| 54 | printf(" [+] openavx --version returned exit code 0.\n"); |
| 55 | |
| 56 | /* 3. Test Subcommand Help Banners */ |
| 57 | printf("[*] 3. Testing Subcommand Help Dispatches...\n"); |
| 58 | const char* subcmds[] = { "find", "monitor", "route", "pattern", "server", "gateway" }; |
| 59 | for (size_t i = 0; i < sizeof(subcmds) / sizeof(subcmds[0]); ++i) { |
| 60 | char args[128]; |
| 61 | snprintf(args, sizeof(args), "%s --help", subcmds[i]); |
| 62 | int ret_sub = run_cli("./bin/openavx", args); |
| 63 | assert(ret_sub == 0); |
| 64 | printf(" [+] Subcommand 'openavx %s --help' returned exit code 0.\n", subcmds[i]); |
| 65 | } |
| 66 | |
| 67 | /* 4. Test Symlink Aliases for Gateway */ |
| 68 | printf("[*] 4. Testing Gateway Symlink Aliases...\n"); |
| 69 | const char* gateway_aliases[] = { |
| 70 | "./bin/openavx-gateway", |
| 71 | "./bin/openavx-web-gateway", |
| 72 | "./bin/openavx_web_gateway" |
| 73 | }; |
| 74 | for (size_t i = 0; i < sizeof(gateway_aliases) / sizeof(gateway_aliases[0]); ++i) { |
| 75 | int ret_alias = run_cli(gateway_aliases[i], "--help"); |
| 76 | if (ret_alias == 0) { |
| 77 | printf(" [+] Alias '%s --help' returned exit code 0.\n", gateway_aliases[i]); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /* 5. Test Invalid Command Error Handling */ |
| 82 | printf("[*] 5. Testing Invalid Command Error Handling...\n"); |
| 83 | char cmd_bad[256]; |
| 84 | snprintf(cmd_bad, sizeof(cmd_bad), "./bin/openavx non_existent_command > /dev/null 2>&1"); |
| 85 | int ret_bad = system(cmd_bad); |
| 86 | if (!WIFEXITED(ret_bad) || WEXITSTATUS(ret_bad) == 0) { |
| 87 | snprintf(cmd_bad, sizeof(cmd_bad), "./build/bin/openavx non_existent_command > /dev/null 2>&1"); |
| 88 | ret_bad = system(cmd_bad); |
| 89 | } |
| 90 | if (!WIFEXITED(ret_bad) || WEXITSTATUS(ret_bad) == 0) { |
| 91 | snprintf(cmd_bad, sizeof(cmd_bad), "./openavx non_existent_command > /dev/null 2>&1"); |
| 92 | ret_bad = system(cmd_bad); |
| 93 | } |
| 94 | assert(WIFEXITED(ret_bad) && WEXITSTATUS(ret_bad) != 0); |
| 95 | printf(" [+] Invalid command correctly returned non-zero exit code (%d).\n", WEXITSTATUS(ret_bad)); |
| 96 | |
| 97 | /* 6. Test Public Logging Level & Callback API */ |
| 98 | printf("[*] 6. Testing Public Logging Level & Callback API...\n"); |
| 99 | { |
| 100 | extern void openavx_gateway_test_log_cb(oavx_log_level_e level, const char *module, |
| 101 | const char *message, void *user_ctx); |
| 102 | oavx_log_level_e orig_level = oavx_get_log_level(); |
| 103 | char captured[512] = {0}; |
| 104 | |
| 105 | oavx_set_log_level(OAVX_LOG_WARN); |
| 106 | assert(oavx_get_log_level() == OAVX_LOG_WARN); |
| 107 | oavx_set_log_callback(openavx_gateway_test_log_cb, captured); |
| 108 | |
| 109 | oavx_log_write(OAVX_LOG_INFO, "test_mod", "filtered_msg"); |
| 110 | assert(captured[0] == '\0'); |
| 111 | |
| 112 | oavx_log_write(OAVX_LOG_WARN, "test_mod", "warn_msg_%d", 42); |
| 113 | const char *expected = "2:test_mod:warn_msg_42\n"; |
| 114 | size_t i = 0; |
| 115 | while (expected[i] != '\0') { |
| 116 | assert(captured[i] == expected[i]); |
| 117 | i++; |
| 118 | } |
| 119 | assert(captured[i] == '\0'); |
| 120 | |
| 121 | oavx_set_log_level(OAVX_LOG_QUIET); |
| 122 | assert(oavx_get_log_level() == OAVX_LOG_QUIET); |
| 123 | oavx_log_write(OAVX_LOG_ERROR, "test_mod", "quiet_filtered"); |
| 124 | assert(captured[i] == '\0'); |
| 125 | |
| 126 | oavx_set_log_callback(NULL, NULL); |
| 127 | oavx_set_log_level(orig_level); |
| 128 | assert(oavx_get_log_level() == orig_level); |
| 129 | } |
| 130 | printf(" [+] Log level filtering and callback routing verified.\n"); |
| 131 | |
| 132 | printf("\n[PASS] openavx_gateway_test\n\n"); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | void openavx_gateway_test_log_cb(oavx_log_level_e level, const char *module, |
| 137 | const char *message, void *user_ctx) { |
| 138 | char *dst = (char *)user_ctx; |
| 139 | if (!dst) return; |
| 140 | size_t len = 0; |
| 141 | while (len < 511 && dst[len] != '\0') len++; |
| 142 | snprintf(dst + len, 512 - len, "%d:%s:%s\n", |
| 143 | (int)level, module ? module : "", message ? message : ""); |
| 144 | } |