Prvni ulozeni z chegewara githubu

This commit is contained in:
2023-02-25 16:13:53 +01:00
commit 01eb80dfe2
3279 changed files with 638407 additions and 0 deletions

3
tests/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build*/
__pycache__/
*.xml

24
tests/democfg/cfg.json Normal file
View File

@ -0,0 +1,24 @@
{
"targets": [
{
"name": "esp32",
"fqbn":[
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dio",
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dout",
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=qio"
]
},
{
"name": "esp32s2",
"fqbn": ["espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app"]
},
{
"name": "esp32c3",
"fqbn": ["espressif:esp32:esp32c3:PartitionScheme=huge_app"]
},
{
"name": "esp32s3",
"fqbn": ["espressif:esp32:esp32s3:PSRAM=opi,USBMode=default,PartitionScheme=huge_app"]
}
]
}

11
tests/democfg/democfg.ino Normal file
View File

@ -0,0 +1,11 @@
void setup(){
Serial.begin(115200);
while (!Serial) {
;
}
Serial.println("Hello cfg!");
}
void loop(){
}

View File

@ -0,0 +1,2 @@
def test_cfg(dut):
dut.expect('Hello cfg!')

View File

@ -0,0 +1,12 @@
void setup(){
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
;
}
Serial.println("Hello Arduino!");
}
void loop(){
}

View File

@ -0,0 +1,2 @@
def test_hello_world(dut):
dut.expect('Hello Arduino!')

39
tests/nvs/cfg.json Normal file
View File

@ -0,0 +1,39 @@
{
"targets": [
{
"name": "esp32",
"fqbn":[
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dio",
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dout,FlashFreq=40",
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=qio",
"espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=qout,FlashFreq=40"
]
},
{
"name": "esp32s2",
"fqbn": [
"espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dio",
"espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dout,FlashFreq=40",
"espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=qio",
"espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app,FlashMode=qout,FlashFreq=40"
]
},
{
"name": "esp32c3",
"fqbn": [
"espressif:esp32:esp32c3:PartitionScheme=huge_app,FlashMode=dio",
"espressif:esp32:esp32c3:PartitionScheme=huge_app,FlashMode=dout,FlashFreq=40",
"espressif:esp32:esp32c3:PartitionScheme=huge_app,FlashMode=qio",
"espressif:esp32:esp32c3:PartitionScheme=huge_app,FlashMode=qout,FlashFreq=40"
]
},
{
"name": "esp32s3",
"fqbn": [
"espressif:esp32:esp32s3:PSRAM=opi,USBMode=default,PartitionScheme=huge_app,FlashMode=qio",
"espressif:esp32:esp32s3:PSRAM=opi,USBMode=default,PartitionScheme=huge_app,FlashMode=qio120",
"espressif:esp32:esp32s3:PSRAM=opi,USBMode=default,PartitionScheme=huge_app,FlashMode=dio"
]
}
]
}

36
tests/nvs/nvs.ino Normal file
View File

@ -0,0 +1,36 @@
#include <Preferences.h>
Preferences preferences;
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
preferences.begin("my-app", false);
// Get the counter value, if the key does not exist, return a default value of 0
unsigned int counter = preferences.getUInt("counter", 0);
// Print the counter to Serial Monitor
Serial.printf("Current counter value: %u\n", counter);
// Increase counter by 1
counter++;
// Store the counter to the Preferences
preferences.putUInt("counter", counter);
// Close the Preferences
preferences.end();
// Wait 1 second
delay(1000);
// Restart ESP
ESP.restart();
}
void loop() {}

7
tests/nvs/test_nvs.py Normal file
View File

@ -0,0 +1,7 @@
def test_nvs(dut):
dut.expect('Current counter value: 0')
dut.expect('Current counter value: 1')
dut.expect('Current counter value: 2')
dut.expect('Current counter value: 3')
dut.expect('Current counter value: 4')
dut.expect('Current counter value: 5')

13
tests/pytest.ini Normal file
View File

