9 local $SIG{__WARN__
} = \
&Carp
::cluck
;
12 use List
::MoreUtils qw
/any uniq/;
14 my $runtest_dir="/usr/lib/ltp/runtest";
15 #my $runtest_dir="runtest";
17 LTPRESULTS
=> "/var/cache/ltp/results",
18 LTPROOT
=> "/usr/lib/ltp",
19 TOOLSDIR
=> "/usr/lib/ltp/tools",
20 LTPTOOLS
=> "/usr/lib/ltp/tools",
21 PATH
=> "$ENV{PATH}:/usr/lib/ltp/testcases/bin",
22 TMP
=> $ENV{TMP
} // $ENV{TMPDIR
} // "/tmp",
37 return $arg if $arg =~ /^\d+$/;
43 my ($used_tests, $environment, $setup, $teardown) = @_;
46 for(keys %$environment) {
48 my $value=$environment->{$_};
53 for(keys %static_env) {
54 my $value=$static_env{$_};
57 if(($environment->{output
} // "") ne "") {
58 $tdir=File
::Temp
::tempdir
(CLEANUP
=> 1);
59 $panopts.=" -o ".shell_quote
($environment->{output
})." -O ".shell_quote
($tdir);
62 if(!$environment->{fulloutput
}) {
66 if(($environment->{failfile
} // "") ne "") {
67 my $ff=$environment->{failfile
};
68 my $out=$environment->{output
}//"";
73 $panopts.=" -C ".shell_quote
($ff);
76 if(($environment->{logfile
} // "") ne "") {
77 my $ff=$environment->{logfile
};
78 my $out=$environment->{output
}//"";
83 $panopts.=" -l ".shell_quote
($ff);
87 if(($environment->{count
} // "") ne "") {
88 $count=$environment->{count
};
89 if($count =~ /^(\d)l$/) {
90 $count=$1*@
$used_tests;
92 $count=to_number
($count);
94 if($environment->{random
}) {
95 $count = $count // scalar @
$used_tests;
98 if(!($environment->{random
})) {
102 if(defined($count)) {
103 $panopts.=" -s ".$count;
106 if(($environment->{time} // "") ne "") {
107 return if !$environment->{time} =~ /[0-9]+[hmsd]?/;
108 $panopts.=" -t ".$environment->{time};
111 if(($environment->{parallel
} // "") ne "") {
112 $panopts.=" -x ".to_number
($environment->{parallel
} // 0);
115 my $ft=new File
::Temp
(TEMPLATE
=> "/tmp/runtestXXXXXXXXX");
116 my $zoo=new File
::Temp
(TEMPLATE
=> "/tmp/zoo$$.XXXXXXXXX");
118 print $ft map { "$_->{id} $_->{command}" } @
$used_tests;
121 system '${LTPTOOLS}/ltp-pan -p -n $$ -a '.$zoo->filename.' -f '.$ft->filename.$panopts;
123 File
::Path
::rmtree
$tdir if defined($tdir);
132 open(FILE
, "<$file");
134 my $ts_desc={ selected
=> 0, tests
=> [] };
140 if($1 =~ /DESCRIPTION:(.*)/) {
141 $ts_desc->{description
}=$1;
142 $last=\
$ts_desc->{description
};
143 } elsif ($1 =~ /ALL:(.*)/) {
144 push @
$allvars, grep m/./, (split qr/ +/, $1);
145 } elsif ($1 =~ /SETUP:(.*)/) {
146 push @
$allsetup, grep m/./, (split qr/ +/, $1);
149 } elsif(defined $last) {
159 next unless /^([^[:space:]]+)[[:space:]]+(.*)/;
161 if(exists($test_hash{"$1 $2"})) {
162 next if exists $test_hash{"$1 $2"}->{files
}->{$name};
163 push @
{$ts_desc->{tests
}}, $test_hash{"$1 $2"};
164 $test_hash{"$1 $2"}->{files
}->{$name}=undef;
165 $ts_desc->{selected
}++ if($test_hash{"$1 $2"}->{selected
});
167 push(@test_data, { id
=> $1, command
=> $2,
168 files
=> {$name => undef}});
170 $test_data[$#test_data]->{vars
}=[(grep { /^\$(.*)/; !exists($static_env{$1}) } ( @
$allvars, $2 =~ /\$[[:alpha:]][[:alnum:]_]*/g ))];
171 $test_data[$#test_data]->{setup
}=$allsetup;
172 push @
{$ts_desc->{tests
}}, \
%{$test_data[$#test_data]};
173 $test_hash{$id}=\
%{$test_data[$#test_data]};
174 $testsuites{"<ALL>"}->{count
}++;
179 $ts_desc->{count
}=$num;
180 $testsuites{$name}=$ts_desc;
185 $testsuites{"<ALL>"}={selected
=> 0, count
=> 0, tests
=> \
@test_data};
188 opendir(DIR
, $runtest_dir) || die("Couldn't open directory $runtest_dir");
194 load_file
("$runtest_dir/$_");
201 return map { (ref($_) eq "ARRAY") ? flatten
(@
$_) : $_ } @_;
207 return uniq
(flatten
(map $_->{vars
}, @
$ts_list));
213 return uniq
(flatten
(map $_->{setup
}, @
$ts_list));
216 sub tests_needing_vars
218 my ($tests, @vars)=@_;
219 my %vars_hash=(map { ($_ => undef) } @vars);
220 return grep { any
{ exists($vars_hash{$_}) } @
{$_->{vars
}} } @
$tests;
225 package Layout
::Proportional
;
227 use Curses
::UI
::Container
;
229 our @ISA=qw
/Curses::UI::Container/;
233 my $self = $class->SUPER::new
( @_, -layoutorder
=> [] );
239 my $ret=$self->SUPER::add
(@_);
240 push @
{$self->{-layoutorder
}}, $self->{-object2id
}->{$ret};
246 $self->Curses::UI
::Widget
::layout
();
248 my $size=($self->{-vertical
} ?
"height" : "width");
249 my $coord=($self->{-vertical
} ?
"y" : "x");
250 my $ot_size=($self->{-vertical
} ?
"width" : "height");
251 my $ot_coord=($self->{-vertical
} ?
"x" : "y");
252 my $padding=($self->{-vertical
} ?
253 sub { my $obj=shift; return ($obj->{-padtop
}//0)+($obj->{-padbottom
}//0); } :
254 sub { my $obj=shift; return ($obj->{-padleft
}//0)+($obj->{-padright
}//0); });
257 my %sizes= ( height
=> $self->canvasheight(), width
=> $self->canvaswidth() );
258 foreach(@
{$self->{-layoutorder
}}) {
259 my $obj=$self->{-id2object
}->{$_};
260 $total_min += $obj->{"-min-$size"} if $obj->{"-min-$size"};
261 $total_mult += $obj->{"-mult-$size"} if $obj->{"-mult-$size"};
263 my $excess = $sizes{$size}-$total_min;
264 my $ratio=($total_mult==0 ?
0 : $excess/$total_mult);
267 foreach(@
{$self->{-layoutorder
}}) {
268 my $obj=$self->{-id2object
}->{$_};
269 $obj->{-$coord}=$cur;
270 $obj->{-$ot_coord}=0;
271 $obj->{-$size}=int (($obj->{"-min-$size"} // 0) + ($obj->{"-mult-$size"} // 0)*$ratio);
272 $cur += $obj->{-$size};
273 $obj->{-$size} = 0 if $obj->{-$size} < 0;
274 delete $obj->{-$ot_size};
275 $obj->{-parent
}=$self;
282 $INC{"Layout/Proportional.pm"}="";
284 package ListBox
::MultiColumn
;
286 use Curses
::UI
::Listbox
;
288 our @ISA=qw
/Curses::UI::Listbox/;
292 my $self = $class->SUPER::new
(
294 "-col-designator" => [],
302 my ($self, $col) = @_;
303 return $self->{-colwidth
}->[$col] if $self->{-colwidth
}->[$col];
309 my $val = $self->values()->[$i];
311 if(ref($val) eq "ARRAY") {
312 for my $idx (0..$#$val-1) {
313 my $len=$self->getcolwidth($idx);
314 push (@disp, $$val[$idx]);
316 push (@disp, $$val[$#$val]);
317 } elsif(ref($val) eq "HASH") {
318 my $cd=$self->{"-col-designator"};
319 return "" unless $cd;
320 for my $idx (0..$#$cd-1) {
321 my $len=$self->getcolwidth($idx);
322 push (@disp, $val->{$cd->[$idx]});
324 push (@disp, $val->{$cd->[$#$cd]});
326 @disp=($self->SUPER::getlabel
($i));
328 @disp=($self->{"-col-formatter"} ?
329 $self->{"-col-formatter"}->(@disp) :
332 my $len=$self->getcolwidth($_);
333 $disp[$_] = sprintf("%-${len}.${len}s", $disp[$_]);
335 return join("|", @disp);
339 use List
::MoreUtils qw
/any/;
345 $INC{"ListBox/MultiColumn.pm"}="";
347 my $cui = new Curses
::UI
(
355 simple_text
(label
=> "Output file", name
=> "output"),
356 simple_text
(label
=> "Log file", name
=> "logfile"),
357 simple_text
(label
=> "Failed command file", name
=> "failfile"),
358 simple_text
(label
=> "Running time", name
=> "time", validator
=> '/^\d*[hdms]?$/'),
359 simple_text
(label
=> "Parallel tests", name
=> "parallel", validator
=> '/^\d*$/'),
360 simple_check
(label
=> "Random tests", name
=> "random"),
361 simple_check
(label
=> "Full Output", name
=> "fulloutput"),
362 simple_text
(label
=> "Test count", name
=> "count", validator
=> '/^\d*l?$/'),
365 my %options =( failfile
=> "/var/tmp/LTP_RUN_ON_%d.failed",
366 logfile
=> "/var/tmp/LTP_RUN_ON_%d.log" );
370 return { label
=> $params{label
}, name
=> $params{name
},
372 my ($parent, $data, @params) = @_;
373 @params=(@params, -regexp
=> $params{validator
}) if exists $params{validator
};
374 my $lab=$parent->add(undef, "TextEntry", @params);
375 $lab->text($data) if defined $data;
378 get
=> sub { return shift()->get(); }
385 return { label
=> $params{label
}, name
=> $params{name
},
387 my ($parent, $data, @params) = @_;
388 my $lab=$parent->add(undef, "Checkbox", @params);
389 $lab->check() if $data;
392 get
=> sub { return shift()->get(); }
399 options_dialog
([@opt_template, map {
401 label
=> $_, name
=> $_,
403 my ($parent, $data, @params) = @_;
404 my $lab=$parent->add(undef, "TextEntry", @params);
405 $lab->text($data) if defined $data;
408 get
=> sub { return shift()->get(); }
410 } LTPTests
::needed_vars
[grep { $_->{selected
} } @test_data]], \
%options);
415 my $selected_tests=[grep { $_->{selected
} } @test_data];
416 my @needed_vars=LTPTests
::needed_vars
$selected_tests;
417 my @unsatisfied_tests=LTPTests
::tests_needing_vars
$selected_tests, (grep !$options{$_}, @needed_vars);
418 if(@unsatisfied_tests) {
419 my $response=$cui->dialog(
420 -message
=> "You have sellected tests that need setting some variables. Would you like to set them now?",
422 {-label
=> "Show the options dialog", -value
=> 0},
423 {-label
=> "Don't run those tests", -value
=> 1},
424 {-label
=> "Cancel", -value
=> 2}
426 -title
=> "Unset variables"
428 return if($response == 2);
431 } else { # filter tests
432 $selected_tests=[grep { !any
{ !$options{$_} } LTPTests
::needed_vars
[$_] } @
$selected_tests ];
435 my @setups = LTPTests
::setup_scripts
$selected_tests;
436 $cui->leave_curses();
437 LTPTests
::execute_tests
($selected_tests, \
%options, ["clear; echo Running LTP Tests; ", map { "$_ setup;" } @setups], [map { "$_ teardown;" } @setups]);
438 $cui->reset_curses();
442 { -label
=> "Load", -value
=> sub {
443 my $file=$cui->loadfilebrowser();
444 LTPTests
::load_file
$file if defined $file;
445 $ts_list->values([sort keys (%testsuites)]);
447 { -label
=> "Execute", -value
=> \
&execute_tests
},
448 { -label
=> "Options", -value
=> \
&show_opt_dialog
},
449 { -label
=> "Exit", -value
=> sub { exit(0) } }
454 my $v=$ts_list->get_active_value();
455 $tc_list->values($testsuites{$v}->{tests
} );
456 my $seh=$tc_list->{-onchange
};
457 $tc_list->onChange(undef);
458 $tc_list->set_selection(grep { $tc_list->{-values}->[$_]->{selected
} } (0..$#{$tc_list->{-values}}));
459 $tc_list->onChange($seh);
460 $tc_list->intellidraw();
463 sub update_tc_selection
465 my @sel=$tc_list->get();
466 for(@
{$tc_list->{-values}}){
469 for(keys %{$_->{files
}}) {
470 $testsuites{$_}->{selected
}--;
472 $testsuites{"<ALL>"}->{selected
}--;
476 if(!$_->{selected
}) {
478 for(keys %{$_->{files
}}) {
479 $testsuites{$_}->{selected
}++;
481 $testsuites{"<ALL>"}->{selected
}++;
484 $ts_list->intellidraw();
490 my $seh=$tc_list->{-onchange
};
491 $tc_list->onChange(undef);
492 $tc_list->set_selection((0..$#{$tc_list->{-values}}));
493 $tc_list->onChange($seh);
495 $tc_list->intellidraw();
501 $tc_list->clear_selection();
502 update_tc_selection
(); # clear_selection doesn't call -onchange callback
503 $tc_list->intellidraw();
508 my $ts=$testsuites{$ts_list->get_active_value()};
509 if($ts->{count
}>$ts->{selected
}) {
527 my ($template, $options)=@_;
529 my $dialog=$cui->add(undef, "Window");
530 my $dialogid=$cui->{-object2id
}->{$dialog};
537 my $label=$dialog->add(undef, "Label", -text
=> $_->{label
},
538 -x
=> 0, -width
=> $labelwidth, -y
=> $line);
539 push @widgets, $_->{create
}->($dialog, $options->{$_->{name
}}, -x
=> $labelwidth+2, -y
=> $line);
542 $line+=max
($label->{-h
}, $widgets[$#widgets]->{-h
});
545 $dialog->add(undef, "Buttonbox", -y
=> $line+1, -buttons
=>[
546 { -label
=> "Ok", -onpress
=> sub { $dialog->loose_focus; } }
552 $options->{$_->{name
}}=$_->{get
}->(shift(@widgets));
555 $cui->delete($dialogid);
556 $cui->root->focus(undef, 1);
559 $win = $cui->add("win", "Window", -padtop
=> 1);
563 -menu
=> [ { -label
=> "File", -submenu
=>$main_menu } ]
567 "layout", "Layout::Proportional", -vertical
=> 0, -border
=> 1
570 $ts_list=$cont->add (
571 "lb", "ListBox::MultiColumn",
572 -values => [sort keys (%testsuites)],
573 -vscrollbar
=> "right",
574 # -padtop => 2, -padleft => 2,
575 # -padright => 2, -padbottom => 2,
576 "-mult-width" => 1, -border
=> 1,
577 -onselchange
=> \
&update_tc_list
,
578 "-col-formatter" => sub {
579 my $tmp=$testsuites{$_[0]} // { selected
=> 0, count
=> 1 };
581 if($tmp->{selected
}==0) {
583 } elsif($tmp->{selected
}<$tmp->{count
}) {
593 $tc_list=$cont->add (
594 "lb2", "ListBox::MultiColumn",
595 -values => \
@test_data,
596 "-col-designator" => ["id", "command"],
597 -vscrollbar
=> "right",
598 # -padtop => 2, -padleft => 2,
599 # -padright => 2, -padbottom => 2,
600 "-mult-width" => 2, -border
=> 1,
602 -onchange
=> \
&update_tc_selection
605 $ts_list->set_routine('option-check', \
&check_ts
);
606 $ts_list->set_routine('option-uncheck', \
&uncheck_ts
);
607 $ts_list->set_routine('option-select', \
&toggle_ts
);
609 $cui->set_binding( sub{ $cui->focus('menu') }, Curses
::KEY_F
(10) );