Пример #1
0
        mock_setaffinity.assert_called_once_with([3, 7])

    def test_cpu_affinity_isolcpus(self):
        runner = perf.text_runner.TextRunner('bench')
        runner.parse_args(['-v'])

        with mock.patch('perf.text_runner.set_cpu_affinity') as mock_setaffinity:
            with mock.patch('perf.text_runner.get_isolated_cpus', return_value=[1, 2]):
                with tests.capture_stdout() as stdout:
                    runner._cpu_affinity()

        self.assertEqual(runner.args.affinity, '1-2')
        self.assertEqual(stdout.getvalue(),
                         'Pin process to isolated CPUs: 1-2\n')
        mock_setaffinity.assert_called_once_with([1, 2])

    def test_cpu_affinity_no_isolcpus(self):
        runner = perf.text_runner.TextRunner('bench')
        runner.parse_args(['-v'])

        with mock.patch('perf.text_runner.set_cpu_affinity') as mock_setaffinity:
            with mock.patch('perf.text_runner.get_isolated_cpus', return_value=None):
                runner._cpu_affinity()

        self.assertFalse(runner.args.affinity)
        self.assertEqual(mock_setaffinity.call_count, 0)


if __name__ == "__main__":
    unittest.main()
Пример #2
0
    def test_cpu_affinity_isolcpus(self):
        runner = perf.Runner()
        runner.parse_args(['-v'])

        with mock.patch('perf._runner.set_cpu_affinity') as mock_setaffinity:
            with mock.patch('perf._runner.get_isolated_cpus',
                            return_value=[1, 2]):
                with tests.capture_stdout() as stdout:
                    runner._cpu_affinity()

        self.assertEqual(runner.args.affinity, '1-2')
        self.assertEqual(stdout.getvalue(),
                         'Pin process to isolated CPUs: 1-2\n')
        mock_setaffinity.assert_called_once_with([1, 2])

    def test_cpu_affinity_no_isolcpus(self):
        runner = perf.Runner()
        runner.parse_args(['-v'])

        with mock.patch('perf._runner.set_cpu_affinity') as mock_setaffinity:
            with mock.patch('perf._runner.get_isolated_cpus',
                            return_value=None):
                runner._cpu_affinity()

        self.assertFalse(runner.args.affinity)
        self.assertEqual(mock_setaffinity.call_count, 0)


if __name__ == "__main__":
    unittest.main()