mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Allow syscall tests to run with hostinet.
Fixes #1207 PiperOrigin-RevId: 283914438
This commit is contained in:
@@ -9,6 +9,7 @@ def syscall_test(
|
||||
use_tmpfs = False,
|
||||
add_overlay = False,
|
||||
add_uds_tree = False,
|
||||
add_hostinet = False,
|
||||
tags = None):
|
||||
_syscall_test(
|
||||
test = test,
|
||||
@@ -65,6 +66,18 @@ def syscall_test(
|
||||
file_access = "shared",
|
||||
)
|
||||
|
||||
if add_hostinet:
|
||||
_syscall_test(
|
||||
test = test,
|
||||
shard_count = shard_count,
|
||||
size = size,
|
||||
platform = "ptrace",
|
||||
use_tmpfs = use_tmpfs,
|
||||
network = "host",
|
||||
add_uds_tree = add_uds_tree,
|
||||
tags = tags,
|
||||
)
|
||||
|
||||
def _syscall_test(
|
||||
test,
|
||||
shard_count,
|
||||
@@ -72,6 +85,7 @@ def _syscall_test(
|
||||
platform,
|
||||
use_tmpfs,
|
||||
tags,
|
||||
network = "none",
|
||||
file_access = "exclusive",
|
||||
overlay = False,
|
||||
add_uds_tree = False):
|
||||
@@ -85,6 +99,8 @@ def _syscall_test(
|
||||
name += "_shared"
|
||||
if overlay:
|
||||
name += "_overlay"
|
||||
if network != "none":
|
||||
name += "_" + network + "net"
|
||||
|
||||
if tags == None:
|
||||
tags = []
|
||||
@@ -107,6 +123,7 @@ def _syscall_test(
|
||||
# Arguments are passed directly to syscall_test_runner binary.
|
||||
"--test-name=" + test_name,
|
||||
"--platform=" + platform,
|
||||
"--network=" + network,
|
||||
"--use-tmpfs=" + str(use_tmpfs),
|
||||
"--file-access=" + file_access,
|
||||
"--overlay=" + str(overlay),
|
||||
|
||||
@@ -46,6 +46,7 @@ var (
|
||||
debug = flag.Bool("debug", false, "enable debug logs")
|
||||
strace = flag.Bool("strace", false, "enable strace logs")
|
||||
platform = flag.String("platform", "ptrace", "platform to run on")
|
||||
network = flag.String("network", "none", "network stack to run on (sandbox, host, none)")
|
||||
useTmpfs = flag.Bool("use-tmpfs", false, "mounts tmpfs for /tmp")
|
||||
fileAccess = flag.String("file-access", "exclusive", "mounts root in exclusive or shared mode")
|
||||
overlay = flag.Bool("overlay", false, "wrap filesystem mounts with writable tmpfs overlay")
|
||||
@@ -137,7 +138,7 @@ func runRunsc(tc gtest.TestCase, spec *specs.Spec) error {
|
||||
|
||||
args := []string{
|
||||
"-root", rootDir,
|
||||
"-network=none",
|
||||
"-network", *network,
|
||||
"-log-format=text",
|
||||
"-TESTONLY-unsafe-nonroot=true",
|
||||
"-net-raw=true",
|
||||
@@ -335,10 +336,11 @@ func runTestCaseRunsc(testBin string, tc gtest.TestCase, t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// Set environment variable that indicates we are
|
||||
// running in gVisor and with the given platform.
|
||||
// Set environment variables that indicate we are
|
||||
// running in gVisor with the given platform and network.
|
||||
platformVar := "TEST_ON_GVISOR"
|
||||
env := append(os.Environ(), platformVar+"="+*platform)
|
||||
networkVar := "GVISOR_NETWORK"
|
||||
env := append(os.Environ(), platformVar+"="+*platform, networkVar+"="+*network)
|
||||
|
||||
// Remove env variables that cause the gunit binary to write output
|
||||
// files, since they will stomp on eachother, and on the output files
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace gvisor {
|
||||
namespace testing {
|
||||
|
||||
#define TEST_ON_GVISOR "TEST_ON_GVISOR"
|
||||
#define GVISOR_NETWORK "GVISOR_NETWORK"
|
||||
|
||||
bool IsRunningOnGvisor() { return GvisorPlatform() != Platform::kNative; }
|
||||
|
||||
@@ -60,6 +61,11 @@ Platform GvisorPlatform() {
|
||||
abort();
|
||||
}
|
||||
|
||||
bool IsRunningWithHostinet() {
|
||||
char* env = getenv(GVISOR_NETWORK);
|
||||
return env && strcmp(env, "host") == 0;
|
||||
}
|
||||
|
||||
// Inline cpuid instruction. Preserve %ebx/%rbx register. In PIC compilations
|
||||
// %ebx contains the address of the global offset table. %rbx is occasionally
|
||||
// used to address stack variables in presence of dynamic allocas.
|
||||
|
||||
@@ -220,6 +220,7 @@ enum class Platform {
|
||||
};
|
||||
bool IsRunningOnGvisor();
|
||||
Platform GvisorPlatform();
|
||||
bool IsRunningWithHostinet();
|
||||
|
||||
#ifdef __linux__
|
||||
void SetupGvisorDeathTest();
|
||||
|
||||
Reference in New Issue
Block a user