Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[2ef78a]: web / Submit.pl Maximize Restore History

Download this file

Submit.pl    972 lines (869 with data), 24.6 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# WineTestBot job submit page
#
# 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;
package SubmitPage;
use CGI qw(:standard);
use Fcntl;
use IO::Handle;
use POSIX qw(:fcntl_h);
use ObjectModel::BasicPropertyDescriptor;
use ObjectModel::CGI::FreeFormPage;
use WineTestBot::Branches;
use WineTestBot::Config;
use WineTestBot::Jobs;
use WineTestBot::Engine::Notify;
use WineTestBot::Utils;
use WineTestBot::VMs;
@SubmitPage::ISA = qw(ObjectModel::CGI::FreeFormPage);
sub _initialize
{
my $self = shift;
$self->{Page} = $self->GetParam("Page") || 1;
my @PropertyDescriptors1;
$PropertyDescriptors1[0] = CreateBasicPropertyDescriptor("Remarks", "Remarks", !1, !1, "A", 50);
$self->{PropertyDescriptors1} = \@PropertyDescriptors1;
my @PropertyDescriptors3;
$PropertyDescriptors3[0] = CreateBasicPropertyDescriptor("TestExecutable", "Test executable", !1, 1, "A", 50);
$PropertyDescriptors3[1] = CreateBasicPropertyDescriptor("CmdLineArg", "Command line arguments", !1, !1, "A", 50);
$PropertyDescriptors3[2] = CreateBasicPropertyDescriptor("Run64", "Run 64-bit tests in addition to 32-bit tests", !1, 1, "B", 1);
$PropertyDescriptors3[3] = CreateBasicPropertyDescriptor("DebugLevel", "Debug level (WINETEST_DEBUG)", !1, 1, "N", 2);
$PropertyDescriptors3[4] = CreateBasicPropertyDescriptor("ReportSuccessfulTests", "Report successful tests (WINETEST_REPORT_SUCCESS)", !1, 1, "B", 1);
$self->{PropertyDescriptors3} = \@PropertyDescriptors3;
if ($self->{Page} == 2)
{
$self->{ShowAll} = defined($self->GetParam("ShowAll"));
}
$self->SUPER::_initialize(undef);
}
sub GetTitle
{
return "Submit a job";
}
sub GetHeaderText
{
my $self = shift;
if ($self->{Page} == 1)
{
return "Specify the patch file that you want to upload and submit " .
"for testing.<br>\n" .
"You can also specify a Windows .exe file, this would normally be " .
"a Wine test executable that you cross-compiled."
}
elsif ($self->{Page} == 2)
{
my $HeaderText = "Select the VMs on which you want to run your test.";
my $VMs = CreateVMs();
$VMs->AddFilter("Status", ["offline"]);
if (! $VMs->IsEmpty())
{
$HeaderText .= "<br>NOTE: Some VMs are currently offline and are not " .
"shown here.";
}
return $HeaderText;
}
elsif ($self->{Page} == 4)
{
return "Your job was successfully queued, but the job engine that takes " .
"care of actually running it seems to be unavailable (perhaps it " .
"crashed). Your job will remain queued until the engine is " .
"restarted.";
}
return "";
}
sub GetPropertyDescriptors
{
my $self = shift;
if ($self->{Page} == 1)
{
return $self->{PropertyDescriptors1};
}
elsif ($self->{Page} == 3)
{
my $IsPatch = ($self->GetParam("FileType") eq "patchdlls" ||
$self->GetParam("FileType") eq "patchprograms");
$self->{PropertyDescriptors3}[0]->{IsRequired} = $IsPatch;
return $self->{PropertyDescriptors3};
}
return $self->SUPER::GetPropertyDescriptors(@_);
}
sub GenerateFields
{
my $self = shift;
print "<div><input type='hidden' name='Page' value='", $self->{Page},
"'></div>\n";
if ($self->{Page} == 1)
{
print "<div class='ItemProperty'><label>File</label>",
"<div class='ItemValue'>",
"<input type='file' name='File' size='64' maxlength='64' />",
"&nbsp;<span class='Required'>*</span></div></div>\n";
my $Branches = CreateBranches();
my $SelectedBranchKey = $self->GetParam("Branch");
if (! defined($SelectedBranchKey))
{
$SelectedBranchKey = $Branches->GetDefaultBranch()->GetKey();
}
if (! $Branches->MultipleBranchesPresent())
{
print "<div><input type='hidden' name='Branch' value='",
$self->CGI->escapeHTML($SelectedBranchKey),
"'></div>\n";
}
else
{
print "<div class='ItemProperty'><label>Branch</label>",
"<div class='ItemValue'>",
"<select name='Branch' size='1'>";
my @SortedKeys = sort { $a cmp $b } @{$Branches->GetKeys()};
foreach my $Key (@SortedKeys)
{
my $Branch = $Branches->GetItem($Key);
print "<option value='", $self->CGI->escapeHTML($Key), "'";
if ($Branch->GetKey() eq $SelectedBranchKey)
{
print " selected";
}
print ">", $self->CGI->escapeHTML($Branch->Name), "</option>";
}
print "</select>",
"&nbsp;<span class='Required'>*</span></div></div>\n";
}
$self->{HasRequired} = 1;
}
else
{
if (! defined($self->{FileName}))
{
$self->{FileName} = $self->GetParam("FileName");
}
if (! defined($self->{FileType}))
{
$self->{FileType} = $self->GetParam("FileType");
}
if (! defined($self->{TestExecutable}))
{
$self->{TestExecutable} = $self->GetParam("TestExecutable");
}
if (! defined($self->{CmdLineArg}))
{
$self->{CmdLineArg} = $self->GetParam("CmdLineArg");
}
print "<div><input type='hidden' name='Remarks' value='",
$self->CGI->escapeHTML($self->GetParam("Remarks")), "'></div>\n";
print "<div><input type='hidden' name='FileName' value='",
$self->CGI->escapeHTML($self->{FileName}), "'></div>\n";
print "<div><input type='hidden' name='FileType' value='",
$self->CGI->escapeHTML($self->{FileType}), "'></div>\n";
print "<div><input type='hidden' name='Branch' value='",
$self->CGI->escapeHTML($self->GetParam("Branch")), "'></div>\n";
if ($self->{Page} != 3)
{
if (defined($self->{TestExecutable}))
{
print "<div><input type='hidden' name='TestExecutable' value='",
$self->CGI->escapeHTML($self->{TestExecutable}), "'></div>\n";
}
if (defined($self->{CmdLineArg}))
{
print "<div><input type='hidden' name='CmdLineArg' value='",
$self->CGI->escapeHTML($self->{CmdLineArg}), "'></div>\n";
}
}
if ($self->{Page} == 2)
{
if ($self->GetParam("Page") == 3)
{
my $VMs = CreateVMs();
foreach my $VMKey (@{$VMs->GetKeys()})
{
my $VM = $VMs->GetItem($VMKey);
my $FieldName = "vm_" . $self->CGI->escapeHTML($VMKey);
if (defined($self->GetParam($FieldName)) && $VM->Type ne "base")
{
$self->{ShowAll} = 1;
last;
}
}
}
if ($self->{ShowAll})
{
print "<div><input type='hidden' name='ShowAll' value='1'></div>\n";
}
my $VMs = CreateVMs();
# Don't even show the 'offline' ones
$VMs->AddFilter("Status", ["reverting", "sleeping", "idle", "running", "dirty"]);
if ($self->{ShowAll})
{
$VMs->AddFilter("Type", ["base", "extra", "retired"]);
}
else
{
$VMs->AddFilter("Type", ["base"]);
}
my $SortedKeys = $VMs->SortKeysBySortOrder($VMs->GetKeys());
foreach my $VMKey (@$SortedKeys)
{
my $VM = $VMs->GetItem($VMKey);
if ($VM->Bits == 64 || $self->{FileType} eq "exe32" ||
$self->{FileType} eq "dll32" ||
$self->{FileType} eq "patchdlls" ||
$self->{FileType} eq "patchprograms" ||
$self->{FileType} eq "zip")
{
my $FieldName = "vm_" . $self->CGI->escapeHTML($VM->GetKey());
print "<div class='ItemProperty'><label>",
$self->CGI->escapeHTML($VM->Name);
if ($VM->Description)
{
print " (", $self->CGI->escapeHTML($VM->Description), ")";
}
print "</label><div class='ItemValue'><input type='checkbox' name='$FieldName'";
if ($self->GetParam("Page") == 1 || $self->GetParam($FieldName))
{
print " checked='checked'";
}
print "/></div></div>\n";
}
}
}
else
{
if (defined($self->{NoCmdLineArgWarn}))
{
print "<div><input type='hidden' name='NoCmdLineArgWarn' value='on'>",
"</div>\n";
}
my $VMs = CreateVMs();
foreach my $VMKey (@{$VMs->GetKeys()})
{
my $VM = $VMs->GetItem($VMKey);
my $FieldName = "vm_" . $self->CGI->escapeHTML($VM->GetKey());
if ($self->GetParam($FieldName))
{
print "<div><input type='hidden' name='$FieldName' value='on'>",
"</div>\n";
}
}
}
}
if ($self->{Page} == 4)
{
if ($self->GetParam("JobKey"))
{
$self->{JobKey} = $self->GetParam("JobKey");
}
print "<div><input type='hidden' name='JobKey' value='", $self->{JobKey},
"'></div>\n";
}
$self->SUPER::GenerateFields(@_);
}
sub GenerateActions
{
my $self = shift;
if ($self->{Page} == 2)
{
print <<EOF;
<script type='text/javascript'>
<!--
function ToggleAll()
{
for (var i = 0; i < document.forms[0].elements.length; i++)
{
if(document.forms[0].elements[i].type == 'checkbox')
document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked);
}
}
// Only put javascript link in document if javascript is enabled
document.write("<div class='ItemActions'><a href='javascript:void(0)' onClick='ToggleAll();'>Toggle All<\\\/a><\\\/div>");
//-->
</script>
EOF
print "<div class='ItemActions'>\n";
print "<input type='submit' name='Action' value='",
$self->{ShowAll} ? "Show base VMs" : "Show all VMs", "'/>\n";
print "</div>\n";
}
$self->SUPER::GenerateActions();
}
sub GetActions
{
my $self = shift;
my $Actions = $self->SUPER::GetActions();
if ($self->{Page} == 1)
{
push(@$Actions, "Next >");
}
elsif ($self->{Page} == 2)
{
push(@$Actions, "< Prev", "Next >");
}
elsif ($self->{Page} == 3)
{
push(@$Actions, "< Prev", "Submit");
}
elsif ($self->{Page} == 4)
{
push(@$Actions, "OK");
}
return $Actions;
}
sub DisplayProperty
{
my $self = shift;
my $PropertyDescriptor = $_[0];
if ($self->{Page} == 3)
{
my $PropertyName = $PropertyDescriptor->GetName();
if ($self->GetParam("FileType") eq "patchdlls" ||
$self->GetParam("FileType") eq "patchprograms")
{
if ($PropertyName eq "Run64")
{
my $Show64 = !1;
my $VMs = CreateVMs();
foreach my $VMKey (@{$VMs->GetKeys()})
{
my $VM = $VMs->GetItem($VMKey);
my $FieldName = "vm_" . $self->CGI->escapeHTML($VM->GetKey());
if ($self->GetParam($FieldName) && $VM->Bits == 64)
{
$Show64 = 1;
last;
}
}
if (! $Show64)
{
return "";
}
}
}
else
{
if ($PropertyName eq "TestExecutable" || $PropertyName eq "Run64")
{
return "";
}
}
}
return $self->SUPER::DisplayProperty(@_);
}
sub GetPropertyValue
{
my $self = shift;
my $PropertyDescriptor = $_[0];
if ($self->{Page} == 3)
{
my $PropertyName = $PropertyDescriptor->GetName();
if ($PropertyName eq "DebugLevel")
{
return 1;
}
if ($PropertyName eq "Run64")
{
return 1;
}
}
return $self->SUPER::GetPropertyValue(@_);
}
sub GetStagingFileName
{
my $self = shift;
my $FileName = $_[0];
if (! $FileName)
{
return undef;
}
return "$DataDir/staging/" . $self->GetCurrentSession()->Id . "_$FileName";
}
sub Validate
{
my $self = shift;
if ($self->{Page} == 2 && $self->GetParam("Page") == 2)
{
my $VMSelected = !1;
my $VMs = CreateVMs();
foreach my $VMKey (@{$VMs->GetKeys()})
{
my $VM = $VMs->GetItem($VMKey);
my $FieldName = "vm_" . $self->CGI->escapeHTML($VM->GetKey());
if ($self->GetParam($FieldName))
{
$VMSelected = 1;
last;
}
}
if (! $VMSelected)
{
$self->{ErrMessage} = "Select at least one VM";
return !1;
}
}
elsif ($self->{Page} == 3 && $self->GetParam("Page") == 3)
{
if (($self->GetParam("FileType") eq "patchdlls" &&
! ($self->GetParam("TestExecutable") =~ m/^[a-zA-Z0-9_]+_test\.exe/)) ||
($self->GetParam("FileType") eq "patchprograms") &&
! ($self->GetParam("TestExecutable") =~ m/^[a-zA-Z0-9_]+\.exe_test\.exe/))
{
$self->{ErrMessage} = "Invalid name for Test executable";
$self->{ErrField} = "TestExecutable";
return !1;
}
if ($self->GetParam("NoCmdLineArgWarn"))
{
$self->{NoCmdLineArgWarn} = 1;
}
elsif (! $self->GetParam("CmdLineArg") &&
$self->GetParam("FileType") ne "dll32" &&
$self->GetParam("FileType") ne "dll64")
{
$self->{ErrMessage} = "You didn't specify a command line argument. " .
"This is most likely not correct, so please " .
"fix this. If you're sure that you really don't " .
'want a command line argument, press "Submit" ' .
"again.";
$self->{ErrField} = "CmdLineArg";
$self->{NoCmdLineArgWarn} = 1;
return !1;
}
}
return $self->SUPER::Validate(@_);
}
sub DetermineFileType
{
my $self = shift;
my $FileName = $_[0];
my $ErrMessage = undef;
my $FileType = "unknown";
my $DllBaseName = undef;
my $TestSet = undef;
if (! sysopen(FH, $FileName, O_RDONLY))
{
return ("Unable to open $FileName", "unknown", undef, undef);
}
my $Buffer;
if (sysread(FH, $Buffer, 0x40))
{
# Unpack IMAGE_DOS_HEADER
my @Fields = unpack "S30I", $Buffer;
if ($Fields[0] == 0x5a4d)
{
seek FH, $Fields[30], SEEK_SET;
if (sysread(FH, $Buffer, 0x18))
{
@Fields = unpack "IS2I3S2", $Buffer;
if ($Fields[0] == 0x00004550)
{
if (($Fields[7] & 0x2000) == 0)
{
$FileType = "exe";
}
else
{
$FileType = "dll";
}
if ($Fields[1] == 0x014c)
{
$FileType .= "32";
}
elsif ($Fields[1] == 0x8664)
{
$FileType .= "64";
}
else
{
$FileType = "unknown";
}
}
}
}
# zip files start with PK, 0x03, 0x04
elsif ($Fields[0] == 0x4b50 && $Fields[1] == 0x0403)
{
$FileType = "zip";
}
}
close FH;
if ($FileType eq "unknown")
{
if (open (FH, "<$FileName"))
{
my $Line;
while (defined($Line = <FH>))
{
if ($Line =~ m/^\+\+\+ .*\/(dlls|programs)\/([^\/]+)\/tests\/([^\/\s]+)/)
{
$FileType = "patch$1";
my $ThisDllBaseName = $2;
my $ThisTestSet = $3;
if ($ThisTestSet =~ m/^(.*)\.c$/)
{
$ThisTestSet = $1;
}
else
{
$ThisTestSet = undef;
}
if ((defined($DllBaseName) && $DllBaseName ne $ThisDllBaseName) ||
(defined($TestSet) && defined($ThisTestSet) &&
$TestSet ne $ThisTestSet))
{
$ErrMessage = "Patch contains changes to multiple tests";
}
else
{
if (defined($ThisDllBaseName))
{
$DllBaseName = $ThisDllBaseName;
}
if (defined($ThisTestSet))
{
$TestSet = $ThisTestSet;
}
}
}
}
close FH;
}
}
return ($ErrMessage, $FileType, $DllBaseName, $TestSet);
}
sub OnPage1Next
{
my $self = shift;
my $FileName = $self->GetParam("File");
if (! $FileName)
{
$self->{ErrField} = "File";
$self->{ErrMessage} = "File: Must be entered";
return !1;
}
my $Fh = $self->CGI->upload("File");
if (defined($Fh))
{
if ($FileName =~ /(\\|\/)/)
{
$FileName =~ m/^.*(\\|\/)(.*)/;
$FileName = $2;
}
if (100 - 32 - 1 < length($FileName))
{
$self->{ErrField} = "File";
$self->{ErrMessage} = "File: Name is too long";
return !1;
}
my $StagingFile = $self->GetStagingFileName($FileName);
my $OldUMask = umask(002);
if (! open (OUTFILE,">$StagingFile"))
{
umask($OldUMask);
$self->{ErrField} = "File";
$self->{ErrMessage} = "Unable to process uploaded file";
return !1;
}
umask($OldUMask);
my $Buffer;
while (sysread($Fh, $Buffer, 4096))
{
print OUTFILE $Buffer;
}
close OUTFILE;
my ($ErrMessage, $FileType, $DllBaseName, $TestSet) = $self->DetermineFileType($StagingFile);
if (defined($ErrMessage))
{
$self->{ErrField} = "File";
$self->{ErrMessage} = $ErrMessage;
return !1;
}
if ($FileType ne "patchdlls" && $FileType ne "patchprograms" &&
$FileType ne "exe32" && $FileType ne "exe64" && $FileType ne "dll32" &&
$FileType ne "zip")
{
$self->{ErrField} = "File";
$self->{ErrMessage} = "Unrecognized file typea";
return !1;
}
$self->{FileName} = $FileName;
$self->{FileType} = $FileType;
if (defined($DllBaseName))
{
$self->{TestExecutable} = $DllBaseName;
if ($FileType eq "patchprograms")
{
$self->{TestExecutable} .= ".exe";
}
$self->{TestExecutable} .= "_test.exe";
}
if (defined($TestSet))
{
$self->{CmdLineArg} = $TestSet;
}
}
else
{
$self->{ErrField} = "File";
$self->{ErrMessage} = "File upload failed";
return !1;
}
if (! $self->Validate)
{
return !1;
}
$self->{Page} = 2;
return 1;
}
sub OnPage2Next
{
my $self = shift;
if (! $self->Validate)
{
return !1;
}
$self->{Page} = 3;
return 1;
}
sub OnNext
{
my $self = shift;
return $self->{Page} == 2 ? $self->OnPage2Next() : $self->OnPage1Next();
}
sub OnPage2Prev
{
my $self = shift;
my $StagingFileName = $self->GetStagingFileName($self->GetParam("FileName"));
if ($StagingFileName)
{
unlink($StagingFileName);
}
$self->{Page} = 1;
return 1;
}
sub OnPage3Prev
{
my $self = shift;
$self->{Page} = 2;
return 1;
}
sub OnPrev
{
my $self = shift;
return $self->{Page} == 3 ? $self->OnPage3Prev() : $self->OnPage2Prev();
}
sub OnSubmit
{
my $self = shift;
if (! $self->Validate())
{
return !1;
}
# Make sure the file has a unique name even when not picked up directly
# by the engine
my $FileNameRandomPart = $self->GetCurrentSession()->Id;
while (-e ("$DataDir/staging/${FileNameRandomPart}_" .
$self->GetParam("FileName")))
{
$FileNameRandomPart = GenerateRandomString(32);
}
if (! rename("$DataDir/staging/" . $self->GetCurrentSession()->Id . "_" .
$self->GetParam("FileName"),
"$DataDir/staging/${FileNameRandomPart}_" .
$self->GetParam("FileName")))
{
# Can't give the file a unique name. Maybe we're lucky and using the
# session id works
$FileNameRandomPart = $self->GetCurrentSession()->Id;
}
# First create a new job
my $Jobs = CreateJobs();
my $NewJob = $Jobs->Add();
$NewJob->User($self->GetCurrentSession()->User);
$NewJob->Priority(5);
if ($self->GetParam("Remarks"))
{
$NewJob->Remarks($self->GetParam("Remarks"));
}
else
{
$NewJob->Remarks($self->GetParam("CmdLineArg"));
}
my $Branch = CreateBranches()->GetItem($self->GetParam("Branch"));
if (defined($Branch))
{
$NewJob->Branch($Branch);
}
# Add a step to the job
my $Steps = $NewJob->Steps;
my $NewStep = $Steps->Add();
$NewStep->FileName($FileNameRandomPart . " " . $self->GetParam("FileName"));
my $FileType = $self->GetParam("FileType");
$NewStep->FileType($FileType);
$NewStep->InStaging(1);
if ($FileType eq "patchdlls" || $FileType eq "patchprograms")
{
$NewStep->Type("build");
$NewStep->DebugLevel(0);
# Add build task
my $Tasks = $NewStep->Tasks;
my $VMs = CreateVMs();
$VMs->AddFilter("Type", ["build"]);
my $BuildKey = ${$VMs->GetKeys()}[0];
my $VM = $VMs->GetItem($BuildKey);
my $Task = $Tasks->Add();
$Task->VM($VM);
$Task->Timeout($BuildTimeout);
# Add test run step
$NewStep = $Steps->Add();
$NewStep->FileName($self->GetParam("TestExecutable"));
$NewStep->FileType("exe32");
$NewStep->InStaging(!1);
}
if ($FileType eq "dll32" && ! $self->GetParam("CmdLineArg"))
{
$NewStep->Type("suite");
}
else
{
$NewStep->Type("single");
}
$NewStep->DebugLevel($self->GetParam("DebugLevel"));
$NewStep->ReportSuccessfulTests(defined($self->GetParam("ReportSuccessfulTests")));
# Add a task for each selected VM
my $Tasks = $NewStep->Tasks;
my $VMs = CreateVMs();
my $SortedKeys = $VMs->SortKeysBySortOrder($VMs->GetKeys());
foreach my $VMKey (@$SortedKeys)
{
my $VM = $VMs->GetItem($VMKey);
my $FieldName = "vm_" . $self->CGI->escapeHTML($VM->GetKey());
if ($self->GetParam($FieldName))
{
my $Task = $Tasks->Add();
$Task->VM($VM);
$Task->Timeout($NewStep->Type eq "suite" ?
$SuiteTimeout : $SingleTimeout);
$Task->CmdLineArg($self->GetParam("CmdLineArg"));
}
}
if (($FileType eq "patchdlls" || $FileType eq "patchprograms") &&
defined($self->GetParam("Run64")))
{
# Add step and tasks for 64-bit exe
$NewStep = $Steps->Add();
my $FileName64 = $self->GetParam("TestExecutable");
$FileName64 =~ s/^([a-zA-Z0-9_.]+)_test\.exe/\1_test64.exe/;
$NewStep->FileName($FileName64);
$NewStep->FileType("exe64");
$NewStep->InStaging(!1);
$NewStep->Type("single");
$NewStep->DebugLevel($self->GetParam("DebugLevel"));
$NewStep->ReportSuccessfulTests(defined($self->GetParam("ReportSuccessfulTests")));
# Add a task for each selected 64-bit VM
my $Tasks = $NewStep->Tasks;
my $VMs = CreateVMs();
my $SortedKeys = $VMs->SortKeysBySortOrder($VMs->GetKeys());
foreach my $VMKey (@$SortedKeys)
{
my $VM = $VMs->GetItem($VMKey);
my $FieldName = "vm_" . $self->CGI->escapeHTML($VM->GetKey());
if ($VM->Bits == 64 && $self->GetParam($FieldName))
{
my $Task = $Tasks->Add();
$Task->VM($VM);
$Task->Timeout($SingleTimeout);
$Task->CmdLineArg($self->GetParam("CmdLineArg"));
}
}
}
# Now save the whole thing
my ($ErrKey, $ErrProperty, $ErrMessage) = $Jobs->Save();
if (defined($ErrMessage))
{
$self->{ErrMessage} = $ErrMessage;
return !1;
}
# Clean up, but save the key of the new job
my $JobKey = $NewJob->GetKey();
$Jobs = undef;
# Notify engine
if (defined(JobSubmit($JobKey)))
{
$self->{Page} = 4;
$self->{JobKey} = $NewJob->GetKey();
return !1;
}
$self->Redirect("/JobDetails.pl?Key=" . $NewJob->Id);
exit;
}
sub OnShowAllVMs
{
my $self = shift;
$self->{ShowAll} = 1;
return !1;
}
sub OnShowBaseVMs
{
my $self = shift;
$self->{ShowAll} = !1;
return !1;
}
sub OnOK
{
my $self = shift;
if (defined($self->GetParam("JobKey")))
{
$self->Redirect("/JobDetails.pl?Key=" . $self->GetParam("JobKey"));
}
else
{
$self->Redirect("/index.pl");
}
}
sub OnAction
{
my $self = shift;
my $Action = $_[0];
if ($Action eq "Next >")
{
return $self->OnNext();
}
elsif ($Action eq "< Prev")
{
return $self->OnPrev();
}
elsif ($Action eq "Submit")
{
return $self->OnSubmit();
}
elsif ($Action eq "Show base VMs")
{
return $self->OnShowBaseVMs();
}
elsif ($Action eq "Show all VMs")
{
return $self->OnShowAllVMs();
}
elsif ($Action eq "OK")
{
return $self->OnOK();
}
return $self->SUPER::OnAction(@_);
}
package main;
my $Request = shift;
my $SubmitPage = SubmitPage->new($Request, "wine-devel");
$SubmitPage->GeneratePage();