Skip to content

Commit fc085f3

Browse files
committed
update tests
1 parent b99e395 commit fc085f3

File tree

2 files changed

+84
-75
lines changed

2 files changed

+84
-75
lines changed

tests/periman/periman.ino

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131

3232
/* Global variables */
3333

34+
bool test_executed = false;
3435
String last_test = "";
35-
int8_t uart1_rx_pin;
36-
int8_t uart1_tx_pin;
36+
int8_t uart1_rx_pin = UART1_RX_DEFAULT;
37+
int8_t uart1_tx_pin = UART1_TX_DEFAULT;
3738

3839
/* Callback functions */
3940

@@ -59,13 +60,17 @@ void setUp(void) {
5960
// This function is automatically called by unity after each test is run
6061
void tearDown(void) {
6162
log_v("Tearing down last test");
62-
Serial1.print(last_test);
63-
Serial1.println(" test: This should not be printed");
64-
Serial1.flush();
63+
if (test_executed) {
64+
Serial1.print(last_test);
65+
Serial1.println(" test: This should not be printed");
66+
Serial1.flush();
67+
68+
Serial1.setPins(uart1_rx_pin, uart1_tx_pin);
69+
uart_internal_loopback(1, RX1);
70+
delay(100);
71+
test_executed = false;
72+
}
6573

66-
Serial1.setPins(uart1_rx_pin, uart1_tx_pin);
67-
uart_internal_loopback(1, RX1);
68-
delay(100);
6974
Serial1.print(last_test);
7075
Serial1.println(" test: This should be printed");
7176
Serial1.flush();
@@ -75,35 +80,48 @@ void tearDown(void) {
7580
/* These functions must only init the peripheral on the same pins and update "last_test" */
7681

7782
void gpio_test(void) {
83+
last_test = "GPIO";
84+
test_executed = true;
7885
pinMode(uart1_rx_pin, INPUT);
7986
pinMode(uart1_tx_pin, OUTPUT);
80-
last_test = "GPIO";
8187
}
8288

83-
#if SOC_SDM_SUPPORTED
8489
void sigmadelta_test(void) {
90+
last_test = "SigmaDelta";
91+
#if SOC_SDM_SUPPORTED
92+
test_executed = true;
8593
if (!sigmaDeltaAttach(uart1_tx_pin, 312500)) {
8694
TEST_FAIL_MESSAGE("SigmaDelta init failed");
8795
}
88-
last_test = "SigmaDelta";
89-
}
96+
if (!sigmaDeltaAttach(uart1_rx_pin, 312500)) {
97+
TEST_FAIL_MESSAGE("SigmaDelta init failed");
98+
}
9099
#endif
100+
}
91101

92-
#if SOC_ADC_SUPPORTED
93102
void adc_oneshot_test(void) {
103+
last_test = "ADC Oneshot";
104+
#if SOC_ADC_SUPPORTED
105+
test_executed = true;
94106
analogReadResolution(12);
107+
analogRead(A3);
95108
analogRead(A4);
96-
last_test = "ADC Oneshot";
109+
#endif
97110
}
98111

112+
#if SOC_ADC_SUPPORTED
99113
volatile bool adc_coversion_done = false;
100114
void ARDUINO_ISR_ATTR adcComplete() {
101115
adc_coversion_done = true;
102116
}
117+
#endif
103118

104119
void adc_continuous_test(void) {
105-
uint8_t adc_pins[] = {A4};
106-
uint8_t adc_pins_count = 1;
120+
last_test = "ADC Continuous";
121+
#if SOC_ADC_SUPPORTED
122+
test_executed = true;
123+
uint8_t adc_pins[] = {A3, A4};
124+
uint8_t adc_pins_count = 2;
107125
adc_continuos_data_t * result = NULL;
108126

109127
analogContinuousSetWidth(12);
@@ -121,78 +139,89 @@ void adc_continuous_test(void) {
121139
}
122140

123141
analogContinuousStop();
124-
125-
last_test = "ADC Continuous";
126-
}
127142
#endif
143+
}
128144

129-
#if SOC_DAC_SUPPORTED
130145
void dac_test(void) {
131-
dacWrite(DAC1, 255);
132146
last_test = "DAC";
133-
}
147+
#if SOC_DAC_SUPPORTED
148+
test_executed = true;
149+
dacWrite(DAC1, 255);
150+
dacWrite(DAC2, 255);
134151
#endif
152+
}
135153

136-
#if SOC_LEDC_SUPPORTED
137154
void ledc_test(void) {
155+
last_test = "LEDC";
156+
#if SOC_LEDC_SUPPORTED
157+
test_executed = true;
158+
if (!ledcAttach(uart1_tx_pin, 5000, 12)) {
159+
TEST_FAIL_MESSAGE("LEDC init failed");
160+
}
138161
if (!ledcAttach(uart1_rx_pin, 5000, 12)) {
139162
TEST_FAIL_MESSAGE("LEDC init failed");
140163
}
141-
last_test = "LEDC";
142-
}
143164
#endif
165+
}
144166

