Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp207814imj; Thu, 14 Feb 2019 18:43:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IZHGgbbeY+eDP0cmEwRgNtUvho+KR20zxI7mUULFCq9PbCHzoiY1BoWoxqGaWXJ4lZk3ubq X-Received: by 2002:a65:520a:: with SMTP id o10mr3184819pgp.276.1550198581305; Thu, 14 Feb 2019 18:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550198581; cv=none; d=google.com; s=arc-20160816; b=QpAk7cd89OE0zdXQjvi0v+jSUxG0bWU6n9xGYNtYuxQVB03uW1tqJszcQdoHsbZcY2 j7eOEkkWx6HQoVyolhVTkWUbRsxK03GsoN+R3ZSdt5tSuqllxLvJab6Jyt6ypgDSmcLf jXp9UWJ+76I1o6T413GfE2B1TZzpntYoOQYF/JynAQcNwM5k/1XtKEFpuTilpjMWyPjI P+EE08QmiWtDjE1S5/RGoe7XmJxC6RgYvoH7j4exPXLoM5YiXRVBSdVibtrWGiIIUTqV Ws7BlftV1SPsLKlogV5+ZEHeq4C85x1imYVQBzJAx01izuXzzcIk5PD7VLikU0+nZmIq efFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kYVYvCrBOXqV6ir57fw9KRLYW6PjSJ+UMmuaHHMQ3+E=; b=DXSqiCfnOWQlzPoPWN9ouo2iAGgZv5v+9nRHV2oOwFIEe60jKflfbQ0lT/U5zYEhGX 0pLRx/PqHMiybDncphrf3+Kq9Nw4w4dd1D7ENCcz7S4ZmLtCONvBw23F6W8RwaVSkrOG PGRg1mhSA9/2U6dlJVNaNumw5jFHQiL15S/eAfFl5MS1qsAsE3wYAic7x2znqdTTTjg2 Uo7DnpbmT3l1TADgX32M3a18bsyvxfQ3ZS0MKHzK8eBTcjtGj+7bBnBlT+3S0XNAkRl+ CO9FVq4xHS7VR8PMsf1/7hxxwqdFFw8Vh+/VAxIYuSZLxnQ4QdnZcXeG6MHCzh/vQOUS mCgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FQMKcH/i"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j132si4200197pfc.84.2019.02.14.18.42.45; Thu, 14 Feb 2019 18:43:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FQMKcH/i"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732003AbfBOClr (ORCPT + 99 others); Thu, 14 Feb 2019 21:41:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:49696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387678AbfBOCJc (ORCPT ); Thu, 14 Feb 2019 21:09:32 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E4167222C9; Fri, 15 Feb 2019 02:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196571; bh=a2XlMNwkxCqbKdEk2qYjdpGrEODXQvqJMMiqtzQmxC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FQMKcH/i8PZ64AahrTK0cWiqMkOsBRqvIyuWpy+qVRfSB9N3cpOJ4TjB168NhvKyO dfPuxTR8DKfZUyqnyG+96EDWeIoomjkeOKNeIfRIEhjJtbYkqAGWxwdPpw6hMoV5Xo n2B6ylwy9yFdUg83bSaqhMu9bkRzXvWmfk59O1c0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexandre Belloni , Shuah Khan , Sasha Levin , linux-rtc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 19/77] selftests: rtc: rtctest: add alarm test on minute boundary Date: Thu, 14 Feb 2019 21:07:57 -0500 Message-Id: <20190215020855.176727-19-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Belloni [ Upstream commit 7b3027728f4d4f6763f4d7e771acfc9424cdd0e6 ] Unfortunately, some RTC don't have a second resolution for alarm so also test for alarm on a minute boundary. Signed-off-by: Alexandre Belloni Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- tools/testing/selftests/rtc/rtctest.c | 102 ++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c index dea4e3d6d9e1..b2065536d407 100644 --- a/tools/testing/selftests/rtc/rtctest.c +++ b/tools/testing/selftests/rtc/rtctest.c @@ -211,6 +211,108 @@ TEST_F(rtc, alarm_wkalm_set) { ASSERT_EQ(new, secs); } +TEST_F(rtc, alarm_alm_set_minute) { + struct timeval tv = { .tv_sec = 62 }; + unsigned long data; + struct rtc_time tm; + fd_set readfds; + time_t secs, new; + int rc; + + rc = ioctl(self->fd, RTC_RD_TIME, &tm); + ASSERT_NE(-1, rc); + + secs = timegm((struct tm *)&tm) + 60 - tm.tm_sec; + gmtime_r(&secs, (struct tm *)&tm); + + rc = ioctl(self->fd, RTC_ALM_SET, &tm); + if (rc == -1) { + ASSERT_EQ(EINVAL, errno); + TH_LOG("skip alarms are not supported."); + return; + } + + rc = ioctl(self->fd, RTC_ALM_READ, &tm); + ASSERT_NE(-1, rc); + + TH_LOG("Alarm time now set to %02d:%02d:%02d.", + tm.tm_hour, tm.tm_min, tm.tm_sec); + + /* Enable alarm interrupts */ + rc = ioctl(self->fd, RTC_AIE_ON, 0); + ASSERT_NE(-1, rc); + + FD_ZERO(&readfds); + FD_SET(self->fd, &readfds); + + rc = select(self->fd + 1, &readfds, NULL, NULL, &tv); + ASSERT_NE(-1, rc); + ASSERT_NE(0, rc); + + /* Disable alarm interrupts */ + rc = ioctl(self->fd, RTC_AIE_OFF, 0); + ASSERT_NE(-1, rc); + + rc = read(self->fd, &data, sizeof(unsigned long)); + ASSERT_NE(-1, rc); + TH_LOG("data: %lx", data); + + rc = ioctl(self->fd, RTC_RD_TIME, &tm); + ASSERT_NE(-1, rc); + + new = timegm((struct tm *)&tm); + ASSERT_EQ(new, secs); +} + +TEST_F(rtc, alarm_wkalm_set_minute) { + struct timeval tv = { .tv_sec = 62 }; + struct rtc_wkalrm alarm = { 0 }; + struct rtc_time tm; + unsigned long data; + fd_set readfds; + time_t secs, new; + int rc; + + rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time); + ASSERT_NE(-1, rc); + + secs = timegm((struct tm *)&alarm.time) + 60 - alarm.time.tm_sec; + gmtime_r(&secs, (struct tm *)&alarm.time); + + alarm.enabled = 1; + + rc = ioctl(self->fd, RTC_WKALM_SET, &alarm); + if (rc == -1) { + ASSERT_EQ(EINVAL, errno); + TH_LOG("skip alarms are not supported."); + return; + } + + rc = ioctl(self->fd, RTC_WKALM_RD, &alarm); + ASSERT_NE(-1, rc); + + TH_LOG("Alarm time now set to %02d/%02d/%02d %02d:%02d:%02d.", + alarm.time.tm_mday, alarm.time.tm_mon + 1, + alarm.time.tm_year + 1900, alarm.time.tm_hour, + alarm.time.tm_min, alarm.time.tm_sec); + + FD_ZERO(&readfds); + FD_SET(self->fd, &readfds); + + rc = select(self->fd + 1, &readfds, NULL, NULL, &tv); + ASSERT_NE(-1, rc); + ASSERT_NE(0, rc); + + rc = read(self->fd, &data, sizeof(unsigned long)); + ASSERT_NE(-1, rc); + + rc = ioctl(self->fd, RTC_RD_TIME, &tm); + ASSERT_NE(-1, rc); + + new = timegm((struct tm *)&tm); + ASSERT_EQ(new, secs); +} + static void __attribute__((constructor)) __constructor_order_last(void) { -- 2.19.1