From patchwork Wed Jun 10 05:36:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1306477 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=o8qpZzXT; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49hbNP0nlvz9sRR for ; Wed, 10 Jun 2020 15:37:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 929A5819A0; Wed, 10 Jun 2020 07:36:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="o8qpZzXT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5EF938168D; Wed, 10 Jun 2020 07:36:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E1666813D4 for ; Wed, 10 Jun 2020 07:36:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bmeng.cn@gmail.com Received: by mail-pf1-x441.google.com with SMTP id 23so600829pfw.10 for ; Tue, 09 Jun 2020 22:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2KalhkKUUjDwQFWr6WSxzhNbQj3qa3b1UAq/SCX6GaI=; b=o8qpZzXTL4Obuxc7OlzDt+LKLgTT5nNvGuZq7T+Ftn6+PgdzX5MRUVFB+2abXfKTqG 5YRYbOR3cvh5Pr0fxbCT6uL1ZVf5viTghPnFuzhvk2sWgKndv+TbT+dHgwoQhZ9vxwE3 B4K4M+Be6m7wD5nR+SxY4u8rFOKx9zXKB5ZRJvgR1nzcptDo4Em30Ta/N5PpnJo3u5Vn qAiYHTEbIGCs6MWoBy5h7nrFJ/Al8GhnSA2rFoT1Xd3Ofa5NBe9/wc1fqtybAyfF1Q2i r/dHYTkgaeIkyyjJhSimYBTqRnHheeaheB0Ququ+wBnwtJWKHN605DHPUEkuSPUnhyig Ha9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2KalhkKUUjDwQFWr6WSxzhNbQj3qa3b1UAq/SCX6GaI=; b=YmIejQp+RYcMgjGJnhmZAbtMe/93qipe9+tp8kjFMu7QJUhtnACwRPXkBnepocwHqO O0RroXzg9lbXgEnDjq9XKKWYgmsykNM1QGOKdm0MWNGqjzAY6GZB696pVBSPML0T40Aw 66b4wSh8u2AVhy2/FeC8gQX1V5fmtIR7DgCIiZUU6eqFxWk9a8evEN8tYSMy123iONRm BA45krvmImPbxFIszGzZ28ef8m3nt+kpek4Gn3MddsM722oP2HwxLkp/K8anXJzpeUCu 31DisY3IAUYzBhNz/wNP0MyN76oZF71Q7Hh3VQnI99+ceysqdbJXr2aUajusMKNLpChH Cezg== X-Gm-Message-State: AOAM530bvd5TRNXXEP649ZOqOgLzCYTS5qTD003kN7FfBnKpE6Tan0Iq WEGxUNr/95UNp81d+/6wU9o= X-Google-Smtp-Source: ABdhPJyu5SGhSaKYgH4qEqSnXyd2a7A8N1DvULGYwVcZH+z4ntGgCPaLbLPurIvkf82XiHVueM4AaA== X-Received: by 2002:a62:d158:: with SMTP id t24mr1185118pfl.267.1591767400604; Tue, 09 Jun 2020 22:36:40 -0700 (PDT) Received: from localhost.localdomain (unknown-224-80.windriver.com. [147.11.224.80]) by smtp.gmail.com with ESMTPSA id q13sm12077522pfk.8.2020.06.09.22.36.39 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 09 Jun 2020 22:36:40 -0700 (PDT) From: Bin Meng To: Simon Glass , U-Boot Mailing List Cc: Bin Meng Subject: [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory() Date: Tue, 9 Jun 2020 22:36:31 -0700 Message-Id: <1591767391-2669-5-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1591767391-2669-1-git-send-email-bmeng.cn@gmail.com> References: <1591767391-2669-1-git-send-email-bmeng.cn@gmail.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean From: Bin Meng This adds a test case to test the functionality of the fdtdec API fdtdec_add_reserved_memory(). Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- Changes in v3: - correct typo in the comments, and some minor rewording test/dm/fdtdec.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c index 999d712..56f6f4f 100644 --- a/test/dm/fdtdec.c +++ b/test/dm/fdtdec.c @@ -59,3 +59,72 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts) } DM_TEST(dm_test_fdtdec_set_carveout, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); + +static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts) +{ + struct fdt_memory resv; + fdt_addr_t addr; + fdt_size_t size; + void *blob; + int blob_sz, parent, subnode; + uint32_t phandle, phandle1; + + blob_sz = fdt_totalsize(gd->fdt_blob) + 128; + blob = malloc(blob_sz); + ut_assertnonnull(blob); + + /* Make a writable copy of the fdt blob */ + ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz)); + + /* Insert a memory region in /reserved-memory node */ + resv.start = 0x1000; + resv.end = 0x1fff; + ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region", + &resv, &phandle)); + + /* Test /reserve-memory and its subnode should exist */ + parent = fdt_path_offset(blob, "/reserved-memory"); + ut_assert(parent > 0); + subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region"); + ut_assert(subnode > 0); + + /* Test reg property of /reserved-memory/rsvd_region node */ + addr = fdtdec_get_addr_size_auto_parent(blob, parent, subnode, + "reg", 0, &size, false); + ut_assert(addr == resv.start); + ut_assert(size == resv.end - resv.start + 1); + + /* Insert another memory region in /reserved-memory node */ + subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1"); + ut_assert(subnode < 0); + + resv.start = 0x2000; + resv.end = 0x2fff; + ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1", + &resv, &phandle1)); + subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1"); + ut_assert(subnode > 0); + + /* phandles must be different */ + ut_assert(phandle != phandle1); + + /* + * Insert a 3rd memory region with the same addr/size as the 1st one, + * but a new node should not be inserted due to the same addr/size. + */ + resv.start = 0x1000; + resv.end = 0x1fff; + ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2", + &resv, &phandle1)); + subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region2"); + ut_assert(subnode < 0); + + /* phandle must be same as the 1st one */ + ut_assert(phandle == phandle1); + + free(blob); + + return 0; +} +DM_TEST(dm_test_fdtdec_add_reserved_memory, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);