1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00
esp8266/tests/device/test_schedule/test_schedule.ino
Ivan Grokhotkov 8bd26f2ded add support for environment variables in device tests
Previously device tests included information such as access point SSID/password at compile time. This made it difficult to compile test binaries once and then send them to multiple test runners for execution.

This change adds a command to the test library to set environment variable on the target device: “setenv key value”. C library setenv/getenv facility is used to store variables.

Test runner, tests, and makefile are updated to use this functionality.
2018-04-11 11:19:21 +08:00

77 lines
1.7 KiB
C++

#include <BSTest.h>
#include <Schedule.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}
TEST_CASE("scheduled functions are executed", "[schedule]")
{
bool executed = false;
CHECK(schedule_function([&](){
executed = true;
}));
run_scheduled_functions();
CHECK(executed);
}
TEST_CASE("scheduled functions are executed in correct order", "[schedule]")
{
int counter = 0;
auto fn = [&](int id) {
CHECK(id == counter);
++counter;
};
for (int i = 0; i < 8; ++i) {
schedule_function(std::bind(fn, i));
}
run_scheduled_functions();
}
TEST_CASE("functions are only executed once", "[schedule]")
{
int counter = 0;
auto fn = [&](){
++counter;
};
schedule_function(fn);
schedule_function(fn);
schedule_function(fn);
run_scheduled_functions();
CHECK(counter == 3);
counter = 0;
run_scheduled_functions();
CHECK(counter == 0);
}
TEST_CASE("can schedule SCHEDULED_FN_MAX_COUNT functions", "[schedule]")
{
int counter = 0;
auto fn = [&](int id) {
CHECK(id == counter);
CHECK(id < SCHEDULED_FN_MAX_COUNT);
++counter;
};
int i;
for (i = 0; i < SCHEDULED_FN_MAX_COUNT; ++i) {
CHECK(schedule_function(std::bind(fn, i)));
}
CHECK(!schedule_function(std::bind(fn, i)));
run_scheduled_functions();
CHECK(counter == SCHEDULED_FN_MAX_COUNT);
counter = 0;
for (i = 0; i < SCHEDULED_FN_MAX_COUNT; ++i) {
CHECK(schedule_function(std::bind(fn, i)));
}
CHECK(!schedule_function(std::bind(fn, i)));
run_scheduled_functions();
CHECK(counter == SCHEDULED_FN_MAX_COUNT);
}
void loop(){}