build-sys: Handle zero length diskstats in tests

vmstat -d testsuite will fail if your /proc/diskstats is present
but zero length. While this seems buggy behaviour from lxcfs, its
there and its a simple matter to test for it and skip those tests
if we are run on a zero length /proc/diskstats system.
This commit is contained in:
Craig Small 2021-03-29 22:23:03 +11:00
parent 3dd1661a3d
commit fc97889b2d

View File

@ -35,20 +35,23 @@ set test "vmstat disk information (-d option)"
if { [ file readable "/sys/block" ] == 0 } { if { [ file readable "/sys/block" ] == 0 } {
unsupported "$test /sys/block not readable" unsupported "$test /sys/block not readable"
} else { } else {
spawn $vmstat -d set fp [open /proc/diskstats ]
expect_pass "$test" "^disk\[ -\]+reads\[ -\]+writes\[ -\]+IO\[ -\]+\\s+total\\s+merged\\s+sectors\\s+ms\\s+total\\s+merged\\s+sectors\\s+ms\\s+cur\\s+sec\\s+" if { [ read $fp ] == "" } {
} close $fp
unsupported "$test /proc/diskstats empty"
} else {
close $fp
spawn $vmstat -d
expect_pass "$test" "^disk\[ -\]+reads\[ -\]+writes\[ -\]+IO\[ -\]+\\s+total\\s+merged\\s+sectors\\s+ms\\s+total\\s+merged\\s+sectors\\s+ms\\s+cur\\s+sec\\s+"
# Need a partition # Need a partition
set diskstats [ exec cat /proc/diskstats ] set diskstats [ exec cat /proc/diskstats ]
if { [ file readable "/sys/block" ] == 0 } { if [ regexp "\\s+\\d+\\s+\\d+\\s+\((?:hd|sd|vd)\[a-z\]\\d+\)\\s+\[0-9\]\[0-9\]+" $diskstats line partition == 1 ] {
unsupported "vmstat partition /sys/block not readable" set test "vmstat partition (using $partition)"
} else { spawn $vmstat -p $partition
if [ regexp "\\s+\\d+\\s+\\d+\\s+\((?:hd|sd|vd)\[a-z\]\\d+\)\\s+\[0-9\]\[0-9\]+" $diskstats line partition == 1 ] { expect_pass "$test" "^${partition}\\s+reads"
set test "vmstat partition (using $partition)" } else {
spawn $vmstat -p $partition unsupported "vmstat partition (cannot find partition)"
expect_pass "$test" "^${partition}\\s+reads" }
} else { }
unsupported "vmstat partition (cannot find partition)"
}
} }