From 74da641c0eec6cd4a29af5cc944fb60525c02a04 Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Tue, 9 Aug 2016 21:26:21 +0800 Subject: common: add disk partitioning test Change-Id: If8a024b0e4290a40a7de6f7c2cb848b3ec77ff30 Signed-off-by: Chase Qi --- common/disk-partitioning-test.yaml | 30 +++++++ common/scripts/disk-partitioning-test.sh | 133 +++++++++++++++++++++++++++++++ common/scripts/include/sh-test-lib | 2 + 3 files changed, 165 insertions(+) create mode 100755 common/disk-partitioning-test.yaml create mode 100755 common/scripts/disk-partitioning-test.sh (limited to 'common') diff --git a/common/disk-partitioning-test.yaml b/common/disk-partitioning-test.yaml new file mode 100755 index 0000000..d15c8bd --- /dev/null +++ b/common/disk-partitioning-test.yaml @@ -0,0 +1,30 @@ +metadata: + name: disk-partitioning-test + format: "Lava-Test-Shell Test Definition 1.0" + description: "Disk partitioning test." + maintainer: + - chase.qi@linaro.org + os: + - debian + - fedora + devices: + - mustang + - hi6220-hikey + - apq8016-sbc + scope: + - functional + environment: + - lava-test-shell + +params: + # The existing disk label on the device will be destroyed, + # and all data on this disk will be lost. + DEVICE: "" + # Supported labels: msdos and gpt + DISKLABEL: "gpt" + FILESYSTEM: "ext4" + +run: + steps: + - ./common/scripts/disk-partitioning-test.sh -d "${DEVICE}" -l "${DISKLABEL}" -f "${FILESYSTEM}" -r "result.txt" + - ./common/scripts/send-to-lava.sh "result.txt" diff --git a/common/scripts/disk-partitioning-test.sh b/common/scripts/disk-partitioning-test.sh new file mode 100755 index 0000000..90768c9 --- /dev/null +++ b/common/scripts/disk-partitioning-test.sh @@ -0,0 +1,133 @@ +#!/bin/sh +# +# Disk partitioning test. +# +# Copyright (C) 2010 - 2016, Linaro Limited. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Author: Chase Qi + +LANG=C +export LANG +. ./common/scripts/include/sh-test-lib +WD="$(pwd)" +RESULT_FILE="${WD}/disk-partitioning-test-result.txt" +DISKLABEL="gpt" +FILESYSTEM="ext4" +SKIP_INSTALL="false" + +usage() { + echo "Usage: $0 [-d ] [-l ] [-f ] + [-r ] [-s ]" 1>&2 + exit 1 +} + +while getopts "d:l:f:r:s:" o; do + case "$o" in + # The existing disk label on the device will be destroyed, + # and all data on this disk will be lost. + d) DEVICE="${OPTARG}" ;; + l) DISKLABEL="${OPTARG}" ;; + f) FILESYSTEM="${OPTARG}" ;; + r) RESULT_FILE="${WD}/${OPTARG}" ;; + s) SKIP_INSTALL="${OPTARG}" ;; + *) usage ;; + esac +done + +[ -z "${DEVICE}" ] && error_msg "Please specify test device with '-d'" +DISKLABEL=${DISKLABEL:-"gpt"} +FILESYSTEM=${FILESYSTEM:-"ext4"} +SKIP_INSTALL=${SKIP_INSTALL:-"false"} + +install() { + if "${SKIP_INSTALL}"; then + info_msg "install_deps skipped" + else + pkgs="parted e2fsprogs dosfstools" + info_msg "Installing ${pkgs}" + install_deps "${pkgs}" + fi +} + +create_disklabel() { + echo + echo "Creating ${DEVICE} disklabel: ${DISKLABEL}" + umount "${DEVICE}*" > /dev/null 2>&1 + parted -s "${DEVICE}" mklabel "${DISKLABEL}" + + # Collect test reuslt with check_return function. + # If mklabel fails, skip the following tests. + check_return "create-disklabel" \ + || error_msg "Partitioning, formatting, and smoke tests skipped" + + sync + sleep 10 +} + +create_partition() { + echo + echo "Creating partition: ${DEVICE}1" + parted -s "${DEVICE}" mkpart primary 0% 100% + + check_return "create-partition" \ + || error_msg "Formatting, and smoke tests skipped" + + sync + sleep 10 +} + +format_partition() { + echo + echo "Formatting ${DEVICE}1 to ${FILESYSTEM}" + if [ "${FILESYSTEM}" = "fat32" ]; then + echo "y" | mkfs -t vfat -F 32 "${DEVICE}1" + else + echo "y" | mkfs -t "${FILESYSTEM}" "${DEVICE}1" + fi + + check_return "format-partition" || error_msg "Smoke test skipped" + + sync + sleep 10 +} + +partition_smoke_test() { + echo + echo "Running mount/umoun tests..." + umount /mnt > /dev/null 2>&1 + mount "${DEVICE}1" /mnt + check_return "mount-partition" || error_msg "umount test skipped" + + umount "${DEVICE}1" + check_return "umount-partition" +} + +# Test run. +! check_root && error_msg "This script must be run as root" +[ -f "${RESULT_FILE}" ] \ + && mv "${RESULT_FILE}" "${RESULT_FILE}_$(date +%Y%m%d%H%M%S)" + +echo +info_msg "About to run disk partitioning test..." +info_msg "Working directory: ${WD}" +info_msg "Result will be saved to: ${RESULT_FILE}" + +install +create_disklabel +create_partition +format_partition +partition_smoke_test diff --git a/common/scripts/include/sh-test-lib b/common/scripts/include/sh-test-lib index 5c1e4a1..3d6fc93 100755 --- a/common/scripts/include/sh-test-lib +++ b/common/scripts/include/sh-test-lib @@ -75,8 +75,10 @@ check_return() { if [ "${exit_code}" -ne 0 ]; then echo "${test} fail" | tee -a "${RESULT_FILE}" + return 1 else echo "${test} pass" | tee -a "${RESULT_FILE}" + return 0 fi } -- cgit v1.2.3