blob: 0a896327fa5976f6b992d3010290c135ef871353 [file] [log] [blame]
Primiano Tucci8934c6c2018-03-15 11:39:27 +00001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "perfetto/base/time.h"
18
19#include "gtest/gtest.h"
20
21namespace perfetto {
22namespace base {
23namespace {
24
25TEST(TimeTest, Conversions) {
26 TimeMillis ms = GetWallTimeMs();
27 TimeNanos ns = GetWallTimeNs();
28 EXPECT_NEAR(ms.count(), ns.count() / 1000000, 1000);
29
30 {
31 struct timespec ts = ToPosixTimespec(TimeMillis(0));
32 EXPECT_EQ(0, ts.tv_sec);
33 EXPECT_EQ(0, ts.tv_nsec);
34 }
35 {
36 struct timespec ts = ToPosixTimespec(TimeMillis(1));
37 EXPECT_EQ(0, ts.tv_sec);
38 EXPECT_EQ(1000000, ts.tv_nsec);
39 }
40 {
41 struct timespec ts = ToPosixTimespec(TimeMillis(12345));
42 EXPECT_EQ(12, ts.tv_sec);
43 EXPECT_EQ(345000000, ts.tv_nsec);
44 }
45 {
46 struct timespec ts = ToPosixTimespec(TimeMillis(1000000000001LL));
47 EXPECT_EQ(1000000000, ts.tv_sec);
48 EXPECT_EQ(1000000, ts.tv_nsec);
49 }
50}
51
52} // namespace
53} // namespace base
54} // namespace perfetto