github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/tests/rkt_ipcns_test.go (about) 1 // Copyright 2016-2017 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build !fly,!kvm 16 17 package main 18 19 import ( 20 "fmt" 21 "os" 22 "testing" 23 24 "github.com/rkt/rkt/tests/testutils" 25 ) 26 27 // TestIpc test that the --ipc option works. 28 func TestIpc(t *testing.T) { 29 imageFile := patchTestACI("rkt-inspect-ipc.aci", "--exec=/inspect --print-ipcns") 30 defer os.Remove(imageFile) 31 32 ctx := testutils.NewRktRunCtx() 33 defer ctx.Cleanup() 34 35 hostIpcNs, err := os.Readlink("/proc/self/ns/ipc") 36 if err != nil { 37 t.Fatalf("Cannot evaluate IPC NS symlink: %v", err) 38 } 39 40 tests := []struct { 41 option string 42 host bool 43 ret int 44 }{ 45 { 46 "", 47 false, 48 0, 49 }, 50 { 51 "--ipc=auto", 52 false, 53 0, 54 }, 55 { 56 "--ipc=private", 57 false, 58 0, 59 }, 60 { 61 "--ipc=parent", 62 true, 63 0, 64 }, 65 { 66 "--ipc=supercalifragilisticexpialidocious", 67 false, 68 254, 69 }, 70 } 71 72 for _, tt := range tests { 73 cmd := fmt.Sprintf("%s run --insecure-options=image %s %s", ctx.Cmd(), tt.option, imageFile) 74 75 child := spawnOrFail(t, cmd) 76 ctx.RegisterChild(child) 77 78 expectedRegex := `IPCNS: (ipc:\[\d+\])` 79 80 result, out, err := expectRegexWithOutput(child, expectedRegex) 81 if tt.ret == 0 { 82 if err != nil { 83 t.Fatalf("Error: %v\nOutput: %v", err, out) 84 } 85 86 nsChanged := hostIpcNs != result[1] 87 if tt.host == nsChanged { 88 t.Fatalf("unexpected ipc ns %q for with option %q (host ipc ns %q)", result, tt.option, hostIpcNs) 89 } 90 } else { 91 if err == nil { 92 t.Fatalf("test %q didn't fail as expected\nOutput: %v", tt.option, out) 93 } 94 95 } 96 97 waitOrFail(t, child, tt.ret) 98 } 99 }