From 41f30ebe742fa6f5f715b6ce77d081f1bcb2b327 Mon Sep 17 00:00:00 2001 From: Michael Moese Date: Thu, 14 Dec 2023 14:50:23 +0100 Subject: [PATCH] Add a smoke test for usb mass storage Assuming a single usb mass storage device is connected to the machine, randomly create a small file, write it to the device, remount it and compare MD5 sums. --- tests/kernel/usb_drive.pm | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/kernel/usb_drive.pm diff --git a/tests/kernel/usb_drive.pm b/tests/kernel/usb_drive.pm new file mode 100644 index 000000000000..e9c90c9302c3 --- /dev/null +++ b/tests/kernel/usb_drive.pm @@ -0,0 +1,60 @@ +# SUSE's openQA tests +# +# Copyright SUSE LLC +# SPDX-License-Identifier: FSFAP + +# Package: usb_nic +# Summary: Simple smoke test for testing USB NIC connected to system +# Maintainer: LSG QE Kernel + +use base 'opensusebasetest'; +use strict; +use warnings; +use testapi; +use serial_terminal 'select_serial_terminal'; +use utils; +use Utils::Logging 'export_logs_basic'; + +sub run { + my ($self) = @_; + + select_serial_terminal; + + my $lun = script_output 'lsscsi -t -v | grep usb | awk -F" " \'{split($2,a,/[\/]/); print a[6]}\''; + my $device = "/dev/" . script_output "lsscsi -v | grep -m1 $lun | awk -F\"/\" \'{print \$3}\'"; + + + # create filesystem, mountpoint and temporary file + my $tmp = script_output 'mktemp -d'; + my $file = "$tmp/file"; + my $md5 = "$tmp/md5"; + my $mountpoint = "$tmp/mount"; + my $file_copy = "$mountpoint/file"; + + assert_script_run "mkdir $mountpoint"; + assert_script_run "mkfs.btrfs -f $device"; + + assert_script_run "mount -t btrfs $device $mountpoint"; + assert_script_run "dd if=/dev/urandom of=$file bs=1M count=16"; + assert_script_run "md5sum $file > $md5"; + assert_script_run "cp $file $file_copy"; + + # sync, unmount and flush slab and page cache + assert_script_run 'sync'; + assert_script_run "umount $mountpoint"; + assert_script_run "echo 3 > /proc/sys/vm/drop_caches"; + + # remount and check md5sum + assert_script_run "mount -t btrfs $device $mountpoint"; + assert_script_run "cd $mountpoint; md5sum -c $md5; cd /"; + + # cleanup + assert_script_run("umount $mountpoint"); + assert_script_run("rm -r $tmp"); +} + +sub test_flags { + return {fatal => 0}; +} + +1;