@ -0,0 +1,13 @@
[pytest]
addopts = --embedded-services esp,arduino
# log related
log_cli = True
log_cli_level = INFO
log_cli_format = %(asctime)s %(levelname)s %(message)s
log_cli_date_format = %Y-%m-%d %H:%M:%S
log_file = test.log
log_file_level = INFO
log_file_format = %(asctime)s %(levelname)s %(message)s
log_file_date_format = %Y-%m-%d %H:%M:%S

13
tests/requirements.txt Normal file
View File

@ -0,0 +1,13 @@
pyserial>=3.0
esptool>=3.1
pytest-cov
cryptography<3.4; platform_machine == "armv7l"
pytest>=6.2.0
pexpect>=4.4
pytest-embedded>=0.5.1
pytest-embedded-serial>=0.5.1
pytest-embedded-serial-esp>=0.5.1
pytest-embedded-arduino>=0.5.1

View File

@ -0,0 +1,2 @@
def test_timer(dut):
dut.expect_unity_test_output(timeout=240)

110
tests/timer/timer.ino Normal file
View File

@ -0,0 +1,110 @@
/* HW Timer test */
#include <unity.h>
#define TIMER_DIVIDER 16
#define TIMER_SCALE (APB_CLK_FREQ / TIMER_DIVIDER)
hw_timer_t * timer = NULL;
static volatile bool alarm_flag;
/* These functions are intended to be called before and after each test. */
void setUp(void) {
timer = timerBegin(0, TIMER_DIVIDER, true);
timerStop(timer);
timerRestart(timer);
}
void tearDown(void){
timerEnd(timer);
}
void ARDUINO_ISR_ATTR onTimer(){
alarm_flag = true;
}
void timer_interrupt_test(void){
alarm_flag = false;
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, (1.2 * TIMER_SCALE), true);
timerAlarmEnable(timer);
timerStart(timer);
delay(2000);
TEST_ASSERT_EQUAL(true, alarm_flag);
timerStop(timer);
timerRestart(timer);
alarm_flag = false;
timerAlarmDisable(timer);
timerStart(timer);
delay(2000);
TEST_ASSERT_EQUAL(false, alarm_flag);
}
void timer_divider_test(void){
uint64_t time_val;
uint64_t comp_time_val;
timerStart(timer);
delay(1000);
time_val = timerRead(timer);
// compare divider 16 and 8, value should be double
timerStop(timer);
timerSetDivider(timer,8);
timerRestart(timer);
timerStart(timer);
delay(1000);
comp_time_val = timerRead(timer);
TEST_ASSERT_INT_WITHIN(5000, 5000000, time_val);
TEST_ASSERT_INT_WITHIN(10000, 10000000, comp_time_val);
// divider is 256, value should be 2^4
timerStop(timer);
timerSetDivider(timer,256);
timerRestart(timer);
timerStart(timer);
delay(1000);
comp_time_val = timerRead(timer);
TEST_ASSERT_INT_WITHIN(5000, 5000000, time_val);
TEST_ASSERT_INT_WITHIN(3126, 312500, comp_time_val);
}
void timer_read_test(void){
uint64_t set_timer_val = 0xFF;
uint64_t get_timer_val = 0;
timerWrite(timer,set_timer_val);
get_timer_val = timerRead(timer);
TEST_ASSERT_EQUAL(set_timer_val, get_timer_val);
}
void setup(){
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
;
}
UNITY_BEGIN();
RUN_TEST(timer_read_test);
RUN_TEST(timer_interrupt_test);
RUN_TEST(timer_divider_test);
UNITY_END();
}
void loop(){
}

View File

@ -0,0 +1,2 @@
def test_unity(dut):
dut.expect_unity_test_output(timeout=240)

33
tests/unity/unity.ino Normal file
View File

@ -0,0 +1,33 @@
#include <unity.h>
/* These functions are intended to be called before and after each test. */
void setUp(void) {
}
void tearDown(void){
}
void test_pass(void){
TEST_ASSERT_EQUAL(1, 1);
}
void test_fail(void){
TEST_ASSERT_EQUAL(1, 1);
}
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
UNITY_BEGIN();
RUN_TEST(test_pass);
RUN_TEST(test_fail);
UNITY_END();
}
void loop() {
}