#!/usr/bin/env perl #----------------------------------------------------------------------------------------------- # # create_production_test # # This utility allows the users to specify configuration tests from an existing case directory # #----------------------------------------------------------------------------------------------- use strict; use Cwd; use English; use Getopt::Long; use IO::File; use IO::Handle; use XML::LibXML; sub usage { die < \$opts{'test'}, "h|help" => \$opts{'help'},) or usage(); usage() if $opts{'help'}; # If specify input test - determine if it is supported by create_production_test my $testname = "ERS_Lm3"; if ($opts{'test'}) { $testname = $opts{'test'}; my $accepttest; my @allowedtests = qw(ERS ERS_Lm3 ERI LAR PFS NCK CME); foreach my $allowedtest (@allowedtests) { if ($testname eq $allowedtest) { $accepttest = 'yes'; last; } } if (! $accepttest) { print " ERROR: allowed supported tests are @allowedtests \n"; die " $testname is not part of the allowed supported tests \n"; } } # Create caseroot and case for call to create_clone my $cimeroot = `./xmlquery CIMEROOT -value`; my $clonecase = `./xmlquery CASE -value`; my $cloneroot = `./xmlquery CASEROOT -value`; my $testroot = "$cloneroot/../${clonecase}_${testname}"; print "\nCreating test $testroot\n"; # Create a new clone case directory my $sysmod = "$cimeroot/scripts/create_clone -case $testroot -clone $cloneroot"; system ($sysmod); if ($? == -1) {die "$sysmod failed: $!\n";} # Change to the new cloned test directory chdir("$testroot"); # Write env_test.xml in the cloned test directory, needed by the test environment setup my $test = $testname; if ($testname eq 'ERS_Lm3') { $test = "ERS"; } writeEnvTestXML($testroot, $test); if ($testname eq 'ERS_Lm3') { $sysmod = "./xmlchange -noecho STOP_OPTION=nmonths" ; system($sysmod) == 0 or die "ERROR: $sysmod failed: $?\n"; $sysmod = "./xmlchange -noecho STOP_N=3" ; system($sysmod) == 0 or die "ERROR: $sysmod failed: $?\n"; } # Create the testing file $testroot/$testname.test my $sysmod = "$cimeroot/scripts/Tools/testcase_setup -caseroot $testroot"; system ($sysmod); if ($? == -1) {die "$sysmod failed: $!\n";} # Cleanly exit exit 0; #----------------------------------------------------------------------------------------------- # Private routines #----------------------------------------------------------------------------------------------- sub writeEnvTestXML { my ($testroot, $testname) = @_; my $model = `./xmlquery MODEL -value`; my $cimeroot = `./xmlquery CIMEROOT -value`; my @dirs = ("$cimeroot/utils/perl5lib/Config"); unshift @INC, @dirs; require ConfigCase; # First create empty config object my $config = ConfigCase->new(""); # Add all the elements of the driver config_component.xml file to $config my $file = "$cimeroot/driver_cpl/cime_config/config_component.xml"; $config->add_config_variables($file, 'unset', $cimeroot, $model); # Then set some new values in $config my $testid = `date +%y%m%d-%H%M%S`; chomp $testid; $config->set('TESTCASE' , $testname); $config->set('TEST_TESTID' , $testid); # Set the parameters for the specified testname. # If no testname matches are found then issue error message. my $file = "$cimeroot/scripts/Testing/Testcases/config_tests.xml"; my $xml = XML::LibXML->new( no_blanks => 1)->parse_file("$file"); my @tests = $xml->findnodes(".//test[\@NAME=\"$testname\"]"); if ($#tests == -1) { die "ERROR create_production_test: no tests with $testname were found in $file \n"; } foreach my $node ($tests[0]->findnodes("./*")) { my $name = $node->nodeName(); my $value = $node->textContent(); $config->set($name, $value); } # Create the file env_test.xml my $caseheaders = ""; $config->write_file("${testroot}/env_test.xml", $caseheaders, $testroot, $cimeroot ); }