ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_modem_at_internal.h File Reference

Test-access surface for ra8_modem_at internal helpers (MC/DC). More...

#include <stdint.h>
#include "ra8_attributes.h"
#include <stddef.h>
Include dependency graph for ra8_modem_at_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ra8_modem_line_kind_t : uint8_t {
  k_ra8_modem_line_kind_empty = 0U ,
  k_ra8_modem_line_kind_echo = 1U ,
  k_ra8_modem_line_kind_urc = 2U ,
  k_ra8_modem_line_kind_final_ok = 3U ,
  k_ra8_modem_line_kind_final_err = 4U ,
  k_ra8_modem_line_kind_payload = 5U
}
 Result of processing a single completed line. More...

Functions

ra8_modem_line_kind_t priv_modem_classify (const char *line, const char *cmd_echo, const char *expected_response)
 Classify a complete (NUL-terminated) line for the FSM.
uint16_t priv_modem_str_len (const char *s)
 NUL-terminated string length, capped at UINT16_MAX.
uint8_t priv_modem_starts_with (const char *hay, const char *needle)
 Return 1 iff hay begins with needle.
uint8_t priv_modem_str_eq (const char *a, const char *b)
 Return 1 iff a and b are byte-for-byte equal.
void priv_modem_capture_line (const char *line, char *capture, size_t capture_len, size_t *used)
 Append a NUL-terminated line into capture (with newline sep).
uint8_t priv_modem_reset_line_should_clear (const void *line_buf, uint16_t line_buf_len)
 Pure (state-free) reimplementation of internal_reset_line's line-227 buffer-clear guard.
uint8_t priv_modem_payload_prefix_matches (const char *line, const char *expected_response)
 Pure sibling of the line-573 payload-prefix AND-decision.
uint8_t priv_modem_capture_should_clear (const void *capture, size_t capture_len)
 Pure sibling of the line-664 capture-buffer-init AND-decision.

Detailed Description

Test-access surface for ra8_modem_at internal helpers (MC/DC).

Not part of the public API. Tests under tests/ MAY include this header to drive compound boolean decisions that sit in TU-private helpers behind the public ra8_modem_at facade. See CLAUDE.md "Test access to internal symbols (MC/DC scope)".

Definition in file ra8_modem_at_internal.h.

Enumeration Type Documentation

◆ ra8_modem_line_kind_t

enum ra8_modem_line_kind_t : uint8_t

Result of processing a single completed line.

Mirror of the TU-local enum in ra8_modem_at.c. Exposed so tests can read the return value of internal_classify().

Enumerator
k_ra8_modem_line_kind_empty 

RA8 modem line kind empty.

k_ra8_modem_line_kind_echo 

RA8 modem line kind echo.

k_ra8_modem_line_kind_urc 

RA8 modem line kind urc.

k_ra8_modem_line_kind_final_ok 

RA8 modem line kind final ok.

k_ra8_modem_line_kind_final_err 

RA8 modem line kind final error.

k_ra8_modem_line_kind_payload 

RA8 modem line kind payload.

Definition at line 32 of file ra8_modem_at_internal.h.

Function Documentation

◆ priv_modem_capture_line()

void priv_modem_capture_line ( const char * line,
char * capture,
size_t capture_len,
size_t * used )

Append a NUL-terminated line into capture (with newline sep).

Promoted from TU-private static linkage so tests can drive the line-469 NULL+len AND-decision under -fcoverage-mcdc. Production callers must keep using the public facade.

Parameters
[in]lineNUL-terminated line to append (must be non-NULL).
[in,out]captureCaller-owned buffer (NULL allowed; no-op).
[in]capture_lenCapacity of capture in bytes.
[in,out]usedBytes already populated; updated on append.
Precondition
line is non-NULL and NUL-terminated.
used is non-NULL when capture is non-NULL.
Postcondition
No write occurs when capture is NULL or capture_len is 0.
Otherwise, *used is monotonically non-decreasing.
Note
Test-access only.
MC/DC:
Drives line 469 (capture == nullptr) || (capture_len == 0U).
Since
0.1.0

See implementation.

