github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/exec.bats (about) 1 #!/usr/bin/env bats 2 3 load helpers 4 5 function setup() { 6 teardown_busybox 7 setup_busybox 8 } 9 10 function teardown() { 11 teardown_busybox 12 } 13 14 @test "runc exec" { 15 # run busybox detached 16 runc run -d --console /dev/pts/ptmx test_busybox 17 [ "$status" -eq 0 ] 18 19 wait_for_container 15 1 test_busybox 20 21 runc exec test_busybox echo Hello from exec 22 [ "$status" -eq 0 ] 23 echo text echoed = "'""${output}""'" 24 [[ "${output}" == *"Hello from exec"* ]] 25 } 26 27 @test "runc exec --pid-file" { 28 # run busybox detached 29 runc run -d --console /dev/pts/ptmx test_busybox 30 [ "$status" -eq 0 ] 31 32 wait_for_container 15 1 test_busybox 33 34 runc exec --pid-file pid.txt test_busybox echo Hello from exec 35 [ "$status" -eq 0 ] 36 echo text echoed = "'""${output}""'" 37 [[ "${output}" == *"Hello from exec"* ]] 38 39 # check pid.txt was generated 40 [ -e pid.txt ] 41 42 run cat pid.txt 43 [ "$status" -eq 0 ] 44 [[ ${lines[0]} =~ [0-9]+ ]] 45 [[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]] 46 } 47 48 @test "runc exec ls -la" { 49 # run busybox detached 50 runc run -d --console /dev/pts/ptmx test_busybox 51 [ "$status" -eq 0 ] 52 53 wait_for_container 15 1 test_busybox 54 55 runc exec test_busybox ls -la 56 [ "$status" -eq 0 ] 57 [[ ${lines[0]} == *"total"* ]] 58 [[ ${lines[1]} == *"."* ]] 59 [[ ${lines[2]} == *".."* ]] 60 } 61 62 @test "runc exec ls -la with --cwd" { 63 # run busybox detached 64 runc run -d --console /dev/pts/ptmx test_busybox 65 [ "$status" -eq 0 ] 66 67 wait_for_container 15 1 test_busybox 68 69 runc exec --cwd /bin test_busybox pwd 70 [ "$status" -eq 0 ] 71 [[ ${output} == "/bin" ]] 72 } 73 74 @test "runc exec --env" { 75 # run busybox detached 76 runc run -d --console /dev/pts/ptmx test_busybox 77 [ "$status" -eq 0 ] 78 79 wait_for_container 15 1 test_busybox 80 81 runc exec --env RUNC_EXEC_TEST=true test_busybox env 82 [ "$status" -eq 0 ] 83 84 [[ ${output} == *"RUNC_EXEC_TEST=true"* ]] 85 } 86 87 @test "runc exec --user" { 88 # run busybox detached 89 runc run -d --console /dev/pts/ptmx test_busybox 90 [ "$status" -eq 0 ] 91 92 wait_for_container 15 1 test_busybox 93 94 runc exec --user 1000:1000 test_busybox id 95 [ "$status" -eq 0 ] 96 97 [[ ${output} == "uid=1000 gid=1000" ]] 98 }