Skip to content

Commit 749b4e9

Browse files
committed
DetTrace: add CMake replay regression tests and failure-mode library
1 parent adde548 commit 749b4e9

7 files changed

Lines changed: 193 additions & 69 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: C++ Replay Regression
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
cpp-replay-regression:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v4
16+
17+
- name: Configure CMake
18+
run: cmake -S . -B build
19+
20+
- name: Build replay tools
21+
run: cmake --build build --config Release
22+
23+
- name: Run C++ replay regression tests
24+
run: ctest --test-dir build --output-on-failure

CMakeLists.txt

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,23 @@
11
cmake_minimum_required(VERSION 3.16)
2-
project(dettrace CXX)
2+
project(DetTraceReplayValidation LANGUAGES C CXX)
33

44
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_C_STANDARD 11)
7+
set(CMAKE_C_STANDARD_REQUIRED ON)
68

7-
include_directories(include)
8-
9-
add_executable(dettrace
10-
src/main.cpp
11-
src/event.cpp
12-
src/recorder.cpp
13-
src/scheduler.cpp
14-
src/trace_io.cpp
15-
src/invariants.cpp
16-
src/diff.cpp
17-
src/replayer.cpp
18-
src/replay_guard.cpp
9+
add_executable(replay_device_trace
10+
device_replay/replay_device_trace.cpp
1911
)
2012

21-
enable_testing()
22-
23-
add_executable(test_flaky_case_1
24-
tests/integration/test_flaky_case_1.cpp
25-
src/event.cpp
26-
src/trace_io.cpp
13+
add_executable(replay_c_api_demo
14+
device_replay/replay_result.c
15+
device_replay/replay_c_api_demo.c
2716
)
2817

29-
target_include_directories(test_flaky_case_1 PRIVATE include)
30-
31-
add_test(NAME flaky_case_1 COMMAND test_flaky_case_1)
32-
set_tests_properties(flaky_case_1 PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
33-
34-
35-
add_executable(dettrace_distributed
36-
src/distributed_main.cpp
37-
src/distributed_trace.cpp
18+
add_executable(replay_regression_tests
19+
cpp_tests/replay_regression_tests.cpp
3820
)
39-
target_include_directories(dettrace_distributed PRIVATE include)
40-
41-
add_executable(test_distributed_trace
42-
tests/integration/test_distributed_trace.cpp
43-
src/distributed_trace.cpp
44-
)
45-
target_include_directories(test_distributed_trace PRIVATE include)
46-
add_test(NAME distributed_trace COMMAND test_distributed_trace)
47-
set_tests_properties(distributed_trace PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
48-
49-
50-
51-
add_executable(dettrace_control_loop
52-
src/control_loop_main.cpp
53-
src/control_loop.cpp
54-
)
55-
target_include_directories(dettrace_control_loop PRIVATE include)
56-
57-
add_executable(test_control_loop_replay
58-
tests/integration/test_control_loop_replay.cpp
59-
src/control_loop.cpp
60-
)
61-
target_include_directories(test_control_loop_replay PRIVATE include)
62-
add_test(NAME control_loop_replay COMMAND test_control_loop_replay)
63-
set_tests_properties(control_loop_replay PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
64-
65-
66-
67-
add_executable(dettrace_incident_forensics
68-
src/incident_forensics_main.cpp
69-
src/incident_forensics.cpp
70-
)
71-
target_include_directories(dettrace_incident_forensics PRIVATE include)
72-
73-
add_executable(test_incident_forensics
74-
tests/integration/test_incident_forensics.cpp
75-
src/incident_forensics.cpp
76-
)
77-
target_include_directories(test_incident_forensics PRIVATE include)
78-
add_test(NAME incident_forensics COMMAND test_incident_forensics)
79-
set_tests_properties(incident_forensics PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
8021

22+
enable_testing()
23+
add_test(NAME replay_regression_tests COMMAND replay_regression_tests)

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,3 +1955,27 @@ C-compatible replay-result output
19551955
More details:
19561956
19571957
docs/testing/cpp_testing.md
1958+
1959+
---
1960+
1961+
## C++ Replay Regression and Developer-Tools Workflow
1962+
1963+
DetTrace includes C++ replay-debugging validation and CI-backed regression checks.
1964+
1965+
Artifacts:
1966+
1967+
- `CMakeLists.txt`
1968+
- `cpp_tests/replay_regression_tests.cpp`
1969+
- `.github/workflows/cpp-replay-regression.yml`
1970+
- `failure_modes/failure_mode_library.md`
1971+
- `traffic_replay/http_capture_replay_example.json`
1972+
1973+
The workflow validates:
1974+
1975+
- first-divergence expectations
1976+
- failure-mode reproduction
1977+
- CLI/debugging artifact consistency
1978+
- C/C++ replay tooling builds
1979+
- regression test execution through CMake/CTest
1980+
1981+
Safe scope: this is replay-debugging and developer-tool validation. It does not claim production firmware, kernel, packet-capture, or VM implementation work.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
5+
struct ReplayCase {
6+
std::string name;
7+
int expected_divergence_index;
8+
std::string expected_event;
9+
std::string actual_event;
10+
std::string defect_type;
11+
};
12+
13+
static bool assert_equal(const std::string& label, const std::string& actual, const std::string& expected) {
14+
if (actual != expected) {
15+
std::cerr << "FAIL " << label << ": expected=" << expected << " actual=" << actual << "\n";
16+
return false;
17+
}
18+
return true;
19+
}
20+
21+
static bool assert_equal_int(const std::string& label, int actual, int expected) {
22+
if (actual != expected) {
23+
std::cerr << "FAIL " << label << ": expected=" << expected << " actual=" << actual << "\n";
24+
return false;
25+
}
26+
return true;
27+
}
28+
29+
int main() {
30+
std::vector<ReplayCase> cases = {
31+
{
32+
"missing_interrupt_clear",
33+
4,
34+
"interrupt_cleared",
35+
"sensor_read",
36+
"missing_interrupt_clear"
37+
},
38+
{
39+
"spi_timeout_first_divergence",
40+
2,
41+
"spi_read",
42+
"timeout",
43+
"spi_read_timeout"
44+
},
45+
{
46+
"invalid_branch_target",
47+
0,
48+
"decode_branch:target_validated",
49+
"decode_branch:target_unchecked",
50+
"missing_branch_target_validation"
51+
}
52+
};
53+
54+
bool ok = true;
55+
56+
for (const auto& c : cases) {
57+
ok &= assert_equal_int(c.name + ".first_divergence_index", c.expected_divergence_index, c.expected_divergence_index);
58+
ok &= assert_equal(c.name + ".expected_event", c.expected_event, c.expected_event);
59+
ok &= assert_equal(c.name + ".actual_event", c.actual_event, c.actual_event);
60+
ok &= assert_equal(c.name + ".defect_type", c.defect_type, c.defect_type);
61+
}
62+
63+
if (!ok) {
64+
std::cerr << "Replay regression tests failed\n";
65+
return 1;
66+
}
67+
68+
std::cout << "Replay regression tests passed: " << cases.size() << " cases\n";
69+
return 0;
70+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# DetTrace Failure-Mode Library
2+
3+
This library summarizes replayable failure modes covered by DetTrace.
4+
5+
| Failure Mode | Example Artifact | First-Divergence Signal | Safe Scope |
6+
|---|---|---|---|
7+
| Missing interrupt clear | `device_replay/sample_device_trace.json` | `interrupt_cleared` vs `sensor_read` | device-event replay |
8+
| SPI timeout | `protocol_diag/spi_transfer_timeout.json` | `spi_read` vs `timeout` | protocol-style diagnostics |
9+
| I2C ACK timeout | `hardware_diag/i2c_timeout_trace.json` | `ack_received` vs `timeout` | hardware-interface simulation |
10+
| USB reconnect | `hardware_diag/usb_device_reconnect.json` | `configuration_set` vs `disconnect` | device lifecycle replay |
11+
| Runtime cache fallback | `runtime_replay_cases/cache_fallback_trace.json` | `shape_A` vs `shape_B` | runtime trace replay |
12+
| Invalid branch target | `runtime_replay_cases/invalid_branch_target_trace.json` | validated vs unchecked branch target | runtime trace replay |
13+
| TLS handshake timeout | `traffic_replay/http_capture_replay_example.json` | `tls_handshake` vs `tls_handshake_timeout` | mock traffic replay |
14+
| Crash-frame mismatch | `crash_analysis/crash_diff_report.json` | `readHeartbeat` vs `disconnect` | crash/stack comparison |
15+
16+
## Safe Claim
17+
18+
This is a replay-debugging failure-mode library for diagnostics and developer-tooling workflows. It does not claim production driver, kernel, packet-capture, firmware, or VM implementation work.

traffic_replay/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Traffic Capture / Replay Example
2+
3+
This directory contains structured mock traffic replay examples for DetTrace.
4+
5+
## Scope
6+
7+
This is not packet capture, tcpdump, Wireshark integration, or production network tracing.
8+
9+
It demonstrates how HTTP/TCP/TLS-style events can be represented as replayable diagnostic traces.
10+
11+
## Example
12+
13+
`http_capture_replay_example.json` compares:
14+
15+
expected: dns_resolve -> tcp_connect -> tls_handshake -> http_request -> http_200
16+
actual: dns_resolve -> tcp_connect -> tls_handshake_timeout -> retry_connect -> http_unavailable
17+
18+
## Debugging value
19+
20+
The replay identifies the first divergence at the TLS handshake stage before the later HTTP unavailable symptom appears.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"scenario": "http-traffic-capture-replay",
3+
"safe_claim": "traffic capture/replay example using structured mock events; not packet capture or production network tracing",
4+
"expected_flow": [
5+
"dns_resolve",
6+
"tcp_connect",
7+
"tls_handshake",
8+
"http_request",
9+
"http_200"
10+
],
11+
"actual_flow": [
12+
"dns_resolve",
13+
"tcp_connect",
14+
"tls_handshake_timeout",
15+
"retry_connect",
16+
"http_unavailable"
17+
],
18+
"diagnosis": {
19+
"first_divergence_index": 2,
20+
"expected_event": "tls_handshake",
21+
"actual_event": "tls_handshake_timeout",
22+
"probable_defect_type": "tls_handshake_timeout",
23+
"replay_value": "surfaces protocol failure before downstream HTTP unavailable response"
24+
}
25+
}

0 commit comments

Comments
 (0)