How jnavila/memtester works
Project type and purpose
• memtester is a standalone, command-line utility written in C that stress-tests a machine’s RAM.
• It is not a client/server or web app but a monolithic CLI tool that performs in-process memory tests and interacts directly with the OS.
File structure
• Top-level C source and headers:
• memtester.c – program entry point, argument parsing, orchestration
• tests.c/.h – implementations of individual memory tests (walking bits, random patterns, etc.)
• output.c/.h – formatting and printing test results
• types.h, sizes.h – platform abstractions (integer sizes, type definitions)
• memtester.h – shared declarations (e.g., global options, API between main and tests)
• trycpp.c – small C++ compilation test (platform/compiler probe)
• extra-libs.sh, conf-cc, conf-ld – build probe/config helpers
• Build and install:
• Makefile (with rules for compile, makelib, load, install)
• make-compile.sh, make-makelib.sh, make-load.sh – auxiliary wrappers
• BUGS, CHANGELOG, COPYING – documentation/legal
README for additional insights
• Single binary with optional “-p physaddr” and “-d device” flags that mmap()/mlock() physical memory.
• Core goals: portability across Unix-like systems, full 64-bit awareness, fast execution.
• No external services: everything runs in the process, but it relies on POSIX syscalls (mlock, mmap, strtoull, etc.).
Main components and their interactions
a. CLI Frontend (memtester.c)
• Parses arguments (memory size, run count, -p/-d options)
• Configures OS mode: standard heap allocation or mmap(physical)
• Initializes global state (do_mlock flag, page size, signal handlers)
• Hands off to the Test Orchestrator
b. Memory Manager
• Standard path: calloc()/malloc()
• Physical-memory path: open(device) → mmap() → optionally mlock()
• Exposes a pointer and byte-count to the orchestrator
c. Test Orchestrator (memtester.c → tests API)
• Iteratively invokes each test function in tests.c
• Passes the memory buffer pointer + size
• Collects pass/fail results
d. Test Modules (tests.c/.h)
• Each test implements a signature like int test_xxx(uint8_t *buf, size_t size)
• Tests include bit walking, random patterns, modulo patterns, fragment tests
e. Output/Reporting (output.c/.h)
• Receives test names and statuses, prints formatted output to stdout/stderr
• Handles verbosity, run counters, and error stops
f. OS Interface
• mlock(), munlock() if locking enabled
• open()/mmap()/munmap() on /dev/mem for physical address testing
• strtoull() for parsing memory sizes
• exit codes and signals for failures
Architectural patterns and design principles
• Modular decomposition: clear separation of CLI logic, memory allocation, test implementations, and output formatting.
• POSIX abstraction: uses platform-probe files (conf-cc, conf-ld) and code in types.h/sizes.h to adapt to different word sizes.
• Single-process, in-memory pipeline: no threads, no network.
Putting it all together
• Outside that, show interactions with kernel (syscalls) and /dev/mem.
• A sidebar for build-time components that generate the binary.