scstadmin: Improve test script robustness

Check the return value of most system() calls. Use gawk instead of awk
when using GNU extensions.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7931 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2019-02-16 17:37:12 +00:00
parent b2119c2133
commit 52f9a2b285
3 changed files with 67 additions and 47 deletions

View File

@@ -20,7 +20,7 @@ BEGIN {
unless(grep /blib/, @INC) {
unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib"));
}
plan tests => 2;
plan tests => 5;
}
use Data::Dumper;
@@ -45,11 +45,17 @@ sub testRestoreConfig {
my $diff = File::Spec->catfile(File::Spec->tmpdir(),
"scstadmin-test-06-$$-diff");
system("$scstadmin -clear_config -force -noprompt -no_lip >/dev/null");
ok(system("$scstadmin -clear_config -force -noprompt -no_lip >/dev/null"), 0);
system("$scstadmin -cont_on_err -no_lip -config $to_be_restored" .
" >/dev/null");
system("$scstadmin -write_config $tmpfilename1 >/dev/null");
system("awk 'BEGIN {t = 0 } /^# Automatically generated by SCST Configurator v/ { \$0 = \"# Automatically generated by SCST Configurator v...\" } /^TARGET_DRIVER.*{\$/ { if (\$0 != \"TARGET_DRIVER scst_local {\") t = 1 } /^}\$/ { if (t == 1) t = 2 } /^\$/ { if (t == 2) { t = 3 } } /^./ { if (t == 3) { t = 0 } } { if (t == 0) print }' <$tmpfilename1 >$tmpfilename2");
ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0);
ok(system("awk 'BEGIN {t = 0 } /^# Automatically generated by SCST Configurator v/ " .
'{ $0 = "# Automatically generated by SCST Configurator v..." } ' .
'/^TARGET_DRIVER.*{$/ { if ($0 != "TARGET_DRIVER scst_local {") t = 1 } ' .
'/^}$/ { if (t == 1) t = 2 }' .
'/^$/ { if (t == 2) { t = 3 } }' .
'/^./ { if (t == 3) { t = 0 } }' .
"{ if (t == 0) print }' <$tmpfilename1 >$tmpfilename2"), 0);
my $compare_result = system("diff -u $tmpfilename2 $expected >$diff");
ok($compare_result, 0);
if ($compare_result == 0) {

View File

@@ -22,7 +22,7 @@ BEGIN {
unless(grep /blib/, @INC) {
unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib"));
}
plan tests => 2;
plan tests => 16;
}
use Data::Dumper;
@@ -35,7 +35,7 @@ sub setup {
my ($drivers, $errorString) = $SCST->drivers();
my %drivers = map { $_ => 1 } @{$drivers};
ok(exists($drivers{'scst_local'}));
system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1");
ok(system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1"), 0);
}
sub teardown {
@@ -51,26 +51,34 @@ sub attributeTest {
my $diff = File::Spec->catfile(File::Spec->tmpdir(),
"scstadmin-test-07-$$-diff");
system("$scstadmin -clear_config -force -noprompt -no_lip $redirect");
system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect");
system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect");
system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect");
system("$scstadmin -driver scst_local -add_target local $redirect");
system("$scstadmin -driver scst_local -target local " .
"-add_lun 0 -device nodev $redirect");
system("$scstadmin -driver scst_local -target local -add_group ig " .
"$redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini1 $redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini2 $redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 0 -device disk0 $redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 1 -device disk1 $redirect");
system("$scstadmin -write_config $tmpfilename1 >/dev/null");
ok(system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"), 0);
ok(system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect"), 0);
ok(system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect"), 0);
ok(system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -add_target local $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local " .
"-add_lun 0 -device nodev $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -add_group ig " .
"$redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini1 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini2 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 0 -device disk0 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 1 -device disk1 $redirect"), 0);
ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0);
# Keep only the scst_local target driver information.
system("awk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ { \$0 = \"# Automatically generated by SCST Configurator v...\" } /^TARGET_DRIVER.*{\$/ { if (match(\$0, \"TARGET_DRIVER ([^ ]*) {\", d) && d[1] != \"scst_local\") t = 1 } /^}\$/ { if (t == 1) t = 2 } /^\$/ { if (t == 2) { t = 3 } } /^./ { if (t == 3) { t = 0 } } { if (t == 0) print }' <$tmpfilename1 >$tmpfilename2");
my $cmd = "gawk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ {" .
'$0 = "# Automatically generated by SCST Configurator v..." } ' .
'/^TARGET_DRIVER.*{$/ { if (match($0, "TARGET_DRIVER ([^ ]*) {", d) && d[1] != "scst_local") t = 1 } ' .
'/^}$/ { if (t == 1) t = 2 } ' .
'/^$/ { if (t == 2) { t = 3 } } ' .
'/^./ { if (t == 3) { t = 0 } } ' .
'{ if (t == 0) print }' .
"' <$tmpfilename1 >$tmpfilename2";
ok(system($cmd), 0);
my $compare_result = system("diff -u $tmpfilename2 $expected >$diff");
ok($compare_result, 0);
if ($compare_result == 0) {

View File

@@ -22,7 +22,7 @@ BEGIN {
unless(grep /blib/, @INC) {
unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib"));
}
plan tests => 9;
plan tests => 24;
}
use Data::Dumper;
@@ -35,7 +35,7 @@ sub setup {
my ($drivers, $errorString) = $SCST->drivers();
my %drivers = map { $_ => 1 } @{$drivers};
ok(exists($drivers{'scst_local'}));
system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1");
ok(system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1"), 0);
}
sub teardown {
@@ -46,7 +46,13 @@ sub filterScstLocal {
my $in = shift;
my $out = shift;
system("awk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ { \$0 = \"# Automatically generated by SCST Configurator v...\" } /^TARGET_DRIVER.*{\$/ { if (match(\$0, \"TARGET_DRIVER ([^ ]*) {\", d) && d[1] != \"scst_local\") t = 1 } /^}\$/ { if (t == 1) t = 2 } /^\$/ { if (t == 2) { t = 3 } } /^./ { if (t == 3) { t = 0 } } { if (t == 0) print }' <" . '"' . "$in" . '" >"' . "$out" . '"');
ok(system("awk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ " .
'{ $0 = "# Automatically generated by SCST Configurator v..." } ' .
'/^TARGET_DRIVER.*{$/ { if (match($0, "TARGET_DRIVER ([^ ]*) {", d) && d[1] != "scst_local") t = 1 } ' .
'/^}$/ { if (t == 1) t = 2 }' .
'/^$/ { if (t == 2) { t = 3 } }' .
'/^./ { if (t == 3) { t = 0 } } ' .
"{ if (t == 0) print }' <" . '"' . "$in" . '" >"' . "$out" . '"'), 0);
}
sub closeDevs {
@@ -68,27 +74,27 @@ sub closeDevTest {
"scstadmin-test-08-$$-2");
my $rc;
system("$scstadmin -clear_config -force -noprompt -no_lip $redirect");
system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect");
system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect");
system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect");
system("$scstadmin -driver scst_local -add_target local $redirect");
system("$scstadmin -driver scst_local -target local " .
"-add_lun 0 -device nodev $redirect");
system("$scstadmin -driver scst_local -target local -add_group ig " .
"$redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini1 $redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini2 $redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 0 -device disk0 $redirect");
system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 1 -device disk1 $redirect");
system("$scstadmin -write_config $tmpfilename1 >/dev/null");
ok(system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"), 0);
ok(system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect"), 0);
ok(system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect"), 0);
ok(system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -add_target local $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local " .
"-add_lun 0 -device nodev $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -add_group ig " .
"$redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini1 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_init ini2 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 0 -device disk0 $redirect"), 0);
ok(system("$scstadmin -driver scst_local -target local -group ig " .
"-add_lun 1 -device disk1 $redirect"), 0);
ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0);
# Keep only the scst_local target driver information.
filterScstLocal("$tmpfilename1", "$tmpfilename2");
system("cd /sys/kernel/scst_tgt && find -ls $redirect");
ok(system("cd /sys/kernel/scst_tgt && find -ls $redirect"), 0);
$rc = system("$scstadmin -dumpAttrs $redirect");
ok($rc, 0);
$rc = closeDevs("nodev");