Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11a0227d authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add uptimeNanos to SystemClock" am: 52c8422e am: c7a22256 am: ba7efc63

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1394287

Change-Id: Ib9e04266b47bdc6129c10c72ee35222c49beff1e
parents 4c5acc0f ba7efc63
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -39,8 +39,15 @@ namespace android {
 */
int64_t uptimeMillis()
{
    int64_t when = systemTime(SYSTEM_TIME_MONOTONIC);
    return (int64_t) nanoseconds_to_milliseconds(when);
    return nanoseconds_to_milliseconds(uptimeNanos());
}

/*
 * public static native long uptimeNanos();
 */
int64_t uptimeNanos()
{
    return systemTime(SYSTEM_TIME_MONOTONIC);
}

/*
+19 −1
Original line number Diff line number Diff line
@@ -29,16 +29,24 @@ static const int64_t SLACK_NS = SLACK_MS * MS_IN_NS;

TEST(SystemClock, SystemClock) {
    auto startUptimeMs = android::uptimeMillis();
    auto startUptimeNs = android::uptimeNanos();
    auto startRealtimeMs = android::elapsedRealtime();
    auto startRealtimeNs = android::elapsedRealtimeNano();

    ASSERT_GT(startUptimeMs, 0)
            << "uptimeMillis() reported an impossible uptime";
    ASSERT_GT(startUptimeNs, 0)
            << "uptimeNanos() reported an impossible uptime";
    ASSERT_GE(startRealtimeMs, startUptimeMs)
            << "elapsedRealtime() thinks we've suspended for negative time";
    ASSERT_GE(startRealtimeNs, startUptimeMs * MS_IN_NS)
    ASSERT_GE(startRealtimeNs, startUptimeNs)
            << "elapsedRealtimeNano() thinks we've suspended for negative time";

    ASSERT_GE(startUptimeNs, startUptimeMs * MS_IN_NS)
            << "uptimeMillis() and uptimeNanos() are inconsistent";
    ASSERT_LT(startUptimeNs, (startUptimeMs + SLACK_MS) * MS_IN_NS)
            << "uptimeMillis() and uptimeNanos() are inconsistent";

    ASSERT_GE(startRealtimeNs, startRealtimeMs * MS_IN_NS)
            << "elapsedRealtime() and elapsedRealtimeNano() are inconsistent";
    ASSERT_LT(startRealtimeNs, (startRealtimeMs + SLACK_MS) * MS_IN_NS)
@@ -51,6 +59,7 @@ TEST(SystemClock, SystemClock) {
    ASSERT_EQ(nanosleepErr, 0) << "nanosleep() failed: " << strerror(errno);

    auto endUptimeMs = android::uptimeMillis();
    auto endUptimeNs = android::uptimeNanos();
    auto endRealtimeMs = android::elapsedRealtime();
    auto endRealtimeNs = android::elapsedRealtimeNano();

@@ -58,6 +67,10 @@ TEST(SystemClock, SystemClock) {
            << "uptimeMillis() advanced too little after nanosleep()";
    EXPECT_LT(endUptimeMs - startUptimeMs, SLEEP_MS + SLACK_MS)
            << "uptimeMillis() advanced too much after nanosleep()";
    EXPECT_GE(endUptimeNs - startUptimeNs, SLEEP_NS)
            << "uptimeNanos() advanced too little after nanosleep()";
    EXPECT_LT(endUptimeNs - startUptimeNs, SLEEP_NS + SLACK_NS)
            << "uptimeNanos() advanced too much after nanosleep()";
    EXPECT_GE(endRealtimeMs - startRealtimeMs, SLEEP_MS)
            << "elapsedRealtime() advanced too little after nanosleep()";
    EXPECT_LT(endRealtimeMs - startRealtimeMs, SLEEP_MS + SLACK_MS)
@@ -67,6 +80,11 @@ TEST(SystemClock, SystemClock) {
    EXPECT_LT(endRealtimeNs - startRealtimeNs, SLEEP_NS + SLACK_NS)
            << "elapsedRealtimeNano() advanced too much after nanosleep()";

    EXPECT_GE(endUptimeNs, endUptimeMs * MS_IN_NS)
            << "uptimeMillis() and uptimeNanos() are inconsistent after nanosleep()";
    EXPECT_LT(endUptimeNs, (endUptimeMs + SLACK_MS) * MS_IN_NS)
            << "uptimeMillis() and uptimeNanos() are inconsistent after nanosleep()";

    EXPECT_GE(endRealtimeNs, endRealtimeMs * MS_IN_NS)
            << "elapsedRealtime() and elapsedRealtimeNano() are inconsistent after nanosleep()";
    EXPECT_LT(endRealtimeNs, (endRealtimeMs + SLACK_MS) * MS_IN_NS)
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
namespace android {

int64_t uptimeMillis();
int64_t uptimeNanos();
int64_t elapsedRealtime();
int64_t elapsedRealtimeNano();