This repository has been archived on 2026-12-03. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Ratatoskr-receiver/plugin/tests/abi_smoke.c
Meta Vens 58210c99fd The squirrel, carrying messages it does not own
Ratatoskr subscribes to a CultMesh media stream and hands frames to a renderer.
First lowering target is OBS.

It exists because the receiver it replaces hand-rolled CultNet RUDP in C++
inside Mimir: acknowledgement, fragment reassembly, sockets, cultmesh:// URL
parsing, wire framing and two erasure codes, in 973 lines of headers linking no
CultLib. That made the receiving end of a protocol a separate implementation
from the sending end, in another language and another repository, and every
CultNet fix from August and September reached cultnet-rs and cultnet-ts without
reaching it.

So the constraint this repo holds is that it implements no transport. It
consumes CultNet. A sequence number or an ACK mask appearing here means
something belongs upstream in CultLib instead, where both ends can share it.

What works: the core opens a subscription over cultnet-rs, drains it, and hands
payloads across a C ABI. Nine Rust tests and fourteen C checks, the latter
loading the cdylib and verifying the header tells the truth rather than assuming
it. The MSVC staticlib is what the plugin will link; the C smoke test loads the
cdylib dynamically so the ABI is checkable with any compiler.

What does not: no reassembly, no FEC, no receiver feedback, and no plugin. It
cannot decode a real Muninn stream yet, because the wire envelope
(MuninnMediaWireRecord, encode_media_wire_record) still lives in Muninn and
needs to move to CultLib where both ends can reach it. README says so plainly
rather than implying more than exists.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 01:41:30 +02:00

77 lines
3.4 KiB
C

/* Proves the C ABI is callable and behaves as its header claims.
*
* Loads the cdylib at runtime rather than linking it. That keeps the test
* compiler-agnostic — the production plugin is built with MSVC, this runs
* anywhere — and it exercises the library the way a host actually loads it.
*/
#include "ratatoskr.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
static int failures = 0;
static void check(int ok, const char *what)
{
if (!ok) { printf("FAIL %s\n", what); failures++; }
else { printf("ok %s\n", what); }
}
typedef int (*open_fn)(const char *, const char *, unsigned int, RatatoskrHandle **);
typedef int (*poll_fn)(RatatoskrHandle *);
typedef int (*next_fn)(RatatoskrHandle *, uint8_t *, size_t, size_t *);
typedef uint16_t (*port_fn)(RatatoskrHandle *);
typedef void (*delivered_fn)(RatatoskrHandle *, uint64_t *, uint64_t *);
typedef size_t (*err_fn)(char *, size_t);
typedef void (*close_fn)(RatatoskrHandle *);
int main(int argc, char **argv)
{
const char *dll = argc > 1 ? argv[1] : "ratatoskr_core.dll";
HMODULE lib = LoadLibraryA(dll);
if (!lib) { printf("FAIL could not load %s (error %lu)\n", dll, GetLastError()); return 1; }
open_fn r_open = (open_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_open");
poll_fn r_poll = (poll_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_poll");
next_fn r_next = (next_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_next_payload");
port_fn r_port = (port_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_local_port");
delivered_fn r_delivered = (delivered_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_delivered");
err_fn r_err = (err_fn)(void *)GetProcAddress(lib, "ratatoskr_last_error");
close_fn r_close = (close_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_close");
check(r_open && r_poll && r_next && r_port && r_delivered && r_err && r_close,
"every documented symbol is exported");
if (failures) { printf("ABI SMOKE FAILED\n"); return 1; }
RatatoskrHandle *handle = NULL;
check(r_open("127.0.0.1:0", "ratatoskr-abi-smoke", 0x0BE00001u, &handle) == RATATOSKR_OK,
"open returns OK");
check(handle != NULL, "open yields a handle");
check(r_port(handle) != 0, "ephemeral bind resolves to a real port");
check(r_poll(handle) == 0, "idle poll reports nothing waiting");
size_t out_len = 12345;
unsigned char buffer[64];
check(r_next(handle, buffer, sizeof buffer, &out_len) == RATATOSKR_NONE,
"empty queue reports NONE, not an error");
check(out_len == 0, "NONE writes a zero length");
uint64_t payloads = 7, bytes = 7;
r_delivered(handle, &payloads, &bytes);
check(payloads == 0 && bytes == 0, "delivered counts start at zero");
r_close(handle);
handle = NULL;
check(r_open("not-an-address", "x", 1, &handle) == RATATOSKR_ERR_ARGUMENT,
"a bad bind address is refused");
check(handle == NULL, "a refused open leaves no handle");
char message[256];
check(r_err(message, sizeof message) > 0, "a failure leaves a message");
check(strstr(message, "not-an-address") != NULL, "the message names the bad input");
r_close(NULL);
check(r_poll(NULL) == RATATOSKR_ERR_ARGUMENT, "null handle is refused");
check(r_port(NULL) == 0, "null handle reports no port");
printf("%s\n", failures ? "ABI SMOKE FAILED" : "ABI SMOKE PASSED");
return failures ? 1 : 0;
}