diff options
author | Andreas Gampe <agampe@google.com> | 2018-03-20 18:36:16 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-03-20 18:36:16 +0000 |
commit | 061bb759154f2626d298dfb8be435d2f61cd04e5 (patch) | |
tree | eda0901f03ce89b0df378c3549760510e72d18d6 /tests | |
parent | 645564b248dbf59c434f730120606df2d3d59474 (diff) | |
parent | 95b60bb00c42c7cdba9bbe3c4fa80c9ace282e01 (diff) | |
download | extras-061bb759154f2626d298dfb8be435d2f61cd04e5.tar.gz |
Merge "Timetest: Clean up" am: dcfb201c61
am: 95b60bb00c
Change-Id: Iabfac97640a0b3b105362d642cb61961546aefbf
Diffstat (limited to 'tests')
-rw-r--r-- | tests/timetest/Android.bp | 17 | ||||
-rw-r--r-- | tests/timetest/Android.mk | 23 | ||||
-rw-r--r-- | tests/timetest/rtc_test.cpp | 46 |
3 files changed, 41 insertions, 45 deletions
diff --git a/tests/timetest/Android.bp b/tests/timetest/Android.bp new file mode 100644 index 00000000..998faeff --- /dev/null +++ b/tests/timetest/Android.bp @@ -0,0 +1,17 @@ +// Copyright 2006 The Android Open Source Project + +cc_test { + name: "time-unit-tests", + cflags: [ + "-fstack-protector-all", + "-g", + "-Wextra", + "-fno-builtin", + ], + srcs: [ + "rtc_test.cpp", + ], + shared_libs: [ + "libbase", + ], +} diff --git a/tests/timetest/Android.mk b/tests/timetest/Android.mk index af3447fd..be311fa4 100644 --- a/tests/timetest/Android.mk +++ b/tests/timetest/Android.mk @@ -10,26 +10,3 @@ LOCAL_MODULE_TAGS := tests LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_STATIC_LIBRARIES := libc include $(BUILD_NATIVE_TEST) - -# ----------------------------------------------------------------------------- -# Unit tests. -# ----------------------------------------------------------------------------- - -test_c_flags := \ - -fstack-protector-all \ - -g \ - -Wall -Wextra \ - -Werror \ - -fno-builtin \ - -test_src_files := \ - rtc_test.cpp - -include $(CLEAR_VARS) -LOCAL_MODULE := time-unit-tests -LOCAL_COMPATIBILITY_SUITE := device-tests -LOCAL_MODULE_TAGS := tests -LOCAL_CFLAGS += $(test_c_flags) -LOCAL_SRC_FILES := $(test_src_files) -include $(BUILD_NATIVE_TEST) - diff --git a/tests/timetest/rtc_test.cpp b/tests/timetest/rtc_test.cpp index 26ca13ad..e7874b1d 100644 --- a/tests/timetest/rtc_test.cpp +++ b/tests/timetest/rtc_test.cpp @@ -24,49 +24,51 @@ #include <gtest/gtest.h> +#include <android-base/unique_fd.h> + static int hwtime(int flag, int request, struct rtc_time *tm) { static const char rtc[] = "/dev/rtc0"; - int ret = TEMP_FAILURE_RETRY(access(rtc, flag & O_WRONLY) ? W_OK : R_OK); + int ret = access(rtc, flag & O_WRONLY); if (ret < 0) { - ret = -errno; - } - if (ret == -EACCES) { - return ret; + return -errno; } if (flag & O_WRONLY) { struct stat st; ret = TEMP_FAILURE_RETRY(stat(rtc, &st)); if (ret < 0) { - ret = -errno; + return -errno; } else if (!(st.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH))) { - ret = -EACCES; + return -EACCES; } } - if (ret == -EACCES) { - return ret; - } - do { + for (int count = 0; count < 10; count++) { ret = TEMP_FAILURE_RETRY(open(rtc, flag)); if (ret < 0) { - ret = -errno; + if (errno == EBUSY) { + sleep(1); + continue; + } + return -errno; } - } while (ret == -EBUSY); - if (ret < 0) { - return ret; + break; } + android::base::unique_fd fd(ret); - int fd = ret; - do { - ret = TEMP_FAILURE_RETRY(ioctl(fd, request, tm)); + for (int count = 0; count < 10; count++) { + ret = TEMP_FAILURE_RETRY(ioctl(fd.get(), request, tm)); if (ret < 0) { - ret = -errno; + if (errno == EBUSY) { + sleep(1); + continue; + } + return -errno; } - } while (ret == -EBUSY); - close(fd); - return ret; + return ret; + }; + return -EBUSY; } static int rd_hwtime(struct rtc_time *tm) { |