Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expect-based testing framework #2983

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
14c1b8f
Lua 5.1 to 5.3 realignement phase 1
TerryE Jul 18, 2019
ba03cb0
Add telnet example
TerryE Jul 19, 2019
bc98174
Updates following JM review
TerryE Jul 19, 2019
39bb60e
Rebased against current dev
TerryE Jul 23, 2019
522b1d0
Rebased against current dev, tweaks for clean compile
TerryE Jul 23, 2019
fff9f95
Merge pull request #2836 from TerryE/dev-new-lua.c
TerryE Sep 7, 2019
32ad759
Add streaming support for hx711 device (#2793)
pjsg Sep 10, 2019
4c3d45e
Revert "Add streaming support for hx711 device (#2793)" (#2914)
marcelstoer Sep 13, 2019
81e213a
Remove superfluous module def
marcelstoer Sep 21, 2019
04287ac
Fix invalid smartconfig include
marcelstoer Sep 29, 2019
043046d
Deprecate crypto.to{Hex,Base64} (#2929)
nwf Sep 30, 2019
f3044e1
Fix typos
marcelstoer Oct 30, 2019
0e34f7d
fix lfs upload issue
Nov 13, 2019
f3b4984
Merge pull request #2961 from seregaxvm/lfsfix
TerryE Nov 14, 2019
e3935de
Improve MQTT documentation (#2967)
stromnet Nov 21, 2019
9a2579d
Improve httpserver documentation (#2971)
HHHartmann Nov 26, 2019
c7d0f83
Update sensor driver for BME680 to 3.5.9 (#2969)
vsky279 Dec 9, 2019
b179f30
Fixes for `ws2812` and `ws2812_effects` (#2953)
HHHartmann Dec 9, 2019
4fc2b85
Streaming support for hx711 (#2915)
marcelstoer Dec 9, 2019
f85c278
New `net.if.info` call to show LwIP information (#2862)
nwf Dec 9, 2019
d84da36
fixed missing forward declaration (#2975)
glumanda Dec 13, 2019
d4bc6ce
mispec: don't use %f
nwf Dec 26, 2019
225964f
mispec: report status TAPishly
nwf Dec 26, 2019
6be9158
mispec: don't use uart.write
nwf Dec 26, 2019
0f6b0fb
expect tests: core library functions
nwf Dec 24, 2019
d6f60a8
expect tests: file xfer module
nwf Dec 26, 2019
c99e2e8
expect tests: add TAP-based test runner
nwf Dec 26, 2019
4fc6174
expect tests: file module
nwf Dec 24, 2019
b4843cf
expect tests: tls module
nwf Dec 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions .gdbinitlua
Expand Up @@ -3,9 +3,9 @@ set pagination off
set print null-stop

define prTS
set $o = &(((TString *)($arg0))->tsv)
set $o = &(((TString *)(($arg0).value))->tsv)
printf "Common header: next = %p, marked = 0x%01x\n", $o->next, $o->marked
printf "String: hash = 0x%08x, len = %u : %s\n", $o->hash, $o->len, (char *)(&$o[1])
printf "String: hash = 0x%08x, len = %u : %s\n", $o->hash, $o->len, (char *)($o+1)
end

define prTnodes
Expand All @@ -24,6 +24,18 @@ define prTnodes
set $i = $i +1
end
end

define prTarray
set $o = (Table *)($arg0)
set $n = $o->sizearray
set $i = 0
while $i < $n
set $nd = ($o->array) + $i
prTV $nd
set $i = $i +1
end
end

define prTV
if $arg0
set $type = ($arg0).tt
Expand Down Expand Up @@ -78,6 +90,10 @@ define prTV
end
if $type == 9
# UserData
set $o = &($val->gc.u.uv)
printf "Common header: next = %p, marked = 0x%01x\n", $o->next, $o->marked
printf "UD = %p Userdata: metatable = ", ($o+1))
print ($o)->metatable
end
if $type == 10
# Thread
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,6 +16,7 @@ tools/toolchains/
.project
.settings/
.vscode
.vs

#ignore temp file for build infos
buildinfo.h
4 changes: 1 addition & 3 deletions app/Makefile
Expand Up @@ -36,7 +36,6 @@ SUBDIRS= \
libc \
lua \
lwip \
task \
smart \
modules \
spiffs \
Expand Down Expand Up @@ -64,8 +63,7 @@ COMPONENTS_eagle.app.v6 = \
user/libuser.a \
crypto/libcrypto.a \
driver/libdriver.a \
platform/libplatform.a \
task/libtask.a \
platform/libplatform.a \
libc/liblibc.a \
lua/liblua.a \
lwip/liblwip.a \
Expand Down
12 changes: 5 additions & 7 deletions app/coap/endpoints.c
Expand Up @@ -162,20 +162,18 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
}

extern int lua_put_line(const char *s, size_t l);

static const coap_endpoint_path_t path_command = {2, {"v1", "c"}};
static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
if (inpkt->payload.len == 0)
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_BAD_REQUEST, COAP_CONTENTTYPE_TEXT_PLAIN);
if (inpkt->payload.len > 0)
{
char line[LUA_MAXINPUT];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) &&
lua_put_line(line, strlen(line))) {
NODE_DBG("\nResult(if any):\n");
system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0);
char line[LUA_MAXINPUT+1];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload)) {
int l = strlen(line);
line[l] = '\n';
lua_input_string(line, l+1);
}
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
}
Expand Down
2 changes: 1 addition & 1 deletion app/driver/Makefile
Expand Up @@ -15,7 +15,7 @@ ifndef PDIR
GEN_LIBS = libdriver.a
endif

STD_CFLAGS=-std=gnu11 -Wimplicit
STD_CFLAGS=-std=gnu11 -Wimplicit -Wall

#############################################################
# Configuration i.e. compile options etc.
Expand Down
196 changes: 196 additions & 0 deletions app/driver/input.c
@@ -0,0 +1,196 @@
#include "platform.h"
#include "driver/uart.h"
#include "driver/input.h"
#include <stdint.h>
#include "mem.h"

/**DEBUG**/extern void dbg_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));

static void input_handler(platform_task_param_t flag, uint8 priority);

static struct input_state {
char *data;
int line_pos;
size_t len;
const char *prompt;
uart_cb_t uart_cb;
platform_task_handle_t input_sig;
int data_len;
bool run_input;
bool uart_echo;
char last_char;
char end_char;
uint8 input_sig_flag;
} ins = {0};

#define NUL '\0'
#define BS '\010'
#define CR '\r'
#define LF '\n'
#define DEL 0x7f
#define BS_OVER "\010 \010"

#define sendStr(s) uart0_sendStr(s)
#define putc(c) uart0_putc(c)

// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;

static bool uart_getc(char *c){
RcvMsgBuff *pRxBuff = &(UartDev.rcv_buff);
if(pRxBuff->pWritePos == pRxBuff->pReadPos){ // empty
return false;
}
// ETS_UART_INTR_DISABLE();
ETS_INTR_LOCK();
*c = (char)*(pRxBuff->pReadPos);
if (pRxBuff->pReadPos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) {
pRxBuff->pReadPos = pRxBuff->pRcvMsgBuff ;
} else {
pRxBuff->pReadPos++;
}
// ETS_UART_INTR_ENABLE();
ETS_INTR_UNLOCK();
return true;
}

/*
** input_handler at high-priority is a system post task used to process pending Rx
** data on UART0. The flag is used as a latch to stop the interrupt handler posting
** multiple pending requests. At low priority it is used the trigger interactive
** compile.
**
** The ins.data check detects up the first task call which used to initialise
** everything.
*/
int lua_main (void);
static bool input_readline(void);

static void input_handler(platform_task_param_t flag, uint8 priority) {
(void) priority;
if (!ins.data) {
lua_main();
return;
}
ins.input_sig_flag = flag & 0x1;
while (input_readline()) {}
}

/*
** The input state (ins) is private, so input_setup() exposes the necessary
** access to public properties and is called in user_init() before the Lua
** enviroment is initialised. The second routine input_setup_receive() is
** called in lua.c after the Lua environment is available to bind the Lua
** input handler. Any UART input before this receive setup is ignored.
*/
void input_setup(int bufsize, const char *prompt) {
// Initialise non-zero elements
ins.run_input = true;
ins.uart_echo = true;
ins.data = os_malloc(bufsize);
ins.len = bufsize;
ins.prompt = prompt;
ins.input_sig = platform_task_get_id(input_handler);
// pass the task CB parameters to the uart driver
uart_init_task(ins.input_sig, &ins.input_sig_flag);
ETS_UART_INTR_ENABLE();
}

void input_setup_receive(uart_cb_t uart_on_data_cb, int data_len, char end_char, bool run_input) {
ins.uart_cb = uart_on_data_cb;
ins.data_len = data_len;
ins.end_char = end_char;
ins.run_input = run_input;
}

void input_setecho (bool flag) {
ins.uart_echo = flag;
}

void input_setprompt (const char *prompt) {
ins.prompt = prompt;
}

/*
** input_readline() is called from the input_handler() event routine which is
** posted by the UART Rx ISR posts. This works in one of two modes depending on
** the bool ins.run_input.
** - TRUE: it clears the UART FIFO up to EOL, doing any callback and sending
** the line to Lua.
** - FALSE: it clears the UART FIFO doing callbacks according to the data_len /
** end_char break.
*/
void lua_input_string (const char *line, int len);

static bool input_readline(void) {
char ch = NUL;
if (ins.run_input) {
while (uart_getc(&ch)) {
/* handle CR & LF characters and aggregate \n\r and \r\n pairs */
if ((ch == CR && ins.last_char == LF) ||
(ch == LF && ins.last_char == CR)) {
ins.last_char = NUL;
continue;
}

/* backspace key */
if (ch == DEL || ch == BS) {
if (ins.line_pos > 0) {
if(ins.uart_echo) sendStr(BS_OVER);
ins.line_pos--;
}
ins.data[ins.line_pos] = 0;
ins.last_char = NUL;
continue;
}
ins.last_char = ch;

/* end of data */
if (ch == CR || ch == LF) {
if (ins.uart_echo) putc(LF);
if (ins.uart_cb) ins.uart_cb(ins.data, ins.line_pos);
if (ins.line_pos == 0) {
/* Get a empty data, then go to get a new data */

sendStr(ins.prompt);
continue;
} else {
ins.data[ins.line_pos++] = LF;
lua_input_string(ins.data, ins.line_pos);
ins.line_pos = 0;
return true;
}
}

if(ins.uart_echo) putc(ch);

/* it's a large data, discard it */
if ( ins.line_pos + 1 >= ins.len ){
ins.line_pos = 0;
}
ins.data[ins.line_pos++] = ch;
}

} else {

if (!ins.uart_cb) {
while (uart_getc(&ch)) {}
} else if (ins.data_len == 0) {
while (uart_getc(&ch)) {
ins.uart_cb(&ch, 1);
}
} else {
while (uart_getc(&ch)) {
ins.data[ins.line_pos++] = ch;
if( ins.line_pos >= ins.len ||
(ins.data_len > 0 && ins.line_pos >= ins.data_len) ||
ch == ins.end_char ) {
ins.uart_cb(ins.data, ins.line_pos);
ins.line_pos = 0;
}
}
}
}
return false;
}

6 changes: 3 additions & 3 deletions app/driver/pwm.c
Expand Up @@ -20,7 +20,7 @@
#include "driver/pwm.h"

// #define PWM_DBG os_printf
#define PWM_DBG
#define PWM_DBG( ... )

// Enabling the next line will cause the interrupt handler to toggle
// this output pin during processing so that the timing is obvious
Expand Down Expand Up @@ -253,7 +253,7 @@ pwm_set_freq(uint16 freq, uint8 channel)

pwm.period = PWM_1S / pwm.freq;
}

#if 0
/******************************************************************************
* FunctionName : pwm_set_freq_duty
* Description : set pwm frequency and each channel's duty
Expand All @@ -274,7 +274,7 @@ pwm_set_freq_duty(uint16 freq, uint16 *duty)
pwm_set_duty(duty[i], pwm_out_io_num[i]);
}
}

#endif
/******************************************************************************
* FunctionName : pwm_get_duty
* Description : get duty of each channel
Expand Down
2 changes: 2 additions & 0 deletions app/driver/pwm2.c
Expand Up @@ -7,11 +7,13 @@

#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "mem.h"
#include "pin_map.h"
#include "platform.h"
#include "hw_timer.h"
#include "driver/pwm2.h"
#include "user_interface.h"

#define PWM2_TMR_MAGIC_80MHZ 16
#define PWM2_TMR_MAGIC_160MHZ 32
Expand Down