1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
7 use lib
"$ENV{ACE_ROOT}/bin";
8 use PerlACE
::TestTarget
;
13 my $test1 = PerlACE
::TestTarget
::create_target
(1) || die "Create target 1 failed\n";
15 my $stdout_file = "test.out";
16 my $stderr_file = "test.err";
17 my $test_stdout_file = $test1->LocalFile ($stdout_file);
18 my $test_stderr_file = $test1->LocalFile ($stderr_file);
22 my $file_name = shift;
23 if (-s
$file_name) # size of file is greater than zero
25 open TESTFILE
, $file_name or die "Couldn't open file: $!";
26 my @teststring = <TESTFILE
>; # read in all of the file
27 print STDERR
"\n@teststring\n";
34 open (OLDOUT
, ">&", \
*STDOUT
) or die "Can't dup STDOUT: $!";
35 open (OLDERR
, ">&", \
*STDERR
) or die "Can't dup STDERR: $!";
36 open STDERR
, '>', $test_stderr_file;
37 open STDOUT
, '>', $test_stdout_file;
42 open (STDERR
, ">&OLDERR") or die "Can't dup OLDERR: $!";
43 open (STDOUT
, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
47 my $persistent_file = "test.dat";
48 $test1->DeleteFile ($persistent_file);
51 my $loop_sleep_msec = 200;
54 for (my $i = 0; $i <= $#ARGV; $i++) {
55 if ($ARGV[$i] eq '-num_loops') {
57 $num_loops = $ARGV[$i];
59 elsif ($ARGV[$i] eq "-loop_sleep") {
61 $loop_sleep_msec = $ARGV[$i];
64 print "Usage: run_test.pl ".
65 "[-num_loops <num=$num_loops>] ".
66 "[-loop_sleep <msec=$loop_sleep_msec>]\n";
72 $T1 = $test1->CreateProcess ("test", "-i 0 -n $num_loops");
74 my $test2 = PerlACE
::TestTarget
::create_target
(2) || die "Create target 1 failed\n";
76 $T2 = $test2->CreateProcess ("test", "-i 1 -n $num_loops -s $loop_sleep_msec");
78 $test1_status = $T1->Spawn ();
80 if ($test1_status != 0) {
81 print STDERR
"ERROR: test 1 returned $test1_status\n";
85 $test2_status = $T2->SpawnWaitKill ($test2->ProcessStartWaitInterval());
87 if ($test2_status != 0) {
88 print STDERR
"ERROR: test 2 returned $test2_status\n";
92 $test1_status = $T1->WaitKill ($test1->ProcessStopWaitInterval());
94 if ($test1_status != 0) {
95 print STDERR
"ERROR: test 1 returned $test1_status\n";
99 $test1->DeleteFile ($persistent_file);
101 sub test_backup_recovery
($)
103 my $bad_file = shift;
107 print STDERR
"Testing recovery of backup file for $bad_file.\n";
109 my $backup_file = "test.dat.bak";
110 copy
($bad_file, "test.dat") or die "Copy failed: $!";
111 copy
("data_files/good.dat", $backup_file) or die "Copy failed: $!";
113 $T = $test1->CreateProcess ("test", "-b");
114 # Redirect output so that expected error messages are not interpreted as
115 # test failure and rely instead of return status.
117 my $test_status = $T->SpawnWaitKill ($test1->ProcessStartWaitInterval());
119 if ($test_status != 0) {
121 print STDERR
"ERROR: Backup recovery test using $bad_file failed\n";
122 cat_file
($test_stderr_file);
123 cat_file
($test_stdout_file);
126 print STDERR
"Recovery successful\n";
129 if (-e
$backup_file) {
130 $test1->DeleteFile ($backup_file);
134 print STDERR
"ERROR: Backup file was not created\n";
136 $test1->DeleteFile ($persistent_file);
137 $test1->DeleteFile ($stdout_file);
138 $test1->DeleteFile ($stderr_file);
143 "data_files/bad_binary.dat",
144 "data_files/bad_int.dat",
145 "data_files/bad_string.dat",
146 "data_files/bad_unsigned_int.dat"
149 foreach $bad_file (@bad_files) {
150 if (test_backup_recovery
($bad_file) != 0) {