Zero-overhead debug, audit, coverage, fault-injection, and test-control primitives for Impulse Graph Engine (modeled on SQLite's sqliteInt.h, main.c sqlite3_test_control, vdbe.h VdbeCoverage, and fault.c).
More...
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
|
| #define | IMPULSE_LIKELY(x) |
| #define | IMPULSE_UNLIKELY(x) |
| #define | IMPULSE_BREAKPOINT() |
| #define | IMPULSE_ASSERT_FAILED_MSG(type, cond_str, file, line, func, msg) |
| #define | IMPULSE_ASSERT_FAILED(type, cond_str, file, line, func) |
| #define | IMPULSE_TESTCTRL_ASSERT 1 |
| #define | IMPULSE_TESTCTRL_ALWAYS 2 |
| #define | IMPULSE_TESTCTRL_NEVER_CORRUPT 3 |
| #define | IMPULSE_TESTCTRL_OPTIMIZATIONS 4 |
| #define | IMPULSE_TESTCTRL_FAULT_CONFIG 5 |
| #define | IMPULSE_TESTCTRL_FAULT_STATUS 6 |
| #define | IMPULSE_TESTCTRL_BENIGN_FAULT 7 |
| #define | IMPULSE_TESTCTRL_VM_BRANCH_COVERAGE 8 |
| #define | IMPULSE_TESTCTRL_TESTCASE_STATS 9 |
| #define | IMPULSE_OPT_CONSTANT_FOLDING (1u << 0) |
| #define | IMPULSE_OPT_KERNEL_FUSION_2HOP (1u << 1) |
| #define | IMPULSE_OPT_DIRECTION_SELECTION (1u << 2) |
| #define | IMPULSE_OPT_REGISTER_PING_PONG (1u << 3) |
| #define | IMPULSE_OPT_SEED_INLINING (1u << 4) |
| #define | IMPULSE_OPT_EARLY_EXIT (1u << 5) |
| #define | IMPULSE_OPT_ADAPTIVE_WALK_PULL (1u << 6) |
| #define | IMPULSE_OPT_SIMD_VECTOR (1u << 7) |
| #define | IMPULSE_OPT_ALL_DISABLED 0x00FFu |
| #define | IMPULSE_COV_BOTH 0 |
| #define | IMPULSE_COV_ALWAYS_TAKEN 1 |
| #define | IMPULSE_COV_NEVER_TAKEN 2 |
| #define | IMPULSE_COV_KIND_TWO_WAY 0x03u |
| #define | IMPULSE_COV_KIND_THREE_WAY 0x07u |
| #define | IMPULSE_CORRUPT_SNAPSHOT (!impulse_test_is_never_corrupt()) |
| #define | IMPULSE_ASSERTIONS_ACTIVE 1 |
| #define | IMPULSE_ASSERT(cond) |
| #define | IMPULSE_ASSERT_MSG(cond, msg) |
| #define | IMPULSE_WELL_FORMED_ASSERT(cond) |
| #define | IMPULSE_VVA_ONLY(X) |
| #define | IMPULSE_TESTONLY(X) |
| #define | IMPULSE_AUDIT_ASSERT(cond) |
| #define | IMPULSE_AUDIT_ASSERT_MSG(cond, msg) |
| #define | IMPULSE_ALWAYS(X) |
| #define | IMPULSE_NEVER(X) |
| #define | IMPULSE_TESTCASE(X) |
| #define | IMPULSE_OK_IF_ALWAYS_TRUE(X) |
| #define | IMPULSE_OK_IF_ALWAYS_FALSE(X) |
|
| static int | impulse_assert_trap_expr (const char *type, const char *cond_str, const char *file, int line, const char *func) |
| int | impulse_test_control (int op,...) |
| int | impulse_test_is_never_corrupt (void) |
| void | impulse_test_set_never_corrupt (int flag) |
| uint32_t | impulse_test_get_opt_disable_mask (void) |
| void | impulse_test_set_opt_disable_mask (uint32_t mask) |
| void | impulse_testcase_record (const char *file, int line, int cond_val) |
| int | impulse_faultsim_step (void) |
| void | impulse_faultsim_begin_benign (void) |
| void | impulse_faultsim_end_benign (void) |
| void | impulse_vm_branch_coverage_reset (void) |
| void | impulse_vm_branch_coverage_set_enabled (int enabled) |
| int | impulse_vm_branch_coverage_is_enabled (void) |
| void | impulse_vm_branch_coverage_record (uint32_t pc, uint8_t opcode, uint32_t site_id, uint8_t kind_mask, uint8_t expectation, uint8_t branch_index) |
| uint8_t | impulse_vm_branch_coverage_get_mask (uint32_t pc, uint8_t opcode, uint32_t site_id) |
| void | impulse_vm_branch_coverage_summary (uint32_t *out_total_sites, uint32_t *out_fully_covered_sites, uint32_t *out_missing_branches) |
Zero-overhead debug, audit, coverage, fault-injection, and test-control primitives for Impulse Graph Engine (modeled on SQLite's sqliteInt.h, main.c sqlite3_test_control, vdbe.h VdbeCoverage, and fault.c).
Distinguishes between:
- IMPULSE_ASSERT: Internal invariant assertions enabled during debug / testing builds.
- IMPULSE_WELL_FORMED_ASSERT: Structural snapshot/bytecode invariants gated by IMPULSE_CORRUPT_SNAPSHOT (SQLite assert(X || CORRUPT_DB) pattern).
- IMPULSE_AUDIT_ASSERT: Expensive O(N) structural invariant assertions enabled only in dedicated deep audit builds.
- IMPULSE_ALWAYS / IMPULSE_NEVER: Tri-mode ductile defensive branch macros (Debug trap, Coverage constant folding, Release self-healing pass-through).
- IMPULSE_TESTCASE: Boundary-value & MC/DC coverage probe macro.
- IMPULSE_VVA_ONLY / IMPULSE_TESTONLY: Ghost variable wrapper for assertion-only state.
ARCHITECTURAL RULE: Never conflate internal invariant assertions with untrusted external input validation. Malformed snapshot files, corrupt binary headers, and invalid user query instructions MUST return impulse_status_t / impulse_vm_status_t error codes and never abort the host.
◆ IMPULSE_ALWAYS
| #define IMPULSE_ALWAYS |
( |
| X | ) |
|
Value:
static int impulse_assert_trap_expr(const char *type, const char *cond_str, const char *file, int line, const char *func)
Definition impulse_assert.h:74
◆ IMPULSE_ASSERT
| #define IMPULSE_ASSERT |
( |
| cond | ) |
|
Value: do { \
if (!(cond)) { \
IMPULSE_ASSERT_FAILED("IMPULSE_ASSERT", #cond, __FILE__, __LINE__, __func__); \
} \
} while (0)
◆ IMPULSE_ASSERT_FAILED
| #define IMPULSE_ASSERT_FAILED |
( |
| type, |
|
|
| cond_str, |
|
|
| file, |
|
|
| line, |
|
|
| func ) |
Value: do { \
fprintf(stderr, \
"[%s FAILED] (%s)\n Location: %s:%d\n Function: %s\n", \
type, cond_str, file, line, func); \
fflush(stderr); \
IMPULSE_BREAKPOINT(); \
} while (0)
◆ IMPULSE_ASSERT_FAILED_MSG
| #define IMPULSE_ASSERT_FAILED_MSG |
( |
| type, |
|
|
| cond_str, |
|
|
| file, |
|
|
| line, |
|
|
| func, |
|
|
| msg ) |
Value: do { \
fprintf(stderr, \
"[%s FAILED] (%s)\n Location: %s:%d\n Function: %s\n Message: %s\n", \
type, cond_str, file, line, func, (msg)); \
fflush(stderr); \
IMPULSE_BREAKPOINT(); \
} while (0)
◆ IMPULSE_ASSERT_MSG
| #define IMPULSE_ASSERT_MSG |
( |
| cond, |
|
|
| msg ) |
Value: do { \
if (!(cond)) { \
IMPULSE_ASSERT_FAILED_MSG("IMPULSE_ASSERT", #cond, __FILE__, __LINE__, __func__, (msg)); \
} \
} while (0)
◆ IMPULSE_ASSERTIONS_ACTIVE
| #define IMPULSE_ASSERTIONS_ACTIVE 1 |
◆ IMPULSE_AUDIT_ASSERT
| #define IMPULSE_AUDIT_ASSERT |
( |
| cond | ) |
|
◆ IMPULSE_AUDIT_ASSERT_MSG
| #define IMPULSE_AUDIT_ASSERT_MSG |
( |
| cond, |
|
|
| msg ) |
◆ IMPULSE_BREAKPOINT
| #define IMPULSE_BREAKPOINT |
( |
| ) |
|
◆ IMPULSE_CORRUPT_SNAPSHOT
SQLite CORRUPT_DB equivalent: True (1) by default when untrusted/corrupt snapshots may be loaded; False (0) when IMPULSE_TESTCTRL_NEVER_CORRUPT is set to 1 in well-formed test suites.
◆ IMPULSE_COV_ALWAYS_TAKEN
| #define IMPULSE_COV_ALWAYS_TAKEN 1 |
Traps if fallthrough (bit 1) ever occurs
◆ IMPULSE_COV_BOTH
| #define IMPULSE_COV_BOTH 0 |
Bytecode branch coverage expectation modes (SQLite VdbeCoverage pattern) Both taken (bit 0) and fallthrough (bit 1) expected
◆ IMPULSE_COV_KIND_THREE_WAY
| #define IMPULSE_COV_KIND_THREE_WAY 0x07u |
◆ IMPULSE_COV_KIND_TWO_WAY
| #define IMPULSE_COV_KIND_TWO_WAY 0x03u |
Bytecode branch coverage kind masks
◆ IMPULSE_COV_NEVER_TAKEN
| #define IMPULSE_COV_NEVER_TAKEN 2 |
Traps if branch taken (bit 0) ever occurs
◆ IMPULSE_LIKELY
| #define IMPULSE_LIKELY |
( |
| x | ) |
|
◆ IMPULSE_NEVER
| #define IMPULSE_NEVER |
( |
| X | ) |
|
◆ IMPULSE_OK_IF_ALWAYS_FALSE
| #define IMPULSE_OK_IF_ALWAYS_FALSE |
( |
| X | ) |
|
◆ IMPULSE_OK_IF_ALWAYS_TRUE
| #define IMPULSE_OK_IF_ALWAYS_TRUE |
( |
| X | ) |
|
Value:Marks pure optimization fast-paths whose truth value does not alter semantics
◆ IMPULSE_OPT_ADAPTIVE_WALK_PULL
| #define IMPULSE_OPT_ADAPTIVE_WALK_PULL (1u << 6) |
◆ IMPULSE_OPT_ALL_DISABLED
| #define IMPULSE_OPT_ALL_DISABLED 0x00FFu |
◆ IMPULSE_OPT_CONSTANT_FOLDING
| #define IMPULSE_OPT_CONSTANT_FOLDING (1u << 0) |
Compiler & VM optimization disable bitmask flags (IMPULSE_TESTCTRL_OPTIMIZATIONS)
◆ IMPULSE_OPT_DIRECTION_SELECTION
| #define IMPULSE_OPT_DIRECTION_SELECTION (1u << 2) |
◆ IMPULSE_OPT_EARLY_EXIT
| #define IMPULSE_OPT_EARLY_EXIT (1u << 5) |
◆ IMPULSE_OPT_KERNEL_FUSION_2HOP
| #define IMPULSE_OPT_KERNEL_FUSION_2HOP (1u << 1) |
◆ IMPULSE_OPT_REGISTER_PING_PONG
| #define IMPULSE_OPT_REGISTER_PING_PONG (1u << 3) |
◆ IMPULSE_OPT_SEED_INLINING
| #define IMPULSE_OPT_SEED_INLINING (1u << 4) |
◆ IMPULSE_OPT_SIMD_VECTOR
| #define IMPULSE_OPT_SIMD_VECTOR (1u << 7) |
◆ IMPULSE_TESTCASE
| #define IMPULSE_TESTCASE |
( |
| X | ) |
|
Value: do { \
impulse_testcase_record(__FILE__, __LINE__, (X) ? 1 : 0); \
} \
} while (0)
#define IMPULSE_UNLIKELY(x)
Definition impulse_assert.h:41
int g_impulse_testcase_enabled
◆ IMPULSE_TESTCTRL_ALWAYS
| #define IMPULSE_TESTCTRL_ALWAYS 2 |
Query/verify IMPULSE_ALWAYS behavior
◆ IMPULSE_TESTCTRL_ASSERT
| #define IMPULSE_TESTCTRL_ASSERT 1 |
impulse_test_control operation codes Query/verify whether IMPULSE_ASSERT is active
◆ IMPULSE_TESTCTRL_BENIGN_FAULT
| #define IMPULSE_TESTCTRL_BENIGN_FAULT 7 |
Enter (1) or exit (0) benign allocation failure scope
◆ IMPULSE_TESTCTRL_FAULT_CONFIG
| #define IMPULSE_TESTCTRL_FAULT_CONFIG 5 |
Configure countdown fault injector (int delay, int repeat)
◆ IMPULSE_TESTCTRL_FAULT_STATUS
| #define IMPULSE_TESTCTRL_FAULT_STATUS 6 |
Query fault injector stats (int* nFail, int* nBenign, int* nTotal)
◆ IMPULSE_TESTCTRL_NEVER_CORRUPT
| #define IMPULSE_TESTCTRL_NEVER_CORRUPT 3 |
Toggle neverCorrupt flag (0=untrusted, 1=well-formed)
◆ IMPULSE_TESTCTRL_OPTIMIZATIONS
| #define IMPULSE_TESTCTRL_OPTIMIZATIONS 4 |
Set/get compiler & VM optimization disable bitmask
◆ IMPULSE_TESTCTRL_TESTCASE_STATS
| #define IMPULSE_TESTCTRL_TESTCASE_STATS 9 |
Sub-ops: 0=reset, 1=stats(uint64_t* hits, uint32_t* sites, uint32_t* both)
◆ IMPULSE_TESTCTRL_VM_BRANCH_COVERAGE
| #define IMPULSE_TESTCTRL_VM_BRANCH_COVERAGE 8 |
Sub-ops: 0=reset, 1=enable(int), 2=summary(uint32_t*, uint32_t*, uint32_t*)
◆ IMPULSE_TESTONLY
| #define IMPULSE_TESTONLY |
( |
| X | ) |
|
◆ IMPULSE_UNLIKELY
| #define IMPULSE_UNLIKELY |
( |
| x | ) |
|
◆ IMPULSE_VVA_ONLY
| #define IMPULSE_VVA_ONLY |
( |
| X | ) |
|
◆ IMPULSE_WELL_FORMED_ASSERT
| #define IMPULSE_WELL_FORMED_ASSERT |
( |
| cond | ) |
|
Value: do { \
IMPULSE_ASSERT_FAILED("IMPULSE_WELL_FORMED_ASSERT", #cond, __FILE__, __LINE__, __func__); \
} \
} while (0)
#define IMPULSE_CORRUPT_SNAPSHOT
Definition impulse_assert.h:155
◆ impulse_assert_trap_expr()
| int impulse_assert_trap_expr |
( |
const char * | type, |
|
|
const char * | cond_str, |
|
|
const char * | file, |
|
|
int | line, |
|
|
const char * | func ) |
|
inlinestatic |
◆ impulse_faultsim_begin_benign()
| void impulse_faultsim_begin_benign |
( |
void | | ) |
|
◆ impulse_faultsim_end_benign()
| void impulse_faultsim_end_benign |
( |
void | | ) |
|
◆ impulse_faultsim_step()
| int impulse_faultsim_step |
( |
void | | ) |
|
Deterministic countdown fault simulator step (returns 0 on success, non-zero on simulated fault)
◆ impulse_test_control()
| int impulse_test_control |
( |
int | op, |
|
|
| ... ) |
Unified C-ABI test control entrypoint
◆ impulse_test_get_opt_disable_mask()
| uint32_t impulse_test_get_opt_disable_mask |
( |
void | | ) |
|
◆ impulse_test_is_never_corrupt()
| int impulse_test_is_never_corrupt |
( |
void | | ) |
|
Direct state accessors used by assertion, coverage, and fault-injection macros
◆ impulse_test_set_never_corrupt()
| void impulse_test_set_never_corrupt |
( |
int | flag | ) |
|
◆ impulse_test_set_opt_disable_mask()
| void impulse_test_set_opt_disable_mask |
( |
uint32_t | mask | ) |
|
◆ impulse_testcase_record()
| void impulse_testcase_record |
( |
const char * | file, |
|
|
int | line, |
|
|
int | cond_val ) |
Boundary testcase probe recording hook
◆ impulse_vm_branch_coverage_get_mask()
| uint8_t impulse_vm_branch_coverage_get_mask |
( |
uint32_t | pc, |
|
|
uint8_t | opcode, |
|
|
uint32_t | site_id ) |
◆ impulse_vm_branch_coverage_is_enabled()
| int impulse_vm_branch_coverage_is_enabled |
( |
void | | ) |
|
◆ impulse_vm_branch_coverage_record()
| void impulse_vm_branch_coverage_record |
( |
uint32_t | pc, |
|
|
uint8_t | opcode, |
|
|
uint32_t | site_id, |
|
|
uint8_t | kind_mask, |
|
|
uint8_t | expectation, |
|
|
uint8_t | branch_index ) |
◆ impulse_vm_branch_coverage_reset()
| void impulse_vm_branch_coverage_reset |
( |
void | | ) |
|
Bytecode-level branch coverage recorder hooks (SQLite vdbeTakeBranch equivalent)
◆ impulse_vm_branch_coverage_set_enabled()
| void impulse_vm_branch_coverage_set_enabled |
( |
int | enabled | ) |
|
◆ impulse_vm_branch_coverage_summary()
| void impulse_vm_branch_coverage_summary |
( |
uint32_t * | out_total_sites, |
|
|
uint32_t * | out_fully_covered_sites, |
|
|
uint32_t * | out_missing_branches ) |
◆ g_impulse_testcase_enabled
| int g_impulse_testcase_enabled |
|
extern |
Fast-path flag for IMPULSE_TESTCASE probes