MCPcopy Create free account
hub / github.com/PiSCSI/piscsi / RunTimerTest

Method RunTimerTest

cpp/scsiloop/scsiloop_timer.cpp:15–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include "hal/log.h"
14
15int ScsiLoop_Timer::RunTimerTest(vector<string> &error_list)
16{
17 uint32_t timer_test_failures = 0;
18
19 ScsiLoop_Cout::StartTest("hardware timer");
20
21 // Allow +/- 2% tolerance when testing the timers
22 double timer_tolerance_percent = 0.02;
23 const uint32_t one_second_in_ns = 1000000;
24
25 //------------------------------------------------------
26 // Test SysTimer::GetTimerLow()
27 LOGDEBUG("++ Testing SysTimer::GetTimerLow()")
28 uint32_t before = SysTimer::GetTimerLow();
29 for (int i = 0; i < 10; i++) {
30 usleep(100000);
31 ScsiLoop_Cout::PrintUpdate();
32 }
33 uint32_t after = SysTimer::GetTimerLow();
34
35 uint32_t elapsed_nanosecs = after - before;
36
37 LOGDEBUG("Elapsed time: %d %08X", elapsed_nanosecs, elapsed_nanosecs);
38
39 if ((elapsed_nanosecs > (one_second_in_ns * (1.0 + timer_tolerance_percent))) ||
40 (elapsed_nanosecs < (one_second_in_ns * (1.0 - timer_tolerance_percent)))) {
41 error_list.push_back(fmt::format("SysTimer::GetTimerLow() test: Expected time approx: {}, but actually {}",
42 one_second_in_ns, elapsed_nanosecs));
43 timer_test_failures++;
44 } else {
45 ScsiLoop_Cout::PrintUpdate();
46 }
47
48 //------------------------------------------------------
49 // Test SysTimer::SleepUsec()
50 LOGDEBUG("++ Testing SysTimer::SleepUsec()")
51
52 uint32_t expected_usec_result = 1000 * 100;
53 before = SysTimer::GetTimerLow();
54 for (int i = 0; i < 100; i++) {
55 SysTimer::SleepUsec(1000);
56 }
57 after = SysTimer::GetTimerLow();
58 elapsed_nanosecs = after - before;
59 LOGDEBUG("SysTimer::SleepUsec() Average %d", elapsed_nanosecs / 100);
60
61 if ((elapsed_nanosecs > expected_usec_result * (1.0 + timer_tolerance_percent)) ||
62 (elapsed_nanosecs < expected_usec_result * (1.0 - timer_tolerance_percent))) {
63 error_list.push_back(fmt::format("SysTimer::SleepUsec Test: Expected time approx: {}, but actually {}",
64 expected_usec_result, elapsed_nanosecs));
65 timer_test_failures++;
66 } else {
67 ScsiLoop_Cout::PrintUpdate();
68 }
69
70 //------------------------------------------------------
71 // Test SysTimer::SleepNsec()
72 LOGDEBUG("++ Testing SysTimer::SleepNsec()")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected