]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/TestSet.pm
Initial revision
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / TestSet.pm
1 #!perl -w
2 #
3 # Test -- test routines, mostly printing hw inventory.
4 #   Copyright (C) 2005  Erik van Konijnenburg
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 #
20 #
21 #
22 use strict;
23 use warnings;
24 use Base;
25 use FsTab;
26 use ActiveBlockDevTab;
27 use BlockSpecialFileTab;
28 use LabeledPartitionTab;
29 use LvmTab;
30 use Hardware;
31 use ModDepTab;
32 use RaidTab;
33 use InputTab;
34 use Image;
35 use Plan;
36 use KConfig;
37
38 package TestSet;
39
40
41 sub testGetFsTab () {
42         print "Entries in fstab:\n";
43         for my $entry (@{FsTab->all}) {
44                 my $str = $entry->string;
45                 my $cmd = $entry->opts->cmdLineVersion;
46                 print "\t$str\n";
47                 print "\t\t$cmd\n";
48         }
49 }
50
51
52 sub testActiveBlockDevs () {
53         print "Block devices in /sys:\n";
54         for my $abd (@{ActiveBlockDevTab::all()}) {
55                 my $str = $abd->string;
56                 print "\t$str\n";
57         }
58 }
59
60 sub testActiveBlockDevPartitions () {
61         print "Partitions for block devices in /sys:\n";
62         for my $abd (@{ActiveBlockDevTab::all()}) {
63                 my $str = $abd->string;
64                 my $hp = $abd->hasPartitions() ? "yes" : "no";
65                 my $partitions = $abd->partitions();
66                 my $partList = '['
67                         . join (',', (map {$_->name} @{$partitions})) . ']';
68                 print "\t$str\n";
69                 print "\t\tpartitioned:\t$hp\n";
70                 print "\t\tpartitions:\t$partList\n";
71         }
72 }
73
74
75 sub testBlockSpecialFiles () {
76         print "Block special files /dev:\n";
77         for my $bsf (@{BlockSpecialFileTab::all()}) {
78                 my $str = $bsf->string;
79                 print "\t$str\n";
80         }
81 }
82
83
84 sub testLabeledPartitions () {
85         print "Labeled partitions detected:\n";
86         for my $lp (@{LabeledPartitionTab::all()}) {
87                 my $str = $lp->string;
88                 print "\t$str\n";
89         }
90 }
91
92
93 sub testLvm () {
94         print "LVM Logical Volumes:\n";
95         for my $lv (@{LvmTab::allLogicalVolumes()}) {
96                 my $str = $lv->string;
97                 print "\t$str\n";
98         }
99
100         print "LVM Volume Groups:\n";
101         for my $vg (@{LvmTab::allVolumeGroups()}) {
102                 my $str = $vg->string;
103                 print "\t$str\n";
104         }
105
106         print "LVM Physical Volumes:\n";
107         for my $pv (@{LvmTab::allPhysicalVolumes()}) {
108                 my $str = $pv->string;
109                 print "\t$str\n";
110         }
111 }
112
113
114 sub testHardware () {
115         print "Hardware modules needed for devices in /sys:\n";
116         for my $abd (@{ActiveBlockDevTab::all()}) {
117                 my $str = $abd->string;
118                 my $hw = $abd->hw;
119                 next unless defined ($hw);
120                 print "\t$str\n";
121                 my $moduleList = Hardware::moduleList ($hw);
122                 print "\t\t[" . join(',', @{$moduleList}) . "]\n";
123         }
124 }
125
126 sub testModDep () {
127         print "Module dependencies:\n";
128         for my $modDep (@{ModDepTab::all()}) {
129                 my $str = ModDepTab::findByModnam($modDep)->string;
130                 print "\t$str\n";
131         }
132 }
133
134 sub testModResolve () {
135         print "Hardware modules with resolved dependencies:\n";
136         for my $abd (@{ActiveBlockDevTab::all()}) {
137                 my $str = $abd->string;
138                 my $hw = $abd->hw;
139                 next unless defined ($hw);
140                 print "\t$str\n";
141                 my $moduleList = Hardware::moduleList ($hw);
142                 print "\t\t[" . join(',', @{$moduleList}) . "]\n";
143                 my $resolveList = ModDepTab::resolve ($moduleList);
144                 print "\t\t[" . join(',', @{$resolveList}) . "]\n";
145         }
146 }
147
148 sub testRaidDevices () {
149         print "Raid devices:\n";
150         for my $rd (@{RaidTab::all()}) {
151                 my $str = $rd->string;
152                 print "\t$str\n";
153         }
154 }
155
156 sub testInput () {
157         print "Input devices:\n";
158         for my $inp (@{InputTab::all()}) {
159                 my $str = $inp->string;
160                 print "\t$str\n";
161         }
162 }
163
164 sub testInterpretation () {
165         print "Interpreted Fstab Entries:\n";
166         for my $fse (@{FsTab->all}) {
167                 my $fseStr = $fse->string;
168                 my $active = $fse->isRequiredAtBoot ? "yes": "no";
169                 my $path = $fse->blockDevPath();
170                 my $lvmStr = "--";
171                 my $devno = "--";
172                 my $hardware;
173                 my $name = "--";
174                 my $modules;
175                 my $resolved;
176                 if (defined ($path) && -b $path) {
177                         $devno = Base::devno ($path);
178                         my $lvmFiles = LvmTab::findPVPathsByLVDevno ($devno);
179                         if (defined ($lvmFiles)) {
180                                 $lvmStr = '[' . join (',', @{$lvmFiles}) . ']';
181                         }
182
183                         my $abd = ActiveBlockDevTab::findByDevno($devno);
184                         if (defined ($abd)) {
185                                 $name = $abd->name();
186                                 my $parent = $abd->parent();
187                                 if (defined ($parent)) {
188                                         $hardware = $parent->hw();
189                                 }
190                                 else {
191                                         $hardware = $abd->hw();
192                                 }
193                         }
194                 }
195                 if (defined ($hardware)) {
196                         my $moduleList = Hardware::moduleList ($hardware);
197                         $modules = "[" . join(',', @{$moduleList}) . "]";
198                         my $resolveList = ModDepTab::resolve ($moduleList);
199                         $resolved = "[" . join(',', @{$resolveList}) . "]";
200                 }
201
202                 $hardware = "--" unless defined ($hardware);
203                 $modules = "--" unless defined ($modules);
204                 $resolved = "--" unless defined ($resolved);
205                 $path = "--" unless defined ($path);
206                 print "\t$fseStr\n";
207                 print "\t\tactive:\t$active\n";
208                 print "\t\tdevno:\t$devno\n";
209                 print "\t\tpath:\t$path\n";
210                 print "\t\tname:\t$name\n";
211                 print "\t\thw:\t$hardware\n";
212                 print "\t\tmods:\t$modules\n";
213                 print "\t\tresolv:\t$resolved\n";
214                 print "\t\tlvm:\t$lvmStr\n";
215
216                 if (defined ($path)) {
217                         my $abd = ActiveBlockDevTab::findByPath($path);
218                         if (defined ($abd)) {
219                                 my $list = ActionList->new();
220                                 Plan::addDevicePlan ($list, $abd, [], []);
221                                 # the output provided by addDevicePlan
222                                 # is enough.
223                                 # print $list->string();
224                         }
225                 }
226         }
227 }
228
229 sub testKconfig () {
230         print "Kernel Builtin Modules:\n";
231         for my $module (@{KConfig::allKnownModules()}) {
232                 my $builtIn = KConfig::isBuiltIn($module) ? "BUILTIN" : "--";
233                 print "\t$module:\t$builtIn\n";
234         }
235 }
236
237 #
238 # testAll -- run various interesting subroutines
239 # that may trigger errors.
240 #
241 sub testAll ()
242 {
243         testGetFsTab ();
244         testBlockSpecialFiles ();
245         testLabeledPartitions ();
246         testActiveBlockDevs ();
247         testActiveBlockDevPartitions ();
248         testLvm ();
249         testHardware ();
250         testModDep ();
251         testModResolve ();
252         testRaidDevices();
253         testInterpretation ();
254         testInput ();
255         testKconfig ();
256         Base::bye ();
257 }
258
259
260 1;