From patchwork Sun Aug 14 05:53:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942843 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10AD4C25B0F for ; Sun, 14 Aug 2022 05:54:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B7BF8E0003; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 917CD8E0001; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B80D8E0003; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6DBFC8E0001 for ; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4535EAB282 for ; Sun, 14 Aug 2022 05:54:09 +0000 (UTC) X-FDA: 79797132618.08.A9F6E32 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf30.hostedemail.com (Postfix) with ESMTP id D13F08019F for ; Sun, 14 Aug 2022 05:54:08 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id l9so2489695ilq.1 for ; Sat, 13 Aug 2022 22:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=TqLTKUmEk/mKGbJa80nE77aaCeS2f2PhLCxbPuooWhk=; b=Q+70lCxo0EOr6ZjULQtULwXoQfFqFrhzmgqGnXuME+BrsXkSjYP3hTsUbnpp1qw43m 1F6K2i2CQKCycUqiGC5ObC9j1BnKh/dxeOxl1qRdJeeFl756TIYVq0Cdz4Yy6uJaEccb T7cm9eYHf//UuNx/gSF5Vgw7Q66vQXTEPwIqZ9kIUu3it4V3EJHPx5/OIeDIxS+tbSm2 O0k9O+veuWtYGdsCjrYkCfd/o5yukBIAFTTWsKBhY/70a0oH2j5KFx6aixZWydOagUfp xCv/B2tiT8441toWEth7/JWx5Y30oN/FMiwPJJtZXMu7AmJgdfR529IUWeaCzuME630I 9KnQ== 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; bh=TqLTKUmEk/mKGbJa80nE77aaCeS2f2PhLCxbPuooWhk=; b=73WPdYgku81TCi6hv3b+Z3wQexUScgzYs5rvzp8VQSrCX+4iI6rccfM98s03de74EG KaChliMVPeKh6wcC1CCIvjXvUNgDxTWWw+4mAx5J8AKlGG92GSQVszx+dNJ2GvH/mH5+ ocGZVHAMGY2uDCeZ0X+OrMjSKiq76k7WUVlO+rV1RLT+zslH2Bvrx7+QD+hQDjJ/oBS+ 7+ltb4BxPNg1L14XYcpvqUiOue88iLXbz2dkdIKIt+gpuv+Dq9BImtZw5dWr1FbR4fZ3 GsIT1iHxBjb9uQhYBRVXup9gajpHQgOS667t0EjKL1dWqaLJWk29Gyqlmknv17ljQeDK UDNA== X-Gm-Message-State: ACgBeo1O2DGO/HG/NRniif4c9haVik4lDR/0KtxAhKV8YM+QkaCXGysq dKiNmgLPPho6ZcA1O4ZHv6Y= X-Google-Smtp-Source: AA6agR57m2tbZb2IQQdr4JcN2+O7/qS5xwfmQSAUfTIGFtypLP3eE76NYeUEL1dj9t1cc0w5ype3xw== X-Received: by 2002:a92:cda9:0:b0:2df:a725:6491 with SMTP id g9-20020a92cda9000000b002dfa7256491mr4968030ild.12.1660456448133; Sat, 13 Aug 2022 22:54:08 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id h8-20020a05660208c800b006882a3bd03fsm432587ioz.16.2022.08.13.22.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:07 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 1/8] memblock tests: update tests to check if memblock_alloc zeroed memory Date: Sun, 14 Aug 2022 00:53:53 -0500 Message-Id: <02d514d86f212c79e52792b8ecd919156d7a9c20.1660454730.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456448; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TqLTKUmEk/mKGbJa80nE77aaCeS2f2PhLCxbPuooWhk=; b=ZbsNmwXgBzKk3rLWJhrP96lgyVwoDvDHe9JtJgU0NHOHU3gLAIa+MNP8sbiegWtijC+R6v U48XNfklVB/AGVzjd3VYIrQxW/fg7Ea9SWSQLev0L6Tl+elgph6EijRhWm8xwm4Ck9Xeqy kzEAajtCYbR2/lFKwyiFl2F/x3Ionfs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Q+70lCxo; spf=pass (imf30.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456448; a=rsa-sha256; cv=none; b=b1kwbCCcIvJny3+F10WeiYc+0UTTRVIzPJX3SNeBPTI5YQjyMGATLi5b21ZkOXatXgMgwz PwgAMxs8Ps7DvY3IItLG8OtquQDd5FzlmFqT9R3s7WWNQAOWNfWOgefewwGHudBpYA6uyK PPJdHvcZY8bjR22zzvDeCRN48s8tYLo= X-Stat-Signature: tp34gin5rttpsmguyg5zy754pa7efuhb X-Rspamd-Queue-Id: D13F08019F Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Q+70lCxo; spf=pass (imf30.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1660456448-402468 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add an assert in memblock_alloc() tests where allocation is expected to occur. The assert checks whether the entire chunk of allocated memory is cleared. The current memblock_alloc() tests do not check whether the allocated memory was zeroed. memblock_alloc() should zero the allocated memory since it is a wrapper for memblock_alloc_try_nid(). Signed-off-by: Rebecca Mckeever Reviewed-by: Shaoqin Huang --- tools/testing/memblock/tests/alloc_api.c | 24 ++++++++++++++++++++++++ tools/testing/memblock/tests/common.c | 7 +++++++ tools/testing/memblock/tests/common.h | 13 +++++++++++++ 3 files changed, 44 insertions(+) diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c index a14f38eb8a89..71c89cb9b2a8 100644 --- a/tools/testing/memblock/tests/alloc_api.c +++ b/tools/testing/memblock/tests/alloc_api.c @@ -22,6 +22,8 @@ static int alloc_top_down_simple_check(void) allocated_ptr = memblock_alloc(size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, expected_start); @@ -80,6 +82,8 @@ static int alloc_top_down_disjoint_check(void) allocated_ptr = memblock_alloc(r2_size, alignment); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -125,6 +129,8 @@ static int alloc_top_down_before_check(void) allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - total_size); @@ -173,6 +179,8 @@ static int alloc_top_down_after_check(void) allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base - r2_size); @@ -223,6 +231,8 @@ static int alloc_top_down_second_fit_check(void) allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + ASSERT_EQ(rgn->size, r2.size + r3_size); ASSERT_EQ(rgn->base, r2.base - r3_size); @@ -277,6 +287,8 @@ static int alloc_in_between_generic_check(void) allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base - r2.size - r3_size); @@ -418,6 +430,8 @@ static int alloc_limited_space_generic_check(void) allocated_ptr = memblock_alloc(available_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, available_size); + ASSERT_EQ(rgn->size, MEM_SIZE); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -442,6 +456,7 @@ static int alloc_no_memory_generic_check(void) PREFIX_PUSH(); reset_memblock_regions(); + fill_memblock(); allocated_ptr = memblock_alloc(SZ_1K, SMP_CACHE_BYTES); @@ -472,6 +487,8 @@ static int alloc_bottom_up_simple_check(void) allocated_ptr = memblock_alloc(SZ_2, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, SZ_2); + ASSERT_EQ(rgn->size, SZ_2); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -528,6 +545,7 @@ static int alloc_bottom_up_disjoint_check(void) allocated_ptr = memblock_alloc(r2_size, alignment); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -571,6 +589,8 @@ static int alloc_bottom_up_before_check(void) allocated_ptr = memblock_alloc(r1_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r1_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -618,6 +638,8 @@ static int alloc_bottom_up_after_check(void) allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base); @@ -669,6 +691,8 @@ static int alloc_bottom_up_second_fit_check(void) allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + ASSERT_EQ(rgn->size, r2.size + r3_size); ASSERT_EQ(rgn->base, r2.base); diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c index 76a8ad818f3a..0ca26fe12c38 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -60,16 +60,23 @@ void reset_memblock_attributes(void) memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE; } +void fill_memblock(void) +{ + memset(memory_block.base, 1, MEM_SIZE); +} + void setup_memblock(void) { reset_memblock_regions(); memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); + fill_memblock(); } void dummy_physical_memory_init(void) { memory_block.base = malloc(MEM_SIZE); assert(memory_block.base); + fill_memblock(); } void dummy_physical_memory_cleanup(void) diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index d396e5423a8e..7a16a7dc8f2c 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -51,6 +51,18 @@ assert((_expected) < (_seen)); \ } while (0) +/** + * ASSERT_MEM_EQ(): + * Check that the first @_size bytes of @_seen are all equal to @_expected. + * If false, print failed test message (if running with --verbose) and then + * assert. + */ +#define ASSERT_MEM_EQ(_seen, _expected, _size) do { \ + for (int _i = 0; _i < (_size); _i++) { \ + ASSERT_EQ((_seen)[_i], (_expected)); \ + } \ +} while (0) + #define PREFIX_PUSH() prefix_push(__func__) /* @@ -70,6 +82,7 @@ struct region { void reset_memblock_regions(void); void reset_memblock_attributes(void); +void fill_memblock(void); void setup_memblock(void); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void);