Skip to content

Commit 489bea0

Browse files
committed
LibTest: Remove uses of gettimeofday in favor of AK::Time
gettimeofday is not a thing on Windows or esoteric Unixen.
1 parent 88fb2b0 commit 489bea0

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

Libraries/LibTest/TestRunnerUtil.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#pragma once
88

9+
#include <AK/Time.h>
910
#include <LibCore/DirIterator.h>
1011
#include <fcntl.h>
1112
#include <sys/stat.h>
@@ -15,10 +16,8 @@ namespace Test {
1516

1617
inline double get_time_in_ms()
1718
{
18-
struct timeval tv1;
19-
auto return_code = gettimeofday(&tv1, nullptr);
20-
VERIFY(return_code >= 0);
21-
return static_cast<double>(tv1.tv_sec) * 1000.0 + static_cast<double>(tv1.tv_usec) / 1000.0;
19+
auto now = UnixDateTime::now();
20+
return static_cast<double>(now.milliseconds_since_epoch());
2221
}
2322

2423
template<typename Callback>

Libraries/LibTest/TestSuite.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <AK/Function.h>
9+
#include <AK/Time.h>
910
#include <LibCore/ArgsParser.h>
1011
#include <LibTest/Macros.h>
1112
#include <LibTest/TestResult.h>
@@ -22,21 +23,15 @@ class TestElapsedTimer {
2223
public:
2324
TestElapsedTimer() { restart(); }
2425

25-
void restart() { gettimeofday(&m_started, nullptr); }
26+
void restart() { m_started = UnixDateTime::now(); }
2627

2728
u64 elapsed_milliseconds()
2829
{
29-
struct timeval now = {};
30-
gettimeofday(&now, nullptr);
31-
32-
struct timeval delta = {};
33-
timersub(&now, &m_started, &delta);
34-
35-
return delta.tv_sec * 1000 + delta.tv_usec / 1000;
30+
return (UnixDateTime::now() - m_started).to_milliseconds();
3631
}
3732

3833
private:
39-
struct timeval m_started = {};
34+
UnixDateTime m_started;
4035
};
4136

4237
// Declared in Macros.h

0 commit comments

Comments
 (0)