From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 241DACF34B0 for ; Thu, 3 Oct 2024 15:49:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D5B6310E886; Thu, 3 Oct 2024 15:49:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="caTgQt96"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4ADA510E886 for ; Thu, 3 Oct 2024 15:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727970569; x=1759506569; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=qapz3Dyx0GOWjLhm8xWvS0lq3rLlrLcBtxjl5vurj+E=; b=caTgQt96n3+wiJGQ6dV2bMqZnjsuwr845nZnjRpw0eXNnhd5jE2duBQO p2lDNPP+4szZD3azdp89hvzTSIZemwjFiaPyrkDg+mRct0AOLTOOgPzHV 8AzeY6uL/HZrCnK51CCgqczoh3bqrNPlmyLXofnGJiWSRUaK50zirxqtv Th13NXbirmZLicwfnrmLJ0IjU3RxkVGEEBfZlbObLoWBBSmff8DlSMnVC Ly2csiu4wEj3A8pjIB1Vz3cI9xAbPkp/U0/A98vkE5xdotkd4DYxHm+tQ TMmWUm+8cWPsKmIaPh6MjTfkZExeLN/f/Mf7ngfTk5rPWjfyJM8IOpT5a A==; X-CSE-ConnectionGUID: mB6ooBrcQIycHL4VnzO2KQ== X-CSE-MsgGUID: mD7Vwis0T1i1337HTpJ3Wg== X-IronPort-AV: E=McAfee;i="6700,10204,11214"; a="31052648" X-IronPort-AV: E=Sophos;i="6.11,174,1725346800"; d="scan'208";a="31052648" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2024 08:49:29 -0700 X-CSE-ConnectionGUID: 0l8pYpu4TGOZSujOMSL4WQ== X-CSE-MsgGUID: LLy9mXyBSaWnuoeY93xO5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,174,1725346800"; d="scan'208";a="97722193" Received: from kbommu-desk.iind.intel.com ([10.145.169.159]) by fmviesa002.fm.intel.com with ESMTP; 03 Oct 2024 08:49:28 -0700 From: Bommu Krishnaiah To: igt-dev@lists.freedesktop.org Cc: Bommu Krishnaiah Subject: [PATCH i-g-t] tests/core_setmaster: simplify device handling Date: Thu, 3 Oct 2024 21:06:11 +0530 Message-Id: <20241003153611.21036-1-krishnaiah.bommu@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" Refactored test setup to dynamically determine the correct drm card for testing. Instead of changing permissions for all cards, change only one that will be tested. Problem Description: The test fails after running the `core_hotunplug@hot*` subtest, where Card0 is populated as card1, This leads to a failure in the subsequent `master-drop-set-user` test. Command sequence for reproducing the issue: - Check available cards: `ls /dev/dri/` - Output: by-path card0 renderD128 - Run the test: `# ./core_hotunplug --r hotrebind-lateclose` - Check again: ‘ls /dev/dri/’ - Output after core_hotunplug : by-path card1 renderD129 - Run the test: `# ./core_setmaster --r master-drop-set-user` - Output: gta@core_setmaster@master-drop-set-user failure This failures on both XE and i915 for above sequence. Signed-off-by: Bommu Krishnaiah krishnaiah.bommu@intel.com Cc: Emil Velikov emil.l.velikov@gmail.com Cc: Himal Prasad Ghimiray himal.prasad.ghimiray@intel.com Cc: Kamil Konieczny kamil.konieczny@linux.intel.com --- tests/core_setmaster.c | 81 ++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/tests/core_setmaster.c b/tests/core_setmaster.c index 9c2083f66..448f4bf7a 100644 --- a/tests/core_setmaster.c +++ b/tests/core_setmaster.c @@ -107,40 +107,31 @@ static void check_drop_set(void) drm_close_driver(master); } -static unsigned tweak_perm(uint8_t *saved_perm, unsigned max_perm, bool save) +static void tweak_perm(uint8_t *saved_perm, char *path, bool save) { - char path[256]; struct stat st; - unsigned i; - - for (i = 0; i < max_perm; i++) { - snprintf(path, sizeof(path), "/dev/dri/card%u", i); - - /* Existing userspace assumes there's no gaps, do the same. */ - if (stat(path, &st) != 0) - break; - - if (save) { - /* Save and toggle */ - saved_perm[i] = st.st_mode & (S_IROTH | S_IWOTH); - st.st_mode |= S_IROTH | S_IWOTH; - } else { - /* Clear and restore */ - st.st_mode &= ~(S_IROTH | S_IWOTH); - st.st_mode |= saved_perm[i]; - } - - /* There's only one way for chmod to fail - race vs rmmod. - * In that case, do _not_ error/skip, since: - * - we need to restore the [correct] permissions - * - __drm_open_driver() can open another device, aka the - * failure may be irrelevant. - */ - chmod(path, st.st_mode); + int ret; + + if (path[0] == 0) + return; + + ret = stat(path, &st); + igt_assert_f(!ret, "stat failed with %d path=%s\n", errno, path); + + if (save) { + /* Save and toggle */ + *saved_perm = st.st_mode & (S_IROTH | S_IWOTH); + st.st_mode |= S_IROTH | S_IWOTH; + } else { + /* Clear and restore */ + st.st_mode &= ~(S_IROTH | S_IWOTH); + st.st_mode |= *saved_perm; } - return i; -} + /* There's only one way for chmod to fail - race vs rmmod. */ + ret = chmod(path, st.st_mode); + igt_assert_f(!ret, "chmod failed with %d path=%s\n", errno, path); +} igt_main { @@ -160,8 +151,8 @@ igt_main igt_subtest_group { - uint8_t saved_perm[255]; - unsigned num; + uint8_t saved_perm; + char buf[255]; /* Upon dropping root we end up as random user, which * a) is not in the video group, and @@ -176,8 +167,28 @@ igt_main * restored on skip or failure. */ igt_fixture { - num = tweak_perm(saved_perm, ARRAY_SIZE(saved_perm), - true); + char path[255]; + int len; + int fd; + + memset(buf, 0, sizeof(buf)); + + fd = __drm_open_driver(DRIVER_ANY); + igt_assert_fd(fd); + + snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); + + len = readlink(path, buf, sizeof(buf) - 1); + igt_assert_f(len > 0, "readlink failed with %d path=%s\n", errno, path); + + buf[len] = '\0'; + if (!(strstr(buf, "/dev/dri/card") == buf || + strstr(buf, "/dev/dri/renderD") == buf)) + igt_assert_f(0, "Not a card nor render, path=%s\n", buf); + + igt_assert_eq(__drm_close_driver(fd), 0); + + tweak_perm(&saved_perm, buf, true); } igt_describe("Ensure first normal user can Set/DropMaster"); @@ -191,7 +202,7 @@ igt_main /* Restore the original permissions */ igt_fixture { - tweak_perm(saved_perm, num, false); + tweak_perm(&saved_perm, buf, false); } } -- 2.34.1