#! /usr/bin/env perl
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************

use CondorTest;


$cmd_template = "job_core_periodicremove_van.template";
$testdesc =  'job_core_periodicremove_van - Test periodicremove / wallclockcheckpoint';
$testname = "job_core_periodicremove_van";
$corename = "job_core_periodicremove_van";

# where am I running
$currenthost = CondorTest::getFqdnHost();

print scalar localtime() . "\n";

$mypid = $$;
$mysaveme = $corename . ".saveme";

if($mypid == 0) {
	die "Saveme setup for test failed\n";
}

$mysubmitnm = $corename . $mypid . ".cmd";
$mysubmitnmout = $corename . $mypid . ".cmd.out";
$mysubmitnmlog = $corename . $mypid . ".log";
$mysubmitnmout = $corename . $mypid . ".log";
$mycorenm = $corename . ".cmd";
$mycorenmout = $corename . ".cmd.out";
$mycorenmlog = $corename . ".log";

CondorTest::debug("Master PID is $mypid\n",1);
CondorTest::debug("Master PID submit file is $mysubmitnm\n",1);

# get a local scheduler running with controlled intervals
my $configloc = CondorTest::StartPersonal( "job_core_periodicremove_van", "x_param.periodicremove" ,"periodocrm");
my @local = split /\+/, $configloc;
my $locconfig = shift @local;
my $locport = shift @local;

CondorTest::debug("---local config is $locconfig and local port is $locport---\n",1);

$ENV{CONDOR_CONFIG} = $locconfig;
# submit into local schedd 


my $result = system("./job_core_periodicremove_van.pl $mycorenm");
CondorTest::debug("Result of crafted periodic remove job is  $result\n",1);

system("cp *periodicremove* $mysaveme");

if( -e "$mysubmitnm" )
{
	system("cp $mysubmitnm $mycorenm");
}

if( -e "$mysubmitnmout" )
{
	system("cp $mysubmitnmout $mycorenmout");
}

if( -e "$mysubmitnmlog" )
{
	system("cp $mysubmitnmlog $mycorenmlog");
}

CondorTest::KillPersonal($locconfig);
print scalar localtime() . "\n";

if( $result != 0 )
{
    # actual test failed but we allowed cleanup
    exit(1);
}
CondorTest::debug("job_core_periodicremove_van SUCCESS\n",1);
exit(0);
