| 1 |
// SPDX-License-Identifier: MPL-2.0 |
| 2 |
|
| 3 |
//go:build linux |
| 4 |
|
| 5 |
// Copyright (C) 2024-2025 Aleksa Sarai <[email protected]> |
| 6 |
// Copyright (C) 2024-2025 SUSE LLC |
| 7 |
// |
| 8 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 9 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 10 |
// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 11 |
|
| 12 |
package procfs |
| 13 |
|
| 14 |
import ( |
| 15 |
"testing" |
| 16 |
) |
| 17 |
|
| 18 |
func testForceGetProcRoot(t *testing.T, testFn func(t *testing.T, expectOvermounts bool)) { |
| 19 |
for _, test := range []struct { |
| 20 |
name string |
| 21 |
forceGetProcRoot forceGetProcRootLevel |
| 22 |
expectOvermounts bool |
| 23 |
}{ |
| 24 |
{`procfd="fsopen()"`, forceGetProcRootDefault, false}, |
| 25 |
{`procfd="open_tree_clone"`, forceGetProcRootOpenTree, false}, |
| 26 |
{`procfd="open_tree_clone(AT_RECURSIVE)"`, forceGetProcRootOpenTreeAtRecursive, true}, |
| 27 |
{`procfd="open()"`, forceGetProcRootUnsafe, true}, |
| 28 |
} { |
| 29 |
test := test // copy iterator |
| 30 |
t.Run(test.name, func(t *testing.T) { |
| 31 |
testingForceGetProcRoot = &test.forceGetProcRoot |
| 32 |
defer func() { testingForceGetProcRoot = nil }() |
| 33 |
|
| 34 |
testFn(t, test.expectOvermounts) |
| 35 |
}) |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
func testForceProcThreadSelf(t *testing.T, testFn func(t *testing.T)) { |
| 40 |
for _, test := range []struct { |
| 41 |
name string |
| 42 |
forceProcThreadSelf forceProcThreadSelfLevel |
| 43 |
}{ |
| 44 |
{`thread-self="thread-self"`, forceProcThreadSelfDefault}, |
| 45 |
{`thread-self="self/task"`, forceProcSelfTask}, |
| 46 |
{`thread-self="self"`, forceProcSelf}, |
| 47 |
} { |
| 48 |
test := test // copy iterator |
| 49 |
t.Run(test.name, func(t *testing.T) { |
| 50 |
testingForceProcThreadSelf = &test.forceProcThreadSelf |
| 51 |
defer func() { testingForceProcThreadSelf = nil }() |
| 52 |
|
| 53 |
testFn(t) |
| 54 |
}) |
| 55 |
} |
| 56 |
} |