Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 695 of 9369. Embedded Systems Reliability and SafetyFree lesson

Applying Boundary Value Analysis for Robust Inputs

Develop test vectors that target extreme input ranges and edge cases to ensure software stability under unexpected environmental conditions.

In this lesson, you will learn how to harden your embedded software by creating targeted test vectors that focus on the precarious edges of input ranges.

The Philosophy of Boundaries

In embedded systems, software often interacts with physical sensors or communication protocols where input values are expected to fall within a specific range (e.g., a temperature sensor reading between -40°C and 125°C). Most developers test the "happy path," but failures rarely occur in the middle of a range. Instead, they happen at the transitions.

Boundary Value Analysis (BVA) is the practice of testing at, just below, and just above the minimum and maximum defined limits. These specific points are high-risk areas where off-by-one errors or overflow conditions typically hide.

Putting BVA into Practice

Consider a function that handles an incoming ADC (Analog-to-Digital Converter) value restricted to a 12-bit range (0 to 4095). If you only test 2048, you miss the potential for integer underflow or buffer index errors at the extremes.

To ensure robustness, you must generate test vectors for these six specific points:

  1. min
  2. min - 1 (Invalid/Under-boundary)
  3. min + 1
  4. max
  5. max + 1 (Invalid/Over-boundary)
  6. max - 1
// Example: Processing a sensor input range [0, 4095]
void process_sensor_data(uint16_t raw_value) {
    if (raw_value > 4095) {
        handle_error_state(); // Boundary check
        return;
    }
    // Logic processing...
}

// Test Vectors:
// [0, 1] - Low boundary
// [4094, 4095, 4096] - High boundary
// [-1] - Underflow test (if using signed intermediate types)

Why This Matters

When performing fault injection testing or unit testing in a simulated environment, BVA provides the most "bang for your buck." By systematically targeting the points where logic transitions from valid to invalid, you force the system to handle unexpected environmental conditions gracefully—whether that means clipping the value, triggering a safe recovery sequence, or executing an exception handler. If your code survives these extreme inputs, you have significantly reduced the surface area for runtime crashes.

Key Takeaway: Robustness is found at the edges; test the minimums and maximums of every input range to ensure your system handles out-of-bounds data before it triggers a critical failure.