Skip to content

feat: add fault injection tests and support - #914

Open
niteshpurohit wants to merge 3 commits into
feat/test-harnessfrom
feat/test-fault-injection
Open

niteshpurohit wants to merge 3 commits into
feat/test-harnessfrom
feat/test-fault-injection

Conversation

@niteshpurohit

Copy link
Copy Markdown
Member
  • Introduced laghu_test_fault_injection_test to validate fault injection scenarios.
  • Added laghu_test_faults.cpp and laghu_test_faults.hpp to implement fault injection mechanisms for allocation and I/O operations.
  • Enhanced CMakeLists.txt to include new test files and support for fault injection.
  • Updated DescriptorOperations and MappingOperations to include context for better fault handling.
  • Created io_operations.cpp and io_operations.hpp to manage I/O operations with fault injection capabilities.
  • Modified existing tests to utilize the new fault injection framework, ensuring robustness against failure scenarios.

closes: #78

@niteshpurohit niteshpurohit self-assigned this Sep 10, 2026
@niteshpurohit
niteshpurohit added this pull request to stack #915 September 10, 2026 01:45
@niteshpurohit
niteshpurohit force-pushed the feat/test-fault-injection branch from 812df6f to 4c5788d Compare September 10, 2026 02:39
Copilot AI lite review requested due to automatic review settings September 10, 2026 02:50
@niteshpurohit
niteshpurohit force-pushed the feat/test-fault-injection branch from 4c5788d to 6ff0269 Compare September 10, 2026 02:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Four moderate findings remain, including incomplete mapping support, missing descriptor-close coverage, and a CMake include-interface issue.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds test-only fault-injection support for allocation, descriptor, and I/O paths, with contextual callbacks and build integration.

Changes:

  • Adds deterministic fault plans, adapters, and failure tests.
  • Threads context through mapping and descriptor operations.
  • Integrates new sources and tests into CMake metadata.
File summaries
File Summary Final findings
tests/support/laghu_test_faults.hpp Fault-injection interfaces and identifiers. Moderate (1 vote): Mapping injection points lack an adapter and are rejected by fail_syscall_on; implement support or remove them.
tests/support/laghu_test_faults.cpp Fault-injection implementations. Moderate (2 votes): Mapping failure IDs are unusable because no mapping adapter calls FailurePlan::next; add the adapter/tests or remove the IDs.
tests/support/fault_injection.cpp Allocation and I/O fault-injection tests. Moderate (1 vote): Add coverage for the descriptor-close adapter and injected errno.
tests/core/mapped_regions.cpp Context-aware mapping test callbacks.
tests/core/fd_handles.cpp Context-aware descriptor test callbacks.
src/os/private/laghu/os/internal/io_operations.hpp I/O operation interface.
src/os/io_operations.cpp Default I/O implementations.
src/core/private/laghu/core/internal/mapping_operations.hpp Mapping callback contexts.
src/core/private/laghu/core/internal/descriptor_operations.hpp Descriptor callback context.
src/core/mapped_regions.cpp Mapping context propagation.
src/core/handles.cpp Descriptor context propagation.
CMakeLists.txt Builds and registers fault-injection tests. Moderate (1 vote): Public support headers depend on private include paths unavailable to consumers; propagate the interface paths or split the target.
cmake/LaghuDependencyDag.cmake Adds the I/O source to dependency metadata.
cmake/LaghuBuildIdentity.cmake Tracks new I/O files in build identity inputs.
Review details

Suppressed comments (3)

CMakeLists.txt:66

  • laghu_test_faults.hpp is exposed through laghu_test_support's PUBLIC include directory, but its core/os internal header dependencies are only on PRIVATE include paths. Consumers of the support library cannot include this new framework unless they duplicate the source-private include roots, as the fault-injection target does at lines 81-83. Propagate the required interface include paths or split the fault support into a target with a complete interface.
target_include_directories(laghu_test_support PRIVATE
  "${CMAKE_SOURCE_DIR}/src/core/contract"
  "${CMAKE_SOURCE_DIR}/src/core/private"
  "${CMAKE_SOURCE_DIR}/src/os/private")

tests/support/fault_injection.cpp:117

  • This suite only registers allocation and read/write tests; it never exercises the newly added descriptor-close adapter and plan rule. The existing fd tests use a separate callback, so regressions in fault_close or descriptor scheduling can pass unnoticed. Add a case that configures descriptor_close, adopts a handle with FaultInjectedDescriptorOperations::operations(), and asserts the injected errno.
