#! /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;
use CondorUtils;
use Check::SimpleJob;
#use Check::CondorLog;
use Check::ProcInfo;

my $configfile = "";


my $firstappend_condor_config = '
	DAEMON_LIST = MASTER,SCHEDD,COLLECTOR,NEGOTIATOR,STARTD
	ALL_DEBUG = 
';

$configfile = CondorTest::CreateLocalConfig($firstappend_condor_config,"affinityoff");

CondorTest::StartCondorWithParams(
	condor_name => "affinityoff",
	fresh_local => "TRUE",
	condorlocalsrc => "$configfile",
);

#Do a couple things before setting cpu affinity
print "First test basic job\n";
SimpleJob::RunCheck();
my $count = 0;
print "First test basic affinity job\n";
$count = ProcInfo::RunAffinityCheck(
	proc_file => "status",
	proc_file_pattern => "Cpus_allowed:",
	cores_desired => -1);

	if($count == 1) {
		print "Only one core makes test meaningless\n";
		CondorTest::EndTest();
	}

my $nextappend_condor_config = '
	DAEMON_LIST = MASTER,SCHEDD,COLLECTOR,NEGOTIATOR,STARTD
	ALL_DEBUG = 
	ASSIGN_CPU_AFFINITY = true
	NUM_SLOTS=1
	NUM_SLOTS_TYPE_1 = 1
	SLOT_TYPE_1_PARTITIONABLE = TRUE
	SLOT_TYPE_1 = cpus=100%,disk=100%,swap=100%
';

$configfile = CondorTest::CreateLocalConfig($nextappend_condor_config,"affinity1");

CondorTest::StartCondorWithParams(
	condor_name => "affinityon1",
	fresh_local => "TRUE",
	condorlocalsrc => "$configfile",
);


$count = ProcInfo::RunAffinityCheck(
	proc_file => "status",
	proc_file_pattern => "Cpus_allowed:",
	cores_desired => 1);

$configfile = CondorTest::CreateLocalConfig($nextappend_condor_config,"affinity2");

CondorTest::StartCondorWithParams(
	condor_name => "affinityon2",
	fresh_local => "TRUE",
	condorlocalsrc => "$configfile",
);

$count = ProcInfo::RunAffinityCheck(
	proc_file => "status",
	proc_file_pattern => "Cpus_allowed:",
	cores_desired => 2);


CondorTest::EndTest();
