chaos-clock-skew
Test and verification.
LD_PRELOADlibrary that shifts the wall-clock time a process reads, for chaos tests of clock-related behaviour in DDS.
- Source: crates/chaos-clock-skew
- API docs: docs.rs/chaos-clock-skew
On Linux, chaos-clock-skew builds a shared library
(crate-type = ["cdylib", "rlib"], file libchaos_clock_skew.so)
that exports clock_gettime and gettimeofday. Both call the libc
implementation, found with dlsym(RTLD_NEXT, …), and then add an offset. The
offset comes from two environment variables that are read on every call:
CHAOS_CLOCK_SKEW_NS: fixed offset in nanoseconds, signed (positive: the clock runs ahead).CHAOS_CLOCK_DRIFT_PPM: rate error in parts per million, signed (100: the clock gains 100 µs per second;-100: it loses 100 µs per second).
Behaviour as implemented:
clock_gettimechanges onlyCLOCK_REALTIME;CLOCK_MONOTONICand all other clocks are passed through unchanged.- The offset is
CHAOS_CLOCK_SKEW_NSplus a drift termelapsed_ns * ppm / 1_000_000.elapsed_nsis the time since the first intercepted call in the process, measured on the realCLOCK_MONOTONIC. gettimeofdayapplies the same offset, truncated to microseconds.- Calls that do not go through libc (a raw
syscall, statically linked binaries) are not intercepted. RustSystemTime::now()goes through libc. - If
dlsymdoes not find the real function, the library panics on the first call.
On other operating systems the crate builds a stub without exported symbols; its only
function unsupported() returns "chaos-clock-skew is Linux-only".
Usage from the crate docs:
cargo build -p chaos-clock-skew --release
LD_PRELOAD=$(pwd)/target/release/libchaos_clock_skew.so \
CHAOS_CLOCK_SKEW_NS=100000000 \
CHAOS_CLOCK_DRIFT_PPM=100 \
./my-process
Consumers
- No crate in the workspace declares a dependency on it. It is loaded into a process at
run time via
LD_PRELOAD. The CI jobchaos-soakruns withCHAOS_CLOCK_SKEW_NS=50000000.
Status
std. Containsunsafecode (FFI: exported functions with#[unsafe(no_mangle)],dlsym, pointer casts); noforbid(unsafe_code). Safety classification in the crate docs: STANDARD (FFI boundary, based ondlsym).- No dependencies, no cargo features, no binary.
- Test functions in the source: 10 in the Linux module (offset arithmetic, drift formula, and calls through the exported functions against the real libc clock), 1 in the stub for other operating systems.
chaos-clock-skew
Test und Verifikation.
LD_PRELOAD-Bibliothek, die die Uhrzeit verschiebt, die ein Prozess liest, für Chaos-Tests von uhrzeitabhängigem Verhalten in DDS.
- Quelle: crates/chaos-clock-skew
- API-Docs: docs.rs/chaos-clock-skew
Unter Linux baut chaos-clock-skew eine gemeinsam genutzte Bibliothek
(crate-type = ["cdylib", "rlib"], Datei libchaos_clock_skew.so),
die clock_gettime und gettimeofday exportiert. Beide rufen die
libc-Implementierung auf, die über dlsym(RTLD_NEXT, …) gefunden wird, und
addieren danach einen Versatz. Der Versatz kommt aus zwei Umgebungsvariablen, die bei jedem
Aufruf gelesen werden:
CHAOS_CLOCK_SKEW_NS: fester Versatz in Nanosekunden, mit Vorzeichen (positiv: die Uhr geht vor).CHAOS_CLOCK_DRIFT_PPM: Gangfehler in Millionsteln, mit Vorzeichen (100: die Uhr gewinnt 100 µs je Sekunde;-100: sie verliert 100 µs je Sekunde).
Verhalten laut Implementierung:
clock_gettimeverändert nurCLOCK_REALTIME;CLOCK_MONOTONICund alle anderen Uhren werden unverändert durchgereicht.- Der Versatz ist
CHAOS_CLOCK_SKEW_NSplus ein Driftanteilelapsed_ns * ppm / 1_000_000.elapsed_nsist die Zeit seit dem ersten abgefangenen Aufruf im Prozess, gemessen an der echtenCLOCK_MONOTONIC. gettimeofdaywendet denselben Versatz an, auf Mikrosekunden gekürzt.- Aufrufe, die nicht über die libc laufen (ein direkter
syscall, statisch gelinkte Programme), werden nicht abgefangen. RustSystemTime::now()läuft über die libc. - Findet
dlsymdie echte Funktion nicht, löst die Bibliothek beim ersten Aufruf eine Panic aus.
Auf anderen Betriebssystemen baut die Crate einen Platzhalter ohne exportierte Symbole;
seine einzige Funktion unsupported() liefert
"chaos-clock-skew is Linux-only".
Verwendung laut Crate-Dokumentation:
cargo build -p chaos-clock-skew --release
LD_PRELOAD=$(pwd)/target/release/libchaos_clock_skew.so \
CHAOS_CLOCK_SKEW_NS=100000000 \
CHAOS_CLOCK_DRIFT_PPM=100 \
./my-process
Konsumenten
- Keine Crate im Workspace deklariert eine Abhängigkeit darauf. Die Bibliothek wird zur
Laufzeit über
LD_PRELOADin einen Prozess geladen. Der CI-Jobchaos-soakläuft mitCHAOS_CLOCK_SKEW_NS=50000000.
Status
std. Enthältunsafe-Code (FFI: exportierte Funktionen mit#[unsafe(no_mangle)],dlsym, Zeiger-Umwandlungen); keinforbid(unsafe_code). Einstufung in der Crate-Dokumentation (safety classification): STANDARD (FFI-Grenze, auf Basis vondlsym).- Keine Abhängigkeiten, keine Cargo-Features, kein Binary.
- Testfunktionen im Quelltext: 10 im Linux-Modul (Versatzrechnung, Driftformel und Aufrufe über die exportierten Funktionen gegen die echte libc-Uhr), 1 im Platzhalter für andere Betriebssysteme.