Skip to content

Commit 76b3e78

Browse files
committed
Update ADC test to handle Linux 4.1+ kernel
1 parent 9fe7d1f commit 76b3e78

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/test_adc.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#debian@beaglebone:~/adafruit-beaglebone-io-python/test$ cat test_adc.py
12
import pytest
23
import os
3-
4+
import platform
45
import Adafruit_BBIO.ADC as ADC
56

7+
68
def teardown_module(module):
79
pass
810
#ADC.cleanup()
@@ -17,14 +19,20 @@ def test_read_raw_adc_no_setup(self):
1719
ADC.read_raw("P9_40")
1820

1921
def test_setup_adc(self):
20-
ADC.setup()
2122

22-
files = os.listdir('/sys/devices')
23-
ocp = '/sys/devices/'+[s for s in files if s.startswith('ocp')][0]
24-
files = os.listdir(ocp)
25-
helper_path = ocp+'/'+[s for s in files if s.startswith('helper')][0]
23+
ADC.setup()
2624

27-
assert os.path.exists(helper_path + "/AIN1")
25+
kernel = platform.release()
26+
if kernel >= '4.1.0':
27+
test_path = "/sys/bus/iio/devices/iio:device0/in_voltage1_raw"
28+
else:
29+
files = os.listdir('/sys/devices')
30+
ocp = '/sys/devices/'+[s for s in files if s.startswith('ocp')][0]
31+
files = os.listdir(ocp)
32+
helper_path = ocp+'/'+[s for s in files if s.startswith('helper')][0]
33+
test_path = helper_path + "/AIN1"
34+
35+
assert os.path.exists(test_path);
2836
#ADC.cleanup()
2937

3038
def test_read_adc(self):
@@ -50,4 +58,4 @@ def test_many_read_adc(self):
5058
start = time.time()
5159
value = -1
5260
value = ADC.read("AIN1")
53-
assert value != -1
61+
assert value != -1

0 commit comments

Comments
 (0)