diff options
author | Kalesh Singh <kaleshsingh@google.com> | 2020-09-01 21:50:04 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-09-01 21:50:04 +0000 |
commit | 22ad13f4c1103d730e6327e81c9a2baad27fbab3 (patch) | |
tree | 69ee8ab74ad322a497b503d2cb17d718f7b691a8 | |
parent | 464218192fe7b9cbbe1f97bbafe528dd37b5c369 (diff) | |
parent | 9be42dbecae721c748e6bbccae1af44417a8ab26 (diff) | |
download | linux-kselftest-22ad13f4c1103d730e6327e81c9a2baad27fbab3.tar.gz |
VTS: kselftest rtctest am: 7b7fc39a3b am: 9be42dbeca
Original change: https://android-review.googlesource.com/c/platform/external/linux-kselftest/+/1416090
Change-Id: I417301fda252a8cc56404975d3e51f7668ad94ff
-rw-r--r-- | tools/testing/selftests/rtc/rtctest.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c index 92c403558dc5..44cd1b652619 100644 --- a/tools/testing/selftests/rtc/rtctest.c +++ b/tools/testing/selftests/rtc/rtctest.c @@ -5,11 +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/time.h> #include <sys/types.h> @@ -23,6 +25,25 @@ 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; }; @@ -40,6 +61,9 @@ 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); |