Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp396228lqb; Tue, 4 Jun 2024 15:01:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVP8GMP8SH+zxwUNhGVC6FdXbOGMMl7yVPijdYX9SK+A33u3JuX7s7AESbVd7Smw9Jeo8hkCscNg0yATKWk/6BewD6WYahiW23SIsuZtA== X-Google-Smtp-Source: AGHT+IE5HrEu2iXREd/dN/mUe1tyfKKHT7Ov8YMAywt/5HELlG96MUHQLw7WNIU0ZVb0pOrVZNnO X-Received: by 2002:a05:6122:179b:b0:4d4:15d2:8b3b with SMTP id 71dfb90a1353d-4eb3a40a462mr1265590e0c.9.1717538515501; Tue, 04 Jun 2024 15:01:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717538515; cv=pass; d=google.com; s=arc-20160816; b=dBtUO8Rj82szCany8OW/me7AtgbxNRp+cu3bWrgKcUT8eUQWDOdhp61xvlnaVB8Oqs GNu1fsFtAD2rfWYFiaKAAoRpi5ODDeziNKXzufgIf4hbO1JUC09WLJUOYXN8pET+u3WH PJPEdQaWn3bPrMDcLV9xVlvDbYVD7JbpZGXcAG8lDR6JgFT27pl6402cAum87DaDM8bM 2RMUmK9SqPsMVZfJJGMRkamyO5KqXznY1rPAvPv34KQ6nQoW0FvoVSZ+D7L0rHSDGQeW dVsvpcCX8HRBMAXrnKtijfHjZWaztGxbdCYDQ6NrloQf08/bMMrN8fKyjbkd80gdrPNT 2DwA== 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:to:from :dkim-signature; bh=IukKNUeQwFyeGm++e5Ng9ZtZqlsDoJ65zsIQjpZSzD0=; fh=nFDG1V4J5Iujx1kdwIVKoLhQiRdMDYXVxpuVzBnCli4=; b=pEhev2Jvil2o/sAlgU8jutZ5IwwyzPDqkL2HfrP3gi8nCvciNfEL56XslFL8VxC/Kw KEVfpAIMApgj/T3lLknGaWL9MspogmQC21cvoliR21LkvpFSHCWGFJRZ8eD0+cDVWUMF qwfQA+cMpXaBgpqxWl/gkFK6aTHt7+SBPG+TrrDfCXkL6JeKrjDcyBPJA0sNZ79ZGCtY EM4BX8orPCdrFSrB6GQNFNzotVyEJ2Mq3013r5mcToJ8TZ4NHq0xcJZtzaJ8YNiQl9NK Fw+TNceNqZD0KqsYLVI1P6qWAy+DnTLNhRZHF4ksNjviBL3bmQ2za58umDUC8H9cDbD7 PqxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BjblrvLp; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-201431-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201431-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48c03b3fdcasi181467137.171.2024.06.04.15.01.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201431-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BjblrvLp; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-201431-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201431-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B9FB11C23A55 for ; Tue, 4 Jun 2024 22:01:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97E99132135; Tue, 4 Jun 2024 22:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BjblrvLp" Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 6BDE9320C for ; Tue, 4 Jun 2024 22:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717538508; cv=none; b=gzWcVjcRXeFMbeg3sm4duYzurxaOg4OFYvzfLQy3q8mWQMFrIDffUYiHEySVHPOrHXYnERcrExp3Vrm36zy/KxHlyYSRdkEyc5rcMWTfCisnZnxrwLwxZL+ZRBgWczDFvH+a402TmzeDPH7QyMyDtBurY1KUQ9VKq3T1O8wrfUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717538508; c=relaxed/simple; bh=AoLRjCk7Gy+e+NqCwI7iR2QlaUB3i7o+sdNHdzHRKy4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qgqx/fbku6oHJkuSwfJQKg8vNGtWMXU4oTaSXnxS08VSFfDAQivV/DIaZ2jUNMppiyQeYG0i25xpVSFqnAup1E/+D29lkB5x23PqJhre1LxPYquFUzif6wCOsZntKNTEWvdNAwNs6eb3Sg1EJsToUAwZyDGgFudefrWMxzLDc1Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BjblrvLp; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2c21571e99bso458322a91.2 for ; Tue, 04 Jun 2024 15:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717538507; x=1718143307; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=IukKNUeQwFyeGm++e5Ng9ZtZqlsDoJ65zsIQjpZSzD0=; b=BjblrvLpckTs4atViKrxi2Lbiw9qtu9UtX0V/rCE5mP0HcWQQjqL6+6wxNhZURocmT XFACsgnq+dNbkl2rdZte8pspOP3vdJxoG/VroIetembHzmbAt+LK/ImXTJ8OXz8ID38h 2FYxbFnyYCBrIq1/FSjZvqmzIM8SPtlXPWla3Yvjw1MzFZk23qx3uF3VTxIb/1RAIlVC E4LrTCuAxxMHfVCBxIcr8CoIDt2AzukE8d0QKxpGlXbGW3aISiJpWqCgAfE+/Emq4xRx dZHFfVVRCF86f3QJAlZ5gjNBHapG/o6ABlJSHYZCLdd5NtX69cwd1CcYjs1bcI6mxbGC x2Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717538507; x=1718143307; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IukKNUeQwFyeGm++e5Ng9ZtZqlsDoJ65zsIQjpZSzD0=; b=dll4Ue04D9TytBgm9J1IjUnOYL7gO6l2ULob3pDENwqYjFeJwxTe5Aw/5QZqI7Pll/ L12UVRtJpXirEK2s5AT29g21opbyVDA7exL7tqhw2WVMBa8FzArA/aGtBG6EEqBAMGfe Fr2rFUhgzh1+9PYMwUCG5hoK23ZYkvtXmAmdjK7c0wkbgTA3wQGSd53RTzFx3OdEXSwb wOKIOwj/TkTXyFPY8ERKuZOwqLe3h5ic2K4fxfJCLIQ5OCAP2I8ap4f9Bk+lwLjVjBaS Cfuwq7jDbHpmInUz5uLxiIaTfxEABRJ3iTHrh8Lnn5PKesk2Sre3H+0rAy2lPGSUkbFB 2O+A== X-Forwarded-Encrypted: i=1; AJvYcCWzgO8P1ROTJLBNzkcLJINY1ibkXKG2ZtJG4sT8qSyvZ6w0PHGNZGqLJT1/hvFN3brmK6TecDE5jMwXnIfIrBqiecIEFoVyVCgzNWFR X-Gm-Message-State: AOJu0Ywquiog/IVqCo8hWDyIXxnLCWd+XDGQ+C9tqTtfMj9B2kaktwfz HyCy9BVxwYma6FBnK4Fj0peDIULmZyica8P3AG3w8tUqcRJXduaA X-Received: by 2002:a17:902:cec2:b0:1f6:1bbb:e07d with SMTP id d9443c01a7336-1f6a5868539mr9569905ad.0.1717538506583; Tue, 04 Jun 2024 15:01:46 -0700 (PDT) Received: from localhost (43.222.125.34.bc.googleusercontent.com. [34.125.222.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f677fc9f24sm45772085ad.309.2024.06.04.15.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:01:46 -0700 (PDT) From: Chia-I Wu To: Greg Kroah-Hartman , Andy Shevchenko , Dave Jiang , Alison Schofield , Andrew Morton , Baoquan He , linux-kernel@vger.kernel.org Subject: [PATCH v2] resource: add a simple test for walk_iomem_res_desc() Date: Tue, 4 Jun 2024 15:01:14 -0700 Message-ID: <20240604220128.682745-1-olvaffe@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This mainly tests that find_next_iomem_res() does not miss resources. Signed-off-by: Chia-I Wu --- v2: update subject, use DEFINE_RES_NAMED and hardcoded offsets --- kernel/resource_kunit.c | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/kernel/resource_kunit.c b/kernel/resource_kunit.c index 58ab9f914602..c3a3f3bdf5d5 100644 --- a/kernel/resource_kunit.c +++ b/kernel/resource_kunit.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #define R0_START 0x0000 @@ -137,9 +138,75 @@ static void resource_test_intersection(struct kunit *test) } while (++i < ARRAY_SIZE(results_for_intersection)); } +static int resource_walk_count(struct resource *res, void *data) +{ + int *count = data; + (*count)++; + return 0; +} + +static void resource_test_walk_iomem_res_desc(struct kunit *test) +{ + struct resource root = { + .name = "Resource Walk Test", + }; + struct resource res[8]; + int count; + + KUNIT_ASSERT_EQ(test, 0, + allocate_resource(&iomem_resource, &root, SZ_1M, + 0, ~0, SZ_1M, NULL, NULL)); + + /* build the resource tree */ + + res[0] = DEFINE_RES_NAMED(root.start, SZ_1K, "SYSRAM 1", + IORESOURCE_SYSTEM_RAM); + res[1] = DEFINE_RES_NAMED(root.start + SZ_1K, SZ_1K, "OTHER", 0); + + res[2] = DEFINE_RES_NAMED(root.start + SZ_1K * 3, SZ_1K, "NESTED", 0); + res[3] = DEFINE_RES_NAMED(root.start + SZ_1K * 3 + SZ_512, SZ_512, + "SYSRAM 2", IORESOURCE_SYSTEM_RAM); + + res[4] = DEFINE_RES_NAMED(root.start + SZ_1K * 4, SZ_1K, "SYSRAM 3", + IORESOURCE_SYSTEM_RAM); + + KUNIT_EXPECT_EQ(test, 0, request_resource(&root, &res[0])); + KUNIT_EXPECT_EQ(test, 0, request_resource(&root, &res[1])); + KUNIT_EXPECT_EQ(test, 0, request_resource(&root, &res[2])); + KUNIT_EXPECT_EQ(test, 0, request_resource(&res[2], &res[3])); + KUNIT_EXPECT_EQ(test, 0, request_resource(&root, &res[4])); + + /* walk the entire region */ + count = 0; + walk_iomem_res_desc(IORES_DESC_NONE, IORESOURCE_SYSTEM_RAM, + root.start, root.end, &count, resource_walk_count); + KUNIT_EXPECT_EQ(test, count, 3); + + /* walk the region requested by res[1] */ + count = 0; + walk_iomem_res_desc(IORES_DESC_NONE, IORESOURCE_SYSTEM_RAM, + res[1].start, res[1].end, &count, resource_walk_count); + KUNIT_EXPECT_EQ(test, count, 0); + + /* walk the region requested by res[2] */ + count = 0; + walk_iomem_res_desc(IORES_DESC_NONE, IORESOURCE_SYSTEM_RAM, + res[2].start, res[2].end, &count, resource_walk_count); + KUNIT_EXPECT_EQ(test, count, 1); + + /* walk the region requested by res[4] */ + count = 0; + walk_iomem_res_desc(IORES_DESC_NONE, IORESOURCE_SYSTEM_RAM, + res[4].start, res[4].end, &count, resource_walk_count); + KUNIT_EXPECT_EQ(test, count, 1); + + release_resource(&root); +} + static struct kunit_case resource_test_cases[] = { KUNIT_CASE(resource_test_union), KUNIT_CASE(resource_test_intersection), + KUNIT_CASE(resource_test_walk_iomem_res_desc), {} }; -- 2.45.1.288.g0e0cd299f1-goog