@@ -493,14 +493,19 @@ def set_frequency(self, frequency) -> bool:
493493
494494class CPUScalingTest :
495495 """A class for CPU scaling test operations."""
496+
496497 test_description = ""
497498 _registry = {}
498499
499- def __init_subclass__ (cls , * , key = None , ** kwargs ):
500- """Register subclasses in the registry."""
501- super ().__init_subclass__ (** kwargs )
502- if key :
503- CPUScalingTest ._registry [key ] = cls
500+ @classmethod
501+ def register (cls , key ):
502+ """Register test classes by governor name."""
503+
504+ def decorator (test_cls ):
505+ cls ._registry [key ] = test_cls
506+ return test_cls
507+
508+ return decorator
504509
505510 def __init__ (self , policy = 0 ):
506511 """
@@ -531,7 +536,7 @@ def create(cls, governor, policy=0):
531536 if test_class is None :
532537 raise ValueError (
533538 "Governor '{}' not supported. Available: {}" .format (
534- governor , ', ' .join (sorted (cls ._registry .keys ()))
539+ governor , ", " .join (sorted (cls ._registry .keys ()))
535540 )
536541 )
537542 return test_class (policy = policy )
@@ -719,10 +724,13 @@ def test_governor(self) -> bool:
719724 Returns:
720725 bool: True if the test passes, False otherwise.
721726 """
722- raise NotImplementedError ("This method should be implemented in subclass." )
727+ raise NotImplementedError (
728+ "This method should be implemented in subclass."
729+ )
723730
724731
725- class UserspaceCPUScalingTest (CPUScalingTest , key = "userspace" ):
732+ @CPUScalingTest .register ("userspace" )
733+ class UserspaceCPUScalingTest (CPUScalingTest ):
726734 """
727735 CPU scaling test operations specific to the userspace governor.
728736 """
@@ -753,7 +761,8 @@ def test_governor(self) -> bool:
753761 )
754762
755763
756- class PerformanceCPUScalingTest (CPUScalingTest , key = "performance" ):
764+ @CPUScalingTest .register ("performance" )
765+ class PerformanceCPUScalingTest (CPUScalingTest ):
757766 """
758767 CPU scaling test operations specific to the performance and powersave
759768 governors.
@@ -779,7 +788,8 @@ def test_governor(self) -> bool:
779788 return self .test_frequency_influence (governor )
780789
781790
782- class PowersaveCPUScalingTest (CPUScalingTest , key = "powersave" ):
791+ @CPUScalingTest .register ("powersave" )
792+ class PowersaveCPUScalingTest (CPUScalingTest ):
783793 """
784794 CPU scaling test operations specific to the powersave governor.
785795 """
@@ -804,7 +814,8 @@ def test_governor(self) -> bool:
804814 return self .test_frequency_influence (governor )
805815
806816
807- class OndemandCPUScalingTest (CPUScalingTest , key = "ondemand" ):
817+ @CPUScalingTest .register ("ondemand" )
818+ class OndemandCPUScalingTest (CPUScalingTest ):
808819 """
809820 CPU scaling test operations specific to the ondemand governor.
810821 """
@@ -830,7 +841,8 @@ def test_governor(self) -> bool:
830841 return self .test_frequency_influence (governor )
831842
832843
833- class ConservativeCPUScalingTest (CPUScalingTest , key = "conservative" ):
844+ @CPUScalingTest .register ("conservative" )
845+ class ConservativeCPUScalingTest (CPUScalingTest ):
834846 """
835847 CPU scaling test operations specific to the conservative governor.
836848 """
@@ -856,7 +868,8 @@ def test_governor(self) -> bool:
856868 return self .test_frequency_influence (governor )
857869
858870
859- class SchedutilCPUScalingTest (CPUScalingTest , key = "schedutil" ):
871+ @CPUScalingTest .register ("schedutil" )
872+ class SchedutilCPUScalingTest (CPUScalingTest ):
860873 """
861874 CPU scaling test operations specific to the schedutil governor.
862875 """
0 commit comments