Merge "Increase coverage of Timers to 100%." am: 2dc28bcfc4
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1710936 Change-Id: I2c722abc2249fc2b4b52486d7d6dd69426394657
This commit is contained in:
commit
1db66002c1
2 changed files with 17 additions and 18 deletions
|
|
@ -14,9 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
|
||||||
// Timer functions.
|
|
||||||
//
|
|
||||||
#include <utils/Timers.h>
|
#include <utils/Timers.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
@ -24,11 +21,12 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <android-base/macros.h>
|
#include <android-base/macros.h>
|
||||||
|
#include <utils/Log.h>
|
||||||
|
|
||||||
static constexpr size_t clock_id_max = 5;
|
static constexpr size_t clock_id_max = 5;
|
||||||
|
|
||||||
static void checkClockId(int clock) {
|
static void checkClockId(int clock) {
|
||||||
if (clock < 0 || clock >= clock_id_max) abort();
|
LOG_ALWAYS_FATAL_IF(clock < 0 || clock >= clock_id_max, "invalid clock id");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
|
@ -56,18 +54,10 @@ nsecs_t systemTime(int clock) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime)
|
int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime) {
|
||||||
{
|
if (timeoutTime <= referenceTime) return 0;
|
||||||
nsecs_t timeoutDelayMillis;
|
|
||||||
if (timeoutTime > referenceTime) {
|
uint64_t timeoutDelay = uint64_t(timeoutTime - referenceTime);
|
||||||
uint64_t timeoutDelay = uint64_t(timeoutTime - referenceTime);
|
if (timeoutDelay > uint64_t((INT_MAX - 1) * 1000000LL)) return -1;
|
||||||
if (timeoutDelay > uint64_t((INT_MAX - 1) * 1000000LL)) {
|
return (timeoutDelay + 999999LL) / 1000000LL;
|
||||||
timeoutDelayMillis = -1;
|
|
||||||
} else {
|
|
||||||
timeoutDelayMillis = (timeoutDelay + 999999LL) / 1000000LL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
timeoutDelayMillis = 0;
|
|
||||||
}
|
|
||||||
return (int)timeoutDelayMillis;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,12 @@ TEST(Timers, systemTime_invalid) {
|
||||||
systemTime(SYSTEM_TIME_BOOTTIME);
|
systemTime(SYSTEM_TIME_BOOTTIME);
|
||||||
EXPECT_EXIT(systemTime(SYSTEM_TIME_BOOTTIME + 1), testing::KilledBySignal(SIGABRT), "");
|
EXPECT_EXIT(systemTime(SYSTEM_TIME_BOOTTIME + 1), testing::KilledBySignal(SIGABRT), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Timers, toMillisecondTimeoutDelay) {
|
||||||
|
EXPECT_EQ(0, toMillisecondTimeoutDelay(100, 100));
|
||||||
|
EXPECT_EQ(0, toMillisecondTimeoutDelay(100, 10));
|
||||||
|
|
||||||
|
EXPECT_EQ(-1, toMillisecondTimeoutDelay(0, INT_MAX * 1000000LL));
|
||||||
|
|
||||||
|
EXPECT_EQ(123, toMillisecondTimeoutDelay(0, 123000000));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue