How would you test firmware under constrained stack, heap and buffer capacity?
Answer
Establish static and runtime budgets, instrument high-water marks, and exercise worst-case call depth, concurrency, message bursts and malformed input. Check allocation failures, fragmentation, stack overflow detection and buffer boundaries, then run long enough to reveal leaks. The build should fail or alarm before safety margin disappears, not only after a device crashes.
Strong answer includes
- measures high-water marks and safety margin
- forces allocation and buffer failures
- combines static analysis with runtime stress
Practical example
A device passes all functional tests with 40% of its stack free on average. Nobody instruments the actual high-water mark, so nobody notices that a rare error-handling branch with deep nested calls uses 95% of the stack. Months later, a malformed network packet triggers exactly that branch in the field and causes a stack overflow crash that a worst-case stack analysis in CI would have caught in minutes.