github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/checkpoint.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 "checkpoint and restore" {
    15    requires criu
    16  
    17    # criu does not work with external terminals so..
    18    # setting terminal and root:readonly: to false
    19    sed -i 's;"terminal": true;"terminal": false;' config.json
    20    sed -i 's;"readonly": true;"readonly": false;' config.json
    21    sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json
    22  
    23    (
    24      # run busybox (not detached)
    25      runc run test_busybox
    26      [ "$status" -eq 0 ]
    27    ) &
    28  
    29    # check state
    30    wait_for_container 15 1 test_busybox
    31  
    32    runc state test_busybox
    33    [ "$status" -eq 0 ]
    34    [[ "${output}" == *"running"* ]]
    35  
    36    # checkpoint the running container
    37    runc --criu "$CRIU" checkpoint test_busybox
    38    # if you are having problems getting criu to work uncomment the following dump:
    39    #cat /run/opencontainer/containers/test_busybox/criu.work/dump.log
    40    [ "$status" -eq 0 ]
    41  
    42    # after checkpoint busybox is no longer running
    43    runc state test_busybox
    44    [ "$status" -ne 0 ]
    45  
    46    # restore from checkpoint
    47    (
    48      runc --criu "$CRIU" restore test_busybox
    49      [ "$status" -eq 0 ]
    50    ) &
    51  
    52    # check state
    53    wait_for_container 15 1 test_busybox
    54  
    55    # busybox should be back up and running
    56    runc state test_busybox
    57    [ "$status" -eq 0 ]
    58    [[ "${output}" == *"running"* ]]
    59  }