github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/functional/vcpus/default_vcpus_test.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2020-2021 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # This will test the default_vcpus 8 # feature is working properly 9 10 set -o errexit 11 set -o nounset 12 set -o pipefail 13 set -o errtrace 14 15 dir_path=$(dirname "$0") 16 source "${dir_path}/../../lib/common.bash" 17 source "${dir_path}/../../.ci/lib.sh" 18 source "/etc/os-release" || source "/usr/lib/os-release" 19 KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}" 20 name="${name:-default_vcpus}" 21 IMAGE="${IMAGE:-quay.io/prometheus/busybox:latest}" 22 CONTAINER_NAME="${CONTAINER_NAME:-test}" 23 PAYLOAD_ARGS="${PAYLOAD_ARGS:-nproc | grep 4}" 24 RUNTIME_CONFIG_PATH="${RUNTIME_CONFIG_PATH:-}" 25 TEST_INITRD="${TEST_INITRD:-no}" 26 issue="github.com/kata-containers/tests/issues/3303" 27 28 if [ "$TEST_INITRD" == "yes" ]; then 29 echo "Skip vcpu test is not working $issue" 30 exit 0 31 fi 32 33 function setup() { 34 restart_containerd_service 35 check_processes 36 extract_kata_env 37 sudo sed -i "s/${name} = 1/${name} = 4/g" "${RUNTIME_CONFIG_PATH}" 38 } 39 40 function test_ctr_with_vcpus() { 41 sudo ctr image pull "${IMAGE}" 42 [ $? != 0 ] && die "Unable to get image $IMAGE" 43 sudo ctr run --runtime="${CTR_RUNTIME}" "${IMAGE}" \ 44 "${CONTAINER_NAME}" sh -c "${PAYLOAD_ARGS}" || die "Test failed" 45 } 46 47 function teardown() { 48 echo "Running teardown" 49 sudo sed -i "s/${name} = 4/${name} = 1/g" "${RUNTIME_CONFIG_PATH}" 50 clean_env_ctr 51 check_processes 52 } 53 54 trap teardown EXIT 55 56 echo "Running setup" 57 setup 58 59 echo "Running ctr integration tests with vcpus" 60 test_ctr_with_vcpus