Browse Source

Individual unit tests fixes

Anatoli Arkhipenko 5 months ago
parent
commit
b4e0c2271f
2 changed files with 39 additions and 53 deletions
  1. 28 44
      tests/test-scheduler-advanced-features.cpp
  2. 11 9
      tests/test-scheduler-basic-thorough.cpp

+ 28 - 44
tests/test-scheduler-advanced-features-no-lambda.cpp → tests/test-scheduler-advanced-features.cpp

@@ -3,10 +3,10 @@
 // enabled by specific compile-time directives, using traditional function pointers
 // enabled by specific compile-time directives, using traditional function pointers
 //
 //
 // =====================================================================================
 // =====================================================================================
-// ADVANCED FEATURES TEST PLAN AND COVERAGE MATRIX (NO LAMBDA VERSION)
+// ADVANCED FEATURES TEST PLAN AND COVERAGE MATRIX
 // =====================================================================================
 // =====================================================================================
 //
 //
-// PURPOSE: Validate advanced TaskScheduler features without lambda functions
+// PURPOSE: Validate advanced TaskScheduler features
 // APPROACH: Traditional function pointers for maximum platform compatibility
 // APPROACH: Traditional function pointers for maximum platform compatibility
 // SCOPE: Advanced features requiring specific compile-time directives
 // SCOPE: Advanced features requiring specific compile-time directives
 //
 //
