diff --git a/scstadmin/Makefile b/scstadmin/Makefile index b778bd3f5..0e050995c 100644 --- a/scstadmin/Makefile +++ b/scstadmin/Makefile @@ -117,6 +117,9 @@ uninstall: perl-module: cd $(SCSTADMIN_DIR) && $(MAKE) $@ +test: + $(MAKE) -C scstadmin test + dist-gzip: name=$(shell basename $$PWD) && \ mkdir $${name}-$(VERSION) && \ diff --git a/scstadmin/scstadmin.sysfs/Makefile b/scstadmin/scstadmin.sysfs/Makefile index f8d630cf7..6c3f6532d 100644 --- a/scstadmin/scstadmin.sysfs/Makefile +++ b/scstadmin/scstadmin.sysfs/Makefile @@ -23,6 +23,9 @@ perl-module: perl Makefile.PL; $(MAKE) -C scst-$(MODULE_VERSION) +test: + $(MAKE) -C scst-$(MODULE_VERSION) test + clean: -$(MAKE) -C scst-$(MODULE_VERSION) clean diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t new file mode 100644 index 000000000..24b5f7e50 --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t @@ -0,0 +1,18 @@ +#!perl + +use strict; +use Test; + +BEGIN { + plan tests => ($> == 0) ? 2 : 0; +} + +if ($> == 0) { + system("/etc/init.d/scst stop"); + ok(!(-d "/sys/module/scst")); + + ok(system("modprobe scst_local add_default_tgt=0 && " . + "modprobe iscsi-scst && " . + "modprobe scst_vdisk && " . + "/usr/local/sbin/iscsi-scstd"), 0); +} diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/02-scst-attr.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/02-scst-attr.t new file mode 100644 index 000000000..2f91137a3 --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/02-scst-attr.t @@ -0,0 +1,46 @@ +#!perl + +use strict; +use Test; + +BEGIN { + plan tests => 6 + ($> == 0 ? 4 : 0); +} + +use SCST::SCST; + +sub getScstThreadCount { + my $SCST = shift; + my $scstAttributes = $SCST->scstAttributes(); + my $threadHash = $scstAttributes->{'threads'}; + return exists($threadHash->{'keys'}) ? $threadHash->{'keys'}->{'0'}->{'value'} : $threadHash->{'value'}; +} + +my $_DEBUG_ = 0; + +my $SCST = eval { new SCST::SCST($_DEBUG_) }; +die("Creation of SCST object failed") if (!defined($SCST)); + +ok($SCST->setScstAttribute(), 1); + +ok($SCST->setScstAttribute('no-such-attribute'), 1); + +ok($SCST->setScstAttribute('no-such-attribute', '1'), + $SCST->SCST_C_BAD_ATTRIBUTES); + +ok($SCST->setScstAttribute('last_sysfs_mgmt_res', '1'), + $SCST->SCST_C_ATTRIBUTE_STATIC); + +my $threads = getScstThreadCount($SCST); +ok(ref(\$threads), "SCALAR"); +ok(defined($threads)); + +if ($> == 0) { + ok($SCST->setScstAttribute('threads', $threads + 1), 0); + + ok(getScstThreadCount($SCST), $threads + 1); + + ok($SCST->setScstAttribute('threads', $threads), 0); + + ok(getScstThreadCount($SCST), $threads); +} diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/03-targets.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/03-targets.t new file mode 100644 index 000000000..d0f9d98b5 --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/03-targets.t @@ -0,0 +1,342 @@ +#!perl + +use strict; +use Test; + +BEGIN { + plan tests => 179; +} + +use Data::Dumper; +use SCST::SCST; + +sub addTargets { + my $SCST = shift; + + ok($SCST->targets('no-such-driver'), undef); + ok($SCST->{'err_string'}, + "targets(): Driver 'no-such-driver' is not available"); + + ok(Dumper($SCST->drivers()), Dumper(['iscsi', 'scst_local'])); + + ok(Dumper($SCST->targets()), Dumper(undef)); + ok(Dumper($SCST->targets('no-such-driver')), Dumper(undef)); + ok($SCST->{'err_string'}, + "targets(): Driver 'no-such-driver' is not available"); + ok(Dumper($SCST->targets('scst_local')), Dumper([])); + ok(Dumper($SCST->targets('iscsi')), Dumper([])); + + ok($SCST->addVirtualTarget('no-such-driver', ''), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->removeVirtualTarget('no-such-driver', ''), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->addVirtualTarget('scst_local', 'local1'), 0); + ok(Dumper($SCST->targetType()), Dumper(undef)); + ok(Dumper($SCST->targetType('scst_local')), Dumper(undef)); + ok($SCST->targetType('scst_local', 'no-such-target'), + $SCST::SCST::TGT_TYPE_VIRTUAL); + ok($SCST->targetType('scst_local', 'local1'), + $SCST::SCST::TGT_TYPE_VIRTUAL); + ok(Dumper($SCST->targets('scst_local')), Dumper(['local1'])); + ok($SCST->removeVirtualTarget('scst_local', 'local2'), + $SCST->SCST_C_TGT_NO_TARGET); + ok(Dumper($SCST->targets('scst_local')), Dumper(['local1'])); + ok($SCST->removeVirtualTarget('scst_local', 'local1'), 0); + ok(Dumper($SCST->targets('scst_local')), Dumper([])); + ok($SCST->addVirtualTarget('scst_local', 'local1', + { 'session_name' => 'local1' }), 0); + ok($SCST->addVirtualTarget('scst_local', 'local2', + { 'session_name' => 'local2' }), 0); + ok(Dumper($SCST->targets('scst_local')), Dumper(['local1', 'local2'])); + + ok($SCST->targetExists(), 0); + ok($SCST->targetExists('no-such-driver'), 0); + ok($SCST->targetExists('no-such-driver', ''), 0); + ok($SCST->targetExists('scst_local', 'no-such-target'), 0); + ok($SCST->targetExists('scst_local', '.'), 0); + ok($SCST->targetExists('scst_local', '..'), 0); + ok($SCST->targetExists('scst_local', 'module'), 0); + ok($SCST->targetExists('scst_local', 'local1'), 1); +} + +sub sessTest { + my $SCST = shift; + + ok(Dumper($SCST->sessions()), Dumper(undef)); + ok(Dumper($SCST->sessions('scst_local')), Dumper(undef)); + my $s = $SCST->sessions('scst_local', 'local1'); + ok(Dumper(sort(keys(%$s))), Dumper('local1')); + ok($s->{'local1'}->{'commands'}->{'value'}, '0'); +} + +sub driverDynamicAttributesTest { + my $SCST = shift; + + ok(Dumper($SCST->driverDynamicAttributes()), Dumper(undef)); + ok(Dumper($SCST->driverDynamicAttributes('no-such-driver')), Dumper(undef)); + ok($SCST->{'err_string'}, + "driverDynamicAttributes(): Driver 'no-such-driver' is not available"); + ok(Dumper($SCST->driverDynamicAttributes('scst_local')), Dumper({})); +} + +sub iniGrpTest { + my $SCST = shift; + + ok(Dumper($SCST->groups()), Dumper(undef)); + ok(Dumper($SCST->groups('scst_local')), Dumper(undef)); + ok(Dumper($SCST->groups('scst_local', 'local1')), Dumper([])); + + ok($SCST->addGroup(), $SCST->SCST_C_GRP_ADD_FAIL); + ok($SCST->addGroup('no-such-driver', 'local1', 'group1'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->addGroup('scst_local', 'no-such-target', 'group1'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->addGroup('scst_local', 'local1', 'group1'), 0); + ok($SCST->addGroup('scst_local', 'local1', 'group1'), + $SCST->SCST_C_GRP_EXISTS); + ok($SCST->addGroup('scst_local', 'local1', 'group2'), 0); + ok($SCST->addGroup('scst_local', 'local1', 'group3'), 0); + ok(Dumper($SCST->groups('scst_local', 'local1')), + Dumper(['group1', 'group2', 'group3'])); + + ok($SCST->groupExists(), 0); + ok($SCST->groupExists('no-such-driver', '', ''), 0); + ok($SCST->groupExists('scst_local', 'no-such-target', ''), 0); + ok($SCST->groupExists('scst_local', 'local1', 'no-such-group'), 0); + ok($SCST->groupExists('scst_local', 'local1', 'group1'), 1); + + ok($SCST->removeGroup(), $SCST->SCST_C_GRP_REM_FAIL); + ok($SCST->removeGroup('no-such-driver', 'local1', 'group1'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->removeGroup('scst_local', 'no-such-target', 'group1'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->removeGroup('scst_local', 'local1', 'group1'), 0); + ok($SCST->removeGroup('scst_local', 'local1', 'group1'), + $SCST->SCST_C_GRP_NO_GROUP); + ok($SCST->removeGroup('scst_local', 'local1', 'group2'), 0); + ok($SCST->removeGroup('scst_local', 'local1', 'group3'), 0); + ok(Dumper($SCST->groups('scst_local', 'local1')), Dumper([])); + + ok($SCST->addGroup('scst_local', 'local1', 'group1'), 0); + ok($SCST->addInitiator('scst_local', 'local1', 'group1'), + $SCST->SCST_C_GRP_ADD_INI_FAIL); + ok($SCST->addInitiator('no-such-driver', 'local1', 'group1', 'ini1'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->addInitiator('scst_local', 'no-such-target', 'group1', 'ini1'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->addInitiator('scst_local', 'local1', 'no-such-group', 'ini1'), + $SCST->SCST_C_GRP_NO_GROUP); + ok($SCST->addInitiator('scst_local', 'local1', 'group1', 'ini1'), 0); + ok($SCST->addInitiator('scst_local', 'local1', 'group1', 'ini2'), 0); + ok($SCST->addInitiator('scst_local', 'local1', 'group1', 'ini1'), + $SCST->SCST_C_GRP_INI_EXISTS); + ok(Dumper($SCST->initiators()), Dumper(undef)); + ok(Dumper($SCST->initiators('scst_local')), Dumper(undef)); + ok(Dumper($SCST->initiators('scst_local', 'local1')), Dumper(undef)); + ok(Dumper($SCST->initiators('scst_local', 'local1', 'group1')), + Dumper(['ini1', 'ini2'])); + + ok($SCST->initiatorExists(), 0); + ok($SCST->initiatorExists('no-such-driver', '', '', ''), 0); + ok($SCST->initiatorExists('scst_local', 'no-such-target', '', ''), 0); + ok($SCST->initiatorExists('scst_local', 'local1', 'no-such-group', ''), 0); + ok($SCST->initiatorExists('scst_local', 'local1', 'group1', 'no-such-ini'), + 0); + ok($SCST->initiatorExists('scst_local', 'local1', 'group1', 'ini1'), 1); + + ok($SCST->addGroup('scst_local', 'local1', 'group2'), 0); + ok($SCST->moveInitiator('scst_local', 'local1', 'group1', 'group2', 'ini1'), + 0); + ok($SCST->initiatorExists('scst_local', 'local1', 'group1', 'ini1'), 0); + ok($SCST->initiatorExists('scst_local', 'local1', 'group2', 'ini1'), 1); + ok($SCST->moveInitiator('scst_local', 'local1', 'group2', 'group1', 'ini1'), + 0); + ok($SCST->initiatorExists('scst_local', 'local1', 'group1', 'ini1'), 1); + ok($SCST->initiatorExists('scst_local', 'local1', 'group2', 'ini1'), 0); + + ok($SCST->removeGroup('scst_local', 'local1', 'group2'), 0); + ok($SCST->removeInitiator('no-such-driver', 'local1', 'group1'), + $SCST->SCST_C_GRP_REM_INI_FAIL); + ok($SCST->removeInitiator('no-such-driver', 'local1', 'group1', 'ini1'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->removeInitiator('scst_local', 'no-such-target', 'group1', 'ini1'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->removeInitiator('scst_local', 'local1', 'no-such-group', 'ini1'), + $SCST->SCST_C_GRP_NO_GROUP); + ok($SCST->removeInitiator('scst_local', 'local1', 'group1', 'ini1'), 0); + ok($SCST->removeInitiator('scst_local', 'local1', 'group1', 'ini2'), 0); + ok($SCST->removeInitiator('scst_local', 'local1', 'group1', 'ini2'), + $SCST->SCST_C_GRP_NO_INI); + ok(Dumper($SCST->initiators('scst_local', 'local1', 'group1')), Dumper([])); + ok($SCST->removeGroup('scst_local', 'local1', 'group1'), 0); +} + +sub lunReadOnly { + my $SCST = shift; + my $driver = shift; + my $target = shift; + my $lun = shift; + + my $a = $SCST->lunAttributes($driver, $target, $lun); + my $roHash = $a->{'read_only'}; + return exists($roHash->{'keys'}) ? $roHash->{'keys'}->{'0'}->{'value'} : + $roHash->{'value'}; +} + +sub lunTest { + my $SCST = shift; + + ok($SCST->openDevice("no-such-handler", "disk01", { }), + $SCST->SCST_C_HND_NO_HANDLER); + ok($SCST->openDevice("vdisk_fileio", "disk01", undef), + $SCST->SCST_C_DEV_OPEN_FAIL); + ok($SCST->openDevice("vdisk_fileio", "disk01", { }), + $SCST->SCST_C_DEV_OPEN_FAIL); + ok($SCST->openDevice("vdisk_fileio", "disk01", + { 'filename' => '/proc/cpuinfo' }), 0); + ok($SCST->openDevice("vdisk_fileio", "disk01", + { 'filename' => '/proc/cpuinfo' }), + $SCST->SCST_C_DEV_EXISTS); + ok($SCST->openDevice("vdisk_fileio", "disk02", + { 'filename' => '/proc/cpuinfo' }), 0); + + ok($SCST->addLun('scst_local', 'local1', 'disk01', 0), + $SCST->SCST_C_TGT_ADD_LUN_FAIL); + ok($SCST->addLun('scst_local', 'local3', 'disk01', 0, { }), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->addLun('scst_local', 'local1', 'disk01', 0, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk02', 1, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk01', 2, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk02', 3, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk01', 3, { }), + $SCST->SCST_C_TGT_LUN_EXISTS); + + ok($SCST->lunExists(), 0); + ok($SCST->lunExists('scst_local'), 0); + ok($SCST->lunExists('scst_local', 'local1'), 0); + ok($SCST->lunExists('no-such-driver', 'local1', 0), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->lunExists('scst_local', 'no-such-target', 0), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->lunExists('scst_local', 'local1', 99), 0); + ok($SCST->lunExists('scst_local', 'local1', 0), 1); + + ok($SCST->addGroup('scst_local', 'local1', 'group1'), 0); + ok($SCST->addInitiator('scst_local', 'local1', 'group1', 'ini1'), 0); + + ok($SCST->addLun('scst_local', 'local1', 'disk01', 0, undef, 'group1'), + $SCST->SCST_C_GRP_ADD_LUN_FAIL); + ok($SCST->addLun('scst_local', 'local1', 'disk01', 0, { }, 'group1'), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk02', 2, { }, 'group1'), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk01', 4, { }, 'group1'), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk02', 6, { }, 'group1'), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk01', 6, { }, 'group1'), + $SCST->SCST_C_GRP_LUN_EXISTS); + + ok($SCST->lunExists('no-such-driver', 'local1', 0, 'group1'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->lunExists('scst_local', 'no-such-target', 0, 'group1'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->lunExists('scst_local', 'local1', 99, 'group1'), 0); + ok($SCST->lunExists('scst_local', 'local1', 0, 'no-such-group'), + $SCST->SCST_C_GRP_NO_GROUP); + ok($SCST->lunExists('scst_local', 'local1', 0, 'group1'), 1); + + ok(Dumper($SCST->luns()), Dumper(undef)); + ok(Dumper($SCST->luns('scst_local')), Dumper(undef)); + ok(Dumper($SCST->luns('no-such-driver', 'local1')), Dumper(undef)); + ok($SCST->{'err_string'}, + "luns(): Driver 'no-such-driver' is not available"); + ok(Dumper($SCST->luns('scst_local', 'no-such-target')), Dumper(undef)); + ok($SCST->{'err_string'}, + "luns(): Target 'no-such-target' is not available"); + ok(Dumper($SCST->luns('scst_local', 'local1')), + Dumper({ '0' => 'disk01', '1' => 'disk02', '2' => 'disk01', + '3' => 'disk02' })); + ok(Dumper($SCST->luns('scst_local', 'local1', 'group1')), + Dumper({ '0' => 'disk01', '2' => 'disk02', '4' => 'disk01', + '6' => 'disk02' })); + + ok(lunReadOnly($SCST, 'scst_local', 'local1', 0), '0'); + ok($SCST->setLunAttribute(), $SCST->SCST_C_LUN_SETATTR_FAIL); + ok($SCST->setLunAttribute('no-such-driver', 'local1', 0, 'read_only', '1'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->setLunAttribute('scst_local', 'no-such-target', 0, 'read_only', '1'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->setLunAttribute('scst_local', 'local1', 99, 'read_only', '1'), + $SCST->SCST_C_TGT_NO_LUN); + ok($SCST->setLunAttribute('scst_local', 'local1', 0, 'read_only', '1'), + $SCST->SCST_C_LUN_ATTRIBUTE_STATIC); + ok(lunReadOnly($SCST, 'scst_local', 'local1', 0), '0'); + ok(lunReadOnly($SCST, 'scst_local', 'local1', 0, 'group1'), '0'); + ok($SCST->setLunAttribute('scst_local', 'local1', 0, 'read_only', '1', 'no-such-group'), + $SCST->SCST_C_GRP_NO_GROUP); + ok($SCST->setLunAttribute('scst_local', 'local1', 99, 'read_only', '1', 'group1'), + $SCST->SCST_C_GRP_NO_LUN); + ok($SCST->setLunAttribute('scst_local', 'local1', 0, 'read_only', '1', 'group1'), + $SCST->SCST_C_LUN_ATTRIBUTE_STATIC); + ok(lunReadOnly($SCST, 'scst_local', 'local1', 0, 'group1'), '0'); + + ok($SCST->replaceLun('scst_local', 'local1', 0, 'disk02', {}), 0); + ok(Dumper($SCST->luns('scst_local', 'local1')), + Dumper({ '0' => 'disk02', '1' => 'disk02', '2' => 'disk01', + '3' => 'disk02' })); + ok($SCST->replaceLun('scst_local', 'local1', 0, 'disk01', {}), 0); + ok(Dumper($SCST->luns('scst_local', 'local1')), + Dumper({ '0' => 'disk01', '1' => 'disk02', '2' => 'disk01', + '3' => 'disk02' })); + + ok($SCST->clearLuns(undef, undef), $SCST->SCST_C_TGT_CLR_LUN_FAIL); + ok($SCST->clearLuns(undef, undef, 'group1'), + $SCST->SCST_C_GRP_CLR_LUN_FAIL); + ok($SCST->removeLun(undef, undef, undef), $SCST->SCST_C_TGT_ADD_LUN_FAIL); + ok($SCST->removeLun('no-such-driver', 'local1', '0'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->removeLun('scst_local', 'no-such-target', '0'), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->removeLun(undef, undef, undef, 'group1'), + $SCST->SCST_C_GRP_REM_LUN_FAIL); + ok($SCST->removeLun('scst_local', 'local1', '4'), $SCST->SCST_C_TGT_NO_LUN); + ok($SCST->removeLun('scst_local', 'local1', '8', 'group1'), + $SCST->SCST_C_GRP_NO_LUN); + ok($SCST->clearLuns('scst_local', 'local1'), 0); + ok(Dumper($SCST->luns('scst_local', 'local1')), Dumper({ })); + ok(Dumper($SCST->luns('scst_local', 'local1', 'group1')), + Dumper({ '0' => 'disk01', '2' => 'disk02', '4' => 'disk01', + '6' => 'disk02' })); + ok($SCST->removeLun('scst_local', 'local1', '4', 'group1'), 0); + ok(Dumper($SCST->luns('scst_local', 'local1', 'group1')), + Dumper({ '0' => 'disk01', '2' => 'disk02', '6' => 'disk02' })); + ok($SCST->clearLuns('scst_local', 'local1', 'group1'), 0); + ok(Dumper($SCST->luns('scst_local', 'local1', 'group1')), Dumper({ })); + + ok($SCST->removeInitiator('scst_local', 'local1', 'group1', 'ini1'), 0); + ok($SCST->removeGroup('scst_local', 'local1', 'group1'), 0); + + ok($SCST->closeDevice("no-such-handler", "disk01"), + $SCST->SCST_C_HND_NO_HANDLER); + ok($SCST->closeDevice("vdisk_fileio", "disk02"), 0); + ok($SCST->closeDevice("vdisk_fileio", "disk01"), 0); + ok($SCST->closeDevice("vdisk_fileio", "disk01"), + $SCST->SCST_C_DEV_NO_DEVICE); +} + +sub remTargets { + my $SCST = shift; + + ok($SCST->removeVirtualTarget('scst_local', 'local2'), 0); + ok($SCST->removeVirtualTarget('scst_local', 'local1'), 0); + ok(Dumper($SCST->targets('scst_local')), Dumper([])); +} + +my $_DEBUG_ = 0; + +my $SCST = eval { new SCST::SCST($_DEBUG_) }; +die("Creation of SCST object failed") if (!defined($SCST)); + +addTargets($SCST); +sessTest($SCST); +driverDynamicAttributesTest($SCST); +iniGrpTest($SCST); +lunTest($SCST); +remTargets($SCST); diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/04-alua.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/04-alua.t new file mode 100644 index 000000000..9949b9211 --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/04-alua.t @@ -0,0 +1,136 @@ +#!perl + +use strict; +use Test; + +BEGIN { + plan tests => 64; +} + +use Data::Dumper; +use SCST::SCST; + +sub setup { + my $SCST = shift; + + ok(Dumper($SCST->drivers()), Dumper(['iscsi', 'scst_local'])); + + ok($SCST->openDevice("vdisk_fileio", "disk01", + { 'filename' => '/proc/cpuinfo' }), 0); + ok($SCST->openDevice("vdisk_fileio", "disk02", + { 'filename' => '/proc/cpuinfo' }), 0); + ok($SCST->openDevice("vdisk_fileio", "disk03", + { 'filename' => '/proc/cpuinfo' }), 0); + ok($SCST->openDevice("vdisk_fileio", "disk04", + { 'filename' => '/proc/cpuinfo' }), 0); + + ok($SCST->addVirtualTarget('scst_local', 'local1'), 0); + + ok($SCST->addLun('scst_local', 'local1', 'disk01', 0, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk02', 1, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk03', 2, { }), 0); + ok($SCST->addLun('scst_local', 'local1', 'disk04', 3, { }), 0); +} + +sub test { + my $SCST = shift; + + ok(Dumper($SCST->deviceGroups()), Dumper([])); + + ok($SCST->addDeviceGroup('dg1'), 0); + ok($SCST->addDeviceGroup('dg2'), 0); + ok($SCST->addDeviceGroup('dg3'), 0); + ok($SCST->addDeviceGroup('dg4'), 0); + + ok(Dumper($SCST->deviceGroups()), Dumper(['dg1', 'dg2', 'dg3', 'dg4'])); + + ok(Dumper($SCST->deviceGroupDevices()), Dumper(undef)); + ok(Dumper($SCST->deviceGroupDevices('dg1')), Dumper([])); + ok($SCST->addDeviceGroupDevice('dg1', 'disk01'), 0); + ok($SCST->addDeviceGroupDevice('dg1', 'disk01'), + $SCST->SCST_C_DGRP_DEVICE_EXISTS); + ok($SCST->addDeviceGroupDevice('dg2', 'disk02'), 0); + ok($SCST->addDeviceGroupDevice('dg2', 'disk01'), + $SCST->SCST_C_DGRP_DEVICE_OTHER); + ok($SCST->addDeviceGroupDevice('dg3', 'disk03'), 0); + ok($SCST->addDeviceGroupDevice('dg4', 'disk04'), 0); + ok(Dumper($SCST->deviceGroupDevices('dg1')), Dumper(['disk01'])); + ok(Dumper($SCST->deviceGroupDevices('dg2')), Dumper(['disk02'])); + ok(Dumper($SCST->deviceGroupDevices('dg3')), Dumper(['disk03'])); + ok(Dumper($SCST->deviceGroupDevices('dg4')), Dumper(['disk04'])); + + ok($SCST->targetGroups(), undef); + ok($SCST->targetGroups('no-such-device-group'), undef); + ok($SCST->{'err_string'}, + "targetGroups(): Device group 'no-such-device-group' does not exist"); + ok(Dumper($SCST->targetGroups('dg1')), Dumper([])); + + ok($SCST->targetGroupTargets(), undef); + ok($SCST->targetGroupTargets('no-such-device-group'), undef); + ok($SCST->targetGroupTargets('no-such-device-group', 'tg1'), undef); + ok($SCST->{'err_string'}, + "targetGroupTargets(): Device group 'no-such-device-group' does not exist"); + ok($SCST->targetGroupTargets('dg1', 'no-such-target-group'), undef); + ok($SCST->{'err_string'}, + "targetGroupTargets(): Target group 'no-such-target-group' does not exist"); + ok($SCST->targetGroupTargets('dg1', 'tg1'), undef); + ok($SCST->addTargetGroup(), $SCST->SCST_C_DGRP_ADD_GRP_FAIL); + ok($SCST->addTargetGroup('no-such-device-group', 'tg1'), + $SCST->SCST_C_DEV_GRP_NO_GROUP); + ok($SCST->addTargetGroup('dg1', 'tg1'), 0); + ok($SCST->addTargetGroup('dg1', 'tg1'), $SCST->SCST_C_DGRP_GROUP_EXISTS); + ok($SCST->addTargetGroup('dg1', 'tg2'), 0); + + ok(Dumper($SCST->targetGroupAttributes('dg1', 'tg1')->{'group_id'}), + Dumper({ 'keys' => { '0' => { 'value' => '0' } }, + 'static' => 0 })); + ok($SCST->setTargetGroupAttribute('dg1', 'tg1', 'group_id', 7), 0); + ok(Dumper($SCST->targetGroupAttributes('dg1', 'tg1')->{'group_id'}), + Dumper({ 'keys' => { '0' => { 'value' => '7' } }, + 'static' => 0 })); + + ok($SCST->addTargetGroupTarget(), $SCST->SCST_C_TGRP_ADD_TGT_FAIL); + ok($SCST->addTargetGroupTarget('no-such-device-group', 'tg1', 'tgt1'), + $SCST->SCST_C_DEV_GRP_NO_GROUP); + ok($SCST->addTargetGroupTarget('dg1', 'no-such-target-group', 'tgt1'), + $SCST->SCST_C_DGRP_NO_GROUP); + ok($SCST->addTargetGroupTarget('dg1', 'tg1', 'tgt1'), 0); + ok($SCST->addTargetGroupTarget('dg1', 'tg1', 'tgt1'), + $SCST->SCST_C_TGRP_TGT_EXISTS); + ok($SCST->addTargetGroupTarget('dg1', 'tg2', 'tgt2'), 0); + + ok(Dumper($SCST->targetGroupTargetAttributes('dg1', 'tg1', 'tgt1') + ->{'rel_tgt_id'}), + Dumper({ 'keys' => { '0' => { 'value' => '0' } }, + 'static' => 0 })); + ok($SCST->setTargetGroupTargetAttribute('dg1', 'tg1', 'tgt1', 'rel_tgt_id', + 8), 0); + ok(Dumper($SCST->targetGroupTargetAttributes('dg1', 'tg1', 'tgt1') + ->{'rel_tgt_id'}), + Dumper({ 'keys' => { '0' => { 'value' => '8' } }, + 'static' => 0 })); + + ok($SCST->removeDeviceGroup('dg1'), 0); + ok($SCST->removeDeviceGroup('dg2'), 0); + ok($SCST->removeDeviceGroup('dg3'), 0); + ok($SCST->removeDeviceGroup('dg4'), 0); + + ok(Dumper($SCST->deviceGroups()), Dumper([])); +} + +sub teardown { + my $SCST = shift; + + ok($SCST->removeVirtualTarget('scst_local', 'local1'), 0); + ok($SCST->closeDevice("vdisk_fileio", "disk01"), 0); + ok($SCST->closeDevice("vdisk_fileio", "disk02"), 0); +} + +my $_DEBUG_ = 0; + +my $SCST = eval { new SCST::SCST($_DEBUG_) }; +die("Creation of SCST object failed") if (!defined($SCST)); + +setup($SCST); +test($SCST); +teardown($SCST); diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/05-dynattr.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/05-dynattr.t new file mode 100644 index 000000000..fc60e3482 --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/05-dynattr.t @@ -0,0 +1,151 @@ +#!perl + +use strict; +use Test; + +BEGIN { + plan tests => 56; +} + +use Data::Dumper; +use SCST::SCST; + +sub setup { + my $SCST = shift; + + ok(Dumper($SCST->drivers()), Dumper(['iscsi', 'scst_local'])); + + ok($SCST->openDevice("vdisk_fileio", "disk01", + { 'filename' => '/proc/cpuinfo' }), 0); + + ok($SCST->addVirtualTarget('iscsi', 'tgt1'), 0); + + ok($SCST->addLun('iscsi', 'tgt1', 'disk01', 0, { }), 0); +} + +sub testDriverDynAttr { + my $SCST = shift; + + ok($SCST->driverDynamicAttributes(), undef); + ok($SCST->driverDynamicAttributes('no-such-driver'), undef); + ok($SCST->{'err_string'}, + "driverDynamicAttributes(): Driver 'no-such-driver' is not available"); + ok(Dumper($SCST->driverDynamicAttributes('scst_local')), Dumper({})); + ok(Dumper($SCST->driverDynamicAttributes('iscsi')), + Dumper({ 'IncomingUser' => '', 'OutgoingUser' => '' })); + ok($SCST->checkDriverDynamicAttributes('no-such-driver'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->checkDriverDynamicAttributes('no-such-driver', { }), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->checkDriverDynamicAttributes('scst_local', { }), 0); + ok($SCST->checkDriverDynamicAttributes('iscsi', { }), 0); + ok($SCST->checkDriverDynamicAttributes('iscsi', + { 'IncomingUser' => ''}), 0); + ok($SCST->checkDriverDynamicAttributes('iscsi', + { 'IncomingUser' => '', + 'OutgoingUser' => '' }), 0); + ok($SCST->checkDriverDynamicAttributes('iscsi', + { 'IncomingUser' => '', + 'OutgoingUser' => '', + 'NoSuchAttribute' => '' }), 1); + + ok($SCST->addDriverDynamicAttribute(), $SCST->SCST_C_DRV_ADDATTR_FAIL); + ok($SCST->addDriverDynamicAttribute('no-such-driver', '', ''), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->addDriverDynamicAttribute('iscsi', 'no-such-attribute', ''), + $SCST->SCST_C_DRV_BAD_ATTRIBUTES); + ok($SCST->addDriverDynamicAttribute('iscsi', 'IncomingUser', + 'bar 12CharSecret'), 0); + ok($SCST->addDriverDynamicAttribute('iscsi', 'IncomingUser', + 'joe 12charsecret'), 0); + ok(Dumper($SCST->driverAttributes('iscsi')->{'IncomingUser'}), + Dumper({ 'keys' => { '0' => { 'value' => 'bar 12CharSecret' }, + '1' => { 'value' => 'joe 12charsecret' } }, + 'static' => 0 })); + ok($SCST->removeDriverDynamicAttribute(), $SCST->SCST_C_DRV_REMATTR_FAIL); + ok($SCST->removeDriverDynamicAttribute('no-such-driver', '', ''), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->removeDriverDynamicAttribute('iscsi', 'no-such-attribute', ''), + $SCST->SCST_C_DRV_BAD_ATTRIBUTES); + ok($SCST->removeDriverDynamicAttribute('iscsi', 'IncomingUser', + 'joe 12charsecret'), 0); + ok($SCST->removeDriverDynamicAttribute('iscsi', 'IncomingUser', + 'bar 12CharSecret'), 0); + ok(!exists($SCST->driverAttributes('iscsi')->{'IncomingUser'})); +} + +sub testTargetDynAttr { + my $SCST = shift; + + ok($SCST->targetDynamicAttributes(), undef); + ok($SCST->targetDynamicAttributes('no-such-driver'), undef); + ok($SCST->{'err_string'}, + "targetDynamicAttributes(): Driver 'no-such-driver' is not available"); + ok(Dumper($SCST->targetDynamicAttributes('scst_local')), Dumper({})); + ok(Dumper($SCST->targetDynamicAttributes('iscsi')), + Dumper({ 'IncomingUser' => '', + 'OutgoingUser' => '', + 'allowed_portal' => '' })); + ok($SCST->checkTargetDynamicAttributes('no-such-driver'), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->checkTargetDynamicAttributes('no-such-driver', { }), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->checkTargetDynamicAttributes('scst_local', { }), 0); + ok($SCST->checkTargetDynamicAttributes('iscsi', { }), 0); + ok($SCST->checkTargetDynamicAttributes('iscsi', + { 'IncomingUser' => ''}), 0); + ok($SCST->checkTargetDynamicAttributes('iscsi', + { 'IncomingUser' => '', + 'OutgoingUser' => '' }), 0); + ok($SCST->checkTargetDynamicAttributes('iscsi', + { 'IncomingUser' => '', + 'OutgoingUser' => '', + 'NoSuchAttribute' => '' }), 1); + + ok($SCST->addTargetDynamicAttribute(), $SCST->SCST_C_TGT_ADDATTR_FAIL); + ok($SCST->addTargetDynamicAttribute('no-such-driver', '', '', ''), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->addTargetDynamicAttribute('iscsi', 'no-such-target', '', ''), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->addTargetDynamicAttribute('iscsi', 'tgt1', 'no-such-attribute', + '', ''), + $SCST->SCST_C_TGT_BAD_ATTRIBUTES); + ok($SCST->addTargetDynamicAttribute('iscsi', 'tgt1', 'IncomingUser', + 'bar 12CharSecret'), 0); + ok($SCST->addTargetDynamicAttribute('iscsi', 'tgt1', 'IncomingUser', + 'joe 12charsecret'), 0); + ok(Dumper($SCST->targetAttributes('iscsi', 'tgt1')->{'IncomingUser'}), + Dumper({ 'keys' => { '0' => { 'value' => 'bar 12CharSecret' }, + '1' => { 'value' => 'joe 12charsecret' } }, + 'static' => 0 })); + ok($SCST->removeTargetDynamicAttribute(), $SCST->SCST_C_TGT_REMATTR_FAIL); + ok($SCST->removeTargetDynamicAttribute('no-such-driver', '', '', ''), + $SCST->SCST_C_DRV_NO_DRIVER); + ok($SCST->removeTargetDynamicAttribute('iscsi', 'no-such-target', '', ''), + $SCST->SCST_C_TGT_NO_TARGET); + ok($SCST->removeTargetDynamicAttribute('iscsi', 'tgt1', 'no-such-attribute', + ''), + $SCST->SCST_C_TGT_BAD_ATTRIBUTES); + ok($SCST->removeTargetDynamicAttribute('iscsi', 'tgt1', 'IncomingUser', + 'joe 12charsecret'), 0); + ok($SCST->removeTargetDynamicAttribute('iscsi', 'tgt1', 'IncomingUser', + 'bar 12CharSecret'), 0); + ok(!exists($SCST->targetAttributes('iscsi', 'tgt1')->{'IncomingUser'})); +} + +sub teardown { + my $SCST = shift; + + ok($SCST->removeVirtualTarget('iscsi', 'tgt1'), 0); + ok($SCST->closeDevice("vdisk_fileio", "disk01"), 0); +} + +my $_DEBUG_ = 0; + +my $SCST = eval { new SCST::SCST($_DEBUG_) }; +die("Creation of SCST object failed") if (!defined($SCST)); + +setup($SCST); +testDriverDynAttr($SCST); +testTargetDynAttr($SCST); +teardown($SCST); diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/99-stop-scst.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/99-stop-scst.t new file mode 100644 index 000000000..b7a762fbd --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/99-stop-scst.t @@ -0,0 +1,15 @@ +#!perl + +use strict; +use Test; + +BEGIN { + plan tests => 1; +} + +if ($> == 0) { + system("/etc/init.d/scst stop"); + ok(!(-d "/sys/module/scst")); +} else { + ok(1); +}