platform-mc: Fix `sensorPollingTest` unit-test error

Even the `doSensorPolling` task is scheduled to run after each
`SENSOR_POLLING_TIME` milliseconds, it does not mean that the kernel
will trigger `doSensorPolling` task at time `t0`, `t0 +
SENSOR_POLLING_TIME`, `t0 + 2*SENSOR_POLLING_TIME`, .., `t0 +
n*SENSOR_POLLING_TIME` because the kernel can busy so it may trigger the
schedule task late. This causes the number of the triggered
`doSensorPolling` tasks after `n*SENSOR_POLLING_TIME` milliseconds can
be less than `n`.
That why the current `sensorPollingTest` unit-test sometime is failed
with below errors especially when run the unit-test in slow local
machine.
```
Actual function call count doesn't match EXPECT_CALL(sensorManager, doSensorPolling(tid))...
         Expected: to be called at least 100 times
           Actual: called 40 times - unsatisfied and active
```

Update the `sensorPollingTest` to check the interval between two
triggered times of the `doSensorPolling` tasks instead of number called
times. This interval should greater than SENSOR_POLLING_TIME ms.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Khang Nguyen <khangng@amperecomputing.com>
Change-Id: I33c31ceba76476ae7f9396f2bbf84093fe3f2519
diff --git a/platform-mc/test/sensor_manager_test.cpp b/platform-mc/test/sensor_manager_test.cpp
index 9fe050b..b3a2d41 100644
--- a/platform-mc/test/sensor_manager_test.cpp
+++ b/platform-mc/test/sensor_manager_test.cpp
@@ -8,9 +8,7 @@
 
 #include <gtest/gtest.h>
 
-using ::testing::_;
-using ::testing::Between;
-using ::testing::Return;
+using namespace ::testing;
 
 class SensorManagerTest : public testing::Test
 {
@@ -152,7 +150,6 @@
 TEST_F(SensorManagerTest, sensorPollingTest)
 {
     uint64_t seconds = 10;
-    uint64_t expectedTimes = (seconds * 1000) / SENSOR_POLLING_TIME;
 
     pldm_tid_t tid = 1;
     termini[tid] = std::make_shared<pldm::platform_mc::Terminus>(tid, 0);
@@ -160,8 +157,16 @@
     termini[tid]->pdrs.push_back(pdr2);
     termini[tid]->parseTerminusPDRs();
 
+    uint64_t t0, t1;
+    ASSERT_TRUE(sd_event_now(event.get(), CLOCK_MONOTONIC, &t0) >= 0);
+    ON_CALL(sensorManager, doSensorPolling(tid))
+        .WillByDefault([this, &t0, &t1](unsigned char) {
+            ASSERT_TRUE(sd_event_now(event.get(), CLOCK_MONOTONIC, &t1) >= 0);
+            EXPECT_GE(t1 - t0, SENSOR_POLLING_TIME * 1000);
+            t0 = t1;
+        });
     EXPECT_CALL(sensorManager, doSensorPolling(tid))
-        .Times(Between(expectedTimes - 3, expectedTimes + 3))
+        .Times(AtLeast(2))
         .WillRepeatedly(Return());
 
     sensorManager.startPolling(tid);