Parameters
[in]lineSee implementation.
[in]captureSee implementation.
[in]capture_lenSee implementation.
[in]usedSee implementation.
Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 578 of file ra8_modem_at.c.

References internal_append_ch().

Referenced by internal_handle_line().

◆ priv_modem_capture_should_clear()

uint8_t priv_modem_capture_should_clear ( const void * capture,
size_t capture_len )

Pure sibling of the line-664 capture-buffer-init AND-decision.

Returns true iff both capture is non-NULL and capture_len is greater than zero, mirroring the AND-decision in internal_wait_response at line 664 of ra8_modem_at.c ((capture != nullptr) && (capture_len > 0U)). The production decision controls a single byte-clear of capture[0] = '\\0'; all four input combinations are exposed here so MC/DC can be driven from a host test (the public send_cmd_capture API rejects capture_len == 0 at the entry guard before internal_wait_response is reached).

Parameters
[in]captureCaller-owned capture buffer (NULL allowed).
[in]capture_lenCapacity of capture in bytes.
Returns
Boolean predicate.
Return values
1capture is non-NULL AND capture_len > 0.
0Either condition fails.
Precondition
None.
None.
Postcondition
No state mutated.
Return value depends solely on the two inputs.
Note
Test-access only. Pure function.
MC/DC:
Drives line 664 of ra8_modem_at.c (2 conditions, AND; N+1 = 3 vectors).
Since
0.1.0

Pure sibling of the line-664 capture-buffer-init AND-decision.

Holds the AND-decision that gates the one-shot capture[0] = '\\0' initialisation in internal_wait_response. Promoted from inline-in-callsite to a TU-external helper so all four input combinations are reachable from a host test (the public send_cmd_capture API rejects capture_len == 0 at the entry guard, so the inline form was structurally limited to (NULL, 0) and (non-NULL, >0)).

Parameters
[in]captureCaller-owned capture buffer (NULL allowed).
[in]capture_lenCapacity of capture in bytes.
Returns
1 iff capture is non-NULL AND capture_len > 0.
Return values
1Both conditions hold.
0Either condition fails.
Precondition
None.
None.
Postcondition
No state mutated.
Return value depends solely on the two inputs.
Note
Pure function; thread-safe.
Since
0.1.0

Definition at line 304 of file ra8_modem_at.c.

Referenced by internal_wait_response().

◆ priv_modem_classify()

ra8_modem_line_kind_t priv_modem_classify ( const char * line,
const char * cmd_echo,
const char * expected_response )

Classify a complete (NUL-terminated) line for the FSM.

Promoted from TU-private static linkage so tests can drive its line-344 compound decision (cmd_echo != nullptr) && (str_eq(line, cmd_echo) != 0U) under -fcoverage-mcdc. Production callers MUST keep using the public ra8_modem_at facade.

Parameters
[in]lineNUL-terminated input line.
[in]cmd_echoOptional expected command echo (NULL = ignore).
[in]expected_responseOptional expected response prefix.
Returns
ra8_modem_line_kind_t Classification.
Return values
k_ra8_modem_line_kind_emptyLine was empty.
k_ra8_modem_line_kind_echoLine matched cmd_echo exactly.
otherOther classification (URC / final / payload).
Precondition
line is non-NULL and NUL-terminated.
Module state is consistent.
Postcondition
No state mutation outside of the URC dispatch path.
Return value reflects the input line.
Note
Test-access only.
MC/DC:
Exposed so tests exercise the line-344 short-circuit AND on the production source.
Since
0.1.0

The expected-prefix and command-echo arguments are caller-supplied because they vary per command invocation. URC dispatch happens inside this helper so the caller does not need to know about it.

Parameters
[in]lineNUL-terminated received line.
[in]cmd_echoCommand we sent (for echo detection), may be NULL when not awaiting echo.
[in]expected_responseOptional caller-specified prefix.
Returns
One of ra8_modem_line_kind_t.
Return values
k_ra8_okOperation succeeded.
Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 438 of file ra8_modem_at.c.

References internal_classify_final(), internal_dispatch_urc(), k_ra8_modem_line_kind_echo, k_ra8_modem_line_kind_empty, k_ra8_modem_line_kind_final_err, k_ra8_modem_line_kind_final_ok, k_ra8_modem_line_kind_payload, k_ra8_modem_line_kind_urc, priv_modem_starts_with(), and priv_modem_str_eq().

