Draft version of test system

This commit is contained in:
sheinz 2016-08-18 18:09:36 +03:00
parent 95081a1e9f
commit 5ace1c5bff
12 changed files with 290 additions and 19 deletions

23
tests/Makefile Normal file
View file

@ -0,0 +1,23 @@
TESTS = $(shell find $(dir $(lastword $(MAKEFILE_LIST))) \
-mindepth 2 -maxdepth 2 -name Makefile | sed s/Makefile//g)
# Generate some dummy .dummybuild/.dummyrebuild target files
TESTS_BUILD = $(patsubst %,%.dummybuild,$(TESTS))
TESTS_TEST = $(patsubst %,%.dummytest,$(TESTS))
all: $(TESTS_BUILD)
$(TESTS_TEST): $(TESTS_BUILD)
test: $(TESTS_TEST)
%.dummybuild:
$(MAKE) -C $(dir $@)
%.dummytest:
$(MAKE) -C $(dir $@) flash
$(MAKE) -C $(dir $@) run_test
.PHONY: all test
.NOTPARALLEL:
.ONESHELL:

10
tests/example/Makefile Normal file
View file

@ -0,0 +1,10 @@
PROGRAM=example_test
EXTRA_COMPONENTS = extras/test
include ../../common.mk
run_test:
python ../../extras/test/run_test.py /dev/ttyUSB0
.PHONY: run_test

View file

@ -0,0 +1,25 @@
#include <stdlib.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "test/test.h"
void test_task(void *pvParameters)
{
// Test will continue even if check is failed
TEST_CHECK(2 + 2 == 4, "math doesn't work");
// Test will end imidiatelly if assertion is failed
TEST_ASSERT(strlen("test") == 4, "strlen doesn't work");
// Finish the test and report the result
TEST_FINISH();
}
void user_init(void)
{
TEST_INIT(5); // 5 seconds timeout
xTaskCreate(test_task, (signed char *)"test_task", 256, NULL, 2, NULL);
}

16
tests/spiffs/Makefile Normal file
View file

@ -0,0 +1,16 @@
PROGRAM=posix_fs_example
PROGRAM_EXTRA_SRC_FILES=./fs-test/fs_test.c
EXTRA_COMPONENTS = extras/spiffs extras/test
FLASH_SIZE = 32
# spiffs configuration
SPIFFS_BASE_ADDR = 0x200000
SPIFFS_SIZE = 0x100000
include ../../common.mk
run_test:
python ../../extras/test/run_test.py /dev/ttyUSB0
.PHONY: run_test

10
tests/spiffs/README.md Normal file
View file

@ -0,0 +1,10 @@
# POSIX file access example
This example runs several file system tests on ESP8266.
It uses fs-test library to perform file operations test. fs-test library uses
only POSIX file functions so can be run on host system as well.
Currently included tests:
* File system load test. Perform multiple file operations in random order.
* File system speed test. Measures files read/write speed.

1
tests/spiffs/fs-test Submodule

@ -0,0 +1 @@
Subproject commit 2ad547adc5f725594b3c6752f036ff4401b221fc

View file

@ -0,0 +1,50 @@
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "esp/timer.h"
#include "FreeRTOS.h"
#include "task.h"
#include "esp8266.h"
#include <stdio.h>
#include "esp_spiffs.h"
#include "spiffs.h"
#include "fs-test/fs_test.h"
#include "test/test.h"
static fs_time_t get_current_time()
{
return timer_get_count(FRC2) / 5000; // to get roughly 1ms resolution
}
void test_task(void *pvParameters)
{
esp_spiffs_init();
esp_spiffs_mount();
SPIFFS_unmount(&fs); // FS must be unmounted before formating
if (SPIFFS_format(&fs) == SPIFFS_OK) {
printf("Format complete\n");
} else {
printf("Format failed\n");
}
esp_spiffs_mount();
TEST_CHECK(fs_load_test_run(100), "Load test failed");
float write_rate, read_rate;
if (fs_speed_test_run(get_current_time, &write_rate, &read_rate)) {
printf("Read speed: %.0f bytes/s\n", read_rate * 1000);
printf("Write speed: %.0f bytes/s\n", write_rate * 1000);
} else {
TEST_FAIL("Speed test failed");
}
TEST_FINISH();
}
void user_init(void)
{
TEST_INIT(60);
xTaskCreate(test_task, (signed char *)"test_task", 1024, NULL, 2, NULL);
}