Skip to content

Commit

Permalink
Add a smoke test for usb mass storage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael Moese authored and frankenmichl committed Feb 2, 2024
1 parent 3e1e960 commit 41f30eb
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/kernel/usb_drive.pm
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

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;

0 comments on commit 41f30eb

Please sign in to comment.