Skip to content

Commit 0829f9c

Browse files
authored
Dev hardware test (#368)
* name of requirements.txt changed, digital io test fixed, eeprom user space test fixed * osensa eeprom test fix * adc, rtd hardware test * delete test_adc_read.py, revised digital io test * added hardware test workflow which requires publish * hardware test passing * pylint fix * label added to route job to the hardware test unit
1 parent 92ee644 commit 0829f9c

File tree

8 files changed

+72
-153
lines changed

8 files changed

+72
-153
lines changed

.github/workflows/build-and-publish-TestPyPI.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,26 @@ jobs:
6969
git config user.email ${{ env.commit_email }}
7070
git cherry-pick ${{ env.bump_commit }}
7171
git push origin dev
72+
Hardware_Test:
73+
needs: publish
74+
name: Hardware Tests
75+
runs-on: [self-hosted, linux, ARM64, hw-test]
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
python-version: ["3.9"]
80+
81+
steps:
82+
- name: Checkout
83+
uses: actions/checkout@v3
84+
- name: Install Dependencies
85+
run: |
86+
python -m pip install --upgrade pip
87+
python -m venv venv_hardware_test
88+
source venv_hardware_test/bin/activate
89+
python -m pip install pytest
90+
if [ -f requirements_hw_test.txt ]; then pip install -r requirements_hw_test.txt; fi
91+
- name: Test with pytest
92+
run: |
93+
source venv_hardware_test/bin/activate
94+
python -m pytest ./tests/hardware_tests
File renamed without changes.

tests/hardware_tests/test_adc_read.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

tests/hardware_tests/test_digital_io.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@
55
from edgepi.digital_input.edgepi_digital_input import EdgePiDigitalInput
66
from edgepi.digital_output.edgepi_digital_output import EdgePiDigitalOutput
77
from edgepi.digital_input.digital_input_constants import DinPins
8-
from edgepi.digital_output.digital_output_constants import DoutPins
8+
from edgepi.digital_output.digital_output_constants import DoutPins, DoutTriState
99

1010
@pytest.mark.parametrize("din_pin, dout_pin", [
1111
(DinPins.DIN1, DoutPins.DOUT1),
1212
(DinPins.DIN2, DoutPins.DOUT2),
13-
(DinPins.DIN3, DoutPins.DOUT3),
14-
(DinPins.DIN4, DoutPins.DOUT4),
15-
(DinPins.DIN5, DoutPins.DOUT5),
16-
(DinPins.DIN6, DoutPins.DOUT6),
17-
(DinPins.DIN7, DoutPins.DOUT7),
18-
(DinPins.DIN8, DoutPins.DOUT8),
13+
(DinPins.DIN3, DoutPins.DOUT3)
1914
])
2015
def test_input_state(din_pin, dout_pin):
2116
din=EdgePiDigitalInput()
2217
dout = EdgePiDigitalOutput()
18+
dout.set_dout_state(dout_pin, DoutTriState.LOW)
2319
initial_state = din.digital_input_state(din_pin)
24-
dout.set_dout_state(dout_pin, True)
20+
dout.set_dout_state(dout_pin, DoutTriState.HIGH)
2521
sleep(0.1)
2622
changed_state = din.digital_input_state(din_pin)
2723
assert initial_state is not changed_state
28-
dout.set_dout_state(dout_pin, False)
24+
dout.set_dout_state(dout_pin, DoutTriState.LOW)
2925
sleep(0.1)
3026
changed_state = din.digital_input_state(din_pin)
3127
assert initial_state is changed_state

tests/hardware_tests/test_eeprom_osensaspace.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_osensa_space_modify_1(eeprom):
5353
assert eeprom_data_origin.adc1_calib_params != eeprom_data_modify.adc1_calib_params
5454
assert eeprom_data_origin.adc2_calib_params != eeprom_data_modify.adc2_calib_params
5555

56-
eeprom.read_edgepi_data(eeprom_data_origin)
56+
eeprom.write_edgepi_data(eeprom_data_origin)
5757

5858
# TC and RTD modification
5959
def test_osensa_space_modify_2(eeprom):
@@ -97,10 +97,10 @@ def test_osensa_space_modify_3(eeprom):
9797
eeprom_data_modify = eeprom.read_edgepi_data()
9898
time.sleep(0.5)
9999

100-
eeprom_data_modify.config_key.certificate = "yeeeeeeet"
101-
eeprom_data_modify.config_key.private_key = "ajksbvjkalsbkvalva"
102-
eeprom_data_modify.data_key.certificate = "asjkdbvakjsnvjka"
103-
eeprom_data_modify.data_key.private_key = "lozxivhzlnjqq"
100+
eeprom_data_modify.config_key.certificate = "This is test string"
101+
eeprom_data_modify.config_key.private_key = "This is test string"
102+
eeprom_data_modify.data_key.certificate = "This is test string"
103+
eeprom_data_modify.data_key.private_key = "This is test string"
104104

105105
eeprom.write_edgepi_data(eeprom_data_modify)
106106
time.sleep(0.5)

tests/hardware_tests/test_eeprom_userspace.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
PATH = os.path.dirname(os.path.abspath(__file__))
1414

1515
import pytest
16-
from edgepi.eeprom.eeprom_constants import EdgePiMemoryInfo, EEPROMInfo
16+
from edgepi.eeprom.eeprom_constants import EEPROMInfo
1717
from edgepi.eeprom.edgepi_eeprom import EdgePiEEPROM
1818

1919

@@ -31,26 +31,6 @@ def read_dummy_json(file_name: str):
3131
dummy = json.load(file)
3232
return dummy
3333

34-
def test__page_write_register(eeprom):
35-
for val in range(0, 256):
36-
_logger.info(f"test__page_write_register: Test Value = {val}")
37-
data = [val]*16384
38-
initial_data = eeprom.read_user_space(0, len(data))
39-
_logger.info(f"test__page_write_register: Initial Value = {len(initial_data)}")
40-
addrx = EdgePiMemoryInfo.USER_SPACE_START_BYTE.value
41-
# pylint: disable=protected-access
42-
page_n = eeprom._EdgePiEEPROM__generate_list_of_pages(addrx, data)
43-
for indx, page in enumerate(page_n):
44-
# pylint: disable=protected-access
45-
eeprom._EdgePiEEPROM__page_write_register(addrx+(indx*EEPROMInfo.PAGE_SIZE.value), page)
46-
time.sleep(0.002)
47-
_logger.info(f"test__page_write_register: Page Written = {len(page_n)}")
48-
new_data = eeprom.read_user_space(0, len(data))
49-
_logger.info(f"test__page_write_register: New Value = {len(new_data)}")
50-
for indx, init_data in enumerate(initial_data):
51-
assert init_data != new_data[indx]
52-
assert new_data[indx] == data[indx]
53-
5434
def test_reset_user_space(eeprom):
5535
reset_vals = []
5636
eeprom.reset_user_space()

tests/hardware_tests/test_rtd_reads.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66

77

88
# This has to be manually set with temperature machine. Use this value for testing.
9-
RTD_TEMP = 50
10-
ERROR = 1
9+
RTD_TEMP = 28
10+
ERROR = 4
1111

1212

1313
@pytest.fixture(name="rtd", scope="module")
1414
def fixture_rtd():
1515
adc = EdgePiADC()
16+
adc.reset()
1617
adc.set_rtd(True)
1718
return adc
1819

1920
def test_single_sample_rtd(rtd):
2021
out = rtd.single_sample_rtd()
2122
assert out == pytest.approx(RTD_TEMP, abs=ERROR)
2223

23-
2424
def test_read_rtd_temperature(rtd):
2525
rtd.set_config(conversion_mode=ConvMode.CONTINUOUS)
26-
rtd.start_conversions(ADCNum.ADC_1)
26+
rtd.start_conversions(ADCNum.ADC_2)
2727
for _ in range(10):
2828
out = rtd.read_rtd_temperature()
2929
assert out == pytest.approx(RTD_TEMP, abs=ERROR)
30-
rtd.stop_conversions(ADCNum.ADC_1)
30+
rtd.stop_conversions(ADCNum.ADC_2)

tests/hardware_tests/test_voltage_rw.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from time import sleep
66
import pytest
77
from edgepi.adc.edgepi_adc import EdgePiADC
8-
from edgepi.adc.adc_constants import AnalogIn, ADCNum, DiffMode
8+
from edgepi.adc.adc_constants import AnalogIn, ADCNum, DiffMode, ADCChannel
99
from edgepi.dac.edgepi_dac import EdgePiDAC
1010
from edgepi.dac.dac_constants import DACChannel
1111

1212

1313
_logger = logging.getLogger(__name__)
1414

1515

16-
NUM_CHANNELS = 8
16+
NUM_CHANNELS = 2
1717
READS_PER_WRITE = 1
1818
RW_ERROR = 1e-1 # TODO: change to mV
1919
MAX_VOLTAGE = 5.0
@@ -36,6 +36,7 @@
3636
@pytest.fixture(name="adc_1", scope="module")
3737
def fixture_adc_1():
3838
adc = EdgePiADC()
39+
adc.reset()
3940
adc.start_conversions(ADCNum.ADC_1)
4041
yield adc
4142
adc.stop_conversions(ADCNum.ADC_1)
@@ -44,6 +45,7 @@ def fixture_adc_1():
4445
@pytest.fixture(name="adc_2", scope="module")
4546
def fixture_adc_2():
4647
adc = EdgePiADC()
48+
adc.reset()
4749
adc.start_conversions(ADCNum.ADC_2)
4850
yield adc
4951
adc.stop_conversions(ADCNum.ADC_2)
@@ -114,11 +116,11 @@ def _generate_diff_test_cases():
114116
f"read_write_error_tolerance: +/- {RW_ERROR} V, num_read_trials: {READS_PER_WRITE}"
115117
)
116118
)
117-
for diff in DiffMode:
118-
voltage = 0
119-
while voltage < MAX_VOLTAGE - VOLTAGE_STEP:
120-
voltage += VOLTAGE_STEP
121-
yield diff, voltage, voltage
119+
diff = DiffMode.DIFF_2
120+
voltage = 0
121+
while voltage < MAX_VOLTAGE - VOLTAGE_STEP:
122+
voltage += VOLTAGE_STEP
123+
yield diff, voltage
122124

