Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1265473lqo; Fri, 17 May 2024 17:17:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/bGmDAXwFYSNaIbFT2Xtg6i+AvbkLZi54w/EYZ9V+7i0UXG0zy6CVkVg9Yk6zyzcKmRDc09lGP3ztxGZIRz2ZFGwTXx+YWhW71RZT4A== X-Google-Smtp-Source: AGHT+IHX5PoqP+RWXV+nIR8G00p1Z+x79180JblcgIo6vxWNIYuzMI+rGO5BslB1yycj7IlWWctR X-Received: by 2002:a17:90a:e616:b0:2b6:214a:71ac with SMTP id 98e67ed59e1d1-2bd60353110mr800055a91.3.1715991431520; Fri, 17 May 2024 17:17:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715991431; cv=pass; d=google.com; s=arc-20160816; b=SvwkG+QJGWJibXDEuFzqmrw8kvttb9P7Jxw3OCVmQq83rqyUmhzeZXHh/bQ9fpUTMM KCYqBN5ucj1xiJWuja8Jc5M08V0DMeNq1ac1hxN+oP+ZtS3Du30VLlOMxRr3jiGpRHrt xEum9ijoyLPWXwZUYyzOMXShHRs/ccMDoDhF0cpiNFxGCxOd3+TlVBDXwLqYA5ORiWHD Oca6NBeOxbKqY0496rvFQ+8WMNTYj1hGHZaBVCV2CgaA9IWMSQnoAFQwh1auoRx5v+Cz eQQj6GMrSWP6+CPl4QTvthtzJcsS0V5vVYMluVTr7ElOd0YH8Z5JGUnoD4TQaYfZMc5m x2OA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=irkVL93e2r7C0Hy5+trw8pmsG8779sgzCHeX9n3CiN0=; fh=jqniecLe4RvYIBd8QCwfkNEyPMAl66RfiHRhzngd8Js=; b=iYWM6SAc+EgfPf9UjCTgMdQogIKLocV+A0Dwx93QM0HHWwAksg5w1VKFNmX58I+xqe hGH9tUZTyoAGBN3/XTHqziVNaot1VCafJ6zcP9+Y14NsBtIvy+3Ff1OR5BSeGNPoLYJV BAaRYYegQ1FgbpOEZOV5Jfz1JPlgRFmcDZOGhXrcPT+uPDVidcVfjWg+y64WfLtqmQuC v3k0Ea0hHjV5/jaoIDGpjYFzorh7hsQ9K+SS5KYupKOwT02iAtXUAfovIPV/a+baf+bU jmZ06jETEyLJpjc8b2jv9BDCZBCcAjekGTHb6dLJ1zJCDgnKceGHDw1yvJIfXzBVfp1g 3BPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UStHqVo3; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-182722-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182722-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-65f0d228c62si2130648a12.470.2024.05.17.17.17.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 17:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182722-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UStHqVo3; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-182722-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182722-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 23D6C282F36 for ; Sat, 18 May 2024 00:17:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD5333211; Sat, 18 May 2024 00:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="UStHqVo3" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F5C336C for ; Sat, 18 May 2024 00:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715991423; cv=none; b=tVQhcpHwVVW1dGa0W/I7sBsINX+/lXpT/alQDE6Dh9WD96jKmx76XEwdK5h0RJv+TG5tm5zxzNHSIOcdpERwYW/30+W0lxh202wYBP0c6psWsLAwd/SjDbgdW6frkPlkrFDqZsPBA+i9/oIBp9sEAeciC5B5dl2KGdElK/jNiDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715991423; c=relaxed/simple; bh=psb/9cAnhp+Xzaq8lXVTJ+5ogfgNeGdZpdDamrOEPi8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=EEEY/LEvojZo/FAo/7OpPau61sxnAbbfpG/s0emEOWVybbVF4eiBIDbm1yOmrhwE/ZbOR2NdwBUSleZs4Lgni8kiEnS4Qp8sz+KRwET8miQdvCOJzEoR3FgjKu4MJqatI+vLJuL9MdN4yUA+RWvADKV4WEKNAq0I97f2GR68zrk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=UStHqVo3; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1ee38966529so8205385ad.1 for ; Fri, 17 May 2024 17:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715991422; x=1716596222; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=irkVL93e2r7C0Hy5+trw8pmsG8779sgzCHeX9n3CiN0=; b=UStHqVo3wPfQ6HcIsDMF5je4Krpa6DYNHvc+Mt2pIrNdhO+8Xg+4dyqNWpt+5z7h9B OnhYLqPbmpstanrboHbljEM5WcDuZFHRrsmpr6eY+EMv3SOI+9vqApWyI0gbywmC5Ayo /qrUvWWX6cr9JfMnBPf9vcObNemy1ZLY+W90w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715991422; x=1716596222; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=irkVL93e2r7C0Hy5+trw8pmsG8779sgzCHeX9n3CiN0=; b=Qi8DkgI9JNi8o4+65hp0V5sjCL2t7/IvdtVZSK0gqLAW0Lb8xFeGcBfCBipdtzkHMq RRPh5VPuPqhe887Fdv0MxeqqxCZp8RkfPQE44MS0+dyF+uOWDKKmK5o3XzzkA+KKUoFh Vx53JvT2LSAWnB/sNL6nq+Ywh5qfzcTkJWVqbGx3qh7VeJMF2sxgDxkXxWSiTliYJzaI hbnIrms6XiVhdHNC5WmFsSiE8KX5/uxA9pJpIBv3bkJGThhnlh00QeJpXbRNTFEC5fx5 qMeIENP4mbikF5menlPZ61F/KnWKc47+HiFrhQK6bX0aBwfU8xuMhDbJ4QNJPGKvq7xE xhtg== X-Forwarded-Encrypted: i=1; AJvYcCUfXivm6WLZAaOWgno3s2FnVu4KDxZetzF3wvmH95ViwD8ForX38mF4ENWF/kFvi16xqLTCRsjTMM/1aVkBPWfcaVRtY02YuQlS5ra2 X-Gm-Message-State: AOJu0Yy6oZImfcXPN/kS5aESAmB3XdAmhIERdP28qIr3nf1FEayJ2R2G lBELuyaMfUO+QG5I8vyeKQPFE3ntH2/wohLKJV0VA6oMPZlW4XXgNBm7aFd59A== X-Received: by 2002:a17:902:e752:b0:1e5:5760:a6c1 with SMTP id d9443c01a7336-1f2ed2ebe08mr7151825ad.21.1715991421580; Fri, 17 May 2024 17:17:01 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bad9da4sm162348915ad.107.2024.05.17.17.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 17:17:00 -0700 (PDT) From: Kees Cook To: Alexandre Belloni Cc: Kees Cook , Shuah Khan , Masahiro Yamada , linux-rtc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] selftests: rtc: rtctest: Do not open-code TEST_HARNESS_MAIN Date: Fri, 17 May 2024 17:16:58 -0700 Message-Id: <20240518001655.work.053-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5223; i=keescook@chromium.org; h=from:subject:message-id; bh=psb/9cAnhp+Xzaq8lXVTJ+5ogfgNeGdZpdDamrOEPi8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmR/N6s/j5oZN920PNFTll/WpzqmtBDGQzJiKQO WN+Gr07bhaJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZkfzegAKCRCJcvTf3G3A JjXID/wMzWXl2uBgZBj8D9wl0hC56WI14SrF0DqQnjVVOg7LoM/vvq3w1s4e2+ZXB/S3ILG7bmj MU6ATJTr3PXZ8D2KLL0HjPnjAHXetcJ6zsbNbfuPsydkqbAt35MDp0uoAePnq3vEzRWLZdnMpCX 75F/1XL6Nm9f4xFfmq9chfi5Z47h0Zt+UyWhs+udLvtadqk3M6nz3xVg67N9N8RvmpqgAOXVAM8 wL4V3CxKhiamcqGuaUmOqQG5ISBPxUPm56WMM/FD524JaiRRv0YKQPU71Xf5wqfh+2idJvoNIG7 1F3KWiieBCi0Hyyy1l8GivFac0+RbslIiHtS6oC4XtqnLn1M1FpsaoeRT3oAYTMaDa4ch8t8wnB GtUxMnCShZyT+DU8/x4WYr2wP1LzT4cEIktWX/Y7uMS0Y4zNDwJCN/lqQAUkZy8nOtFxNvvRGaP DszsKzBQQiBFpq4msqQn8TK2baNbnr97VkD3hu553LBpJlLIIW2AFZj2vWM+8NJE50JOKv6LpY7 Sqh7k3tUNxdyzpC8rLKRzXj16sWpdHEohdTmzKcjSk7N/phEwMhraCx7Y1Rr0q59ASm4fx1Udzj 9vUjis3AFvsmdsm1kyESB1sGYgAKnQRnTdWgjmmilHeC/x6DG+U3mELMcmhq+EBtFhhhmD0Nxut uzugFPC 4cjHaSJg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Argument processing is specific to the test harness code. Any optional information needs to be passed via environment variables. Move alternate path to the RTC_DEV environment variable. Also do not open-code TEST_HARNESS_MAIN because its definition may change. Additionally, setup checking can be done in the FIXTURE_SETUP(). With this adjustment, also improve the error reporting when the device cannot be opened. Signed-off-by: Kees Cook --- Cc: Alexandre Belloni Cc: Shuah Khan Cc: Masahiro Yamada Cc: linux-rtc@vger.kernel.org Cc: linux-kselftest@vger.kernel.org --- tools/testing/selftests/rtc/Makefile | 2 +- tools/testing/selftests/rtc/rtctest.c | 66 +++++---------------------- 2 files changed, 13 insertions(+), 55 deletions(-) diff --git a/tools/testing/selftests/rtc/Makefile b/tools/testing/selftests/rtc/Makefile index 55198ecc04db..654f9d58da3c 100644 --- a/tools/testing/selftests/rtc/Makefile +++ b/tools/testing/selftests/rtc/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS += -O3 -Wl,-no-as-needed -Wall +CFLAGS += -O3 -Wl,-no-as-needed -Wall $(KHDR_INCLUDES) LDLIBS += -lrt -lpthread -lm TEST_GEN_PROGS = rtctest diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c index 63ce02d1d5cc..41cfefcc20e1 100644 --- a/tools/testing/selftests/rtc/rtctest.c +++ b/tools/testing/selftests/rtc/rtctest.c @@ -30,7 +30,18 @@ FIXTURE(rtc) { }; FIXTURE_SETUP(rtc) { + char *alternate = getenv("RTC_DEV"); + + if (alternate) + rtc_file = alternate; + self->fd = open(rtc_file, O_RDONLY); + + if (self->fd == -1 && errno == ENOENT) + SKIP(return, "Skipping test since %s does not exist", rtc_file); + EXPECT_NE(-1, self->fd) { + TH_LOG("%s: %s\n", rtc_file, strerror(errno)); + } } FIXTURE_TEARDOWN(rtc) { @@ -41,10 +52,6 @@ TEST_F(rtc, date_read) { int rc; struct rtc_time rtc_tm; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - /* Read the RTC time/date */ rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm); ASSERT_NE(-1, rc); @@ -88,10 +95,6 @@ TEST_F_TIMEOUT(rtc, date_read_loop, READ_LOOP_DURATION_SEC + 2) { struct rtc_time rtc_tm; time_t start_rtc_read, prev_rtc_read; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - TH_LOG("Continuously reading RTC time for %ds (with %dms breaks after every read).", READ_LOOP_DURATION_SEC, READ_LOOP_SLEEP_MS); @@ -126,10 +129,6 @@ TEST_F_TIMEOUT(rtc, uie_read, NUM_UIE + 2) { int i, rc, irq = 0; unsigned long data; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - /* Turn on update interrupts */ rc = ioctl(self->fd, RTC_UIE_ON, 0); if (rc == -1) { @@ -155,10 +154,6 @@ TEST_F(rtc, uie_select) { int i, rc, irq = 0; unsigned long data; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - /* Turn on update interrupts */ rc = ioctl(self->fd, RTC_UIE_ON, 0); if (rc == -1) { @@ -198,10 +193,6 @@ TEST_F(rtc, alarm_alm_set) { time_t secs, new; int rc; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - rc = ioctl(self->fd, RTC_RD_TIME, &tm); ASSERT_NE(-1, rc); @@ -256,10 +247,6 @@ TEST_F(rtc, alarm_wkalm_set) { time_t secs, new; int rc; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time); ASSERT_NE(-1, rc); @@ -308,10 +295,6 @@ TEST_F_TIMEOUT(rtc, alarm_alm_set_minute, 65) { time_t secs, new; int rc; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - rc = ioctl(self->fd, RTC_RD_TIME, &tm); ASSERT_NE(-1, rc); @@ -366,10 +349,6 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) { time_t secs, new; int rc; - if (self->fd == -1 && errno == ENOENT) - SKIP(return, "Skipping test since %s does not exist", rtc_file); - ASSERT_NE(-1, self->fd); - rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time); ASSERT_NE(-1, rc); @@ -410,25 +389,4 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) { ASSERT_EQ(new, secs); } -static void __attribute__((constructor)) -__constructor_order_last(void) -{ - if (!__constructor_order) - __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; -} - -int main(int argc, char **argv) -{ - switch (argc) { - case 2: - rtc_file = argv[1]; - /* FALLTHROUGH */ - case 1: - break; - default: - fprintf(stderr, "usage: %s [rtcdev]\n", argv[0]); - return 1; - } - - return test_harness_run(argc, argv); -} +TEST_HARNESS_MAIN -- 2.34.1