[7908f1]: lib / WineTestBot / Tasks.pm Maximize Restore History

Download this file

Tasks.pm    152 lines (125 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Individual task of a job collection and items
#
# Copyright 2009 Ge van Geldorp
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
use strict;
=head1 NAME
WineTestBot::Tasks - Job task collection
=cut
package WineTestBot::Task;
use ObjectModel::BackEnd;
use WineTestBot::Config;
use WineTestBot::Jobs;
use WineTestBot::Steps;
use WineTestBot::WineTestBotObjects;
use vars qw(@ISA @EXPORT);
require Exporter;
@ISA = qw(WineTestBot::WineTestBotItem Exporter);
sub InitializeNew
{
my $self = shift;
my ($Collection) = @_;
$self->Status("queued");
my $Keys = $Collection->GetKeys();
$self->No(scalar @$Keys + 1);
$self->SUPER::InitializeNew(@_);
}
sub Run
{
my $self = shift;
my ($JobId, $StepNo) = @_;
$self->Status("running");
$self->Save();
$self->GetBackEnd()->PrepareForFork();
my $Pid = fork;
if (defined($Pid) && ! $Pid)
{
my $Jobs = WineTestBot::Jobs::CreateJobs();
my $Job = $Jobs->GetItem($JobId);
my $Step = $Job->Steps->GetItem($StepNo);
my $RunScript;
if ($Step->Type eq "build")
{
$RunScript = "$BinDir/${ProjectName}RunBuild.pl";
}
elsif ($Step->Type eq "reconfig")
{
$RunScript = "$BinDir/${ProjectName}RunReconfig.pl";
}
else
{
$RunScript = "$BinDir/${ProjectName}RunTask.pl";
}
$Step = undef;
$Job = undef;
$Jobs = undef;
$ENV{PATH} = "/usr/bin:/bin";
delete $ENV{ENV};
exec($RunScript, $JobId, $StepNo, $self->No);
exit;
}
if (! defined($Pid))
{
return "Unable to start child process: $!";
}
$self->ChildPid($Pid);
$self->Started(time);
my ($ErrProperty, $ErrMessage) = $self->Save();
return $ErrMessage;
}
package WineTestBot::Tasks;
use ObjectModel::BasicPropertyDescriptor;
use ObjectModel::ItemrefPropertyDescriptor;
use ObjectModel::PropertyDescriptor;
use WineTestBot::VMs;
use WineTestBot::WineTestBotObjects;
use vars qw(@ISA @EXPORT @PropertyDescriptors);
require Exporter;
@ISA = qw(WineTestBot::WineTestBotCollection Exporter);
@EXPORT = qw(&CreateTasks);
BEGIN
{
$PropertyDescriptors[0] =
CreateBasicPropertyDescriptor("No", "Task no", 1, 1, "N", 2);
$PropertyDescriptors[1] =
CreateBasicPropertyDescriptor("Status", "Status", !1, 1, "A", 9);
$PropertyDescriptors[2] =
CreateItemrefPropertyDescriptor("VM", "VM", !1, 1, \&CreateVMs, ["VMName"]);
$PropertyDescriptors[3] =
CreateBasicPropertyDescriptor("Timeout", "Timeout", !1, 1, "N", 4);
$PropertyDescriptors[4] =
CreateBasicPropertyDescriptor("CmdLineArg", "Command line args", !1, !1, "A", 256);
$PropertyDescriptors[5] =
CreateBasicPropertyDescriptor("ChildPid", "Process id of child process", !1, !1, "N", 5);
$PropertyDescriptors[6] =
CreateBasicPropertyDescriptor("Started", "Execution started", !1, !1, "DT", 19);
$PropertyDescriptors[7] =
CreateBasicPropertyDescriptor("Ended", "Execution ended", !1, !1, "DT", 19);
$PropertyDescriptors[8] =
CreateBasicPropertyDescriptor("TestFailures", "Number of test failures", !1, !1, "N", 5);
}
sub CreateItem
{
my $self = shift;
return WineTestBot::Task->new($self);
}
sub CreateTasks
{
my $Step = shift;
return WineTestBot::Tasks->new("Tasks", "Tasks", "Task",
\@PropertyDescriptors, $Step);
}
1;