123125

124126
def _measure_voltage_differential(
@@ -127,48 +129,52 @@ def _measure_voltage_differential(
127129
# write to DAC channel
128130
for channel, write_voltage in write_voltages.items():
129131
dac.write_voltage(channel, write_voltage)
130-
132+
write_volt = write_voltage
133+
sleep(WRITE_READ_DELAY)
131134
for _ in range(READS_PER_WRITE):
132135
read_voltage = adc.read_voltage(adc_num)
133136
_logger.info(f"diff_read_voltage = {read_voltage}")
134-
_assert_approx(0, read_voltage, RW_ERROR)
137+
_assert_approx(write_volt/2, read_voltage, RW_ERROR)
135138

136139

137140
_diff_ch_map = {
138-
AnalogIn.AIN1: DACChannel.AOUT1,
139-
AnalogIn.AIN2: DACChannel.AOUT2,
140-
AnalogIn.AIN3: DACChannel.AOUT3,
141-
AnalogIn.AIN4: DACChannel.AOUT4,
142-
AnalogIn.AIN5: DACChannel.AOUT5,
143-
AnalogIn.AIN6: DACChannel.AOUT6,
144-
AnalogIn.AIN7: DACChannel.AOUT7,
145-
AnalogIn.AIN8: DACChannel.AOUT8,
141+
ADCChannel.AIN0: DACChannel.AOUT1,
142+
ADCChannel.AIN1: DACChannel.AOUT2,
143+
ADCChannel.AIN2: DACChannel.AOUT3,
144+
ADCChannel.AIN3: DACChannel.AOUT4,
145+
ADCChannel.AIN4: DACChannel.AOUT5,
146+
ADCChannel.AIN5: DACChannel.AOUT6,
147+
ADCChannel.AIN6: DACChannel.AOUT7,
148+
ADCChannel.AIN7: DACChannel.AOUT8,
146149
}
147150

148151

149-
@pytest.mark.parametrize("diff, mux_p_volt, mux_n_volt", _generate_diff_test_cases())
150-
def test_differential_rw_adc_1(diff, mux_p_volt, mux_n_volt, adc_1, dac):
152+
@pytest.mark.parametrize("diff, mux_p_volt", _generate_diff_test_cases())
153+
def test_differential_rw_adc_1(diff, mux_p_volt, adc_1, dac):
151154
adc_1.select_differential(ADCNum.ADC_1, diff)
155+
adc_1.start_conversions(ADCNum.ADC_1)
152156
_logger.info(
153157
f"voltage read/write diff pair: mux_p = {diff.value.mux_p}, mux_n = {diff.value.mux_n}"
154158
)
155-
_logger.info(f"mux_p_write_voltage = {mux_p_volt}, mux_n_write_voltage = {mux_n_volt}")
159+
_logger.info(f"mux_p_write_voltage = {mux_p_volt}")
156160
write_voltages = {
157-
_diff_ch_map[diff.value.mux_p]: mux_p_volt,
158-
_diff_ch_map[diff.value.mux_n]: mux_n_volt,
161+
_diff_ch_map[diff.value.mux_p]: mux_p_volt
159162
}
160163
_measure_voltage_differential(adc_1, dac, ADCNum.ADC_1, write_voltages)
164+
adc_1.stop_conversions(ADCNum.ADC_1)
165+
161166

162167

163-
@pytest.mark.parametrize("diff, mux_p_volt, mux_n_volt", _generate_diff_test_cases())
164-
def test_differential_rw_adc_2(diff, mux_p_volt, mux_n_volt, adc_2, dac):
168+
@pytest.mark.parametrize("diff, mux_p_volt", _generate_diff_test_cases())
169+
def test_differential_rw_adc_2(diff, mux_p_volt, adc_2, dac):
165170
adc_2.select_differential(ADCNum.ADC_2, diff)
171+
adc_2.start_conversions(ADCNum.ADC_2)
166172
_logger.info(
167173
f"voltage read/write diff pair: mux_p = {diff.value.mux_p}, mux_n = {diff.value.mux_n}"
168174
)
169-
_logger.info(f"mux_p_write_voltage = {mux_p_volt}, mux_n_write_voltage = {mux_n_volt}")
175+
_logger.info(f"mux_p_write_voltage = {mux_p_volt}")
170176
write_voltages = {
171-
_diff_ch_map[diff.value.mux_p]: mux_p_volt,
172-
_diff_ch_map[diff.value.mux_n]: mux_n_volt,
177+
_diff_ch_map[diff.value.mux_p]: mux_p_volt
173178
}
174179
_measure_voltage_differential(adc_2, dac, ADCNum.ADC_2, write_voltages)
180+
adc_2.stop_conversions(ADCNum.ADC_2)

0 commit comments

Comments
 (0)