Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp384284lqb; Tue, 4 Jun 2024 14:32:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVxCByCVfbAQes7P+KRGTnHK3ZzgcABDs2ze1G6PhTfkFs8HDetSuY1uqPUat2kwXR2RjuBA2xBtBvSBu/UMCMaxTij2YjdRHj9m5U2bQ== X-Google-Smtp-Source: AGHT+IHY49lcEESURpJKiNesYPIuF8ZGDdKvcxqzXg5/A5nYMQNpn1lYjji5mG0AtZYT8JcaEvd6 X-Received: by 2002:a05:6a00:1a94:b0:6e6:5396:ce43 with SMTP id d2e1a72fcca58-703e5920d72mr859911b3a.7.1717536743474; Tue, 04 Jun 2024 14:32:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717536743; cv=pass; d=google.com; s=arc-20160816; b=CSsR2/5+uTA5BYsn2z5d/MqgRPZLJvRJDKUvzBAYIOrTddx74+Pko+BYmlTajP7Id3 k1Pfa2IwUMrejjPP43elg8r8iTcWOH1wbkvRxWQ2bdcPSDmhUTqgRxQYSNCk527ABX7q PRU6v8Yk3Gj8N3+Ad1Ui8W+q8DxKp7pz+5/NfqGgo7oklKP44zAy0a424InaRTexwodX nz5o/KnoBuBm6+ZiG1XzJ4Sm6GzExiEjtSihdXBxKb8LUYUJHWN0l71LAdXGeiN4EbfK 3xg09cJzodyguUEu2s8+Fqd/jtdGqidcCkfFVKh0fOXRNVvwo0weZGUYhpa446Phx7Nh mUJg== 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=8xczI7Fw8ihY2GJQ7xJJ7qToPNGT2Ft+3JlNRhzE1Eg=; fh=SwWCHnr7Nw/bqe5kF9bLc/pHP7mXtzd1MHZKk+YTkM8=; b=lR/fjZjqaknsPrY2kh4vIzbfXYS4ZGEC0BHEYQtRlcmvrNPh2sYXi08hXcIAE2Gv2u GwHYRXxUuQV/kXd9miF9eE3IY1NJC8ghWy1dTQevvhmuMmH91vkSRA2B5yIfrG/OkhJS s2jMsogmAslq00oJ55MnYpXmLoe/K/53vf53q3v5KudorrnVTKcEQMr260UIe7gOp2mR meidTWinc6/OQggLxLAu6TSN4OATGlF40NctHqA7Qd08uQEQF3v3g1y6tEy7uEtzXn5M aXhm/Aj2TUHukHz9CKancU+nGtupmeh3f4Isg/sRUb47bymvAMfzxY65Pme4eVWx7Sds bvpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZzC3pI8r; 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-201406-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201406-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-702425e20edsi8795939b3a.30.2024.06.04.14.32.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 14:32:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201406-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZzC3pI8r; 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-201406-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201406-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E1E172868D4 for ; Tue, 4 Jun 2024 21:32:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2A8B14B968; Tue, 4 Jun 2024 21:32:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZzC3pI8r" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 77CEB84E1C for ; Tue, 4 Jun 2024 21:32:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717536730; cv=none; b=YgBHNc9CHz7UGryttPrhXBIBQjt8C/1GhIGUKSpxBq01FnbYvaMTiGno63f7eqvx9DyU7JNEARjTE8z4cj7Um6pVtXmbIHjKF5nUsrrPsua+S86JjmFJk2Iab9T94OjiUzutcuis3Y2KRjyfhqLo8SycOWNTKrSdqkNT7aJpkfg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717536730; c=relaxed/simple; bh=m3dDas0clsrGaGIyLTBKgF2yMVGjZPTMNU0t2WsL8kE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Da8vXokTNuuLLdxsmWTP+6ps8riIQTGT8w9XIX9NPvigR8MOeskbwuqjkLRCiacymjK0QDT6i28wOnlAu2F2jcbb3dsw6pk1n2zu2X/JUDTC9VDMM5bREIYP5AcBFzRUHfSlLjTIS3gUWykhEzYNDZnQi60ON+G+NSFPSI7KZV0= 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=ZzC3pI8r; arc=none smtp.client-ip=209.85.214.171 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-pl1-f171.google.com with SMTP id d9443c01a7336-1f2e3249d5eso5089825ad.3 for ; Tue, 04 Jun 2024 14:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717536728; x=1718141528; 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=8xczI7Fw8ihY2GJQ7xJJ7qToPNGT2Ft+3JlNRhzE1Eg=; b=ZzC3pI8rWTCDDBsnyomVyg+VKhvOpLCS4MXFx7tHnzbJ9fUzve8Kv82G8PKNLSmyvg GtczDWieDEsV1EDu4qqtBUw/FM5G3sJm0a4nF7l44Zz2uWd2m0gztykq2iuYBT0u7EBs 33W2I6r/LUDGbr75yK8zFvfC+yaLJqv7ienypugbb/WeK7YP04ymwslWGLrjiU4b4ojd bd9B1Q4JZf27Rao3eG2HfymkflK0GkI3EbFWtfiZ5n3ThggluiZ5zJY1JvKS1HUFuFsV iU4dDRo7ucuIu1R9r2hK/rDtuVuV9VnvKfWzdZruvd/oN3DGIBprWB155O6E8ClqLbDy 99ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717536728; x=1718141528; 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=8xczI7Fw8ihY2GJQ7xJJ7qToPNGT2Ft+3JlNRhzE1Eg=; b=gibwVvl/MJ3o6zep6eY3eUvPOS3BEAU7mhsxW8oGb569O8iro0L6vEbzjK3ej2rrvz 01fi+tnfPx1HX3KOhQaNYQjCgXFpREjY4iuMWZGYy7Ozo0lDn/KsHtEXdDlCXmgOx3T0 perKU6VW3nqf8ogNhliU+ynReq8fYda0YkkiilznbIjPH0mh1w1LVpKbgkBv9tU1029a 95qVfHcoHc+OJAJlp8xkbC2boWUEES961tBVcRcu64K5BCy5d1Uy9LNd2jy3b6GjhewV jUXXzWI3q/gz0fVjB/Fu55lSn+8u20bD4Yyf69sZNjWVvNs2WywOebzmP5ygWW2OdXrA TB0w== X-Forwarded-Encrypted: i=1; AJvYcCVmMtiSACb/WptsQ7XDY+PqNT2V3rE/WvQ6xre4ShW0QndVFHiScACJuGbHCTQIwFp2BjjczJrwB+6GHyUkdR6PWBFf0gQHKS9r6BXl X-Gm-Message-State: AOJu0YzFQ5jdpobFPAUmkjfH6JrWeV7uByzvHiDS9lKhCzRYY5TLDFOR fhmt19TfiHriJnYMAm5Rw40T0tuwzSHhTflTJoenF/FcPzR5pFob X-Received: by 2002:a17:903:2445:b0:1f6:226f:cc44 with SMTP id d9443c01a7336-1f6a5a84e75mr8220585ad.3.1717536728435; Tue, 04 Jun 2024 14:32:08 -0700 (PDT) Received: from localhost (43.222.125.34.bc.googleusercontent.com. [34.125.222.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6939bc65dsm21923045ad.136.2024.06.04.14.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 14:32:08 -0700 (PDT) From: Chia-I Wu To: Greg Kroah-Hartman , Andy Shevchenko , Andrew Morton , AKASHI Takahiro , Dan Williams , Baoquan He , Alison Schofield , linux-kernel@vger.kernel.org Subject: [PATCH] resource: add a basic test for walk_iomem_res_desc Date: Tue, 4 Jun 2024 14:31:46 -0700 Message-ID: <20240604213200.672279-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 --- kernel/resource_kunit.c | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/kernel/resource_kunit.c b/kernel/resource_kunit.c index 58ab9f914602b..1cbeeb44d0822 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,104 @@ 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]; + resource_size_t offset; + int count; + + KUNIT_ASSERT_EQ(test, 0, + allocate_resource(&iomem_resource, &root, SZ_1M, + 0, ~0, SZ_1M, NULL, NULL)); + + /* build the resource tree */ + offset = root.start; + res[0] = (struct resource){ + .start = offset, + .end = offset + SZ_1K - 1, + .name = "SYSRAM 1", + .flags = IORESOURCE_SYSTEM_RAM, + }; + offset += SZ_1K; + + res[1] = (struct resource){ + .start = offset, + .end = offset + SZ_1K - 1, + .name = "OTHER", + }; + offset += SZ_1K; + + /* hole */ + offset += SZ_1K; + + res[2] = (struct resource){ + .start = offset, + .end = offset + SZ_1K - 1, + .name = "NESTED", + }; + res[3] = (struct resource){ + .start = offset + SZ_512, + .end = offset + SZ_1K - 1, + .name = "SYSRAM 2", + .flags = IORESOURCE_SYSTEM_RAM, + }; + offset += SZ_1K; + + res[4] = (struct resource){ + .start = offset, + .end = offset + SZ_1K - 1, + .name = "SYSRAM 3", + .flags = IORESOURCE_SYSTEM_RAM, + }; + offset += SZ_1K; + + 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