aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_os_utils.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-28 14:24:35 -0400
committerJack Lloyd <[email protected]>2018-03-28 14:24:35 -0400
commita0833f827f96a82db6be1466b3fd382fda615dbc (patch)
treed72aac98dac75c98eb3a71ba84387f5627b4a295 /src/tests/test_os_utils.cpp
parent0787c4b05b1bba7276846839a4b372539ee370ec (diff)
Improve test of cycle counter to avoid bogus failures
GH #1515
Diffstat (limited to 'src/tests/test_os_utils.cpp')
-rw-r--r--src/tests/test_os_utils.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/tests/test_os_utils.cpp b/src/tests/test_os_utils.cpp
index 1c159ca75..83f3fda00 100644
--- a/src/tests/test_os_utils.cpp
+++ b/src/tests/test_os_utils.cpp
@@ -66,29 +66,22 @@ class OS_Utils_Tests final : public Test
Test::Result test_get_processor_timestamp()
{
- // TODO better tests
Test::Result result("OS::get_processor_timestamp");
const uint64_t proc_ts1 = Botan::OS::get_processor_timestamp();
- // do something that consumes a little time
- volatile int x = 11;
- while(x < 65535)
- {
- x *= 2;
- x -= 10;
- }
-
- uint64_t proc_ts2 = Botan::OS::get_processor_timestamp();
-
if(proc_ts1 == 0)
{
+ const uint64_t proc_ts2 = Botan::OS::get_processor_timestamp();
result.test_is_eq("Disabled processor timestamp stays at zero", proc_ts1, proc_ts2);
+ return result;
}
- else
- {
- result.confirm("Processor timestamp does not duplicate", proc_ts1 != proc_ts2);
- }
+
+ size_t counts = 0;
+ while(Botan::OS::get_processor_timestamp() == proc_ts1)
+ ++counts;
+
+ result.test_lt("CPU cycle counter eventually changes value", counts, 10);
return result;
}