8000 PolledTimeout Class for wrapping millis() loops (WIP) by devyte · Pull Request #5198 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

PolledTimeout Class for wrapping millis() loops (WIP) #5198

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

Merged
merged 16 commits into from
Nov 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add fuzzyness to timing tests for CI jitter
  • Loading branch information
devyte committed Nov 26, 2018
commit 54a187d21423c1285b3429bec96bd51e078590ff
42 changes: 17 additions & 25 deletions tests/host/core/test_PolledTimeout.cpp
< 3DAC tr data-hunk="5f66481cfd4050326d055e8b64add6291cc10dec04809ae410c4068bdc8059d6" class="show-top-border">
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include <catch.hpp>
#include "PolledTimeout.h"

//This won't work for
template<typename argT>
inline bool
fuzzycomp(argT a, argT b)
{
const argT epsilon = 10;
return (std::max(a,b) - std::min(a,b) <= epsilon);
}

TEST_CASE("OneShot Timeout 3000ms", "[polledTimeout]")
{
Expand All @@ -10,34 +18,30 @@ TEST_CASE("OneShot Timeout 3000ms", "[polledTimeout]")

Serial.println("OneShot Timeout 3000ms");

Serial.print("before while 1\n");
polledTimeoutOneShot timeout(3000);
before = millis();
while(!timeout.expired())
yield();
after = millis();
Serial.print("after while 1\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 3000);
REQUIRE(fuzzycomp(delta, (timeType)3000));


Serial.print("reset\n");

Serial.print("before while 2\n");
timeout.reset();
before = millis();
while(!timeout)
yield();
after = millis();
Serial.print("after while 2\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 3000);
REQUIRE(fuzzycomp(delta, (timeType)3000));
}

TEST_CASE("OneShot Timeout 3000ms reset to 1000ms", "[polledTimeout]")
Expand All @@ -48,34 +52,30 @@ TEST_CASE("OneShot Timeout 3000ms reset to 1000ms", "[polledTimeout]")

Serial.println("OneShot Timeout 3000ms");

Serial.print("before while 1\n");
polledTimeoutOneShot timeout(3000);
before = millis();
while(!timeout.expired())
yield();
after = millis();
Serial.print("after while 1\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 3000);
REQUIRE(fuzzycomp(delta, (timeType)3000));


Serial.print("reset\n");

Serial.print("before while 2\n");
timeout.reset(1000);
before = millis();
while(!timeout)
yield();
after = millis();
Serial.print("after while 2\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 1000);
REQUIRE(fuzzycomp(delta, (timeType)1000));
}

TEST_CASE("Periodic Timeout 1T 3000ms", "[polledTimeout]")
Expand All @@ -86,32 +86,28 @@ TEST_CASE("Periodic Timeout 1T 3000ms", "[polledTimeout]")

Serial.println("Periodic Timeout 1T 3000ms");

Serial.print("before while 1\n");
polledTimeoutPeriodic timeout(3000);
before = millis();
while(!timeout)
yield();
after = millis();
Serial.print("after while 1\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 3000);
REQUIRE(fuzzycomp(delta, (timeType)3000));

Serial.print("no reset needed\n");

Serial.print("before while 2\n");
before = millis();
while(!timeout)
yield();
after = millis();
Serial.print("after while 2\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 3000);
REQUIRE(fuzzycomp(delta, (timeType)3000));
}

TEST_CASE("Periodic Timeout 10T 1000ms", "[polledTimeout]")
Expand Down Expand Up @@ -140,7 +136,7 @@ TEST_CASE("Periodic Timeout 10T 1000ms", "[polledTimeout]")

delta = after - before;
Serial.printf("\ndelta = %lu\n", delta);
REQUIRE(delta == 10000);
REQUIRE(fuzzycomp(delta, (timeType)10000));
}

TEST_CASE("OneShot Timeout 3000ms reset to 1000ms custom yield", "[polledTimeout]")
Expand All @@ -153,31 +149,27 @@ TEST_CASE("OneShot Timeout 3000ms reset to 1000ms custom yield", "[polledTimeout
Serial.println("OneShot Timeout 3000ms");


Serial.print("before while 1\n");
polledTimeoutOneShotYield timeout(3000);
before = millis();
while(!timeout.expired());
after = millis();
Serial.print("after while 1\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 3000);
REQUIRE(fuzzycomp(delta, (timeType)3000));


Serial.print("reset\n");

Serial.print("before while 2\n");
timeout.reset(1000);
before = millis();
while(!timeout);
after = millis();
Serial.print("after while 2\n");

delta = after - before;
Serial.printf("delta = %lu\n", delta);

REQUIRE(delta == 1000);
REQUIRE(fuzzycomp(delta, (timeType)1000));
}

0