1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

device tests: some of them can be run on host (#6912)

* device tests: mock scripts + rename some tests to enable mock-testing them

* move symbol
This commit is contained in:
david gauchard
2019-12-16 19:20:07 +01:00
committed by GitHub
parent d1237fd016
commit d40dbb4584
16 changed files with 41 additions and 6 deletions

View File

@ -0,0 +1,80 @@
#include <BSTest.h>
#include <Schedule.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}
bool pretest()
{
return true;
}
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(){}