Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-m-adams committed Jan 18, 2025
1 parent 425dc0f commit 77d4bef
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions tests/unit/scheduler_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <unistd.h>
#endif

uint8_t currentlyAccessingCard = false;
uint32_t usbLock = false;
bool sdRoutineLock = false;
namespace {

struct SelfRemoving {
Expand Down Expand Up @@ -63,7 +66,7 @@ TEST(Scheduler, schedule) {
mock().clear();
// will be called one less time due to the time the sleep takes not being zero
mock().expectNCalls(0.01 / 0.001 - 1, "sleep_50ns");
addRepeatingTask(sleep_50ns, 0, 0.001, 0.001, 0.001, "sleep_50ns");
addRepeatingTask(sleep_50ns, 0, 0.001, 0.001, 0.001, "sleep_50ns", NO_RESOURCE);
// run the scheduler for just under 10ms, calling the function to sleep 50ns every 1ms
taskManager.start(0.0095);
mock().checkExpectations();
Expand All @@ -72,7 +75,7 @@ TEST(Scheduler, schedule) {
TEST(Scheduler, remove) {
static SelfRemoving selfRemoving;

TaskID id = addRepeatingTask([]() { selfRemoving.runFiveTimes(); }, 0, 0.001, 0.001, 0.001, "run five times");
TaskID id = addRepeatingTask([]() { selfRemoving.runFiveTimes(); }, 0, 0.001, 0.001, 0.001, "run five times", NO_RESOURCE);
selfRemoving.id = id;
mock().clear();
// will be called one less time due to the time the sleep takes not being zero
Expand All @@ -87,7 +90,7 @@ TEST(Scheduler, scheduleOnce) {
mock().clear();
// will be called one less time due to the time the sleep takes not being zero
mock().expectNCalls(1, "sleep_50ns");
addOnceTask(sleep_50ns, 0, 0.001, "sleep 50ns");
addOnceTask(sleep_50ns, 0, 0.001, "sleep 50ns", NO_RESOURCE);
// run the scheduler for just under 10ms, calling the function to sleep 50ns every 1ms
taskManager.start(0.0095);
mock().checkExpectations();
Expand All @@ -97,7 +100,7 @@ TEST(Scheduler, scheduleConditional) {
mock().clear();
mock().expectNCalls(1, "sleep_50ns");
// will load as blocked but immediately pass condition
addConditionalTask(sleep_50ns, 0, []() { return true; }, "sleep 50ns");
addConditionalTask(sleep_50ns, 0, []() { return true; }, "sleep 50ns", NO_RESOURCE);
// run the scheduler for just under 10ms, calling the function to sleep 50ns every 1ms
taskManager.start(0.0095);
mock().checkExpectations();
Expand All @@ -107,7 +110,7 @@ TEST(Scheduler, scheduleConditionalDoesntRun) {
mock().clear();
mock().expectNCalls(0, "sleep_50ns");
// will load as blocked but immediately pass condition
addConditionalTask(sleep_50ns, 0, []() { return false; }, "sleep 50ns");
addConditionalTask(sleep_50ns, 0, []() { return false; }, "sleep 50ns", NO_RESOURCE);
// run the scheduler for just under 10ms, calling the function to sleep 50ns every 1ms
taskManager.start(0.0095);
mock().checkExpectations();
Expand All @@ -117,7 +120,7 @@ TEST(Scheduler, backOffTime) {
mock().clear();
// will be called one less time due to the time the sleep takes not being zero
mock().expectNCalls(9, "sleep_50ns");
addRepeatingTask(sleep_50ns, 1, 0.01, 0.001, 1.0, "sleep_50ns");
addRepeatingTask(sleep_50ns, 1, 0.01, 0.001, 1.0, "sleep_50ns", NO_RESOURCE);
// run the scheduler for just under 10ms, calling the function to sleep 50ns every 1ms
taskManager.start(0.1);
mock().checkExpectations();
Expand All @@ -129,8 +132,8 @@ TEST(Scheduler, scheduleOnceWithRepeating) {
mock().expectNCalls(0.01 / 0.001 - 2, "sleep_50ns");
mock().expectNCalls(1, "sleep_2ms");
// every 1ms sleep for 50ns and 10ns
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep_50ns");
addOnceTask(sleep_2ms, 11, 0, "sleep 2ms");
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep_50ns", NO_RESOURCE);
addOnceTask(sleep_2ms, 11, 0, "sleep 2ms", NO_RESOURCE);
// run the scheduler for 10ms
taskManager.start(0.01);
mock().checkExpectations();
Expand All @@ -142,8 +145,8 @@ TEST(Scheduler, yield) {
mock().expectNCalls(0.01 / 0.001 - 1, "sleep_50ns");
mock().expectNCalls(1, "yield_2ms");
// every 1ms sleep for 50ns and 10ns
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep_50ns");
addOnceTask(yield_2ms, 2, 0, "sleep 2ms");
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep_50ns", NO_RESOURCE);
addOnceTask(yield_2ms, 2, 0, "sleep 2ms", NO_RESOURCE);
// run the scheduler for 10ms
taskManager.start(0.01);
mock().checkExpectations();
Expand All @@ -154,11 +157,11 @@ TEST(Scheduler, removeWithPriZero) {
mock().expectNCalls((0.01 - 0.002) / 0.001 - 1, "sleep_50ns");
mock().expectNCalls(2, "sleep_2ms");
// every 1ms sleep for 50ns and 10ns
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep 50ns");
addRepeatingTask([]() { passMockTime(0.00001); }, 0, 0.001, 0.001, 0.001, "mock time");
addOnceTask(sleep_2ms, 11, 0.002, "sleep 2 ms");
addRepeatingTask([]() { passMockTime(0.00003); }, 0, 0.001, 0.001, 0.001, "mock time");
addOnceTask(sleep_2ms, 11, 0.009, "sleep 2ms");
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep 50ns", NO_RESOURCE);
addRepeatingTask([]() { passMockTime(0.00001); }, 0, 0.001, 0.001, 0.001, "mock time", NO_RESOURCE);
addOnceTask(sleep_2ms, 11, 0.002, "sleep 2 ms", NO_RESOURCE);
addRepeatingTask([]() { passMockTime(0.00003); }, 0, 0.001, 0.001, 0.001, "mock time", NO_RESOURCE);
addOnceTask(sleep_2ms, 11, 0.009, "sleep 2ms", NO_RESOURCE);
// run the scheduler for 10ms
taskManager.start(0.01);
mock().checkExpectations();
Expand All @@ -171,7 +174,7 @@ TEST(Scheduler, tooManyTasks) {
mock().expectNCalls(kMaxTasks, "sleep_50ns");
// more than allowed
for (int i = 0; i <= kMaxTasks + 10; i++) {
addOnceTask(sleep_50ns, 0, 0.001, "sleep 50ns");
addOnceTask(sleep_50ns, 0, 0.001, "sleep 50ns", NO_RESOURCE);
}

// run the scheduler for 10ms
Expand All @@ -186,15 +189,15 @@ void reAdd50() {
passMockTime(0.00002);
numCalls += 1;
if (numCalls < 50) {
TaskID id = addOnceTask(reAdd50, 0, 0, "reAdd 50");
TaskID id = addOnceTask(reAdd50, 0, 0, "reAdd 50", NO_RESOURCE);
}
};
/// dynamically schedules more than kMaxTask tasks while remaining under kMaxTasks at all times
TEST(Scheduler, moreThanMaxTotal) {
numCalls = 0;
mock().clear();
mock().expectNCalls(50, "reAdd50");
addOnceTask(reAdd50, 0, 0, "reAdd50");
addOnceTask(reAdd50, 0, 0, "reAdd50", NO_RESOURCE);
taskManager.start(0.01);
mock().checkExpectations();
}
Expand All @@ -205,9 +208,9 @@ TEST(Scheduler, scheduleMultiple) {
mock().expectNCalls(0.01 / 0.001 - 1, "sleep_20ns");
mock().expectNCalls(1, "sleep_2ms");
// every 1ms sleep for 50ns and 10ns
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep 50ns");
addRepeatingTask(sleep_20ns, 0, 0.001, 0.001, 0.001, "sleep 20ns");
addOnceTask(sleep_2ms, 11, 0.0094, "sleep 2ms");
addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep 50ns", NO_RESOURCE);
addRepeatingTask(sleep_20ns, 0, 0.001, 0.001, 0.001, "sleep 20ns", NO_RESOURCE);
addOnceTask(sleep_2ms, 11, 0.0094, "sleep 2ms", NO_RESOURCE);
// run the scheduler for 10ms
taskManager.start(0.0095);
mock().checkExpectations();
Expand All @@ -223,9 +226,9 @@ TEST(Scheduler, overSchedule) {
mock().expectNCalls(0.006 / 0.001, "sleep_20ns");

// every 1ms sleep for 50ns and 10ns
auto fiftynshandle = addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep 50ns");
auto tennshandle = addRepeatingTask(sleep_20ns, 0, 0.001, 0.001, 0.001, "sleep 20ns");
auto twomsHandle = addRepeatingTask(sleep_2ms, 100, 0.001, 0.002, 0.005, "sleep 2ms");
auto fiftynshandle = addRepeatingTask(sleep_50ns, 10, 0.001, 0.001, 0.001, "sleep 50ns", NO_RESOURCE);
auto tennshandle = addRepeatingTask(sleep_20ns, 0, 0.001, 0.001, 0.001, "sleep 20ns", NO_RESOURCE);
auto twomsHandle = addRepeatingTask(sleep_2ms, 100, 0.001, 0.002, 0.005, "sleep 2ms", NO_RESOURCE);
// run the scheduler for 10ms
taskManager.start(0.0099);

Expand Down

0 comments on commit 77d4bef

Please sign in to comment.