Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3358854rwi; Fri, 21 Oct 2022 15:27:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7K1fqCR9okIDAw8Yo4GP3zY/L2wifj6m22I4l2TEYUIuYssqsYPKCvtdLflddp95Rxy8se X-Received: by 2002:a63:2d8:0:b0:46e:9da4:df67 with SMTP id 207-20020a6302d8000000b0046e9da4df67mr8608367pgc.176.1666391240056; Fri, 21 Oct 2022 15:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666391240; cv=none; d=google.com; s=arc-20160816; b=zYGu/S8Jg5WTTBZMeTLZoo1AkkVm2WtQ4evsmdTK6Uk335BVXD53WPSm5CLrdSFUN2 yAB1lz9BcoDmPDGV+DJSZe6NRsnuY9WAFCzVOsN7I/0YY+BbRvQ+t4pMtJXPOD9mBipq 2n4xdbsEy662X6Ms6mLPDO7qYtxa0AbVBo61hWWZo9A1xWDJBKc20kHqi5dMI2FPf/X8 BZf7MP5s3aKSjMw9vQMYggc11g1XaGj+M1cWH8epcqXYrw4y3vrz7fYJg8FZdiJWqem3 VaW8xV1Fb2ReH2VchdQewpeO6VS0La7ofhrxgkal1QOWyEzsmIRrY1eZM81PKSIszYCt 0keA== 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=BZvHy7jdg7bn/NJGr1GFQwTrExyfPTldTZ+sxF4fBFk=; b=VORDt3Wpcav6TISKu0oFDbHHF4jIvT6nxtBWimOgKhMvM+1RiJiNvzUkHCWBD2SrjE QRIZ8R7zGa99tR6jt1rw5xJQSzRF1D5plO832h30uVv2kWI4UFkgUhOejAGDAEu6P1Fc gdDFrm2Q4brg9+cj7glOXRcgbX3FVc40WQ6xbd6pXy/emAFbNcu/SB9fEeQnLjTGgBRJ cVIXshjqX3joydXLdMCl6fvL2vPgDkJXuCUCOPaZwDy7DFiYxgzIIL/FJdSEHQZVRb/p ZOfwAVjguY4RbLg4dbVthTkuhapaNJtukYtpQWqO+QYJj1iq2XVJGMVUl7l6UMNs1TY2 ly+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=DPPzQn6b; 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 g15-20020a17090a708f00b002000867929fsi7257949pjk.183.2022.10.21.15.27.07; Fri, 21 Oct 2022 15:27:20 -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=DPPzQn6b; 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 S229728AbiJUWS3 (ORCPT + 99 others); Fri, 21 Oct 2022 18:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiJUWSZ (ORCPT ); Fri, 21 Oct 2022 18:18:25 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB082AB11A for ; Fri, 21 Oct 2022 15:18:23 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id y80so3495625iof.3 for ; Fri, 21 Oct 2022 15:18:23 -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=BZvHy7jdg7bn/NJGr1GFQwTrExyfPTldTZ+sxF4fBFk=; b=DPPzQn6bpnBujPZ4Po2qLVhYnKyqqB56z+hRzedBT+NeViwX3jGWzdOS1lofPngvYL 0qf2JZIGX5bKY6sUyjWrRR90ki955StSmKMtrfGaqk79n8luJpEQ527LqW78kcgn0wyx cnvmOnTqlf4WGWa5dQKEeCEZLXZdrLNoea3t4= 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=BZvHy7jdg7bn/NJGr1GFQwTrExyfPTldTZ+sxF4fBFk=; b=7hOGzVzaGJHCGSSMCYFOiAI8oltgoEUoK2Sb6C2HW7Z+06ksNjT8RDpJxMNnRNyW5X NXk3JB68WspEHmpWtRhhMzPkcEDIckJ6VscxsyM9vqWkemxiYSigiSFU/gx+rflBd+HU +Gnx/PBowHJmMHykiM66uRQwqKZz8B/FrdbNkiBkXqwunO+H6JQw6te44JQelXrk+dXl 1IHiXXu4hbXJUNHRgYpNrkZ3WaSzvdyt7EQZ+gHxe5K6VhEMkWsUvb3P6d9LDRy4Wk2f sYG+EXFpaJEdF3+ioHoqwpYDxO4Dt9QE1nrcE1iHpJfYYf5xIJteDP+n0OdpBP3Cd6N6 O3RA== X-Gm-Message-State: ACrzQf35mgkDqPVK0JFTnsd3vtezHOGJekqA+8ZSvMvqitOQ/tskIi5i txltigy++0vXLvDxO/ungbl0Dw== X-Received: by 2002:a02:390c:0:b0:363:79f0:ad37 with SMTP id l12-20020a02390c000000b0036379f0ad37mr16856345jaa.95.1666390702490; Fri, 21 Oct 2022 15:18:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:18:21 -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 1/4] selftests/watchdog: change to print reset reason info. Date: Fri, 21 Oct 2022 16:18:16 -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=unavailable 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 The test prints reset reason when WDIOC_GETBOOTSTATUS returns a 0 flag value and all other cases simply say watchdog. Parse the flag values returned by WDIOC_GETBOOTSTATUS and print corresponding reset reason for each WDIOF_* boot status. Signed-off-by: Shuah Khan --- .../selftests/watchdog/watchdog-test.c | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c index f45e510500c0..5db9ad8b543c 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c @@ -1,6 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Watchdog Driver Test Program +* Watchdog Driver Test Program +* - Tests all ioctls except WDIOC_GETTEMP +* - Tests Magic Close - CONFIG_WATCHDOG_NOWAYOUT +* - 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. +* +* Reference: Documentation/watchdog/watchdog-api.rst */ #include @@ -91,6 +102,44 @@ static void usage(char *progname) printf("Example: %s -t 12 -T -n 7 -N\n", progname); } +struct wdiof_status { + int flag; + const char *status_str; +}; + +#define WDIOF_NUM_BOOTSTATUS 7 + +static const struct wdiof_status wdiof_bootstatus[WDIOF_NUM_BOOTSTATUS] = { + {WDIOF_OVERHEAT, "Reset due to CPU overheat"}, + {WDIOF_FANFAULT, "Fan failed"}, + {WDIOF_EXTERN1, "External relay 1"}, + {WDIOF_EXTERN2, "External relay 2"}, + {WDIOF_POWERUNDER, "Power bad/power fault"}, + {WDIOF_CARDRESET, "Card previously reset the CPU"}, + {WDIOF_POWEROVER, "Power over voltage"}, +}; + +static void print_boot_status(int flags) +{ + int wdiof = 0; + + if (flags == WDIOF_UNKNOWN) { + printf("Unknown flag error from WDIOC_GETBOOTSTATUS\n"); + return; + } + + if (flags == 0) { + printf("Last boot is caused by: Power-On-Reset\n"); + return; + } + + for (wdiof = 0; wdiof < WDIOF_NUM_BOOTSTATUS; wdiof++) { + if (flags & wdiof_bootstatus[wdiof].flag) + printf("Last boot is caused by: %s\n", + wdiof_bootstatus[wdiof].status_str); + } +} + int main(int argc, char *argv[]) { int flags; @@ -140,8 +189,7 @@ int main(int argc, char *argv[]) oneshot = 1; ret = ioctl(fd, WDIOC_GETBOOTSTATUS, &flags); if (!ret) - printf("Last boot is caused by: %s.\n", (flags != 0) ? - "Watchdog" : "Power-On-Reset"); + print_boot_status(flags); else printf("WDIOC_GETBOOTSTATUS error '%s'\n", strerror(errno)); break; @@ -249,6 +297,10 @@ int main(int argc, char *argv[]) sleep(ping_rate); } end: + /* + * Send specific magic character 'V' just in case Magic Close is + * enabled to ensure watchdog gets disabled on close. + */ ret = write(fd, &v, 1); if (ret < 0) printf("Stopping watchdog ticks failed (%d)...\n", errno); -- 2.34.1