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
|
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;
# -*- perl -*-
use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;
use File::Copy;
my $status = 0;
my $test1 = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
my $stdout_file = "test.out";
my $stderr_file = "test.err";
my $test_stdout_file = $test1->LocalFile ($stdout_file);
my $test_stderr_file = $test1->LocalFile ($stderr_file);
sub cat_file($)
{
my $file_name = shift;
if (-s $file_name ) # size of file is greater than zero
{
open TESTFILE, $file_name or die "Couldn't open file: $!";
my @teststring = <TESTFILE>; # read in all of the file
print STDERR "\n@teststring\n";
close TESTFILE;
}
}
sub redirect_output()
{
open (OLDOUT, ">&", \*STDOUT) or die "Can't dup STDOUT: $!";
open (OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!";
open STDERR, '>', $test_stderr_file;
open STDOUT, '>', $test_stdout_file;
}
sub restore_output()
{
open (STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!";
open (STDOUT, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
}
my $persistent_file = "test.dat";
$test1->DeleteFile ($persistent_file);
my $num_loops = 5;
my $loop_sleep_msec = 200;
if ($#ARGV >= 0) {
for (my $i = 0; $i <= $#ARGV; $i++) {
if ($ARGV[$i] eq '-num_loops') {
$i++;
$num_loops = $ARGV[$i];
}
elsif ($ARGV[$i] eq "-loop_sleep") {
$i++;
$loop_sleep_msec = $ARGV[$i];
}
else {
print "Usage: run_test.pl ".
"[-num_loops <num=$num_loops>] ".
"[-loop_sleep <msec=$loop_sleep_msec>]\n";
exit 1;
}
}
}
$T1 = $test1->CreateProcess ("test", "-i 0 -n $num_loops");
my $test2 = PerlACE::TestTarget::create_target (2) || die "Create target 1 failed\n";
$T2 = $test2->CreateProcess ("test", "-i 1 -n $num_loops -s $loop_sleep_msec");
$test1_status = $T1->Spawn ();
if ($test1_status != 0) {
print STDERR "ERROR: test 1 returned $test1_status\n";
$status = 1;
}
$test2_status = $T2->SpawnWaitKill ($test2->ProcessStartWaitInterval());
if ($test2_status != 0) {
print STDERR "ERROR: test 2 returned $test2_status\n";
$status = 1;
}
$test1_status = $T1->WaitKill ($test1->ProcessStopWaitInterval());
if ($test1_status != 0) {
print STDERR "ERROR: test 1 returned $test1_status\n";
$status = 1;
}
$test1->DeleteFile ($persistent_file);
sub test_backup_recovery($)
{
my $bad_file = shift;
my $status = 0;
print STDERR "Testing recovery of backup file for $bad_file.\n";
my $backup_file = "test.dat.bak";
copy($bad_file, "test.dat") or die "Copy failed: $!";
copy("data_files/good.dat", $backup_file) or die "Copy failed: $!";
$T = $test1->CreateProcess ("test", "-b");
# Redirect output so that expected error messages are not interpreted as
# test failure and rely instead of return status.
redirect_output();
my $test_status = $T->SpawnWaitKill ($test1->ProcessStartWaitInterval());
restore_output();
if ($test_status != 0) {
$status = 1;
print STDERR "ERROR: Backup recovery test using $bad_file failed\n";
cat_file($test_stderr_file);
cat_file($test_stdout_file);
}
else {
print STDERR "Recovery successful\n";
}
if (-e $backup_file) {
$test1->DeleteFile ($backup_file);
}
else {
$status = 1;
print STDERR "ERROR: Backup file was not created\n";
}
$test1->DeleteFile ($persistent_file);
$test1->DeleteFile ($stdout_file);
$test1->DeleteFile ($stderr_file);
return $status;
}
@bad_files = (
"data_files/bad_binary.dat",
"data_files/bad_int.dat",
"data_files/bad_string.dat",
"data_files/bad_unsigned_int.dat"
);
foreach $bad_file (@bad_files) {
if (test_backup_recovery ($bad_file) != 0) {
$status = 1;
}
}
exit $status
|