@@ -12,27 +12,31 @@ def teardown_module(module):
1212 PWM .cleanup ()
1313
1414
15+ def get_pwm_dir ():
16+ if kernel >= '4.1.0' :
17+ # On 4.1+, the pwm subdirectory sometimes takes different names:
18+ # .pwm or .ehrpwm, etc.
19+ results = glob .glob (
20+ "/sys/devices/platform/ocp/48302000.*/" +
21+ "48302200.*/pwm/pwmchip?/pwm0" )
22+ # We expect that there will be a result (a directory fitting
23+ # our path exists) so test that with an assertion.
24+ assert len (results ) > 0
25+ # Continue with the pwm_dir found
26+ return results [0 ]
27+ else :
28+ files = os .listdir ('/sys/devices' )
29+ ocp = '/sys/devices/' + [s for s in files if s .startswith ('ocp' )][0 ]
30+ files = os .listdir (ocp )
31+ return ocp + '/' + [s for s in files if s .startswith ('pwm_test_P9_14' )][0 ]
32+
33+
1534class TestPwmSetup :
1635 def test_start_pwm (self ):
1736 PWM .cleanup ()
1837 PWM .start ("P9_14" , 0 )
1938
20- if kernel >= '4.1.0' :
21- # On 4.1+, the pwm subdirectory sometimes takes different names:
22- # .pwm or .ehrpwm, etc.
23- results = glob .glob (
24- "/sys/devices/platform/ocp/48302000.*/" +
25- "48302200.*/pwm/pwmchip2/pwm0" )
26- # We expect that there will be a result (a directory fitting
27- # our path exists) so test that with an assertion.
28- assert len (results ) > 0
29- # Continue with the pwm_dir found
30- pwm_dir = results [0 ]
31- else :
32- files = os .listdir ('/sys/devices' )
33- ocp = '/sys/devices/' + [s for s in files if s .startswith ('ocp' )][0 ]
34- files = os .listdir (ocp )
35- pwm_dir = ocp + '/' + [s for s in files if s .startswith ('pwm_test_P9_14' )][0 ]
39+ pwm_dir = get_pwm_dir ()
3640
3741 assert os .path .exists (pwm_dir )
3842 if kernel >= '4.1.0' :
@@ -48,13 +52,7 @@ def test_start_pwm_with_polarity_one(self):
4852 PWM .cleanup ()
4953 PWM .start ("P9_14" , 0 , 2000 , 1 )
5054
51- if kernel >= '4.1.0' :
52- pwm_dir = "/sys/devices/platform/ocp/48302000.epwmss/48302200.ehrpwm/pwm/pwmchip2/pwm0"
53- else :
54- files = os .listdir ('/sys/devices' )
55- ocp = '/sys/devices/' + [s for s in files if s .startswith ('ocp' )][0 ]
56- files = os .listdir (ocp )
57- pwm_dir = ocp + '/' + [s for s in files if s .startswith ('pwm_test_P9_14' )][0 ]
55+ pwm_dir = get_pwm_dir ()
5856
5957 assert os .path .exists (pwm_dir )
6058 if kernel >= '4.1.0' :
@@ -76,13 +74,7 @@ def test_start_pwm_with_polarity_default(self):
7674 PWM .cleanup ()
7775 PWM .start ("P9_14" , 0 , 2000 )
7876
79- if kernel >= '4.1.0' :
80- pwm_dir = "/sys/devices/platform/ocp/48302000.epwmss/48302200.ehrpwm/pwm/pwmchip2/pwm0"
81- else :
82- files = os .listdir ('/sys/devices' )
83- ocp = '/sys/devices/' + [s for s in files if s .startswith ('ocp' )][0 ]
84- files = os .listdir (ocp )
85- pwm_dir = ocp + '/' + [s for s in files if s .startswith ('pwm_test_P9_14' )][0 ]
77+ pwm_dir = get_pwm_dir ()
8678
8779 assert os .path .exists (pwm_dir )
8880 if kernel >= '4.1.0' :
@@ -104,13 +96,7 @@ def test_start_pwm_with_polarity_zero(self):
10496 PWM .cleanup ()
10597 PWM .start ("P9_14" , 0 , 2000 , 0 )
10698
107- if kernel >= '4.1.0' :
108- pwm_dir = "/sys/devices/platform/ocp/48302000.epwmss/48302200.ehrpwm/pwm/pwmchip2/pwm0"
109- else :
110- files = os .listdir ('/sys/devices' )
111- ocp = '/sys/devices/' + [s for s in files if s .startswith ('ocp' )][0 ]
112- files = os .listdir (ocp )
113- pwm_dir = ocp + '/' + [s for s in files if s .startswith ('pwm_test_P9_14' )][0 ]
99+ pwm_dir = get_pwm_dir ()
114100
115101 assert os .path .exists (pwm_dir )
116102 if kernel >= '4.1.0' :
@@ -189,13 +175,7 @@ def test_pwm_duty_modified(self):
189175 PWM .cleanup ()
190176 PWM .start ("P9_14" , 0 )
191177
192- if kernel >= '4.1.0' :
193- pwm_dir = "/sys/devices/platform/ocp/48302000.epwmss/48302200.ehrpwm/pwm/pwmchip2/pwm0"
194- else :
195- files = os .listdir ('/sys/devices' )
196- ocp = '/sys/devices/' + [s for s in files if s .startswith ('ocp' )][0 ]
197- files = os .listdir (ocp )
198- pwm_dir = ocp + '/' + [s for s in files if s .startswith ('pwm_test_P9_14' )][0 ]
178+ pwm_dir = get_pwm_dir ()
199179
200180 assert os .path .exists (pwm_dir )
201181 if kernel >= '4.1.0' :
0 commit comments