Skip to content

Make netebpfext unit test resilient to fault injection. - #5547

Open
Shankar Seal (shankarseal) wants to merge 3 commits into
microsoft:mainfrom
shankarseal:shankarseal-fix-netebpfext-fault-injection
Open

Make netebpfext unit test resilient to fault injection.#5547
Shankar Seal (shankarseal) wants to merge 3 commits into
microsoft:mainfrom
shankarseal:shankarseal-fix-netebpfext-fault-injection

Conversation

@shankarseal

@shankarseal Shankar Seal (shankarseal) commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Description

Fixes #5460 .

Issues

  • Fault injection could cause the mock FwpmFilterAdd0() in usersim.dll to fail during the netebpfext test case initialization, prior to NMR hook provider could bind, leaving the corresponding provider unavailable. Subsequent tests assumed initialization had succeeded, accessed the missing provider data, and crashed on a null pointer.
  • fault.log file was not getting uploaded
  • netebpfext unit test was not built in native flavor.

Changes

The PR includes the following changes.

  • Update usersim to support suspend/resume fault injection.
  • Suspend usersim fault injection while the netebpfext test helper initializes and tears down.
  • Add a unit test that exercises all NMR bindings with fault injection enabled.
  • Require all expected NMR bindings for existing tests while excluding helper initialization from fault injection.
  • Add a CI step that collects fault-injection logs so they are uploaded with the test results.
  • Build Debug/Release configurations of netebpfext_unit. as part of NativeOnly* builds.

Testing

Do any existing tests cover this change? Are new tests needed?

If new tests were added:

  • Unit tests are added.
  • Driver tests are added.
  • Fuzz tests are added.

Documentation

Is there any documentation impact for this change?

Installation

Is there any installer impact for this change?

@github-actions

This comment was marked as resolved.

@shankarseal
Shankar Seal (shankarseal) marked this pull request as draft August 31, 2026 22:12
@shankarseal
Shankar Seal (shankarseal) force-pushed the shankarseal-fix-netebpfext-fault-injection branch from 0be3f74 to a8e58db Compare September 1, 2026 01:29
@github-actions

This comment was marked as resolved.

1 similar comment
@github-actions

This comment was marked as resolved.

Shankar Seal added 2 commits September 1, 2026 18:13
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ea587460-e416-414f-9687-d52ae0a34d8f
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ea587460-e416-414f-9687-d52ae0a34d8f
@shankarseal
Shankar Seal (shankarseal) force-pushed the shankarseal-fix-netebpfext-fault-injection branch from dba2b3f to 60bebfe Compare September 2, 2026 01:13
@github-actions

This comment was marked as resolved.

@shankarseal Shankar Seal (shankarseal) changed the title update netebpfext unit test to suspend fault injection during test init. Make netebpfext unit test resilient to fault injection. Sep 2, 2026
@shankarseal
Shankar Seal (shankarseal) marked this pull request as ready for review September 2, 2026 01:20
Comment thread tests/netebpfext_unit/netebpfext_unit.vcxproj Outdated
Comment thread tests/netebpfext_unit/netebpfext_unit.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new nmr_client_handle registration wrapper treats NULL handles as “registered” and may call NmrDeregisterClient(NULL) on registration failure, which can reintroduce crashes under fault injection.

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

Pull request overview

This PR hardens the netebpfext unit tests against usersim fault injection during NMR/WFP initialization, preventing null-provider crashes and improving CI diagnostics by ensuring fault-injection logs are collected.

Changes:

  • Add a fault-injection policy to the netebpf_ext_helper and introduce require_initialized() so tests fail fast if required NMR providers didn’t bind.
  • Add a new unit test that validates all expected NMR bindings while fault injection is enabled.
  • Enable building netebpfext_unit under the NativeOnlyDebug configuration and add a CI step to copy fault-injection logs into TestLogs for upload.
File summaries
File Description
tests/netebpfext_unit/netebpfext_unit.vcxproj Adds NativeOnlyDebug configuration so the unit test participates in native-only builds.
tests/netebpfext_unit/netebpfext_unit.cpp Adds an NMR-binding validation test and enforces initialization checks across existing tests.
tests/netebpfext_unit/netebpf_ext_helper.h Adds fault-injection policy controls and helper state to validate initialization/bindings.
tests/netebpfext_unit/netebpf_ext_helper.cpp Suspends/resumes fault injection around helper init/teardown and tracks successful hook-provider bindings.
ebpf-for-windows.sln Wires the netebpfext_unit project into NativeOnlyDebug solution configuration.
.github/workflows/reusable-test.yml Copies fault-injection logs into TestLogs so they get uploaded with test artifacts.
Review details
  • Files reviewed: 7/7 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/netebpfext_unit/netebpf_ext_helper.h

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues remain in Azure fault-log collection and helper initialization and fault-injection lifecycle handling.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

tests/netebpfext_unit/netebpf_ext_helper.cpp:100

  • This guard is created before ebpf_platform_initiate() runs at line 111. On the first helper in a fault-injection process, usersim's suspend call is a no-op because the fault-injection singleton is created by platform initialization, so the subsequent NMR/provider setup is still fault-injectable despite the default suspend policy. The matching destructor can also call resume against an unsuspended singleton. Arrange suspension after platform initialization, or explicitly handle this two-phase initialization and keep suspend/resume balanced.
    _usersim_fault_injection_suspension fault_injection_suspension(
        fault_injection_policy == fault_injection_policy_t::suspend);
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread .github/workflows/reusable-test.yml
Comment thread tests/netebpfext_unit/netebpf_ext_helper.cpp
Copilot AI review requested due to automatic review settings September 11, 2026 22:49
@shankarseal
Shankar Seal (shankarseal) force-pushed the shankarseal-fix-netebpfext-fault-injection branch from d6d93af to c65040f Compare September 11, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Several helper-based tests still lack initialization guards, and fault-injection coverage still assumes every NMR binding succeeds.

Review details

Suppressed comments (2)

tests/netebpfext_unit/netebpf_ext_helper.cpp:188

  • Please apply this guard to the remaining helper-based tests as well: sock_addr_bind_invoke, both bind-context tests, sock_addr_bind_callout_disambiguation, sock_addr_bind_get_network_context, and sock_addr_bind_set_redirect_context_rejected still construct a helper without calling require_initialized(). The constructor can return after a partial initialization, and the callbacks in the network-context and redirect-context tests immediately dereference get_program_info_provider_data(...); those tests can therefore still hit the null-provider crash this change is intended to prevent.
void
_netebpf_ext_helper::require_initialized() const
{
    REQUIRE(nmr_program_info_client_handle != nullptr);
    REQUIRE(nmr_program_info_client_handle->is_registered());

tests/netebpfext_unit/netebpfext_unit.cpp:67

  • With allow_fault_injection, this helper keeps fault injection active while platform/WFP setup, provider registration, and both NMR registrations run. An injected FwpmFilterAdd0 failure makes the corresponding hook attach fail, so the binding count is intentionally below all 12 expected providers and require_initialized() fails on the fault-injection iteration this test is meant to exercise. Please make the test validate graceful partial initialization (or otherwise avoid requiring every binding when an injected failure occurred) instead of unconditionally requiring full initialization.
        initialize_platform,
        allow_fault_injection);
    helper.require_initialized();
  • Files reviewed: 8/8 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

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Workflow failed - netebpfext_fault_injection_full

4 participants