diff --git a/tests/metrics/README.md b/tests/metrics/README.md index 2f726e1f54..825018b016 100644 --- a/tests/metrics/README.md +++ b/tests/metrics/README.md @@ -83,6 +83,12 @@ convolutional models. For further details see the [machine learning tests documentation](machine_learning). +### `CPU` + +Tests related with `CPU` performance. + +For further details see the [`cpu` tests documentation](cpu). + ## Saving Results In order to ensure continuity, and thus testing and historical tracking of results, diff --git a/tests/metrics/cpu/README.md b/tests/metrics/cpu/README.md new file mode 100644 index 0000000000..3dd3a29280 --- /dev/null +++ b/tests/metrics/cpu/README.md @@ -0,0 +1,9 @@ +# Kata Containers C-Ray Metrics +This is a test of C-Ray which is a simple raytracer designed to test the floating-point CPU performance. + +## Running the C-Ray test +Individual test can be run by hand, for example: + +``` +$ cd metrics/disk/c-ray $ ./cray.sh +``` diff --git a/tests/metrics/cpu/c-ray/Dockerfile b/tests/metrics/cpu/c-ray/Dockerfile new file mode 100644 index 0000000000..41db08b7ac --- /dev/null +++ b/tests/metrics/cpu/c-ray/Dockerfile @@ -0,0 +1,26 @@ +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +# Usage: FROM [image name] +FROM ubuntu:20.04 + +# Version of the Dockerfile +LABEL DOCKERFILE_VERSION="1.0" + +ENV DEBIAN_FRONTEND=noninteractive + +# URL for c-ray benchmark +ENV CRAY_URL "http://www.phoronix-test-suite.com/benchmark-files/c-ray-1.1.tar.gz" + +RUN apt-get update && \ + apt-get install -y --no-install-recommends build-essential gcc curl && \ + apt-get remove -y unattended-upgrades && \ + curl -OkL "${CRAY_URL}" && \ + tar -zxvf c-ray-1.1.tar.gz && \ + cd c-ray-1.1 && \ + cc -o c-ray-mt c-ray-mt.c -lm -lpthread && \ + make && \ + make install + +CMD ["/bin/bash"] diff --git a/tests/metrics/cpu/c-ray/cray.sh b/tests/metrics/cpu/c-ray/cray.sh new file mode 100755 index 0000000000..f84502c413 --- /dev/null +++ b/tests/metrics/cpu/c-ray/cray.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +set -e + +# General env +SCRIPT_PATH=$(dirname "$(readlink -f "$0")") +source "${SCRIPT_PATH}/../../lib/common.bash" + +TEST_NAME="cray" +IMAGE="docker.io/library/cray:latest" +DOCKERFILE="${SCRIPT_PATH}/Dockerfile" +CMD="cd c-ray-1.1 && ./c-ray-mt -t 32 -s 1024x768 -r 8 -i sphfract -o output.ppm 2>&1 | tee -a output.txt && cat output.txt" +cray_file=$(mktemp crayresults.XXXXXXXXXX) + +function remove_tmp_file() { + rm -rf "${cray_file}" +} + +trap remove_tmp_file EXIT + +function main() { + # Check tools/commands dependencies + cmds=("awk" "docker") + init_env + check_cmds "${cmds[@]}" + check_ctr_images "$IMAGE" "$DOCKERFILE" + + sudo -E "${CTR_EXE}" run --rm --runtime="${CTR_RUNTIME}" "${IMAGE}" test sh -c "${CMD}" > "${cray_file}" + metrics_json_init + results=$(cat "${cray_file}" | grep seconds | awk '{print $3}' | head -n 1) + metrics_json_start_array + + local json="$(cat << EOF + { + "rendering": { + "Result": ${results}, + "Units": "s" + } + } +EOF +)" + metrics_json_add_array_element "$json" + metrics_json_end_array "Results" + metrics_json_save + + clean_env_ctr +} + +main "$@"