From patchwork Fri Aug 21 15:37:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11729819 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42C55739 for ; Fri, 21 Aug 2020 15:38:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2BD3B2078B for ; Fri, 21 Aug 2020 15:38:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BD3B2078B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F94F6E859; Fri, 21 Aug 2020 15:38:40 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id B18F76E82B; Fri, 21 Aug 2020 15:38:37 +0000 (UTC) IronPort-SDR: 1gl0D9lH8+2J8nWSPkIxBmHSqiW5AWaC4aXj3wqab8cY8qoHbumIPFis0VwxVO4g4KmdlyjmG7 Cjc24BLBpdxw== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="240381879" X-IronPort-AV: E=Sophos;i="5.76,337,1592895600"; d="scan'208";a="240381879" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 08:38:37 -0700 IronPort-SDR: WCICd6r78oQWQD2Ci7XoyHJjAjEbb6reIJgMrUdf6XzESDo4ntk3jKy5v3Atx4BS9DPfmPfx80 2hehqW7KeeXQ== X-IronPort-AV: E=Sophos;i="5.76,337,1592895600"; d="scan'208";a="473086607" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.18]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 08:38:35 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Fri, 21 Aug 2020 17:37:55 +0200 Message-Id: <20200821153807.18613-9-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200821153807.18613-1-janusz.krzysztofik@linux.intel.com> References: <20200821153807.18613-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v4 08/20] tests/core_hotunplug: Handle device close errors X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The test now ignores device close errors. Those errors are believed to have no influence on device health so there is no need to process them the same way as we mostly do on errors, i.e., notify CI about a problem via igt_abort. However, those errors may indicate issues with the test itself. Moreover, impact of those errors on operations performed by subtests, like driver unbind or device remove, should be perceived as undefined. Then, we should fail as soon as a device or device sysfs node close error occurs in a subtest and also skip subsequent subtests. However, once a driver unbind or device unplug operation has been attempted by a subtest, we would still like to check the device health. When in a subtest, store results of device close operations for future reference. Reuse file descriptor fields of the hotunplug structure for that. Unless in between of a driver remove or device unplug operation and a successful device health check completion, fail current test section right after a device close error occurs, warn otherwise. If still running, examine device file descriptor fields in subsequent igt_fixture sections and skip on errors. v2: Fix a typo in post_healthcheck function name. v3: Don't fail on close error after successful health check, warn only, - move duplicated messages to helpers. Signed-off-by: Janusz Krzysztofik Reviewed-by: MichaƂ Winiarski # v1 --- tests/core_hotunplug.c | 64 +++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/tests/core_hotunplug.c b/tests/core_hotunplug.c index 4f7e89c95..f7a54010b 100644 --- a/tests/core_hotunplug.c +++ b/tests/core_hotunplug.c @@ -43,7 +43,7 @@ struct hotunplug { int sysfs_dev; int sysfs_bus; int sysfs_drv; - } fd; + } fd; /* >= 0: valid fd, == -1: closed, < -1: close failed */ const char *dev_bus_addr; const char *failure; }; @@ -67,6 +67,25 @@ static int local_drm_open_driver(const char *prefix, const char *suffix) return fd_drm; } +static int local_close(int fd, const char *message) +{ + errno = 0; + if (igt_warn_on_f(close(fd), "%s\n", message)) + return -errno; /* (never -1) */ + + return -1; /* success - return 'closed' */ +} + +static int close_device(int fd_drm) +{ + return local_close(fd_drm, "Device close failed"); +} + +static int close_sysfs(int fd_sysfs_dev) +{ + return local_close(fd_sysfs_dev, "Device sysfs node close failed"); +} + static void prepare_for_unbind(struct hotunplug *priv, char *buf, int buflen) { int len; @@ -83,7 +102,8 @@ static void prepare_for_unbind(struct hotunplug *priv, char *buf, int buflen) igt_assert(priv->dev_bus_addr++); /* sysfs_dev no longer needed */ - close(priv->fd.sysfs_dev); + priv->fd.sysfs_dev = close_sysfs(priv->fd.sysfs_dev); + igt_assert_eq(priv->fd.sysfs_dev, -1); } static void prepare(struct hotunplug *priv, char *buf, int buflen) @@ -142,7 +162,7 @@ static void device_unplug(struct hotunplug *priv, const char *prefix) igt_reset_timeout(); priv->failure = NULL; - close(priv->fd.sysfs_dev); + priv->fd.sysfs_dev = close_sysfs(priv->fd.sysfs_dev); } /* Re-discover the device by rescanning its bus */ @@ -161,6 +181,7 @@ static void bus_rescan(struct hotunplug *priv) static void healthcheck(struct hotunplug *priv) { + /* preserve error code potentially stored before in priv->fd.drm */ int fd_drm; /* device name may have changed, rebuild IGT device list */ @@ -176,7 +197,17 @@ static void healthcheck(struct hotunplug *priv) priv->failure = NULL; } - close(fd_drm); + fd_drm = close_device(fd_drm); + if (priv->fd.drm == -1) /* store result if no error code to preserve */ + priv->fd.drm = fd_drm; +} + +static void post_healthcheck(struct hotunplug *priv) +{ + igt_abort_on_f(priv->failure, "%s\n", priv->failure); + + igt_require(priv->fd.drm == -1); + igt_require(priv->fd.sysfs_dev == -1); } static void set_filter_from_device(int fd) @@ -203,7 +234,8 @@ static void unbind_rebind(struct hotunplug *priv) prepare(priv, buf, sizeof(buf)); igt_debug("closing the device\n"); - close(priv->fd.drm); + priv->fd.drm = close_device(priv->fd.drm); + igt_assert_eq(priv->fd.drm, -1); driver_unbind(priv, ""); @@ -217,7 +249,8 @@ static void unplug_rescan(struct hotunplug *priv) prepare(priv, NULL, 0); igt_debug("closing the device\n"); - close(priv->fd.drm); + priv->fd.drm = close_device(priv->fd.drm); + igt_assert_eq(priv->fd.drm, -1); device_unplug(priv, ""); @@ -237,7 +270,7 @@ static void hotunbind_lateclose(struct hotunplug *priv) driver_bind(priv); igt_debug("late closing the unbound device instance\n"); - close(priv->fd.drm); + priv->fd.drm = close_device(priv->fd.drm); healthcheck(priv); } @@ -251,7 +284,7 @@ static void hotunplug_lateclose(struct hotunplug *priv) bus_rescan(priv); igt_debug("late closing the removed device instance\n"); - close(priv->fd.drm); + priv->fd.drm = close_device(priv->fd.drm); healthcheck(priv); } @@ -260,7 +293,10 @@ static void hotunplug_lateclose(struct hotunplug *priv) igt_main { - struct hotunplug priv = { .failure = NULL, }; + struct hotunplug priv = { + .fd = { .drm = -1, .sysfs_dev = -1, }, + .failure = NULL, + }; igt_fixture { int fd_drm; @@ -276,7 +312,7 @@ igt_main /* Make sure subtests always reopen the same device */ set_filter_from_device(fd_drm); - close(fd_drm); + igt_assert_eq(close_device(fd_drm), -1); } igt_describe("Check if the driver can be cleanly unbound from a device believed to be closed"); @@ -284,26 +320,26 @@ igt_main unbind_rebind(&priv); igt_fixture - igt_abort_on_f(priv.failure, "%s\n", priv.failure); + post_healthcheck(&priv); igt_describe("Check if a device believed to be closed can be cleanly unplugged"); igt_subtest("unplug-rescan") unplug_rescan(&priv); igt_fixture - igt_abort_on_f(priv.failure, "%s\n", priv.failure); + post_healthcheck(&priv); igt_describe("Check if the driver can be cleanly unbound from a still open device, then released"); igt_subtest("hotunbind-lateclose") hotunbind_lateclose(&priv); igt_fixture - igt_abort_on_f(priv.failure, "%s\n", priv.failure); + post_healthcheck(&priv); igt_describe("Check if a still open device can be cleanly unplugged, then released"); igt_subtest("hotunplug-lateclose") hotunplug_lateclose(&priv); igt_fixture - igt_abort_on_f(priv.failure, "%s\n", priv.failure); + post_healthcheck(&priv); }