diff options
author | Kalesh Singh <kaleshsingh@google.com> | 2020-09-10 03:38:02 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-09-10 03:38:02 +0000 |
commit | 78625800abb936767b44448eb17bff4b1c4e9943 (patch) | |
tree | 5758935bae5a35a9c29c5f07e6296798a260c813 | |
parent | 3a328c7680b6bfe873623bd8017982c65ef4d997 (diff) | |
parent | 6fe283693ec06247a8cb37d90e02b2f88d30795c (diff) | |
download | linux-kselftest-78625800abb936767b44448eb17bff4b1c4e9943.tar.gz |
Merge changes I2bcbe6fa,I302b77bb am: 233c77b06d am: c75a928ae1 am: dc0a6ca342 am: 6fe283693e
Original change: https://android-review.googlesource.com/c/platform/external/linux-kselftest/+/1423571
Change-Id: I34e2c0367cb09fabb172e2dc195283fceda6ba5c
-rw-r--r-- | tools/testing/selftests/rtc/rtctest.c | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c index 44cd1b652619..845f07733216 100644 --- a/tools/testing/selftests/rtc/rtctest.c +++ b/tools/testing/selftests/rtc/rtctest.c @@ -5,14 +5,13 @@ * Copyright (c) 2018 Alexandre Belloni <alexandre.belloni@bootlin.com> */ -#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <linux/rtc.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <sys/ioctl.h> +#include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <time.h> @@ -25,25 +24,6 @@ static char *rtc_file = "/dev/rtc0"; -/* Returns 1 if file matching /dev/rtc* is found, else 0. */ -static int has_rtc(void) -{ - DIR *dev_dir; - struct dirent *dir; - - dev_dir = opendir("/dev"); - if (!dev_dir) - return 0; - while ((dir = readdir(dev_dir))) { - if (!strncmp(dir->d_name, "rtc", 3)) { - closedir(dev_dir); - return 1; - } - } - closedir(dev_dir); - return 0; -} - FIXTURE(rtc) { int fd; }; @@ -61,9 +41,6 @@ TEST_F(rtc, date_read) { int rc; struct rtc_time rtc_tm; - if (!has_rtc()) - return; - /* Read the RTC time/date */ rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm); ASSERT_NE(-1, rc); @@ -348,6 +325,8 @@ __constructor_order_last(void) int main(int argc, char **argv) { + struct stat st; + switch (argc) { case 2: rtc_file = argv[1]; @@ -359,5 +338,10 @@ int main(int argc, char **argv) return 1; } + if (stat(rtc_file, &st) < 0 || !S_ISCHR(st.st_mode)) { + printf("no RTC present\n"); + return 0; + } + return test_harness_run(argc, argv); } |