int main() {
  constexpr std::array tests{
      laghu::test::TestCase{"fault_injection.allocation_rollback", check_allocation_rollback},
      laghu::test::TestCase{"fault_injection.short_io_and_eintr", check_short_io_and_eintr},
  };

tests/support/laghu_test_faults.hpp:17

  • mapping_map and mapping_unmap are declared as injection points, but there is no FaultInjectedMappingOperations adapter and FailurePlan::fail_syscall_on rejects both (it only accepts I/O points or descriptor_close). Callers therefore cannot configure either mapping failure through this framework. Implement the mapping adapter/tests or remove these IDs until they are supported.
  mapping_map = 3,
  mapping_unmap = 4,
  • Files reviewed: 14/14 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/support/laghu_test_faults.cpp Outdated
@niteshpurohit niteshpurohit changed the title feat(tests): add fault injection tests and support feat: add fault injection tests and support Sep 10, 2026
- Introduced `laghu_test_fault_injection_test` to validate fault injection scenarios.
- Added `laghu_test_faults.cpp` and `laghu_test_faults.hpp` to implement fault injection mechanisms for allocation and I/O operations.
- Enhanced `CMakeLists.txt` to include new test files and support for fault injection.
- Updated `DescriptorOperations` and `MappingOperations` to include context for better fault handling.
- Created `io_operations.cpp` and `io_operations.hpp` to manage I/O operations with fault injection capabilities.
- Modified existing tests to utilize the new fault injection framework, ensuring robustness against failure scenarios.

closes: #78
Copilot AI review requested due to automatic review settings September 10, 2026 03:30
@niteshpurohit
niteshpurohit force-pushed the feat/test-fault-injection branch from 6ff0269 to 000831b Compare September 10, 2026 03:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The CMake link-target issue and unsupported mapping fault points remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

tests/support/laghu_test_faults.cpp:125

  • mapping_map and mapping_unmap are exposed as stable failure points, but this predicate rejects both and there is no mapping adapter that calls FailurePlan::next() for them. Consequently fail_syscall_on(FailurePoint::mapping_map, ...) and mapping_unmap always return false, so the advertised map/unmap seams cannot be injected. Add the mapping adapter and coverage, or remove these IDs until they are supported.
  return (is_io_point(point) || point == FailurePoint::descriptor_close) && native_error != 0 &&
         set(point, nth_call, FailureAction{FailureActionKind::errno_failure, native_error, 0});

tests/support/laghu_test_faults.hpp:17

  • These mapping failure points are advertised but cannot currently be injected: fail_syscall_on rejects both values, and no FaultInjectedMappingOperations wrapper calls FailurePlan::next for them. A plan configured for mapping_map or mapping_unmap therefore cannot trigger the corresponding syscall failure, so either wire these points through MappingOperations or remove the IDs until they are supported.
  mapping_map = 3,
  mapping_unmap = 4,
  • Files reviewed: 14/14 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread CMakeLists.txt Outdated
Comment thread tests/support/fault_injection.cpp
Copilot AI review requested due to automatic review settings September 10, 2026 03:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved correctness and test-safety issues remain in the fault-injection implementation and tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

tests/support/fault_injection.cpp:163

  • The short-I/O behavior of fault_read is not exercised here: this test covers a short write and an interrupted read, but never configures short_io_on(os_read, ...). A regression in the read-side count clamping could therefore pass while the advertised read short-I/O seam is broken; add a read case that verifies the returned count and bytes.

tests/support/fault_injection.cpp:173

  • This blocking read happens before checking partial; if the injected write returns an error or fewer than two bytes, the pipe's write end remains open and the test can hang indefinitely instead of reporting a failure. Guard the read on the expected successful count (or make the pipe nonblocking) so fault regressions fail promptly.
  const ssize_t read_count = ::read(pipe_descriptors[0], received.data(), received.size());

tests/support/laghu_test_faults.cpp:237

  • When the wrapped source has release == nullptr, this always supplies fault_release as a non-null BufferBlockSource::Release, so BoundedBuffer accepts the source, can acquire a block, and then silently drops it because fault_release does nothing. Preserve the invalid-source signal by returning a null release callback when the underlying release callback is absent, so BoundedBuffer rejects it before allocating.
laghu::core::BufferBlockSource FaultInjectedBufferSource::block_source() noexcept {
  return laghu::core::BufferBlockSource{this, fault_acquire, fault_release};
}
  • Files reviewed: 14/14 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread tests/support/fault_injection.cpp Outdated
Copilot AI review requested due to automatic review settings September 10, 2026 04:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes add deterministic fault-injection coverage and build integration with no unresolved blocking issues.

Review details
  • Files reviewed: 14/14 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement allocation, syscall, and short-I/O fault injection

3 participants