1717import random
1818import pytest
1919from tests import common
20- from pepclibs import CPUInfo , CPUOnline
20+ from pepclibs import CPUInfoVars
2121from pepclibs .helperlibs import Trivial
2222
2323if typing .TYPE_CHECKING :
2424 from typing import Generator , cast , TypedDict
2525 from tests .common import CommonTestParamsTypedDict
26+ from pepclibs import CPUInfo
2627 from pepclibs .helperlibs .ProcessManager import ProcessManagerType
2728 from pepclibs .CPUInfoTypes import AbsNumsType , RelNumsType , ScopeNameType
2829
@@ -111,7 +112,7 @@ def _get_snames_and_nums(cpuinfo: CPUInfo.CPUInfo) -> \
111112 A tuple containing the scope name and the result of '_get_scope_nums()' for that scope name.
112113 """
113114
114- for sname in CPUInfo .SCOPE_NAMES :
115+ for sname in CPUInfoVars .SCOPE_NAMES :
115116 yield (sname , _get_scope_nums (sname , cpuinfo ))
116117
117118def _get_expected_topology (full_tlines : list [dict [ScopeNameType , int ]],
@@ -197,61 +198,6 @@ def _validate_topo(cpuinfo: CPUInfo.CPUInfo, exp_topo: _ExpectedTopology):
197198 f"get_compute_dies() returned { dies [pkg ]} for package { pkg } , " \
198199 f"expected { exp_topo ['dies' ][pkg ]} "
199200
200- def _get_cpuinfos (params : CommonTestParamsTypedDict ) -> Generator [CPUInfo .CPUInfo , None , None ]:
201- """
202- Yield 'CPUInfo' objects for testing based on the host type.
203-
204- This generator yields CPUInfo objects with different CPU online/offline patterns:
205- 1. All CPUs online (initial state)
206- 2. Odd-numbered CPUs offline
207- 3. Even-numbered CPUs offline (excluding CPU 0)
208-
209- Args:
210- params: Dictionary containing test parameters.
211-
212- Yields:
213- 'CPUInfo' objects configured according to the host type for use in tests.
214- """
215-
216- pman = params ["pman" ]
217-
218- with CPUInfo .CPUInfo (pman = pman ) as cpuinfo :
219- full_tlines = list (cpuinfo .get_topology ())
220-
221- # Ensure that all CPUs are online.
222- with CPUOnline .CPUOnline (pman = pman , cpuinfo = cpuinfo ) as cpuonline :
223- cpuonline .online ()
224-
225- full_exp_topo = _get_expected_topology (full_tlines , set ())
226-
227- with CPUInfo .CPUInfo (pman = pman ) as cpuinfo , \
228- CPUOnline .CPUOnline (pman = pman , cpuinfo = cpuinfo ) as cpuonline :
229- # Pattern 0: All CPUs online
230- yield cpuinfo
231- _validate_topo (cpuinfo , full_exp_topo )
232-
233- # Pattern 1: Take odd-numbered CPUs offline.
234- all_cpus = cpuinfo .get_cpus ()
235- odd_cpus = [cpu for cpu in all_cpus if cpu % 2 == 1 ]
236-
237- if odd_cpus :
238- cpuonline .offline (cpus = odd_cpus )
239- yield cpuinfo
240- _validate_topo (cpuinfo , _get_expected_topology (full_tlines , set (odd_cpus )))
241-
242- cpuonline .online (cpus = odd_cpus )
243- _validate_topo (cpuinfo , full_exp_topo )
244-
245- # Pattern 2: Take even-numbered CPUs offline, excluding CPU 0, which can't be offlined.
246- even_cpus = [cpu for cpu in all_cpus if cpu % 2 == 0 and cpu != 0 ]
247- if even_cpus :
248- cpuonline .offline (cpus = even_cpus )
249- yield cpuinfo
250- _validate_topo (cpuinfo , _get_expected_topology (full_tlines , set (even_cpus )))
251-
252- cpuonline .online (cpus = even_cpus )
253- _validate_topo (cpuinfo , full_exp_topo )
254-
255201def _run_method (name : str ,
256202 cpuinfo : CPUInfo .CPUInfo ,
257203 args : list | tuple | None = None ,
@@ -330,7 +276,7 @@ def _test_get_good(cpuinfo: CPUInfo.CPUInfo):
330276 assert ref_nums , \
331277 f"'get_{ sname } s()' is expected to return list of { sname } s, got: '{ ref_nums } '"
332278
333- for order in CPUInfo .SCOPE_NAMES :
279+ for order in CPUInfoVars .SCOPE_NAMES :
334280 nums = _get_scope_nums (sname , cpuinfo , order = order )
335281 if sname in ("die" , "core" ):
336282 # For dies and cores, the numbers are relative to the package numbers.
@@ -360,7 +306,7 @@ def test_cpuinfo_get(params: CommonTestParamsTypedDict):
360306 params: The test parameters.
361307 """
362308
363- for cpuinfo in _get_cpuinfos (params ):
309+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
364310 _test_get_good (cpuinfo )
365311
366312def test_cpuinfo_get_count (params : CommonTestParamsTypedDict ):
@@ -371,7 +317,7 @@ def test_cpuinfo_get_count(params: CommonTestParamsTypedDict):
371317 params: The test parameters.
372318 """
373319
374- for cpuinfo in _get_cpuinfos (params ):
320+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
375321 for sname , nums in _get_snames_and_nums (cpuinfo ):
376322 if sname in ("core" , "die" ):
377323 if typing .TYPE_CHECKING :
@@ -445,7 +391,7 @@ def test_cpuinfo_convert(params: CommonTestParamsTypedDict):
445391 params: The test parameters.
446392 """
447393
448- for cpuinfo in _get_cpuinfos (params ):
394+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
449395 _test_convert_good (cpuinfo )
450396
451397def _test_normalize_good (cpuinfo : CPUInfo .CPUInfo ):
@@ -512,7 +458,7 @@ def test_cpuinfo_normalize(params: CommonTestParamsTypedDict):
512458 params: The test parameters.
513459 """
514460
515- for cpuinfo in _get_cpuinfos (params ):
461+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
516462 _test_normalize_good (cpuinfo )
517463
518464def _is_globally_numbered (sname : ScopeNameType ) -> bool :
@@ -657,7 +603,7 @@ def test_cpuinfo_div(params: CommonTestParamsTypedDict):
657603 params: The test parameters.
658604 """
659605
660- for cpuinfo in _get_cpuinfos (params ):
606+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
661607 _test_cpuinfo_div (cpuinfo )
662608
663609def test_core_siblings (params : CommonTestParamsTypedDict ):
@@ -668,7 +614,7 @@ def test_core_siblings(params: CommonTestParamsTypedDict):
668614 params: The test parameters.
669615 """
670616
671- for cpuinfo in _get_cpuinfos (params ):
617+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
672618 topology = cpuinfo .get_topology (order = "core" )
673619
674620 # We get the CPU siblings count for the first core in the topology list. Depending on how
@@ -720,7 +666,7 @@ def test_delayed_init(params: CommonTestParamsTypedDict):
720666
721667 # pylint: disable=protected-access
722668
723- for cpuinfo in _get_cpuinfos (params ):
669+ for cpuinfo in common . get_cpuinfos (params [ "pman" ] ):
724670 # A newly created 'CPUInfo' object should not have any topology initialized.
725671 assert "CPU" not in cpuinfo ._initialized_snames , "'CPU' scope should not be initialized"
726672 assert "die" not in cpuinfo ._initialized_snames , "'die' scope should not be initialized"
0 commit comments