Referenced by internal_pump_one(), and ra8_modem_at_poll().

◆ priv_modem_payload_prefix_matches()

uint8_t priv_modem_payload_prefix_matches ( const char * line,
const char * expected_response )

Pure sibling of the line-573 payload-prefix AND-decision.

Returns true iff expected_response is non-NULL, non-empty, and line begins with expected_response. This mirrors the three-condition short-circuit AND in internal_handle_line at line 573 of ra8_modem_at.c ((expected_response != nullptr) && (expected_response[0] != '\0') && (priv_modem_starts_with(line, expected_response) != 0U)). The production helper consults s_mod state to mutate seen_exp; this pure sibling exposes the boolean predicate alone so all four short-circuit MC/DC vectors are reachable from a host test.

Parameters
[in]lineNUL-terminated input line (must be non-NULL).
[in]expected_responseOptional NUL-terminated expected prefix.
Returns
Boolean predicate.
Return values
1All three conditions hold (line begins with the prefix).
0Any one of the three conditions fails (short-circuited).
Precondition
line is non-NULL and NUL-terminated.
No state mutation.
Postcondition
No state mutated.
Return value depends solely on the two inputs.
Note
Test-access only. Pure function.
MC/DC:
Drives line 573 of ra8_modem_at.c (3 conditions, AND; N+1 = 4 vectors).
Since
0.1.0

Pure sibling of the line-573 payload-prefix AND-decision.

Holds the three-condition short-circuit AND that classifies a payload-kind line as matching the caller-supplied expected_response prefix. Promoted from inline-in-callsite to a TU-external helper so all four short-circuit MC/DC vectors can be driven from a host test (the public-API path through send_cmd / send_cmd_capture reaches only a subset of the four input combinations).

Parameters
[in]lineNUL-terminated input line (must be non-NULL).
[in]expected_responseOptional NUL-terminated expected prefix.
Returns
1 iff all three conditions hold.
Return values
1expected_response != NULL && expected_response[0] != '\0' && starts_with(line, expected_response).
0Any one of the three conditions fails.
Precondition
line is non-NULL and NUL-terminated.
No precondition on expected_response (NULL accepted).
Postcondition
No state mutated.
Return value depends solely on the two inputs.
Note
Pure function; thread-safe.
Since
0.1.0

Definition at line 271 of file ra8_modem_at.c.

References priv_modem_starts_with().

Referenced by internal_handle_line().

◆ priv_modem_reset_line_should_clear()

uint8_t priv_modem_reset_line_should_clear ( const void * line_buf,
uint16_t line_buf_len )

Pure (state-free) reimplementation of internal_reset_line's line-227 buffer-clear guard.

Returns true iff line_buf is non-NULL and line_buf_len > 0 – the exact decision exercised by the production helper internal_reset_line at line 227. The state-reading wrapper passes through s_mod.cfg.line_buf / s_mod.cfg.line_buf_len, both of which are gated by the init validator. This pure sibling exists so tests can drive the AND under -fcoverage-mcdc with all four input combinations.

Parameters
[in]line_bufCaller-owned line buffer (NULL when absent).
[in]line_buf_lenCapacity of line_buf in bytes.
Returns
Boolean predicate.
Return values
trueBoth arguments are non-NULL / non-zero (would clear).
falseEither argument signals "no buffer installed".
Precondition
None.
None.
Postcondition
No state mutated.
Return value depends solely on the two inputs.
Note
Test-access only. Pure function.
MC/DC:
Drives line 227 (s_mod.cfg.line_buf != nullptr) && (s_mod.cfg.line_buf_len > 0U) (2 conditions, AND; N+1 = 3 vectors).
Since
0.1.0

Pure (state-free) reimplementation of internal_reset_line's line-227 buffer-clear guard.

Promoted as a free function so tests can drive both (line_buf, line_buf_len) input combinations directly under -fcoverage-mcdc on the production source. The state- reading wrapper internal_reset_line forwards to this helper with s_mod.cfg.line_buf and s_mod.cfg.line_buf_len.

