Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Storable / run_test.pl
blob1561816555666f36de3e7e50b7136dddf62ef3d9
1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
3 if 0;
5 # -*- perl -*-
7 use lib "$ENV{ACE_ROOT}/bin";
8 use PerlACE::TestTarget;
9 use File::Copy;
11 my $status = 0;
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);
20 sub cat_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";
28 close TESTFILE;
32 sub redirect_output()
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;
40 sub restore_output()
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);
50 my $num_loops = 5;
51 my $loop_sleep_msec = 200;
53 if ($#ARGV >= 0) {
54 for (my $i = 0; $i <= $#ARGV; $i++) {
55 if ($ARGV[$i] eq '-num_loops') {
56 $i++;
57 $num_loops = $ARGV[$i];
59 elsif ($ARGV[$i] eq "-loop_sleep") {
60 $i++;
61 $loop_sleep_msec = $ARGV[$i];
63 else {
64 print "Usage: run_test.pl ".
65 "[-num_loops <num=$num_loops>] ".
66 "[-loop_sleep <msec=$loop_sleep_msec>]\n";
67 exit 1;
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";
82 $status = 1;
85 $test2_status = $T2->SpawnWaitKill ($test2->ProcessStartWaitInterval());
87 if ($test2_status != 0) {
88 print STDERR "ERROR: test 2 returned $test2_status\n";
89 $status = 1;
92 $test1_status = $T1->WaitKill ($test1->ProcessStopWaitInterval());
94 if ($test1_status != 0) {
95 print STDERR "ERROR: test 1 returned $test1_status\n";
96 $status = 1;
99 $test1->DeleteFile ($persistent_file);
101 sub test_backup_recovery($)
103 my $bad_file = shift;
105 my $status = 0;
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.
116 redirect_output();
117 my $test_status = $T->SpawnWaitKill ($test1->ProcessStartWaitInterval());
118 restore_output();
119 if ($test_status != 0) {
120 $status = 1;
121 print STDERR "ERROR: Backup recovery test using $bad_file failed\n";
122 cat_file($test_stderr_file);
123 cat_file($test_stdout_file);
125 else {
126 print STDERR "Recovery successful\n";
129 if (-e $backup_file) {
130 $test1->DeleteFile ($backup_file);
132 else {
133 $status = 1;
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);
139 return $status;
142 @bad_files = (
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) {
151 $status = 1;
155 exit $status