From f00faec518b33cf5a6103d1de402927c6702ff7f Mon Sep 17 00:00:00 2001 From: Naresh Kamboju Date: Sun, 17 Mar 2024 18:21:16 +0530 Subject: [PATCH] linux: adding xfstests xfstests is a test suite for validating the reliability and stability of file systems in the Linux kernel. It covers a broad range of file systems, including ext4, XFS, Btrfs, and others, with tests for performance, error handling, and filesystem operations. Signed-off-by: Naresh Kamboju --- automated/linux/xfstests/xfstests.sh | 177 +++++++++++++++++++++++++ automated/linux/xfstests/xfstests.yaml | 38 ++++++ 2 files changed, 215 insertions(+) create mode 100755 automated/linux/xfstests/xfstests.sh create mode 100644 automated/linux/xfstests/xfstests.yaml diff --git a/automated/linux/xfstests/xfstests.sh b/automated/linux/xfstests/xfstests.sh new file mode 100755 index 000000000..5f74f3723 --- /dev/null +++ b/automated/linux/xfstests/xfstests.sh @@ -0,0 +1,177 @@ +#!/bin/sh +# Shell Script for Running XFS Tests + +# Load required libraries +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib + +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE + +# Results logs +RESULT_LOG="${OUTPUT}/logs.txt" +RESULT_PASS="${OUTPUT}/pass.txt" +RESULT_FAIL="${OUTPUT}/fail.txt" +RESULT_SKIP="${OUTPUT}/skip.txt" + +SKIP_INSTALL="false" + +# xfstests test build path +XFSTESTS_PATH="/opt/xfstests" + +TEST_IMG=test.img +SCRATCH_IMG=scratch.img +TEST_DEV=/dev/loop0 +SCRATCH_DEV=/dev/loop1 +TEST_DIR=/mnt/test +SCRATCH_MNT=/mnt/scratch +FILESYSTEM="ext4" +T_SIZE="5G" +S_SIZE="8G" + +# usage +usage() { + echo "Usage: $0 [-d ] [-e ] + [-f ] [-m ] + [-t ] [-s ] + [-x <10G>] [-z <10G>] + + -d Specify the test device path (default: /dev/loop0) + -e Specify the scratch device path (default: /dev/loop1) + -f Set the filesystem type (default: ext4) + -m Set the scratch mount path (default: /mnt/scratch) + -t Set the test mount path (default: /mnt/test) + -s Skip package installation (default: false) + -x Set the test and scratch size (default: 5G for test, 8G for scratch) + -z Set the test and scratch size (default: 5G for test, 8G for scratch) + " 1>&2 + exit 1 +} + +results_parser() { + # Parse pass test cases + find results/*/*.full -print0 | awk -v RS='\0' -F'/' '{print $2"-"$3" pass"}' | sed 's/.full$//' >> "${RESULT_PASS}" + # Parse fail test cases + find results/*/*.out.bad -print0 | awk -v RS='\0' -F'/' '{print $2"-"$3" fail"}' | sed 's/.out.bad$//' >> "${RESULT_FAIL}" + # Parse skip test cases + find results/*/*.notrun -print0 | awk -v RS='\0' -F'/' '{print $2"-"$3" skip"}' | sed 's/.notrun$//' >> "${RESULT_SKIP}" + # Append all the results to results.txt file + cat "${RESULT_PASS}" "${RESULT_FAIL}" "${RESULT_SKIP}" 2>&1 | tee -a "${RESULT_FILE}" +} + +# test setup +test_setup() { + export TEST_IMG="${TEST_IMG}" + export SCRATCH_IMG="${SCRATCH_IMG}" + export TEST_DEV="${TEST_DEV}" + export SCRATCH_DEV="${SCRATCH_DEV}" + export TEST_DIR="${TEST_DIR}" + export SCRATCH_MNT="${SCRATCH_MNT}" + export FILESYSTEM="${FILESYSTEM}" +} + +# run_xfstests ext4 +run_xfstests() { + # shellcheck disable=SC2039 + local FILESYSTEM=$1 + echo "run xfstests : ${FILESYSTEM}" + test_setup + df + mount + if [ "${FILESYSTEM}" = "xfs" ]; then + ./check -g "${FILESYSTEM}"/quick -x dmapi 2>&1 | tee -a "${RESULT_LOG}" + elif [ "${FILESYSTEM}" = "ext2" ]; then + ./check -g generic 2>&1 | tee -a "${RESULT_LOG}" + elif [ "${FILESYSTEM}" = "ext3" ]; then + ./check -g generic 2>&1 | tee -a "${RESULT_LOG}" + else + ./check -g "${FILESYSTEM}"/quick 2>&1 | tee -a "${RESULT_LOG}" + fi +} + +# format_disk_partitions "/dev/sdb" "ext4" +format_disk_partitions() { + # shellcheck disable=SC2039 + local DEVICE=$1 + # shellcheck disable=SC2039 + local FILESYSTEM=$2 + echo "Format disk partitions of: ${DEVICE}" + mkfs."${FILESYSTEM}" "${DEVICE}" + exit_on_fail "format-disk-partitions" +} + +# fallocate - manipulate file space +# fallocate_manipulate_file_space "/test-dir" "5G" +fallocate_manipulate_file_space() { + # shellcheck disable=SC2039 + local IMG=$1 + # shellcheck disable=SC2039 + local SIZE=$2 + echo "fallocate - manipulate file space" + fallocate -l "${SIZE}" "${IMG}" + exit_on_fail "fallocate-l-${SIZE}-${IMG}" +} + +# Create fsgqa test users and groups +create_fsgqa_test_users_groups() { + echo + echo "Creating fsgqa test users and groups: " + useradd -m fsgqa + useradd 123456-fsgqa + useradd fsgqa2 + groupadd fsgqa +} + +while getopts "d:e:f:m:s:t:x:z:" arg; do + case "$arg" in + d) TEST_DEV="${OPTARG}";; + e) SCRATCH_DEV="${OPTARG}" ;; + f) FILESYSTEM="${OPTARG}" ;; + m) SCRATCH_MNT="${OPTARG}" ;; + t) TEST_DIR="${OPTARG}" ;; + s) SKIP_INSTALL="${OPTARG}";; + x) T_SIZE="${OPTARG}";; + z) S_SIZE="${OPTARG}";; + *) usage ;; + esac +done + +# Test run. +! check_root && error_msg "You need to be root to run this script." +create_out_dir "${OUTPUT}" + +info_msg "About to run fdisk tests ..." +info_msg "Output directory: ${OUTPUT}" + +pkgs="acl attr automake bc dbench dump e2fsprogs fio gawk gcc git indent libacl1-dev libaio-dev libcap-dev libgdbm-dev libtool libtool-bin liburing-dev libuuid1 lvm2 make psmisc python3 quota sed uuid-dev uuid-runtime xfsprogs linux-headers-$(uname -r) sqlite3 libgdbm-compat-dev" +install_deps "${pkgs}" "${SKIP_INSTALL}" + +if [ -d "${XFSTESTS_PATH}" ]; then + echo "xfstests found on rootfs" + # shellcheck disable=SC2164 + cd "${XFSTESTS_PATH}" || exit 1 +else + echo "xfstests not found" + error_fatal "xfstests-not-found" +fi + +mkdir -p "${TEST_DIR}" +mkdir -p "${SCRATCH_MNT}" + +create_fsgqa_test_users_groups + +fallocate_manipulate_file_space "${TEST_IMG}" "${T_SIZE}" +fallocate_manipulate_file_space "${SCRATCH_IMG}" "${S_SIZE}" + +format_disk_partitions "${TEST_IMG}" "${FILESYSTEM}" +format_disk_partitions "${SCRATCH_IMG}" "${FILESYSTEM}" + +TEST_DEV=$(losetup -f "${TEST_IMG}" --show) +SCRATCH_DEV=$(losetup -f "${SCRATCH_IMG}" --show) + +# Run xfstests +run_xfstests "${FILESYSTEM}" + +# Parse xfstests results +results_parser diff --git a/automated/linux/xfstests/xfstests.yaml b/automated/linux/xfstests/xfstests.yaml new file mode 100644 index 000000000..e128d9256 --- /dev/null +++ b/automated/linux/xfstests/xfstests.yaml @@ -0,0 +1,38 @@ +metadata: + name: xfstests + format: "Lava-Test Test Definition 1.0" + description: "xfstests is a test suite for validating the reliability and + stability of file systems in the Linux kernel." + maintainer: + - anders.roxell@linaro.org + - naresh.kamboju@linaro.org + os: + - debian + - ubuntu + scope: + - functional + devices: + - all + environment: + - lava-test-shell + +params: + # example: TEST_DEV=/dev/loop0 + TEST_DEV: "/dev/loop0" + # example: SCRATCH_DEV=/dev/loop1 + SCRATCH_DEV: "/dev/loop1" + # example: TEST_DIR=/mnt/test + TEST_DIR: "/mnt/test" + # example: SCRATCH_MNT=/mnt/scratch + SCRATCH_MNT: "/mnt/scratch" + + FILESYSTEM: "ext4" + T_SIZE: "5G" + S_SIZE: "8G" + SKIP_INSTALL: "true" + +run: + steps: + - cd ./automated/linux/xfstests/ + - ./xfstests.sh -d "${TEST_DEV}" -e "${SCRATCH_DEV}" -f "${FILESYSTEM}" -m "${SCRATCH_MNT}" -s "${SKIP_INSTALL}" -t "${TEST_DIR}" -x "${T_SIZE}" -z "${S_SIZE}" + - ../../utils/send-to-lava.sh ./output/result.txt