(dirname, monkeypatch)
| 21 | |
| 22 | @pytest.mark.parametrize("dirname", ["cpuacct,cpu", "cpu,cpuacct", None]) |
| 23 | def test_cpu_count_cgroups(dirname, monkeypatch): |
| 24 | def mycpu_count(): |
| 25 | # Absurdly high, unlikely to match real value |
| 26 | return 250 |
| 27 | |
| 28 | monkeypatch.setattr(os, "cpu_count", mycpu_count) |
| 29 | |
| 30 | class MyProcess: |
| 31 | def cpu_affinity(self): |
| 32 | # No affinity set |
| 33 | return [] |
| 34 | |
| 35 | monkeypatch.setattr(psutil, "Process", MyProcess) |
| 36 | |
| 37 | if dirname: |
| 38 | paths = { |
| 39 | "/sys/fs/cgroup/%s/cpu.cfs_quota_us" % dirname: io.StringIO("2005"), |
| 40 | "/sys/fs/cgroup/%s/cpu.cfs_period_us" % dirname: io.StringIO("10"), |
| 41 | } |
| 42 | builtin_open = builtins.open |
| 43 | |
| 44 | def myopen(path, *args, **kwargs): |
| 45 | if path in paths: |
| 46 | return paths.get(path) |
| 47 | return builtin_open(path, *args, **kwargs) |
| 48 | |
| 49 | monkeypatch.setattr(builtins, "open", myopen) |
| 50 | monkeypatch.setattr(sys, "platform", "linux") |
| 51 | |
| 52 | count = cpu_count() |
| 53 | if dirname: |
| 54 | # Rounds up |
| 55 | assert count == 201 |
| 56 | else: |
| 57 | assert count == 250 |
| 58 | |
| 59 | |
| 60 | @pytest.mark.parametrize("group_name", ["/", "/user.slice", "/user.slice/more.slice"]) |
nothing calls this directly
no test coverage detected