Skip to content

Repository files navigation

microassert

CILicense: MITC99

microassert is a small assert and panic library for C and C++ consumers. It has no third-party dependencies and formats messages with the standard C library vsnprintf.

Features

  • explicit, status-returning initialization
  • caller-owned hook storage and retained history storage
  • WARN, ERROR, FATAL, and HALT severities
  • copied history entries with bounded text buffers
  • deterministic nested-panic handling and terminal callbacks
  • C99 minimum, C11-compatible source
  • C and C++ header compatibility

Quick Start

#include"massert.h"staticuint32_tclock_ms(void)
{
return1234u;
}
staticvoidreset_cb(void*ctx)
{
(void)ctx;
}
staticvoidhalt_cb(void*ctx)
{
(void)ctx;
}
intmain(void)
{
massert_hook_slot_thooks[2];
massert_history_entry_thistory[4];
massert_tma;
massert_config_tconfig= {
hooks,
2u,
history,
4u,
clock_ms,
reset_cb,
NULL,
halt_cb,
NULL
};
if (massert_init(&ma, &config) !=MASSERT_STATUS_OK) {
return1;
}
MASSERT_WARN(1==1, "not reached");
MASSERT_MSG(2==3, "mismatch: %d", 3);
MPANIC("fatal condition");
}

Build

Direct Makefile workflow:

mingw32-make test

CMake workflow:

cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build
ctest --test-dir build --output-on-failure
cmake --install build --prefix /tmp/microassert-install

Public API

  • massert_init() validates caller storage and copies callbacks by value.
  • massert_set_reset() and massert_set_halt() reject mutation while a panic is active.
  • massert_fire() routes WARN and ERROR back to the caller, while FATAL and HALT are terminal.
  • massert_panic_fatal() calls reset, then halt if reset returns, then spins.
  • massert_panic_halt() calls halt, then spins if halt returns.
  • massert_history_at() returns retained copied history, valid until overwritten or reinit.

Notes

  • Hooks are best-effort and do not guarantee logging, persistence, or flushing.
  • The global singleton is deterministic, but the library is not thread-safe.
  • FATAL and HALT do not unwind C frames or run C++ destructors.
  • Hardware fault handling, signals, and power-loss recovery are outside the library contract.

Documentation

License

MIT, see LICENSE.

About

Unified panic and assert system for embedded C projects (C99), with hook chain, panic history, and configurable severity handling (WARN/ERROR/FATAL/HALT).

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages