avoid false negatives when running tests on a simulator

After time measurements' accuracy was fixed, some test verifying TPM
time readings started failing because the tests do not expect it to be
possible to have to back to back commands to happen within the same
millisecond.

This patch adds a two milliseconds delay in the function returning the
time (responding to the TPM2_ReadClock command) when in simulation
mode, which allows the tests pass reliably.

BUG=chrome-os-partner:43025
TEST=intermittent test failures (one in five on average) are not
     happening any more (tried 30 times).

Change-Id: Ie9fd948dfaf25cc5f66aaa896f6570ac1d0509bb
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/308000
Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org>
diff --git a/ReadClock.c b/ReadClock.c
index e9ae872..5ba470c 100644
--- a/ReadClock.c
+++ b/ReadClock.c
@@ -13,9 +13,20 @@
    )
 {
 // Command Output
-
    out->currentTime.time = g_time;
    TimeFillInfo(&out->currentTime.clockInfo);
 
+#ifndef EMBEDDED_MODE
+   {
+       UINT64 start_time = _plat__ClockTimeFromStart();
+       // When running on a simulator, some tests fail, because two commands
+       // invoked back to back happen to run within the same millisecond, but
+       // the test expects time readings to be different. Modifying the tests
+       // is more involved, let's just wait a couple of milliseconds here to
+       // avoid those tests' false negatives.
+       while ((_plat__ClockTimeFromStart() - start_time) < 2)
+           ;
+   }
+#endif
    return TPM_RC_SUCCESS;
 }