145-
#if SOC_RMT_SUPPORTED
146167
void rmt_test(void) {
168+
last_test = "RMT";
169+
#if SOC_RMT_SUPPORTED
170+
test_executed = true;
147171
if (!rmtInit(uart1_rx_pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
148172
TEST_FAIL_MESSAGE("RMT init failed");
149173
}
150174
if (!rmtInit(uart1_tx_pin, RMT_RX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
151175
TEST_FAIL_MESSAGE("RMT init failed");
152176
}
153-
last_test = "RMT";
154-
}
155177
#endif
178+
}
156179

157-
#if SOC_I2S_SUPPORTED
158180
void i2s_test(void) {
181+
last_test = "I2S";
182+
#if SOC_I2S_SUPPORTED
183+
test_executed = true;
159184
I2SClass i2s;
160185

161186
i2s.setPins(uart1_rx_pin, uart1_tx_pin, -1);
162187
i2s.setTimeout(1000);
163188
if (!i2s.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO)) {
164189
TEST_FAIL_MESSAGE("I2S init failed");
165190
}
166-
last_test = "I2S";
167-
}
168191
#endif
192+
}
169193

170-
#if SOC_I2C_SUPPORTED
171194
void i2c_test(void) {
195+
last_test = "I2C";
196+
#if SOC_I2C_SUPPORTED
197+
test_executed = true;
172198
if (!Wire.begin(uart1_rx_pin, uart1_tx_pin)) {
173199
TEST_FAIL_MESSAGE("I2C init failed");
174200
}
175-
last_test = "I2C";
176-
}
177201
#endif
202+
}
178203

179-
#if SOC_GPSPI_SUPPORTED
180204
void spi_test(void) {
181-
SPI.begin(uart1_rx_pin, uart1_tx_pin, -1, -1);
182205
last_test = "SPI";
183-
}
206+
#if SOC_GPSPI_SUPPORTED
207+
test_executed = true;
208+
SPI.begin(uart1_rx_pin, uart1_tx_pin, -1, -1);
184209
#endif
210+
}
185211

186-
#if SOC_TOUCH_SENSOR_SUPPORTED
187212
void touch_test(void) {
188-
touchRead(T1);
189213
last_test = "Touch";
190-
}
214+
#if SOC_TOUCH_SENSOR_SUPPORTED
215+
test_executed = true;
216+
touchRead(T1);
217+
touchRead(T2);
191218
#endif
219+
}
192220

193221
void eth_test(void) {
194-
ETH.begin();
195222
last_test = "ETH";
223+
test_executed = true;
224+
ETH.begin();
196225
}
197226

198227
/* Main functions */
@@ -204,56 +233,28 @@ void setup() {
204233
Serial1.setPins(UART1_RX_DEFAULT, UART1_TX_DEFAULT);
205234
Serial1.begin(115200);
206235
while(!Serial1) { delay(10); }
207-
Serial1.onReceive([]() {onReceive_cb();});
236+
Serial1.onReceive(onReceive_cb);
208237
uart_internal_loopback(1, RX1);
209238

210239
UNITY_BEGIN();
211240

212-
uart1_rx_pin = UART1_RX_DEFAULT;
213-
uart1_tx_pin = UART1_TX_DEFAULT;
214-
215241
RUN_TEST(gpio_test);
216-
217-
#if SOC_SDM_SUPPORTED
218242
RUN_TEST(sigmadelta_test);
219-
#endif
220-
221-
#if SOC_LEDC_SUPPORTED
222243
RUN_TEST(ledc_test);
223-
#endif
224-
225-
#if SOC_RMT_SUPPORTED
226244
RUN_TEST(rmt_test);
227-
#endif
228-
229-
#if SOC_I2S_SUPPORTED
230245
RUN_TEST(i2s_test);
231-
#endif
232-
233-
#if SOC_I2C_SUPPORTED
234246
RUN_TEST(i2c_test);
235-
#endif
236-
237-
#if SOC_GPSPI_SUPPORTED
238247
RUN_TEST(spi_test);
239-
#endif
240-
241-
#if SOC_ADC_SUPPORTED
242-
uart1_tx_pin = A4;
248+
uart1_tx_pin = A3;
249+
uart1_rx_pin = A4;
243250
RUN_TEST(adc_oneshot_test);
244251
RUN_TEST(adc_continuous_test);
245-
#endif
246-
247-
#if SOC_DAC_SUPPORTED
248252
uart1_tx_pin = DAC1;
253+
uart1_rx_pin = DAC2;
249254
RUN_TEST(dac_test);
250-
#endif
251-
252-
#if SOC_TOUCH_SENSOR_SUPPORTED
253255
uart1_tx_pin = T1;
256+
uart1_rx_pin = T2;
254257
RUN_TEST(touch_test);
255-
#endif
256-
257258
RUN_TEST(eth_test);
258259

259260
UNITY_END();

tests/periman/test_periman.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
def test_periman(dut):
2-
dut.expect("I2C test: This should be printed")
2+
dut.expect("GPIO test: This should be printed")
3+
dut.expect("SigmaDelta test: This should be printed")
34
dut.expect("LEDC test: This should be printed")
45
dut.expect("RMT test: This should be printed")
6+
dut.expect("I2S test: This should be printed")
7+
dut.expect("I2C test: This should be printed")
58
dut.expect("SPI test: This should be printed")
9+
dut.expect("ADC Oneshot test: This should be printed")
10+
dut.expect("ADC Continuous test: This should be printed")
11+
dut.expect("DAC test: This should be printed")
12+
dut.expect("Touch test: This should be printed")
13+
dut.expect("ETH test: This should be printed")

0 commit comments

Comments
 (0)