Repository navigation
test(uffd): lift cross-process test infrastructure for UFFD work #2461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,10 +102,13 @@ func configureCrossProcessTest(t *testing.T, tt testConfig) (*testHandler, error | |
| err = register(uffdFd, memoryStart, uint64(size), UFFDIO_REGISTER_MODE_MISSING|UFFDIO_REGISTER_MODE_WP) | ||
| require.NoError(t, err) | ||
|
|
||
| cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=TestHelperServingProcess") | ||
| cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=TestHelperServingProcess", "-test.timeout=0") | ||
| cmd.Env = append(os.Environ(), "GO_TEST_HELPER_PROCESS=1") | ||
| cmd.Env = append(cmd.Env, fmt.Sprintf("GO_MMAP_START=%d", memoryStart)) | ||
| cmd.Env = append(cmd.Env, fmt.Sprintf("GO_MMAP_PAGE_SIZE=%d", tt.pagesize)) | ||
| if tt.alwaysWP { | ||
| cmd.Env = append(cmd.Env, "GO_ALWAYS_WP=1") | ||
| } | ||
|
|
||
| dup, err := syscall.Dup(int(uffdFd)) | ||
| require.NoError(t, err) | ||
|
Comment on lines
108
to
114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 In Extended reasoning...What the bug is and how it manifests In cmd.Env = append(os.Environ(), "GO_TEST_HELPER_PROCESS=1")
// ...
if tt.alwaysWP {
cmd.Env = append(cmd.Env, "GO_ALWAYS_WP=1")
}The code only appends The specific code path that triggers it If a developer or CI runner executes if os.Getenv("GO_ALWAYS_WP") == "1" {
uffd.defaultCopyMode = UFFDIO_COPY_MODE_WP
}This sets Why existing code doesn't prevent it The pattern What the impact would be Non- Step-by-step proof
Addressing the refutation The refuter correctly notes that |
||
|
|
@@ -293,6 +296,10 @@ func crossProcessServe() error { | |
| return fmt.Errorf("exit creating uffd: %w", err) | ||
| } | ||
|
|
||
| if os.Getenv("GO_ALWAYS_WP") == "1" { | ||
| uffd.defaultCopyMode = UFFDIO_COPY_MODE_WP | ||
| } | ||
|
|
||
| offsetsFile := os.NewFile(uintptr(5), "offsets") | ||
|
|
||
| offsetsSignal := make(chan os.Signal, 1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,32 +119,24 @@ func TestMissingWrite(t *testing.T) { | |
| h, err := configureCrossProcessTest(t, tt) | ||
| require.NoError(t, err) | ||
|
|
||
| for _, operation := range tt.operations { | ||
| if operation.mode == operationModeRead { | ||
| err := h.executeRead(t.Context(), operation) | ||
| require.NoError(t, err, "for operation %+v", operation) | ||
| } | ||
|
|
||
| if operation.mode == operationModeWrite { | ||
| err := h.executeWrite(t.Context(), operation) | ||
| require.NoError(t, err, "for operation %+v", operation) | ||
| } | ||
| } | ||
| h.executeAll(t, tt.operations) | ||
|
|
||
| expectedAccessedOffsets := getOperationsOffsets(tt.operations, operationModeRead|operationModeWrite) | ||
|
|
||
|
Comment on lines
119
to
125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟣 The four tests in Extended reasoning...What the bug is and how it manifests
The specific code path that triggers it
Why existing code does not prevent it Each of the four test functions calls What the impact would be A contributor running How to fix it Add if os.Geteuid() \!= 0 {
t.Skip("skipping test as not running as root")
}Step-by-step proof
|
||
| accessedOffsets, err := h.offsetsOnce() | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, expectedAccessedOffsets, accessedOffsets, "checking which pages were faulted") | ||
|
|
||
| h.checkDirtiness(t, tt.operations) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestParallelMissingWrite(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| parallelOperations := 1_000_000 | ||
| parallelOperations := 10_000 | ||
|
|
||
| tt := testConfig{ | ||
| pagesize: header.PageSize, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper process environment is seeded from
os.Environ()andGO_ALWAYS_WPis only appended whentt.alwaysWPis true, so any ambientGO_ALWAYS_WPvalue from the parent shell can override the test config and change helper behavior unexpectedly. This makesconfigureCrossProcessTestnon-deterministic across environments (e.g., non-alwaysWPcases can still run with forced WP), which can produce flaky or misleading test results.Useful? React with 👍 / 👎.