Parameters
[in]line_bufCaller-owned buffer pointer (NULL allowed).
[in]line_buf_lenCapacity of line_buf in bytes.
Returns
1 iff both arguments indicate an installed buffer.
Return values
1line_buf!=NULL and line_buf_len>0.
0Either argument signals "no buffer".
Precondition
None.
None.
Postcondition
No state mutated.
Return value depends solely on the two inputs.
Note
Pure function; thread-safe.
Since
0.1.0

Definition at line 238 of file ra8_modem_at.c.

Referenced by internal_reset_line().

◆ priv_modem_starts_with()

uint8_t priv_modem_starts_with ( const char * hay,
const char * needle )

Return 1 iff hay begins with needle.

Promoted from TU-private static linkage so tests can drive the inner compare branch on the production source.

Parameters
[in]hayNUL-terminated haystack.
[in]needleNUL-terminated prefix.
Returns
1 on match, 0 otherwise.
Return values
1hay begins with needle (or needle is empty).
0needle differs from the leading bytes of hay.
Precondition
hay is non-NULL and NUL-terminated.
needle is non-NULL and NUL-terminated.
Postcondition
No state mutated.
Return value reflects byte-wise prefix comparison.
Note
Test-access only.
Since
0.1.0

Return 1 iff hay begins with needle.

Parameters
[in]hayNUL-terminated haystack.
[in]needleNUL-terminated prefix.
Returns
1 on match, 0 otherwise.

See implementation.

Return values
k_ra8_okOperation succeeded.
Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 149 of file ra8_modem_at.c.

Referenced by internal_classify_final(), internal_dispatch_urc(), priv_modem_classify(), and priv_modem_payload_prefix_matches().

◆ priv_modem_str_eq()

uint8_t priv_modem_str_eq ( const char * a,
const char * b )

Return 1 iff a and b are byte-for-byte equal.

Promoted from TU-private static linkage so tests can drive the line-177 loop AND and the line-184 terminator AND on the production source under -fcoverage-mcdc.

Parameters
[in]aNUL-terminated string.
[in]bNUL-terminated string.
Returns
1 if equal, 0 otherwise.
Return values
1Both strings are byte-for-byte equal including length.
0Strings differ in length or any byte.
Precondition
a is non-NULL and NUL-terminated.
b is non-NULL and NUL-terminated.
Postcondition
No state mutated.
Return value reflects exact byte-wise equality.
Note
Test-access only.
MC/DC:
Drives lines 177 (a[i] != '\0') && (b[i] != '\0') and 184 (a[i] == '\0') && (b[i] == '\0').
Since
0.1.0

Return 1 iff a and b are byte-for-byte equal.

Parameters
[in]aFirst string.
[in]bSecond string.
Returns
1 if equal, 0 otherwise.

See implementation.

Return values
k_ra8_okOperation succeeded.
Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 177 of file ra8_modem_at.c.

Referenced by internal_classify_final(), internal_urc_replace(), and priv_modem_classify().

◆ priv_modem_str_len()

uint16_t priv_modem_str_len ( const char * s)

NUL-terminated string length, capped at UINT16_MAX.

Promoted from TU-private static linkage so tests can drive its line-124 compound decision under -fcoverage-mcdc. Production callers must keep using the public facade.

Parameters
[in]sNUL-terminated input string (must be non-NULL).
Returns
Length in bytes (0..UINT16_MAX-1).
Return values
0s[0] is the NUL terminator (empty string).
Precondition
s is non-NULL.
s is NUL-terminated within UINT16_MAX bytes.
Postcondition
No state mutated.
Return value matches the position of the first NUL byte.
Note
Test-access only.
MC/DC:
Drives line 124 (i < UINT16_MAX) && (s[i] != '\0').
Since
0.1.0

NUL-terminated string length, capped at UINT16_MAX.

Parameters
[in]sNUL-terminated input string (must be non-NULL).
Returns
Length in bytes, capped at UINT16_MAX.

See implementation.

Return values
k_ra8_okOperation succeeded.
Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 124 of file ra8_modem_at.c.

Referenced by ra8_modem_at_register_unsolicited_handler().