From patchwork Tue Jan 31 15:26:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1734949 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=ZIgTmN7G; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P5pvL2b4Cz23gV for ; Wed, 1 Feb 2023 02:32:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 900C785B30; Tue, 31 Jan 2023 16:29:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZIgTmN7G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C7B7685ADE; Tue, 31 Jan 2023 16:28:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (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 EB34385AEB for ; Tue, 31 Jan 2023 16:27:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x136.google.com with SMTP id k12so1587727ilv.10 for ; Tue, 31 Jan 2023 07:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nJVXVWYl1lxM2baLV8pX1S7C8KHWIhQVbdgbTuUF30U=; b=ZIgTmN7Gq0dr0WTMzvy/M9x5SpWs6lUHhiFxgyiyqytfnAOSCxsIMK3gWKYHODGqW8 /5mM2z5jtgTymSc94guanDhtq4tlNAY5u/TtXpT9qqMFN+u7CmpHy1t7b/JfY2pVKjoU mGbmGChVrg+nayAgiNeELe72dtbc/bemKySgU= 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 :subject:date:message-id:reply-to; bh=nJVXVWYl1lxM2baLV8pX1S7C8KHWIhQVbdgbTuUF30U=; b=KRiDgd0OslfaWpoGp8wpTRXf2U7o+1iedtfXsVOSZKiy80V/F4AzNOOdLrcagEPZzX TaQ/lm1kvl82eGkFJqIF+5iLRdY94B0zPHYi6CiS4KwiJ/y0he+qzMLRQqOyFQMzlxp0 E71Zjh3ob7Qmu+YOTOr6TymOrvJhfXHob1FfIVY3yoI2so1W464sHm5S7ZOb/DoqT9bX b0aMgn3wktTsEdWwh/pK6ChFpCh9NGuK+TF9jbKy5IVP6Dg2I15lbMJpqMFWRDQ2u0Ax c/DUt+8cy85DUWIR25dmOGKRCCKLc8pdSvFuvwHXLy+otECycSlJ+rf6Z5k3zJPsew2e bvWw== X-Gm-Message-State: AFqh2kpAZyCrkgZQAEvlKw14fkJy5zlHnLljMueQBd7N5f6zq6OhqPyP WjkowdbG0x1ImaCEmQvk6E4vOKPhgcARPjw6 X-Google-Smtp-Source: AMrXdXu3kLpxzc9YOCOcFnvG3Pqwl76jP4afr+7G7UsUFmxqcVd4NPKhvSk7mRIP9myQTPaMvnv9Eg== X-Received: by 2002:a05:6e02:b29:b0:30f:6206:566e with SMTP id e9-20020a056e020b2900b0030f6206566emr31560462ilu.31.1675178872337; Tue, 31 Jan 2023 07:27:52 -0800 (PST) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id u4-20020a02cb84000000b0039db6cffcbasm5649328jap.71.2023.01.31.07.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:27:52 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH 17/32] fixdep: Add some tests for parse_config_line() Date: Tue, 31 Jan 2023 08:26:47 -0700 Message-Id: <20230131152702.249197-18-sjg@chromium.org> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog In-Reply-To: <20230131152702.249197-1-sjg@chromium.org> References: <20230131152702.249197-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean Add tests for this code to cover the basic cases. Signed-off-by: Simon Glass --- scripts/basic/fixdep.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index a49d35ba5f6..fe8180ab4e7 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -425,11 +425,84 @@ static void parse_dep_file(char *m, const char *target) xprintf("$(deps_%s):\n", target); } +#define CHECKP(expect, got) \ + if (expect != got) { \ + fprintf(stderr, "Test failed at line %d: expect %ld, got %ld\n", \ + __LINE__, expect - buf, got - buf); \ + return 1; \ + } + +#define CHECK(expect, got) \ + if (expect != got) { \ + fprintf(stderr, "Test failed at line %d: expect %p, got %p\n", \ + __LINE__, expect, got); \ + return 1; \ + } + +static int run_tests(void) +{ + const char *out, *end; + char buf_s[40], *buf = buf_s + 1; + + /* make sure the previous char doesn't look like part of the CONFIG */ + buf_s[0] = ' '; + + strcpy(buf, ""); + out = parse_config_line(buf, &end); + CHECK(NULL, out); + CHECK(NULL, end); + + strcpy(buf, "nothing"); + out = parse_config_line(buf, &end); + CHECK(NULL, out); + CHECK(NULL, end); + + strcpy(buf, "CONFIG_OPTION_MORE"); + out = parse_config_line(buf, &end); + CHECKP(buf + 7, out); + CHECKP(buf + 18, end); + + strcpy(buf, "some CONFIG_OPTION_MORE"); + out = parse_config_line(buf, &end); + CHECKP(buf + 12, out); + CHECKP(buf + 23, end); + + strcpy(buf, "some CONFIG_OPTION_MORE here"); + out = parse_config_line(buf, &end); + CHECKP(buf + 12, out); + CHECKP(buf + 23, end); + + strcpy(buf, "CONFIG_OPTION_MODULE"); + out = parse_config_line(buf, &end); + CHECKP(buf + 7, out); + CHECKP(buf + 13, end); + + strcpy(buf, "CONFIG_IS_ENABLED(FRED)"); + out = parse_config_line(buf, &end); + CHECKP(buf + 18, out); + CHECKP(buf + 22, end); + + strcpy(buf, "CONFIG_VAL(MARY)"); + out = parse_config_line(buf, &end); + CHECKP(buf + 11, out); + CHECKP(buf + 15, end); + + return 0; +} + int main(int argc, char *argv[]) { const char *depfile, *target, *cmdline; void *buf; + if (argc == 2 && !strcmp("-t", argv[1])) { + if (run_tests()) { + fprintf(stderr, "Tests failed\n"); + return 1; + } + printf("Tests passed\n"); + return 0; + } if (argc != 4) usage();