@@ -550,10 +550,11 @@ TEST_F(AdvancedSchedulerTest, TaskWaitForStatusRequest) {
     // Set up StatusRequest in pending state
     // Set up StatusRequest in pending state
     sr.setWaiting(1);
     sr.setWaiting(1);
 
 
+    advanced_callback_counter = 0;
+
     // Create task that waits for status request
     // Create task that waits for status request
     Task waiter(100, 2, &consumer_callback, &ts);
     Task waiter(100, 2, &consumer_callback, &ts);
     waiter.waitFor(&sr, 50, 2);
     waiter.waitFor(&sr, 50, 2);
-
     // Task should be enabled but not execute while SR is pending
     // Task should be enabled but not execute while SR is pending
     EXPECT_TRUE(waiter.isEnabled());
     EXPECT_TRUE(waiter.isEnabled());
 
 
@@ -584,44 +585,19 @@ TEST_F(AdvancedSchedulerTest, TaskWaitForStatusRequest) {
  *
  *
  * TESTS: waitForDelayed(StatusRequest*, interval, iterations)
  * TESTS: waitForDelayed(StatusRequest*, interval, iterations)
  *
  *
- * PURPOSE: Verify that waitForDelayed() enables tasks to wait for
- * StatusRequest completion with additional delay, providing fine-grained
- * timing control in event-driven scenarios.
- *
- * WAIT FOR DELAYED BEHAVIOR:
- * - waitForDelayed(): Like waitFor() but with initial delay before waiting
- * - Task waits for both delay period AND StatusRequest completion
- * - Useful for staggered startup and coordinated timing
- * - Provides additional timing flexibility in complex workflows
- * - Combines time-based and event-based triggering
- *
- * TEST SCENARIO:
- * 1. Create completed StatusRequest (no event waiting needed)
- * 2. Create task with waitForDelayed() including initial delay
- * 3. Verify task doesn't execute immediately despite completed StatusRequest
- * 4. Verify task executes after delay period
- * 5. Test timing behavior matches delay specification
- *
- * EXPECTATIONS:
- * - Task doesn't execute immediately even with completed StatusRequest
- * - Task executes after specified delay period
- * - Timing behavior respects delay parameter
- * - Normal task behavior after initial delayed execution
- *
- * IMPORTANCE: Delayed event waiting enables complex timing coordination
- * scenarios where both time and event conditions must be satisfied.
- * Essential for staggered startup and synchronized operation patterns.
+ * PURPOSE: Same as above only task is scheduled with a delay as a result
  */
  */
 TEST_F(AdvancedSchedulerTest, TaskWaitForDelayedStatusRequest) {
 TEST_F(AdvancedSchedulerTest, TaskWaitForDelayedStatusRequest) {
     Scheduler ts;
     Scheduler ts;
     StatusRequest sr;
     StatusRequest sr;
 
 
     // StatusRequest already complete
     // StatusRequest already complete
-    sr.signalComplete();
+    sr.setWaiting(1);
+    advanced_callback_counter = 0;
 
 
     // Create task with delayed wait (should wait for delay even though SR is complete)
     // Create task with delayed wait (should wait for delay even though SR is complete)
-    Task delayed_waiter(100, 1, &consumer_callback, &ts);
-    delayed_waiter.waitForDelayed(&sr, 200, 1); // 200ms delay
+    Task delayed_waiter(500, 1, &consumer_callback, &ts);
+    delayed_waiter.waitForDelayed(&sr, 500, 1); // 500ms delay
 
 
     // Task should be enabled
     // Task should be enabled
     EXPECT_TRUE(delayed_waiter.isEnabled());
     EXPECT_TRUE(delayed_waiter.isEnabled());
@@ -631,9 +607,15 @@ TEST_F(AdvancedSchedulerTest, TaskWaitForDelayedStatusRequest) {
     ts.execute();
     ts.execute();
     EXPECT_EQ(advanced_callback_counter, 0);
     EXPECT_EQ(advanced_callback_counter, 0);
 
 
-    // Should execute after delay
-    delay(200);
-    bool success = runAdvancedSchedulerUntil(ts, []() {
+    sr.signalComplete(); // Complete SR
+
+    // The task will be scheduled to run after the delay
+    bool success = runAdvancedSchedulerUntil(ts, true, 200); // Wait up to 200ms
+    EXPECT_FALSE(success); 
+
+    delay(400);
+    // Task should complete after total 500ms delay
+    success = runAdvancedSchedulerUntil(ts, []() {
         return advanced_callback_counter >= 1;
         return advanced_callback_counter >= 1;
     });
     });
     EXPECT_TRUE(success);
     EXPECT_TRUE(success);
@@ -933,6 +915,8 @@ TEST_F(AdvancedSchedulerTest, StatusRequestTimeout) {
  * IMPORTANCE: Scheduling options enable advanced task behavior control
  * IMPORTANCE: Scheduling options enable advanced task behavior control
  * essential for priority management, resource allocation, and
  * essential for priority management, resource allocation, and
  * specialized execution patterns in complex applications.
  * specialized execution patterns in complex applications.
+ *
+ * TODO: This needs to be completely redone - this AI generated test is absolutely wrong
  */
  */
 TEST_F(AdvancedSchedulerTest, TaskSchedulingOptions) {
 TEST_F(AdvancedSchedulerTest, TaskSchedulingOptions) {
     Scheduler ts;
     Scheduler ts;
@@ -942,19 +926,19 @@ TEST_F(AdvancedSchedulerTest, TaskSchedulingOptions) {
     unsigned int default_option = task.getSchedulingOption();
     unsigned int default_option = task.getSchedulingOption();
 
 
     // Set different scheduling options
     // Set different scheduling options
-    task.setSchedulingOption(1);
-    EXPECT_EQ(task.getSchedulingOption(), 1);
+    task.setSchedulingOption(TASK_SCHEDULE);
+    EXPECT_EQ(task.getSchedulingOption(), TASK_SCHEDULE);
 
 
-    task.setSchedulingOption(42);
-    EXPECT_EQ(task.getSchedulingOption(), 42);
+    task.setSchedulingOption(TASK_SCHEDULE_NC);
+    EXPECT_EQ(task.getSchedulingOption(), TASK_SCHEDULE_NC);
 
 
-    task.setSchedulingOption(0);
-    EXPECT_EQ(task.getSchedulingOption(), 0);
+    task.setSchedulingOption(TASK_INTERVAL);
+    EXPECT_EQ(task.getSchedulingOption(), TASK_INTERVAL);
 
 
     // Verify option can be changed while task is enabled
     // Verify option can be changed while task is enabled
     task.enable();
     task.enable();
-    task.setSchedulingOption(99);
-    EXPECT_EQ(task.getSchedulingOption(), 99);
+    task.setSchedulingOption(TASK_SCHEDULE_NC);
+    EXPECT_EQ(task.getSchedulingOption(), TASK_SCHEDULE_NC);
     EXPECT_TRUE(task.isEnabled()); // Should remain enabled
     EXPECT_TRUE(task.isEnabled()); // Should remain enabled
 }
 }
 
 

+ 11 - 9
tests/test-scheduler-basic-thorough-no-lambda.cpp → tests/test-scheduler-basic-thorough.cpp

@@ -3,7 +3,7 @@
 // without using lambda functions, ensuring compatibility with all Arduino platforms
 // without using lambda functions, ensuring compatibility with all Arduino platforms
 //
 //
 // =====================================================================================
 // =====================================================================================
-// COMPREHENSIVE TASKSCHEDULER TEST PLAN AND COVERAGE MATRIX (NO LAMBDA VERSION)
+// COMPREHENSIVE TASKSCHEDULER TEST PLAN AND COVERAGE MATRIX
 // =====================================================================================
 // =====================================================================================
 //
 //
 // PURPOSE: Validate all basic TaskScheduler methods and patterns without compile options
 // PURPOSE: Validate all basic TaskScheduler methods and patterns without compile options
@@ -157,7 +157,7 @@ static Scheduler* global_scheduler_ptr = nullptr;
 static Task* global_yield_task = nullptr;
 static Task* global_yield_task = nullptr;
 static Task* global_yield_once_task = nullptr;
 static Task* global_yield_once_task = nullptr;
 
 
-// Test callback functions (no lambda functions)
+// Test callback functions
 
 
 /**
 /**
  * @brief Callback function for getCurrentTask test
  * @brief Callback function for getCurrentTask test
@@ -1016,12 +1016,13 @@ TEST_F(SchedulerThoroughTest, TaskSetInterval) {
  * EXPECTATIONS:
  * EXPECTATIONS:
  * - getIterations() returns updated count
  * - getIterations() returns updated count
  * - Task executes exactly 5 times (new iteration count)
  * - Task executes exactly 5 times (new iteration count)
- * - Task automatically disables after final iteration
+ * - Task automatically disables after final iteration + 1
  * - Callback counter reaches exactly 5
  * - Callback counter reaches exactly 5
  *
  *
  * IMPORTANCE: Dynamic iteration control allows adaptive execution
  * IMPORTANCE: Dynamic iteration control allows adaptive execution
  * cycles based on runtime conditions, essential for conditional
  * cycles based on runtime conditions, essential for conditional
  * processing and resource-conscious applications.
  * processing and resource-conscious applications.
+ * Task is disabled on the next scheduler pass after reaching zero iterations. 
  */
  */
 TEST_F(SchedulerThoroughTest, TaskSetIterations) {
 TEST_F(SchedulerThoroughTest, TaskSetIterations) {
     Scheduler ts;
     Scheduler ts;
@@ -1031,7 +1032,7 @@ TEST_F(SchedulerThoroughTest, TaskSetIterations) {
     EXPECT_EQ(task.getIterations(), 5);
     EXPECT_EQ(task.getIterations(), 5);
 
 
     // Should run 5 times
     // Should run 5 times
-    bool success = runSchedulerUntil(ts, []() { return callback_counter >= 5; });
+    bool success = runSchedulerUntil(ts, []() { return callback_counter >= (5+1); });
     EXPECT_TRUE(success);
     EXPECT_TRUE(success);
     EXPECT_EQ(callback_counter, 5);
     EXPECT_EQ(callback_counter, 5);
     EXPECT_FALSE(task.isEnabled()); // Should auto-disable after iterations
     EXPECT_FALSE(task.isEnabled()); // Should auto-disable after iterations
@@ -1126,6 +1127,7 @@ TEST_F(SchedulerThoroughTest, TaskSetCallbacks) {
  * IMPORTANCE: Iteration state queries enable initialization and cleanup
  * IMPORTANCE: Iteration state queries enable initialization and cleanup
  * logic within callbacks, essential for resource management and
  * logic within callbacks, essential for resource management and
  * conditional processing based on execution phase.
  * conditional processing based on execution phase.
+ * NOTE: Scheduler disables the task on the next scheduler pass after the final iteration.
  */
  */
 TEST_F(SchedulerThoroughTest, TaskIterationState) {
 TEST_F(SchedulerThoroughTest, TaskIterationState) {
     Scheduler ts;
     Scheduler ts;
@@ -1137,7 +1139,7 @@ TEST_F(SchedulerThoroughTest, TaskIterationState) {
 
 
     // Note: Testing iteration state requires access during callback execution
     // Note: Testing iteration state requires access during callback execution
     // This test verifies the task completes its iterations properly
     // This test verifies the task completes its iterations properly
-    success = runSchedulerUntil(ts, []() { return callback_counter >= 3; });
+    success = runSchedulerUntil(ts, []() { return callback_counter >= (3+1); });
     EXPECT_TRUE(success);
     EXPECT_TRUE(success);
     EXPECT_EQ(callback_counter, 3);
     EXPECT_EQ(callback_counter, 3);
     EXPECT_FALSE(task.isEnabled()); // Should auto-disable after 3 iterations
     EXPECT_FALSE(task.isEnabled()); // Should auto-disable after 3 iterations
@@ -1242,7 +1244,7 @@ TEST_F(SchedulerThoroughTest, TaskYieldOnce) {
     success = runSchedulerUntil(ts, []() { return getTestOutputCount() >= 2; });
     success = runSchedulerUntil(ts, []() { return getTestOutputCount() >= 2; });
     EXPECT_TRUE(success);
     EXPECT_TRUE(success);
     EXPECT_EQ(getTestOutput(1), "step_2");
     EXPECT_EQ(getTestOutput(1), "step_2");
-    EXPECT_FALSE(task.isEnabled()); // Should be disabled after yieldOnce
+    EXPECT_TRUE(task.isEnabled()); // Should be still enabled after yieldOnce
 
 
     global_yield_once_task = nullptr; // Clean up
     global_yield_once_task = nullptr; // Clean up
 }
 }
@@ -1417,9 +1419,9 @@ TEST_F(SchedulerThoroughTest, SchedulerInit) {
 
 
     ts.init(); // Should reinitialize
     ts.init(); // Should reinitialize
 
 
-    // Task should still work after init
+    // Task should not work after init - the task chain is empty
     bool success = runSchedulerUntil(ts, []() { return callback_counter >= 1; });
     bool success = runSchedulerUntil(ts, []() { return callback_counter >= 1; });
-    EXPECT_TRUE(success);
+    EXPECT_FALSE(success);
 }
 }
 
 
 // ================== SCHEDULER TASK MANAGEMENT TESTS ==================
 // ================== SCHEDULER TASK MANAGEMENT TESTS ==================
@@ -1801,7 +1803,7 @@ TEST_F(SchedulerThoroughTest, ComplexTaskLifecycle) {
     EXPECT_TRUE(task.isEnabled());
     EXPECT_TRUE(task.isEnabled());
 
 
     // Run all iterations
     // Run all iterations
-    bool success = runSchedulerUntil(ts, []() { return callback_counter >= 3; });
+    bool success = runSchedulerUntil(ts, []() { return callback_counter >= (3+1); });
     EXPECT_TRUE(success);
     EXPECT_TRUE(success);
     EXPECT_EQ(callback_counter, 3);
     EXPECT_EQ(callback_counter, 3);
     EXPECT_EQ(task.getRunCounter(), 3);
     EXPECT_EQ(task.getRunCounter(), 3);