fix testresults dir bug
[os-autoinst:os-autoinst.git] / autotest.pm
1 package autotest;
2 use bmwqemu;
3
4 sub runtest
5 {
6         my($script,$testfunc)=@_;
7         my $name=$script;
8         $name=~s{.*/}{}; $name=~s{^\d+_}{}; $name=~s/\.pm$//;
9         {
10                 eval "package $name;
11                 require \$script;" or (diag("error on $script: $@") and return);
12         }
13         my $test=$name->new();
14         return unless $test->is_applicable;
15         if (defined $testfunc) {
16                 my $ret;
17                 unless(defined $ENV{'checklog_working'} && $ENV{'checklog_working'}) {
18                         if(open(my $fd, ">currentstep")) { # to track progress
19                                 print $fd "$script\n$name\n";
20                                 close $fd;
21                         }
22                         modstart "starting $name $script";
23                         $ret=&$testfunc($test);
24                         sleep 1;
25                         diag "||| finished $name";
26                 }
27                 else {
28                         modstart "checking $name $script";
29                         $ret=&$testfunc($test);
30                         diag "";
31                 }
32
33                 return $ret;
34         }
35         else {
36                 diag "scheduling $name $script";
37         }
38 }
39
40 sub runtestlist($&)
41 {
42         my($tests,$testfunc)=@_;
43         foreach my $script (@$tests) {
44                 runtest($script,$testfunc);
45         }
46 }
47
48 sub runtestdir($&)
49 { my($dir,$testfunc)=@_;
50         foreach my $script (<$dir/*.pm>) {
51                 runtest($script,$testfunc);
52         }
53 }
54
55 1;