github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/start_detached.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 run detached" {
    15    # run busybox detached
    16    runc run -d --console /dev/pts/ptmx test_busybox
    17    [ "$status" -eq 0 ]
    18  
    19    # check state
    20    wait_for_container 15 1 test_busybox
    21  
    22    testcontainer test_busybox running
    23  }
    24  
    25  @test "runc run detached ({u,g}id != 0)" {
    26    # replace "uid": 0 with "uid": 1000
    27    # and do a similar thing for gid.
    28    sed -i 's;"uid": 0;"uid": 1000;g' config.json
    29    sed -i 's;"gid": 0;"gid": 100;g' config.json
    30  
    31    # run busybox detached
    32    runc run -d --console /dev/pts/ptmx test_busybox
    33    [ "$status" -eq 0 ]
    34  
    35    # check state
    36    wait_for_container 15 1 test_busybox
    37  
    38    testcontainer test_busybox running
    39  }
    40  
    41  @test "runc run detached --pid-file" {
    42    # run busybox detached
    43    runc run --pid-file pid.txt -d --console /dev/pts/ptmx test_busybox
    44    [ "$status" -eq 0 ]
    45  
    46    # check state
    47    wait_for_container 15 1 test_busybox
    48  
    49    testcontainer test_busybox running
    50  
    51    # check pid.txt was generated
    52    [ -e pid.txt ]
    53  
    54    run cat pid.txt
    55    [ "$status" -eq 0 ]
    56    [[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
    57  }