From 018d4b98b37a73742a2bf3335e473ad6895290f9 Mon Sep 17 00:00:00 2001 From: Ryan Harkin Date: Mon, 30 Mar 2020 11:48:10 +0100 Subject: [PATCH] block-device test added Test a partition on a block device. Check that files can be written and read reliably, measure the timings for read and write, and run the bonnie++ block device test on the device. Signed-off-by: Ryan Harkin --- automated/linux/block-device/block-device.sh | 261 ++++++++++++++++++ .../linux/block-device/block-device.yaml | 39 +++ 2 files changed, 300 insertions(+) create mode 100755 automated/linux/block-device/block-device.sh create mode 100644 automated/linux/block-device/block-device.yaml diff --git a/automated/linux/block-device/block-device.sh b/automated/linux/block-device/block-device.sh new file mode 100755 index 000000000..9a483d939 --- /dev/null +++ b/automated/linux/block-device/block-device.sh @@ -0,0 +1,261 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Linaro Ltd. + +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" + +PARTDEV="" +PARTNAME="" +DEVICE="" +DEVNAME="" + +SKIP_INSTALL="false" +FORMAT_DEVICE="false" + +MOUNT_DIR=$(mktemp -d "/tmp/block-device.XXXXX") +TMPFILE=$(mktemp "/tmp/10M.XXXXX") +RESULT=pass + +usage() { + echo "\ + Usage: $0 + [-d ] + [-f ] + [-s ] + + -d + This is the block device to be tested, eg. /dev/sda1. + It should be a partition, not a raw block device + -f + This will erase the device and create a new partition table + with a single ext4 partition on it. + -s + Tell the test to skip installation of dependencies, or not + + This test will perform tests on a block device. + " +} + +while getopts "d:f:s:h" opts; do + case "$opts" in + d) PARTDEV="${OPTARG}"; + PARTNAME=$(basename -- "${PARTDEV}"); + DEVICE=${PARTDEV/%[[:digit:]]/} + DEVNAME=$(basename -- "${DEVICE}") + ;; + f) FORMAT_DEVICE="${OPTARG,,}" ;; + s) SKIP_INSTALL="${OPTARG,,}" ;; + h|*) usage ; exit 1 ;; + esac +done + +install() { + if [ "${SKIP_INSTALL}" = "true" ]; then + info_msg "Skip installing dependencies" + else + # install dependencies + dist= + dist_name + case "${dist}" in + debian|ubuntu) + pkgs="bonnie++" + install_deps "${pkgs}" "${SKIP_INSTALL}" + ;; + fedora|centos) + pkgs="bonnie++" + install_deps "${pkgs}" "${SKIP_INSTALL}" + ;; + # When we don't have a package manager + # Assume dependencies pre-installed + *) + echo "Unsupported distro: ${dist}! Package installation skipped!" + ;; + esac + fi +} + +block_device_exists () { + local device=$1 + + if [[ -b ${device} ]]; then + echo true + else + echo false + fi +} + +wait_for_device () { + local device=$1 + local retries=20 + + echo -n "Waiting for ${device}: " + for ((i=0;i "${timings}" && sync) || RESULT=fail + cat "${timings}" + + if [ "${RESULT}" == "pass" ] ; then + local seconds + local mbps + seconds=$(tail -1 "${timings}" | awk '{print $8}') + mbps=$(tail -1 "${timings}" | awk '{print $10}') + echo "block-device-${PARTNAME}-${test_name}-timing ${RESULT} ${seconds} seconds" | tee -a "${RESULT_FILE}" + echo "block-device-${PARTNAME}-${test_name}-throughput ${RESULT} ${mbps} MB/s" | tee -a "${RESULT_FILE}" + fi + rm -f "${timings}" + + echo "block-device-${PARTNAME}-${test_name}-cp ${RESULT}" | tee -a "${RESULT_FILE}" + fi + if [ "${RESULT}" == "pass" ] ; then + cmp "${infile}" "${outfile}" || RESULT=fail + echo "block-device-${PARTNAME}-${test_name}-cmp ${RESULT}" | tee -a "${RESULT_FILE}" + fi +} + +write_timing () { + if [ "${RESULT}" == "pass" ] ; then + echo "Writing 10MB file to ${PARTDEV}" + dd if=/dev/urandom of="${TMPFILE}" bs=1024 count=10240 || RESULT=fail + echo "block-device-${PARTNAME}-create-10M-file ${RESULT}" | tee -a "${RESULT_FILE}" + fi + if [ "${RESULT}" == "pass" ] ; then + # shellcheck disable=SC2086 + copy_timing_test "write" "${TMPFILE}" "${MOUNT_DIR}/$(basename -- ${TMPFILE})" || RESULT=fail + fi + rm -f "${TMPFILE}" +} + +read_timing () { + if [ "${RESULT}" == "pass" ] ; then + echo "Reading 10MB file to ${PARTDEV}" + # shellcheck disable=SC2086 + copy_timing_test "read" "${MOUNT_DIR}/$(basename -- ${TMPFILE})" "${TMPFILE}" || RESULT=fail + rm -f "${TMPFILE}" + fi +} + +bonnie_test () { + if [ "${RESULT}" == "pass" ] ; then + BONNIE_LOG=$(mktemp "/tmp/bonnie.XXXXX") + bonnie\+\+ -u root -d "${MOUNT_DIR}" | tee -a "${BONNIE_LOG}" || RESULT=fail + echo "block-device-${PARTNAME}-bonnie++ ${RESULT}" | tee -a "${RESULT_FILE}" + fi +} + +################################################################################ +# Run the test actions +################################################################################ +echo "Test Parameters" +echo "---------------" +echo "PARTDEV: ${PARTDEV}" +echo "PARTNAME: ${PARTNAME}" +echo "DEVICE: ${DEVICE}" +echo "RESULT_FILE: ${RESULT_FILE}" +echo "" +echo "MOUNT_DIR: ${MOUNT_DIR}" +echo "TMPFILE: ${TMPFILE}" +echo "" + +install +create_out_dir "${OUTPUT}" +wait_for_device "${DEVICE}" +format_device +mount_device +write_timing +read_timing +bonnie_test +umount_device + +# Cleanup temporary files +rm -f "${TMPFILE}" +rm -rf "${MOUNT_DIR}" diff --git a/automated/linux/block-device/block-device.yaml b/automated/linux/block-device/block-device.yaml new file mode 100644 index 000000000..a3a119ccf --- /dev/null +++ b/automated/linux/block-device/block-device.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Schneider Electric +metadata: + format: Lava-Test Test Definition 1.0 + name: block-device + description: "Test a partition on a block device. + + Check that files can be written and read reliably, measure the timings + for read and write, and run the bonnie++ block device test on the + device." + + maintainer: + - ryan.harkin@linaro.org + os: + - debian + - ubuntu + - fedora + - centos + - openembedded + scope: + - blkdev + - bonnie++ + - performance + - functional + + devices: + - rzn1d + - soca9 + +params: + DEVICE: "/dev/sdXN" + FORMAT_DEVICE: "False" + SKIP_INSTALL: "False" + +run: + steps: + - cd ./automated/linux/block-device + - ./block-device.sh -s "${SKIP_INSTALL}" -d "${DEVICE}" -f "${FORMAT_DEVICE}" + - ../../utils/send-to-lava.sh ./output/result.txt