|
3 | 3 | require_relative '../lib/benchmark_runner' |
4 | 4 |
|
5 | 5 | describe CPUConfig do |
| 6 | + describe '.build' do |
| 7 | + it 'returns IntelCPUConfig when Intel pstate files exist' do |
| 8 | + File.stub :exist?, ->(path) { path.include?('intel_pstate') } do |
| 9 | + config = CPUConfig.build |
| 10 | + assert_instance_of IntelCPUConfig, config |
| 11 | + end |
| 12 | + end |
| 13 | + |
| 14 | + it 'returns AMDCPUConfig when AMD cpufreq files exist' do |
| 15 | + File.stub :exist?, ->(path) { path.include?('cpufreq/boost') } do |
| 16 | + config = CPUConfig.build |
| 17 | + assert_instance_of AMDCPUConfig, config |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + it 'returns NullCPUConfig when no CPU files exist' do |
| 22 | + File.stub :exist?, false do |
| 23 | + config = CPUConfig.build |
| 24 | + assert_instance_of NullCPUConfig, config |
| 25 | + end |
| 26 | + end |
| 27 | + end |
| 28 | +end |
| 29 | + |
| 30 | +describe NullCPUConfig do |
6 | 31 | describe '#configure_for_benchmarking' do |
7 | 32 | it 'does nothing when CPU frequency files do not exist' do |
8 | 33 | call_count = 0 |
9 | 34 | at_exit_called = false |
10 | 35 | exit_called = false |
11 | 36 |
|
12 | 37 | File.stub :exist?, false do |
13 | | - cpu_config = CPUConfig.new |
| 38 | + cpu_config = NullCPUConfig.new |
14 | 39 | cpu_config.stub :at_exit, ->(&block) { at_exit_called = true } do |
15 | 40 | cpu_config.stub :exit, ->(code) { exit_called = true } do |
16 | 41 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) { call_count += 1 } do |
|
25 | 50 | end |
26 | 51 | end |
27 | 52 | end |
| 53 | + end |
| 54 | +end |
28 | 55 |
|
| 56 | +describe IntelCPUConfig do |
| 57 | + describe '#configure_for_benchmarking' do |
29 | 58 | it 'does not call commands or exit when Intel CPU is already properly configured with turbo disabled' do |
30 | 59 | call_count = 0 |
31 | 60 | at_exit_called = false |
32 | 61 | exit_called = false |
33 | 62 |
|
34 | 63 | File.stub :exist?, ->(path) { path.include?('intel_pstate') } do |
35 | | - cpu_config = CPUConfig.new |
| 64 | + cpu_config = IntelCPUConfig.new |
36 | 65 | cpu_config.stub :at_exit, ->(&block) { at_exit_called = true } do |
37 | 66 | cpu_config.stub :exit, ->(code) { exit_called = true } do |
38 | 67 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) { call_count += 1 } do |
|
62 | 91 | exit_called = false |
63 | 92 |
|
64 | 93 | File.stub :exist?, ->(path) { path.include?('intel_pstate') } do |
65 | | - cpu_config = CPUConfig.new |
| 94 | + cpu_config = IntelCPUConfig.new |
66 | 95 | cpu_config.stub :at_exit, ->(&block) { at_exit_called = true } do |
67 | 96 | cpu_config.stub :exit, ->(code) { exit_called = true } do |
68 | 97 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) { call_count += 1 } do |
|
94 | 123 | read_count = 0 |
95 | 124 |
|
96 | 125 | File.stub :exist?, ->(path) { path.include?('intel_pstate') } do |
97 | | - cpu_config = CPUConfig.new |
| 126 | + cpu_config = IntelCPUConfig.new |
98 | 127 | cpu_config.stub :at_exit, ->(&block) { at_exit_called = true; at_exit_block = block } do |
99 | 128 | cpu_config.stub :exit, ->(code) { exit_called = true } do |
100 | 129 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) { call_count += 1 } do |
|
138 | 167 | exit_code = nil |
139 | 168 | output = capture_io do |
140 | 169 | File.stub :exist?, ->(path) { path.include?('intel_pstate') } do |
141 | | - cpu_config = CPUConfig.new |
| 170 | + cpu_config = IntelCPUConfig.new |
142 | 171 | cpu_config.stub :at_exit, ->(&block) {} do |
143 | 172 | cpu_config.stub :exit, ->(code) { exit_code = code } do |
144 | 173 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) {} do |
|
166 | 195 | exit_code = nil |
167 | 196 | output = capture_io do |
168 | 197 | File.stub :exist?, ->(path) { path.include?('intel_pstate') } do |
169 | | - cpu_config = CPUConfig.new |
| 198 | + cpu_config = IntelCPUConfig.new |
170 | 199 | cpu_config.stub :at_exit, ->(&block) {} do |
171 | 200 | cpu_config.stub :exit, ->(code) { exit_code = code } do |
172 | 201 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) {} do |
|
189 | 218 | assert_includes output[0], "You forgot to set the min perf percentage to 100" |
190 | 219 | assert_includes output[0], "sudo sh -c 'echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct'" |
191 | 220 | end |
| 221 | + end |
| 222 | +end |
192 | 223 |
|
| 224 | +describe AMDCPUConfig do |
| 225 | + describe '#configure_for_benchmarking' do |
193 | 226 | it 'does not call commands or exit when AMD CPU is already properly configured with turbo disabled' do |
194 | 227 | call_count = 0 |
195 | 228 | at_exit_called = false |
196 | 229 | exit_called = false |
197 | 230 |
|
198 | 231 | File.stub :exist?, ->(path) { path.include?('cpufreq/boost') } do |
199 | | - cpu_config = CPUConfig.new |
| 232 | + cpu_config = AMDCPUConfig.new |
200 | 233 | cpu_config.stub :at_exit, ->(&block) { at_exit_called = true } do |
201 | 234 | cpu_config.stub :exit, ->(code) { exit_called = true } do |
202 | 235 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) { call_count += 1 } do |
|
230 | 263 | read_count = 0 |
231 | 264 |
|
232 | 265 | File.stub :exist?, ->(path) { path.include?('cpufreq/boost') } do |
233 | | - cpu_config = CPUConfig.new |
| 266 | + cpu_config = AMDCPUConfig.new |
234 | 267 | cpu_config.stub :at_exit, ->(&block) { at_exit_called = true; at_exit_block = block } do |
235 | 268 | cpu_config.stub :exit, ->(code) { exit_called = true } do |
236 | 269 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) { call_count += 1 } do |
|
273 | 306 | exit_code = nil |
274 | 307 | output = capture_io do |
275 | 308 | File.stub :exist?, ->(path) { path.include?('cpufreq/boost') } do |
276 | | - cpu_config = CPUConfig.new |
| 309 | + cpu_config = AMDCPUConfig.new |
277 | 310 | cpu_config.stub :at_exit, ->(&block) {} do |
278 | 311 | cpu_config.stub :exit, ->(code) { exit_code = code } do |
279 | 312 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) {} do |
|
303 | 336 | exit_code = nil |
304 | 337 | output = capture_io do |
305 | 338 | File.stub :exist?, ->(path) { path.include?('cpufreq/boost') } do |
306 | | - cpu_config = CPUConfig.new |
| 339 | + cpu_config = AMDCPUConfig.new |
307 | 340 | cpu_config.stub :at_exit, ->(&block) {} do |
308 | 341 | cpu_config.stub :exit, ->(code) { exit_code = code } do |
309 | 342 | BenchmarkRunner.stub :check_call, ->(*_args, **_kwargs) {} do |
|
0 commit comments