tests: Add two devices test
This commit is contained in:
parent
5ace1c5bff
commit
33d695ec83
11 changed files with 277 additions and 10 deletions
|
|
@ -34,6 +34,7 @@ class Test(threading.Thread):
|
||||||
def wait_start(self):
|
def wait_start(self):
|
||||||
skip_lines = 100
|
skip_lines = 100
|
||||||
while skip_lines > 0:
|
while skip_lines > 0:
|
||||||
|
self._port.write('START\n'.encode())
|
||||||
l = self._port.readline()
|
l = self._port.readline()
|
||||||
if 'TEST_INIT: TIMEOUT=' in l:
|
if 'TEST_INIT: TIMEOUT=' in l:
|
||||||
res = re.findall(r'\d+', l)
|
res = re.findall(r'\d+', l)
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,35 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "task.h"
|
||||||
|
#include "esp/uart.h"
|
||||||
|
|
||||||
bool test_result = true;
|
bool test_result = true;
|
||||||
|
|
||||||
|
void test_init(uint32_t timeout)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
int data_len = 0;
|
||||||
|
buf[data_len] = 0;
|
||||||
|
|
||||||
|
uart_set_baud(0, 115200);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int c = getchar();
|
||||||
|
if (c == EOF || c == '\n' || c == '\r') {
|
||||||
|
if (strcmp(buf, "START") == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
data_len = 0;
|
||||||
|
buf[data_len] = 0;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
buf[data_len++] = c;
|
||||||
|
buf[data_len] = 0;
|
||||||
|
}
|
||||||
|
taskYIELD();
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("TEST_INIT: TIMEOUT=%ds\n", timeout); \
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "esp/uart.h"
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
|
||||||
extern bool test_result;
|
extern bool test_result;
|
||||||
|
|
@ -56,12 +55,8 @@ extern bool test_result;
|
||||||
printf("TEST_FINISH: FAIL\n"); \
|
printf("TEST_FINISH: FAIL\n"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_INIT(timeout) \
|
#define TEST_INIT(timeout) test_init(timeout)
|
||||||
if (true) { \
|
|
||||||
test_result = true; \
|
|
||||||
uart_set_baud(0, 115200); \
|
|
||||||
printf("TEST_INIT: TIMEOUT=%ds\n", timeout); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void test_init(uint32_t timeout);
|
||||||
|
|
||||||
#endif // __TEST_H__
|
#endif // __TEST_H__
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,12 @@ $(TESTS_TEST): $(TESTS_BUILD)
|
||||||
|
|
||||||
test: $(TESTS_TEST)
|
test: $(TESTS_TEST)
|
||||||
|
|
||||||
|
clean: $(TESTS_BUILD)
|
||||||
|
|
||||||
|
clean: GOAL=clean
|
||||||
|
|
||||||
%.dummybuild:
|
%.dummybuild:
|
||||||
$(MAKE) -C $(dir $@)
|
$(MAKE) -C $(dir $@) $(GOAL)
|
||||||
|
|
||||||
%.dummytest:
|
%.dummytest:
|
||||||
$(MAKE) -C $(dir $@) flash
|
$(MAKE) -C $(dir $@) flash
|
||||||
|
|
|
||||||
29
tests/basic_wifi/Makefile
Normal file
29
tests/basic_wifi/Makefile
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
STATION_PORT := $(ESPPORT)
|
||||||
|
AP_PORT := /dev/tty.SLAB_USBtoUART59
|
||||||
|
|
||||||
|
all: station ap
|
||||||
|
|
||||||
|
flash: ap station
|
||||||
|
|
||||||
|
clean: ap station
|
||||||
|
|
||||||
|
flash: GOAL=flash
|
||||||
|
|
||||||
|
clean: GOAL=clean
|
||||||
|
|
||||||
|
station: ESPPORT=$(STATION_PORT)
|
||||||
|
|
||||||
|
ap: ESPPORT=$(AP_PORT)
|
||||||
|
|
||||||
|
station:
|
||||||
|
$(MAKE) -C station $(GOAL)
|
||||||
|
|
||||||
|
ap:
|
||||||
|
$(MAKE) -C ap $(GOAL)
|
||||||
|
|
||||||
|
run_test:
|
||||||
|
python ../../extras/test/run_test.py $(STATION_PORT) $(AP_PORT)
|
||||||
|
|
||||||
|
.PHONY: all station ap run_test flash clean
|
||||||
|
|
||||||
5
tests/basic_wifi/ap/Makefile
Normal file
5
tests/basic_wifi/ap/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Makefile for access_point example
|
||||||
|
PROGRAM=access_point
|
||||||
|
EXTRA_COMPONENTS=extras/dhcpserver extras/test
|
||||||
|
|
||||||
|
include ../../../common.mk
|
||||||
96
tests/basic_wifi/ap/ap.c
Normal file
96
tests/basic_wifi/ap/ap.c
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
/* Very basic example showing usage of access point mode and the DHCP server.
|
||||||
|
|
||||||
|
The ESP in the example runs a telnet server on 172.16.0.1 (port 23) that
|
||||||
|
outputs some status information if you connect to it, then closes
|
||||||
|
the connection.
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <espressif/esp_common.h>
|
||||||
|
#include <esp/uart.h>
|
||||||
|
#include <FreeRTOS.h>
|
||||||
|
#include <task.h>
|
||||||
|
#include <queue.h>
|
||||||
|
#include <dhcpserver.h>
|
||||||
|
|
||||||
|
#include <lwip/api.h>
|
||||||
|
|
||||||
|
#include "test/test.h"
|
||||||
|
|
||||||
|
#define AP_SSID "esp-open-rtos-ap"
|
||||||
|
#define AP_PSK "esp-open-rtos"
|
||||||
|
|
||||||
|
#define TELNET_PORT 23
|
||||||
|
|
||||||
|
static void telnetTask(void *pvParameters);
|
||||||
|
|
||||||
|
void user_init(void)
|
||||||
|
{
|
||||||
|
TEST_INIT(30);
|
||||||
|
|
||||||
|
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||||
|
|
||||||
|
sdk_wifi_set_opmode(SOFTAP_MODE);
|
||||||
|
struct ip_info ap_ip;
|
||||||
|
IP4_ADDR(&ap_ip.ip, 172, 16, 0, 1);
|
||||||
|
IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0);
|
||||||
|
IP4_ADDR(&ap_ip.netmask, 255, 255, 0, 0);
|
||||||
|
sdk_wifi_set_ip_info(1, &ap_ip);
|
||||||
|
|
||||||
|
struct sdk_softap_config ap_config = {
|
||||||
|
.ssid = AP_SSID,
|
||||||
|
.ssid_hidden = 0,
|
||||||
|
.channel = 3,
|
||||||
|
.ssid_len = strlen(AP_SSID),
|
||||||
|
.authmode = AUTH_WPA_WPA2_PSK,
|
||||||
|
.password = AP_PSK,
|
||||||
|
.max_connection = 3,
|
||||||
|
.beacon_interval = 100,
|
||||||
|
};
|
||||||
|
sdk_wifi_softap_set_config(&ap_config);
|
||||||
|
|
||||||
|
ip_addr_t first_client_ip;
|
||||||
|
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||||
|
dhcpserver_start(&first_client_ip, 4);
|
||||||
|
|
||||||
|
xTaskCreate(telnetTask, (signed char *)"telnetTask", 512, NULL, 2, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Telnet task listens on port 23, returns some status information and then closes
|
||||||
|
the connection if you connect to it.
|
||||||
|
*/
|
||||||
|
static void telnetTask(void *pvParameters)
|
||||||
|
{
|
||||||
|
struct netconn *nc = netconn_new (NETCONN_TCP);
|
||||||
|
if(!nc) {
|
||||||
|
printf("failed to allocate socket.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
netconn_bind(nc, IP_ADDR_ANY, TELNET_PORT);
|
||||||
|
netconn_listen(nc);
|
||||||
|
|
||||||
|
struct netconn *client = NULL;
|
||||||
|
err_t err = netconn_accept(nc, &client);
|
||||||
|
|
||||||
|
if ( err != ERR_OK ) {
|
||||||
|
if(client)
|
||||||
|
netconn_delete(client);
|
||||||
|
TEST_FAIL("Error accepting connection");
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_addr_t client_addr;
|
||||||
|
uint16_t port_ignore;
|
||||||
|
netconn_peer(client, &client_addr, &port_ignore);
|
||||||
|
|
||||||
|
char buf[80];
|
||||||
|
snprintf(buf, sizeof(buf), "test ping\r\n");
|
||||||
|
printf("writing data to socket: %s\n", buf);
|
||||||
|
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||||
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||||
|
|
||||||
|
netconn_delete(client);
|
||||||
|
|
||||||
|
TEST_FINISH();
|
||||||
|
}
|
||||||
3
tests/basic_wifi/station/Makefile
Normal file
3
tests/basic_wifi/station/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
PROGRAM=http_get
|
||||||
|
EXTRA_COMPONENTS=extras/test
|
||||||
|
include ../../../common.mk
|
||||||
104
tests/basic_wifi/station/station.c
Normal file
104
tests/basic_wifi/station/station.c
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
/* http_get - Retrieves a web page over HTTP GET.
|
||||||
|
*
|
||||||
|
* See http_get_ssl for a TLS-enabled version.
|
||||||
|
*
|
||||||
|
* This sample code is in the public domain.,
|
||||||
|
*/
|
||||||
|
#include "espressif/esp_common.h"
|
||||||
|
#include "esp/uart.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
#include "lwip/err.h"
|
||||||
|
#include "lwip/sockets.h"
|
||||||
|
#include "lwip/sys.h"
|
||||||
|
#include "lwip/netdb.h"
|
||||||
|
#include "lwip/dns.h"
|
||||||
|
|
||||||
|
#include "ssid_config.h"
|
||||||
|
|
||||||
|
#include "test/test.h"
|
||||||
|
|
||||||
|
#define AP_SSID "esp-open-rtos-ap"
|
||||||
|
#define AP_PSK "esp-open-rtos"
|
||||||
|
#define SERVER "172.16.0.1"
|
||||||
|
#define PORT 23
|
||||||
|
|
||||||
|
void connect_task(void *pvParameters)
|
||||||
|
{
|
||||||
|
printf("HTTP get task starting...\r\n");
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
struct sockaddr_in serv_addr;
|
||||||
|
uint8_t buf[256];
|
||||||
|
|
||||||
|
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if(s < 0) {
|
||||||
|
printf("failed to allocate socket.\n");
|
||||||
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero(&serv_addr, sizeof(serv_addr));
|
||||||
|
serv_addr.sin_port = htons(23);
|
||||||
|
serv_addr.sin_family = AF_INET;
|
||||||
|
if (inet_aton(SERVER, &serv_addr.sin_addr.s_addr) == 0) {
|
||||||
|
printf("failed to set IP address\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("allocated socket\n");
|
||||||
|
|
||||||
|
if(connect(s, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) != 0) {
|
||||||
|
close(s);
|
||||||
|
printf("socket connect failed.\n");
|
||||||
|
vTaskDelay(4000 / portTICK_RATE_MS);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("connected\n");
|
||||||
|
|
||||||
|
bzero(buf, 256);
|
||||||
|
|
||||||
|
int r = 0;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
r = read(s, buf, 256);
|
||||||
|
if (r > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||||
|
}
|
||||||
|
printf("data: %s\n", buf);
|
||||||
|
TEST_CHECK(r > 0, "no data received");
|
||||||
|
|
||||||
|
TEST_CHECK(strcmp((const char*)buf, "test ping\r\n") == 0,
|
||||||
|
"received wrong data");
|
||||||
|
|
||||||
|
close(s);
|
||||||
|
|
||||||
|
TEST_FINISH();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void user_init(void)
|
||||||
|
{
|
||||||
|
TEST_INIT(30);
|
||||||
|
|
||||||
|
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||||
|
|
||||||
|
struct sdk_station_config config = {
|
||||||
|
.ssid = AP_SSID,
|
||||||
|
.password = AP_PSK,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* required to call wifi_set_opmode before station_set_config */
|
||||||
|
sdk_wifi_set_opmode(STATION_MODE);
|
||||||
|
sdk_wifi_station_set_config(&config);
|
||||||
|
|
||||||
|
xTaskCreate(&connect_task, (signed char *)"connect_task", 256, NULL, 2, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -5,6 +5,6 @@ EXTRA_COMPONENTS = extras/test
|
||||||
include ../../common.mk
|
include ../../common.mk
|
||||||
|
|
||||||
run_test:
|
run_test:
|
||||||
python ../../extras/test/run_test.py /dev/ttyUSB0
|
python ../../extras/test/run_test.py $(ESPPORT)
|
||||||
|
|
||||||
.PHONY: run_test
|
.PHONY: run_test
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ SPIFFS_SIZE = 0x100000
|
||||||
include ../../common.mk
|
include ../../common.mk
|
||||||
|
|
||||||
run_test:
|
run_test:
|
||||||
python ../../extras/test/run_test.py /dev/ttyUSB0
|
python ../../extras/test/run_test.py $(ESPPORT)
|
||||||
|
|
||||||
.PHONY: run_test
|
.PHONY: run_test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue