feat(runner): compile Go and check answers per test group
This commit is contained in:
1 parent
e95c681165
commit
afee564bf4
61 files changed
+2592
-143
No files matched your search
@@ -39,7 +39,11 @@ func flagValue(t *testing.T, args []string, flag string) string {
|
||||
func TestNsjailArgsKeepEveryIsolationSwitch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
spec := Spec{Argv: []string{"/usr/local/bin/python3", "-I", "/box/main.py"}, BoxDir: "/work/run-1"}
|
||||
spec := Spec{
|
||||
Argv: []string{"/usr/local/bin/python3", "-I", "/box/main.py"},
|
||||
Mounts: []Mount{{Source: "/work/run-1/src", Target: BoxPath}, {Source: "/work/run-1/out", Target: OutPath}},
|
||||
Env: []string{"GOMAXPROCS=1"},
|
||||
}
|
||||
limits := Limits{CPUTime: 1500 * time.Millisecond, WallTime: 3500 * time.Millisecond, MemoryBytes: 64 << 20, OutputBytes: 1 << 16}
|
||||
args := nsjailArgs(testConfig(), spec, limits, "POLICY")
|
||||
|
||||
@@ -74,17 +78,32 @@ func TestNsjailArgsKeepEveryIsolationSwitch(t *testing.T) {
|
||||
t.Errorf("args miss %s", required)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(args, "/work/run-1:/box") {
|
||||
t.Errorf("the box is not mounted at /box: %q", args)
|
||||
if !slices.Contains(args, "/work/run-1/src:/box") || !slices.Contains(args, "/work/run-1/out:/out") {
|
||||
t.Errorf("the box is not mounted read-only: %q", args)
|
||||
}
|
||||
if !slices.Contains(args, "GOMAXPROCS=1") || !slices.Contains(args, "LANG=C.UTF-8") {
|
||||
t.Errorf("args miss the environment: %q", args)
|
||||
}
|
||||
|
||||
compile := spec
|
||||
compile.WorkDir = BoxPath
|
||||
compile.Mounts = []Mount{{Source: "/work/run-1/out", Target: OutPath, Writable: true}}
|
||||
compileArgs := nsjailArgs(testConfig(), compile, Limits{CPUTime: time.Second, WallTime: time.Second, FileSizeBytes: 64 << 20}, "POLICY")
|
||||
if got := flagValue(t, compileArgs, "--cwd"); got != BoxPath {
|
||||
t.Errorf("compile --cwd = %q", got)
|
||||
}
|
||||
if got := flagValue(t, compileArgs, "--rlimit_fsize"); got != "64" {
|
||||
t.Errorf("compile --rlimit_fsize = %q", got)
|
||||
}
|
||||
if got := writableMounts(compileArgs); !slices.Equal(got, []string{"/work/run-1/out:/out", "/dev/null"}) {
|
||||
t.Errorf("compile writable mounts = %q", got)
|
||||
}
|
||||
separator := slices.Index(args, "--")
|
||||
if separator < 0 || !slices.Equal(args[separator+1:], spec.Argv) {
|
||||
t.Errorf("command after -- = %q, want %q", args[separator+1:], spec.Argv)
|
||||
}
|
||||
for _, writable := range writableMounts(args) {
|
||||
if writable != "/dev/null" {
|
||||
t.Errorf("unexpected writable bind mount %q", writable)
|
||||
}
|
||||
if got := writableMounts(args); !slices.Equal(got, []string{"/dev/null"}) {
|
||||
t.Errorf("unexpected writable bind mounts %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,13 +209,27 @@ func TestBoxIsReadOnlyAndRemovable(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
root := t.TempDir()
|
||||
box, err := CreateBox(root, "main.py", []byte("print(1)"))
|
||||
box, err := CreateBox(root, "main.py", []byte("print(1)"), Owner{UID: -1, GID: -1})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateBox: %v", err)
|
||||
}
|
||||
info, err := os.Stat(filepath.Join(box.Dir(), "main.py"))
|
||||
info, err := os.Stat(filepath.Join(box.Dir(), "src", "main.py"))
|
||||
if err != nil || info.Mode().Perm() != boxFileMode {
|
||||
t.Fatalf("source file mode = %v, %v", info.Mode(), err)
|
||||
t.Fatalf("source file mode = %v, %v", info, err)
|
||||
}
|
||||
mounts := box.Mounts(false)
|
||||
if mounts[0].Target != BoxPath || mounts[0].Writable || mounts[1].Target != OutPath || mounts[1].Writable {
|
||||
t.Fatalf("mounts = %+v", mounts)
|
||||
}
|
||||
check, remove, err := box.AddCheckFiles(map[string][]byte{"actual": []byte("1")})
|
||||
if err != nil || check.Target != CheckPath || check.Writable {
|
||||
t.Fatalf("AddCheckFiles = %+v, %v", check, err)
|
||||
}
|
||||
if err := remove(); err != nil {
|
||||
t.Fatalf("remove check files: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(check.Source); !os.IsNotExist(err) {
|
||||
t.Fatalf("check files remain: %v", err)
|
||||
}
|
||||
if err := box.Remove(); err != nil {
|
||||
t.Fatalf("Remove: %v", err)
|
||||
@@ -205,7 +238,7 @@ func TestBoxIsReadOnlyAndRemovable(t *testing.T) {
|
||||
t.Fatalf("root after Remove = %v, %v", entries, err)
|
||||
}
|
||||
for _, name := range []string{"", "../main.py", ".hidden", "dir/main.py"} {
|
||||
if _, err := CreateBox(root, name, nil); err == nil {
|
||||
if _, err := CreateBox(root, name, nil, Owner{UID: -1, GID: -1}); err == nil {
|
||||
t.Errorf("CreateBox accepted file name %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user