Fix test sleep on iOS. am: a9f051faac

Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/13805070

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I83b4fe9f33fb61fc1b4a57088783513d9e5abbae
This commit is contained in:
Rahul Frias
2021-03-10 15:42:42 +00:00
committed by Automerger Merge Worker

View File

@@ -9,6 +9,9 @@
#else #else
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#ifdef __APPLE__
# include <TargetConditionals.h>
#endif
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
@@ -73,10 +76,13 @@ bool TestSleep::RollbackSystemTime(int seconds) {
file_time.dwHighDateTime = long_time >> 32; file_time.dwHighDateTime = long_time >> 32;
if (!FileTimeToSystemTime(&file_time, &time)) return false; if (!FileTimeToSystemTime(&file_time, &time)) return false;
if (!SetSystemTime(&time)) return false; if (!SetSystemTime(&time)) return false;
#elif TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
LOGE("iOS time rollback: cannot set system time.");
return false;
#else #else
auto time = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::now();
auto modified_time = time - std::chrono::seconds(seconds); auto modified_time = time - std::chrono::seconds(seconds);
;
timespec time_spec; timespec time_spec;
time_spec.tv_sec = std::chrono::duration_cast<std::chrono::seconds>( time_spec.tv_sec = std::chrono::duration_cast<std::chrono::seconds>(
modified_time.time_since_epoch()) modified_time.time_since_epoch())
@@ -140,6 +146,9 @@ bool TestSleep::CanChangeSystemTime() {
} }
LOGE("Win32 time rollback: cannot set system time."); LOGE("Win32 time rollback: cannot set system time.");
return false; return false;
#elif TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
LOGE("iOS time rollback: cannot set system time.");
return false;
#else #else
// Otherwise, the test needs to be run as root. // Otherwise, the test needs to be run as root.
const uid_t uid = getuid(); const uid_t uid = getuid();