Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3357976rwi; Fri, 21 Oct 2022 15:26:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7cujPbtA460bKTJegEhKUG3cHAqxdy0JnU2N5NznYhoppl62fUkTCHZ+pbfrNp8dFWSHql X-Received: by 2002:a63:1d22:0:b0:439:3e7c:8af7 with SMTP id d34-20020a631d22000000b004393e7c8af7mr18104712pgd.78.1666391170956; Fri, 21 Oct 2022 15:26:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666391170; cv=none; d=google.com; s=arc-20160816; b=zMMP+J2aJlDVbZ4Fns4dxTTKJ0QFpqu1tckbCVoz3lyj+MhYFLuXZO/XBi0uidyxjc Hx14UOXrrhVu8amSqKUO9oja+CjqhxIFbjIlM9aIbYIVM7tp5AQpY9izQr4wNJr/m/8I ZytzKKQkLg1XX6cAdeocmTEXFBHEHn4X5vVZGsBErJr2aA6q8zkRrLSkUHzp71QOq23j Te60QV5aYH4+DZLBPBYq+iJuD9zTAPhAwmrMewMv6xhoz3kRPFhy8FhaykWGmUGMSIQ+ u810JtHgcpHf2FfsTbAZ9/zP7+r4Mvjak5uHlDfII3TZQgKoBCLjg6/CKZwuerH6X3qJ tCWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mlh6byGTM8abd+hoZXnHkK8wpHen7Kg7enAq8H4CPPg=; b=eDOD3gPoLmn0Gl39j8iNIpkiZTtRhK4dT7DiC6MYfBNJIwgHut6WowYyYVowqDqMgu kqxZfzguwE97CyZGvmViYSG2HArK3jUesXHwyY6yTmWdQ0spCJn0RO27+XUuq7vorRew enYtN4ELjVG78vZJs7KhiQMulLXXLNi/Wotom+dfgkPHmUEuibaWvrbzH/z/1vHRRT3j z+X4ReJO2NCex033ffi6wTnLBZH4FgZKtTP5SCHCu5a2Hg63Hw+wMWAIZDsJ+k7kJLrZ Fyd8IKm2ENZoP6Odwp4iyirzrdACffzvHgVijknIxi+fApCyyWxF68ZRSf/IKvl+lz9e r5yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=fx3eYTlJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 37-20020a630d65000000b0046b15902616si28459489pgn.270.2022.10.21.15.25.49; Fri, 21 Oct 2022 15:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=fx3eYTlJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbiJUWSb (ORCPT + 99 others); Fri, 21 Oct 2022 18:18:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiJUWS0 (ORCPT ); Fri, 21 Oct 2022 18:18:26 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 715A72AA17B for ; Fri, 21 Oct 2022 15:18:24 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id i9so2386509ilv.9 for ; Fri, 21 Oct 2022 15:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mlh6byGTM8abd+hoZXnHkK8wpHen7Kg7enAq8H4CPPg=; b=fx3eYTlJhUHw9ssE2UFhZioTH5qkq8bbUlKoP3gCYFuyZ5CTJ6I30rvFDFt0xTwsls 4FeyxKdYL6SCSn9DwNscDbkvWF5Cg3ZDfomKYrLavJn5sZk98NMu24LI2sAw/kdoHDHA Y5+TArRJuMGxlCjU1GzHehRi13O8t3D21O2iU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mlh6byGTM8abd+hoZXnHkK8wpHen7Kg7enAq8H4CPPg=; b=GZmcaF7neUKsdb/qEP3pj2Qver8Mh9MRNahpXVONbBGdSCU/chWLjH154ZC8448MDk wgTlNne5VwAfrYQbdot/zi0XMgjfI3y6JvFnFq6p8ue+B+9AHmEt7CmsM8G06D5ZA1iN Q1PzBdUl+WpwXqlWa1bIQGlFD6WMtxs33bjuz/FOoHJbM9lbYQ8DsFiNymh+BU0HAho8 kuIxX0TSCsUyMh7NjW0Uf8cRdnra0kf0HTqTdFXMopb5LJ55MGWFq0exxu+n8YPCnV11 PPurv7TCNlQx7vr4e4ZRd1A0KtkIj2TK5tHBc9LJb96CaArPmCpD0jB280iSI0kTtl4w ro8Q== X-Gm-Message-State: ACrzQf2fsEsjy9BSituYjIX6yInwP/VQd2TYzeIrVu+ksR6dZBGaHNuH zQtBtZJNvdGeEoXQY6NdgPhtmQ== X-Received: by 2002:a05:6e02:1c0c:b0:2fa:bd75:55a5 with SMTP id l12-20020a056e021c0c00b002fabd7555a5mr15240001ilh.234.1666390703410; Fri, 21 Oct 2022 15:18:23 -0700 (PDT) Received: from shuah-tx13.internal ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id cp6-20020a056638480600b0036cc14af7adsm430740jab.149.2022.10.21.15.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:18:22 -0700 (PDT) From: Shuah Khan To: skhan@linuxfoundation.org, shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] selftests/watchdog: add support for WDIOC_GETSTATUS Date: Fri, 21 Oct 2022 16:18:17 -0600 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for calling WDIOC_GETSTATUS and printing supported features and status. Signed-off-by: Shuah Khan --- .../selftests/watchdog/watchdog-test.c | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c index 5db9ad8b543c..e6af6e327eb3 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c @@ -6,8 +6,6 @@ * - Could be tested against softdog driver on systems that * don't have watchdog hadrware. * - TODO: -* - WDIOC_GETSTATUS is called when WDIOC_GETBOOTSTATUS is called. -* - Enhance the logic to call WDIOC_GETSTATUS and test return values. * - Enhance coverage of ioctl return values - flags and status. * - Enhance test to add coverage for WDIOC_GETTEMP. * @@ -30,13 +28,14 @@ int fd; const char v = 'V'; -static const char sopts[] = "bdehp:t:Tn:NLf:i"; +static const char sopts[] = "bdehp:st:Tn:NLf:i"; static const struct option lopts[] = { {"bootstatus", no_argument, NULL, 'b'}, {"disable", no_argument, NULL, 'd'}, {"enable", no_argument, NULL, 'e'}, {"help", no_argument, NULL, 'h'}, {"pingrate", required_argument, NULL, 'p'}, + {"status", no_argument, NULL, 's'}, {"timeout", required_argument, NULL, 't'}, {"gettimeout", no_argument, NULL, 'T'}, {"pretimeout", required_argument, NULL, 'n'}, @@ -85,6 +84,7 @@ static void usage(char *progname) printf(" -f, --file\t\tOpen watchdog device file\n"); printf("\t\t\tDefault is /dev/watchdog\n"); printf(" -i, --info\t\tShow watchdog_info\n"); + printf(" -s, --status\t\tGet status & supported features\n"); printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n"); printf(" -d, --disable\t\tTurn off the watchdog timer\n"); printf(" -e, --enable\t\tTurn on the watchdog timer\n"); @@ -107,6 +107,35 @@ struct wdiof_status { const char *status_str; }; +#define WDIOF_NUM_STATUS 8 + +static const struct wdiof_status wdiof_status[WDIOF_NUM_STATUS] = { + {WDIOF_SETTIMEOUT, "Set timeout (in seconds)"}, + {WDIOF_MAGICCLOSE, "Supports magic close char"}, + {WDIOF_PRETIMEOUT, "Pretimeout (in seconds), get/set"}, + {WDIOF_ALARMONLY, "Watchdog triggers a management or other external alarm not a reboot"}, + {WDIOF_KEEPALIVEPING, "Keep alive ping reply"}, + {WDIOS_DISABLECARD, "Turn off the watchdog timer"}, + {WDIOS_ENABLECARD, "Turn on the watchdog timer"}, + {WDIOS_TEMPPANIC, "Kernel panic on temperature trip"}, +}; + +static void print_status(int flags) +{ + int wdiof = 0; + + if (flags == WDIOS_UNKNOWN) { + printf("Unknown status error from WDIOC_GETSTATUS\n"); + return; + } + + for (wdiof = 0; wdiof < WDIOF_NUM_STATUS; wdiof++) { + if (flags & wdiof_status[wdiof].flag) + printf("Support/Status: %s\n", + wdiof_status[wdiof].status_str); + } +} + #define WDIOF_NUM_BOOTSTATUS 7 static const struct wdiof_status wdiof_bootstatus[WDIOF_NUM_BOOTSTATUS] = { @@ -219,6 +248,15 @@ int main(int argc, char *argv[]) ping_rate = DEFAULT_PING_RATE; printf("Watchdog ping rate set to %u seconds.\n", ping_rate); break; + case 's': + flags = 0; + oneshot = 1; + ret = ioctl(fd, WDIOC_GETSTATUS, &flags); + if (!ret) + print_status(flags); + else + printf("WDIOC_GETSTATUS error '%s'\n", strerror(errno)); + break; case 't': flags = strtoul(optarg, NULL, 0); ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags); -- 2.34.1