예제 #1
0
    def test_power8_cpu_frequencies(self):
        def mock_open(filename, *args, **kw):
            filename = filename.replace('\\', '/')
            if filename == '/proc/cpuinfo':
                data = self.POWER8_CPUINFO
            else:
                raise ValueError("unexpect open: %r" % filename)
            return six.StringIO(data)

        with mock.patch('pyperf._utils.open', create=True, side_effect=mock_open):
            metadata = {}
            perf_metadata.collect_cpu_freq(metadata, [0, 159])
            perf_metadata.collect_cpu_model(metadata)
            self.assertEqual(metadata['cpu_freq'],
                             '0,159=3425 MHz')
            self.assertEqual(metadata['cpu_machine'],
                             'PowerNV 8247-22L')
예제 #2
0
    def test_intel_cpu_frequencies(self):
        def mock_open(filename, *args, **kw):
            filename = filename.replace('\\', '/')
            if filename == '/proc/cpuinfo':
                data = self.INTEL_CPU_INFO
            elif filename == '/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver':
                data = 'DRIVER\n'
            elif filename == '/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor':
                data = 'GOVERNOR\n'
            elif filename.startswith('/sys/devices/system/cpu/cpu2'):
                raise IOError
            else:
                raise ValueError("unexpect open: %r" % filename)
            return six.StringIO(data)

        with mock.patch('pyperf._utils.open', create=True, side_effect=mock_open):
            metadata = {}
            perf_metadata.collect_cpu_freq(metadata, [0, 2])
            perf_metadata.collect_cpu_model(metadata)
            self.assertEqual(metadata['cpu_freq'],
                             '0=1288 MHz; 2=1200 MHz')
            self.assertEqual(metadata['cpu_model_name'],
                             'Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz')