-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_tests
executable file
·121 lines (92 loc) · 4.26 KB
/
run_tests
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
#!/usr/bin/env perl
#
# Run all cprnc tests
# See usage message for details
#
# Bill Sacks
# 5-28-13
use strict;
use Getopt::Long;
#----------------------------------------------------------------------
# Define parameters
#----------------------------------------------------------------------
# Hash giving info about each test. Key is the test file; value is a
# hash reference containing at least the associated control file (key:
# control), and possibly extra arguments to cprnc (key: extra_args)
my %tests = ('copy.nc' => {control => 'control.nc'},
'extra_variables.nc' => {control => 'control.nc'},
'diffs_in_vals.nc' => {control => 'control.nc'},
'diffs_in_vals_and_extra_and_missing.nc' => {control => 'control.nc'},
'diffs_in_fill.nc' => {control => 'control.nc'},
'diffs_in_vals_and_diffs_in_fill.nc' => {control => 'control.nc'},
'diffs_in_vals_and_fill.nc' => {control => 'control.nc'},
'lon_differs.nc' => {control => 'control.nc'},
'missing_variables.nc' => {control => 'control.nc'},
'vals_differ_by_1.1.nc' => {control => 'control.nc'},
'vals_differ_by_1.1_somewhere.nc' => {control => 'control.nc'},
'vals_differ_by_varying_amounts.nc' => {control => 'control.nc'},
'vals_differ_by_varying_amounts2.nc' => {control => 'control.nc'},
'int_missing.nc' => {control => 'control_int.nc'},
'multipleTimes_someTimeless_diffs_in_vals_and_fill.nc' => {control => 'control_multipleTimes_someTimeless.nc'},
'multipleTimes_someTimeless_extra_and_missing.nc' => {control => 'control_multipleTimes_someTimeless.nc'},
'noTime_diffs_in_vals_and_fill.nc' => {control => 'control_noTime.nc',
extra_args => '-m'},
'noTime_extra_and_missing.nc' => {control => 'control_noTime.nc',
extra_args => '-m'},
'diffs_0d.nc' => {control => 'control_0d.nc',
extra_args => '-m'},
'cpl.hi.subset.test.nc' => {control => 'cpl.hi.subset.control.nc'},
'clm2.h0.subset.test.nc' => {control => 'clm2.h0.subset.control.nc'},
'clm2.h1.subset.test.nc' => {control => 'clm2.h1.subset.control.nc'},
'diffs_in_attribute.nc' => {control => 'control_attributes.nc'},
'copy_char.nc' => {control => 'control_char.nc',
extra_args => '-m'},
'diffs_in_nans.nc' => {control => 'control_floatDoubleNan.nc'},
);
#----------------------------------------------------------------------
# Get arguments and check them
#----------------------------------------------------------------------
my %opts;
GetOptions(
"outdir=s" => \$opts{'outdir'},
"h|help" => \$opts{'help'},
) or usage();
usage() if $opts{'help'};
if (@ARGV) {
print "ERROR: unrecognized arguments: @ARGV\n";
usage();
}
if (!$opts{'outdir'}) {
print "ERROR: -outdir must be provided\n";
usage();
}
#----------------------------------------------------------------------
# Main script
#----------------------------------------------------------------------
mkdir $opts{'outdir'} or die "ERROR creating directory $opts{'outdir'};
note that this directory should NOT exist before running this script\n";
my $num_tests = keys %tests;
print "Running $num_tests tests...\n";
foreach my $test (keys %tests) {
print "$test\n";
my $test_file = $test;
my $control_file = $tests{$test}{'control'};
my $outfile = "$opts{'outdir'}/${test}.out";
my $extra_args = $tests{$test}{'extra_args'};
open (my $file, ">", "$outfile") or die "ERROR opening $outfile";
print $file `./cprnc $extra_args test_inputs/$control_file test_inputs/$test_file`;
close $file;
}
#----------------------------------------------------------------------
# Subroutines
#----------------------------------------------------------------------
sub usage {
die <<EOF;
SYNOPSIS
run_tests -outdir <outdir> [OPTIONS]
Run all cprnc tests, putting output in directory given by <outdir>.
<outdir> should NOT exist before running this script.
OPTIONS
-help [or -h] Display this help
EOF
}