github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/tests/integration/cgroups.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  TEST_CGROUP_NAME="runc-cgroups-integration-test"
     6  CGROUP_MEMORY="${CGROUP_BASE_PATH}/${TEST_CGROUP_NAME}"
     7  
     8  function teardown() {
     9      rm -f $BATS_TMPDIR/runc-update-integration-test.json
    10      teardown_running_container test_cgroups_kmem
    11      teardown_busybox
    12  }
    13  
    14  function setup() {
    15      teardown
    16      setup_busybox
    17  }
    18  
    19  function check_cgroup_value() {
    20      cgroup=$1
    21      source=$2
    22      expected=$3
    23  
    24      current=$(cat $cgroup/$source)
    25      echo  $cgroup/$source
    26      echo "current" $current "!?" "$expected"
    27      [ "$current" -eq "$expected" ]
    28  }
    29  
    30  @test "runc update --kernel-memory (initialized)" {
    31      requires cgroups_kmem
    32      # Add cgroup path
    33      sed -i 's/\("linux": {\)/\1\n    "cgroupsPath": "\/runc-cgroups-integration-test",/'  ${BUSYBOX_BUNDLE}/config.json
    34  
    35      # Set some initial known values
    36      DATA=$(cat <<-EOF
    37      "memory": {
    38          "kernel": 16777216
    39      },
    40  EOF
    41      )
    42      DATA=$(echo ${DATA} | sed 's/\n/\\n/g')
    43      sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
    44  
    45      # run a detached busybox to work with
    46      runc run -d --console /dev/pts/ptmx test_cgroups_kmem
    47      [ "$status" -eq 0 ]
    48      wait_for_container 15 1 test_cgroups_kmem
    49  
    50      # update kernel memory limit
    51      runc update test_cgroups_kmem --kernel-memory 50331648
    52      [ "$status" -eq 0 ]
    53  
    54  	# check the value
    55      check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
    56  }
    57  
    58  @test "runc update --kernel-memory (uninitialized)" {
    59      requires cgroups_kmem
    60      # Add cgroup path
    61      sed -i 's/\("linux": {\)/\1\n    "cgroupsPath": "\/runc-cgroups-integration-test",/'  ${BUSYBOX_BUNDLE}/config.json
    62  
    63      # run a detached busybox to work with
    64      runc run -d --console /dev/pts/ptmx test_cgroups_kmem
    65      [ "$status" -eq 0 ]
    66      wait_for_container 15 1 test_cgroups_kmem
    67  
    68      # update kernel memory limit
    69      runc update test_cgroups_kmem --kernel-memory 50331648
    70      # Since kernel 4.6, we can update kernel memory without initialization
    71      # because it's accounted by default.
    72      if [ "$KERNEL_MAJOR" -lt 4 ] || [ "$KERNEL_MAJOR" -eq 4 -a "$KERNEL_MINOR" -le 5 ]; then
    73          [ ! "$status" -eq 0 ]
    74      else
    75          [ "$status" -eq 0 ]
    76          check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
    77      fi
    78  }