|
|
@ -1,11 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
import multiprocessing
|
|
|
|
import multiprocessing
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
import mock
|
|
|
|
|
|
|
|
import unittest2
|
|
|
|
|
|
|
|
import testlib
|
|
|
|
import testlib
|
|
|
|
|
|
|
|
|
|
|
|
import mitogen.parent
|
|
|
|
import mitogen.parent
|
|
|
@ -18,7 +16,7 @@ class NullFixedPolicy(ansible_mitogen.affinity.FixedPolicy):
|
|
|
|
self.mask = mask
|
|
|
|
self.mask = mask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@unittest2.skipIf(
|
|
|
|
@unittest.skipIf(
|
|
|
|
reason='Linux only',
|
|
|
|
reason='Linux only',
|
|
|
|
condition=(not os.uname()[0] == 'Linux')
|
|
|
|
condition=(not os.uname()[0] == 'Linux')
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -29,139 +27,139 @@ class FixedPolicyTest(testlib.TestCase):
|
|
|
|
# Uniprocessor .
|
|
|
|
# Uniprocessor .
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_controller_2core(self):
|
|
|
|
def test_assign_controller_2core(self):
|
|
|
|
# Small SMP gets 1.. % cpu_count
|
|
|
|
# Small SMP gets 1.. % cpu_count
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_controller_3core(self):
|
|
|
|
def test_assign_controller_3core(self):
|
|
|
|
# Small SMP gets 1.. % cpu_count
|
|
|
|
# Small SMP gets 1.. % cpu_count
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x4, policy.mask)
|
|
|
|
self.assertEqual(0x4, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x4, policy.mask)
|
|
|
|
self.assertEqual(0x4, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_controller_4core(self):
|
|
|
|
def test_assign_controller_4core(self):
|
|
|
|
# Big SMP gets a dedicated core.
|
|
|
|
# Big SMP gets a dedicated core.
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_controller()
|
|
|
|
policy.assign_controller()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_muxprocess_1core(self):
|
|
|
|
def test_assign_muxprocess_1core(self):
|
|
|
|
# Uniprocessor .
|
|
|
|
# Uniprocessor .
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_muxprocess_2core(self):
|
|
|
|
def test_assign_muxprocess_2core(self):
|
|
|
|
# Small SMP gets dedicated core.
|
|
|
|
# Small SMP gets dedicated core.
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_muxprocess_3core(self):
|
|
|
|
def test_assign_muxprocess_3core(self):
|
|
|
|
# Small SMP gets a dedicated core.
|
|
|
|
# Small SMP gets a dedicated core.
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_muxprocess_4core(self):
|
|
|
|
def test_assign_muxprocess_4core(self):
|
|
|
|
# Big SMP gets a dedicated core.
|
|
|
|
# Big SMP gets a dedicated core.
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
policy.assign_muxprocess(0)
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_worker_1core(self):
|
|
|
|
def test_assign_worker_1core(self):
|
|
|
|
# Balance n % 1
|
|
|
|
# Balance n % 1
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_worker_2core(self):
|
|
|
|
def test_assign_worker_2core(self):
|
|
|
|
# Balance n % 1
|
|
|
|
# Balance n % 1
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_worker_3core(self):
|
|
|
|
def test_assign_worker_3core(self):
|
|
|
|
# Balance n % 1
|
|
|
|
# Balance n % 1
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x4, policy.mask)
|
|
|
|
self.assertEqual(0x4, policy.mask)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_worker_4core(self):
|
|
|
|
def test_assign_worker_4core(self):
|
|
|
|
# Balance n % 1
|
|
|
|
# Balance n % 1
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(4, policy.mask)
|
|
|
|
self.assertEqual(4, policy.mask)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(8, policy.mask)
|
|
|
|
self.assertEqual(8, policy.mask)
|
|
|
|
policy.assign_worker()
|
|
|
|
policy.assign_worker()
|
|
|
|
self.assertEquals(4, policy.mask)
|
|
|
|
self.assertEqual(4, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_subprocess_1core(self):
|
|
|
|
def test_assign_subprocess_1core(self):
|
|
|
|
# allow all except reserved.
|
|
|
|
# allow all except reserved.
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy = self.klass(cpu_count=1)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x1, policy.mask)
|
|
|
|
self.assertEqual(0x1, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_subprocess_2core(self):
|
|
|
|
def test_assign_subprocess_2core(self):
|
|
|
|
# allow all except reserved.
|
|
|
|
# allow all except reserved.
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy = self.klass(cpu_count=2)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x2, policy.mask)
|
|
|
|
self.assertEqual(0x2, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_subprocess_3core(self):
|
|
|
|
def test_assign_subprocess_3core(self):
|
|
|
|
# allow all except reserved.
|
|
|
|
# allow all except reserved.
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy = self.klass(cpu_count=3)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x2 + 0x4, policy.mask)
|
|
|
|
self.assertEqual(0x2 + 0x4, policy.mask)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x2 + 0x4, policy.mask)
|
|
|
|
self.assertEqual(0x2 + 0x4, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
def test_assign_subprocess_4core(self):
|
|
|
|
def test_assign_subprocess_4core(self):
|
|
|
|
# allow all except reserved.
|
|
|
|
# allow all except reserved.
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy = self.klass(cpu_count=4)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x4 + 0x8, policy.mask)
|
|
|
|
self.assertEqual(0x4 + 0x8, policy.mask)
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
self.assertEquals(0x4 + 0x8, policy.mask)
|
|
|
|
self.assertEqual(0x4 + 0x8, policy.mask)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@unittest2.skipIf(
|
|
|
|
@unittest.skipIf(
|
|
|
|
reason='Linux/SMP only',
|
|
|
|
reason='Linux/SMP only',
|
|
|
|
condition=(not (
|
|
|
|
condition=(not (
|
|
|
|
os.uname()[0] == 'Linux' and
|
|
|
|
os.uname()[0] == 'Linux' and
|
|
|
@ -186,13 +184,13 @@ class LinuxPolicyTest(testlib.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_cpu_mask(self):
|
|
|
|
def test_set_cpu_mask(self):
|
|
|
|
self.policy._set_cpu_mask(0x1)
|
|
|
|
self.policy._set_cpu_mask(0x1)
|
|
|
|
self.assertEquals(0x1, self._get_cpus())
|
|
|
|
self.assertEqual(0x1, self._get_cpus())
|
|
|
|
|
|
|
|
|
|
|
|
self.policy._set_cpu_mask(0x2)
|
|
|
|
self.policy._set_cpu_mask(0x2)
|
|
|
|
self.assertEquals(0x2, self._get_cpus())
|
|
|
|
self.assertEqual(0x2, self._get_cpus())
|
|
|
|
|
|
|
|
|
|
|
|
self.policy._set_cpu_mask(0x3)
|
|
|
|
self.policy._set_cpu_mask(0x3)
|
|
|
|
self.assertEquals(0x3, self._get_cpus())
|
|
|
|
self.assertEqual(0x3, self._get_cpus())
|
|
|
|
|
|
|
|
|
|
|
|
def test_clear_on_popen(self):
|
|
|
|
def test_clear_on_popen(self):
|
|
|
|
tf = tempfile.NamedTemporaryFile()
|
|
|
|
tf = tempfile.NamedTemporaryFile()
|
|
|
@ -223,11 +221,7 @@ class MockLinuxPolicyTest(testlib.TestCase):
|
|
|
|
for x in range(1, 4096, 32):
|
|
|
|
for x in range(1, 4096, 32):
|
|
|
|
policy.assign_subprocess()
|
|
|
|
policy.assign_subprocess()
|
|
|
|
|
|
|
|
|
|
|
|
MockLinuxPolicyTest = unittest2.skipIf(
|
|
|
|
MockLinuxPolicyTest = unittest.skipIf(
|
|
|
|
condition=(not sys.platform.startswith('linuxPolicy')),
|
|
|
|
condition=(not sys.platform.startswith('linuxPolicy')),
|
|
|
|
reason='select.select() not supported'
|
|
|
|
reason='select.select() not supported'
|
|
|
|
)(MockLinuxPolicyTest)
|
|
|
|
)(MockLinuxPolicyTest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
unittest2.main()
|
|
|
|
|
|
|
|