From patchwork Sun Feb 12 23:15:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1741202 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=eBm7eP5Q; 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 4PFNqV70F7z23qt for ; Mon, 13 Feb 2023 10:25:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 630198596B; Mon, 13 Feb 2023 00:20: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=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="eBm7eP5Q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D7B2685899; Mon, 13 Feb 2023 00:18:29 +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-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) (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 3A3BB857EC for ; Mon, 13 Feb 2023 00:17:57 +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-io1-xd29.google.com with SMTP id l128so3958228iof.2 for ; Sun, 12 Feb 2023 15:17:57 -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=Gs7BDYPQ1GbtsDOx/LyDb/wFKSXyUkRkuT54M+uDlcs=; b=eBm7eP5QV98F6O6usg1XlJCcXw/REOYNMIoMJjKzPa1wnzLrsUMY8L3xcYU7Ng7xUY mQ5gzHlBWlNbVnYTw+MwdQkbpb0szuaMu9TgHoBlpjLGMEuQhWxoI2ZK7eMaVpLiVJaE FgIhcWHqIFUbb9tO8JlD40zelg7Bisbae7zl8= 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=Gs7BDYPQ1GbtsDOx/LyDb/wFKSXyUkRkuT54M+uDlcs=; b=CZcZisSTJha9QK+N6n4OOezbr5+Rt3Rs8t4/vyzImkZxIDvWXm4qDmhqJJRT5Jfj0r 5a9kUY01AKPkhtP9txIfJ2S6Mm2q1Bu4/C7Bq0IL7fCNbmLr2v4bD8RUKoiKCp/co7Ul iCE3d8QeMpsSHHsAMWrQGUzBtLyMpwhQA8V/e1UHYcSQTD2M7rKitamXAN4dNL6lP5WN V6dx5ZASk4WGWwJtuMBvtLKjrRuTp3NNs0AC25qiVuxiNdZs/dL2wzUQlB5Tym+KcjoV mTjT0Q1WiB78EzGLAS1aTS59VqNml9jhAlVBDBuKVNG9MyL0wTpPn1wigMGynmyZLa9r wYxQ== X-Gm-Message-State: AO0yUKVxR/CoxV2FMNKBBzEZ5F5PY3yAZ08ppzc6Qg+0vUE1+lIxUw68 rvBECgZTmpP9e53EXUOcoG1vaWqYl6xq9TjX X-Google-Smtp-Source: AK7set//dpVtI1dlGUi98H+aq5atNvRFd/CuWZiIqlwa/ylERGJpHS91wuvmIoIoF3jpQFAB/upW9Q== X-Received: by 2002:a6b:b443:0:b0:723:3ea8:5e86 with SMTP id d64-20020a6bb443000000b007233ea85e86mr17505741iof.13.1676243876733; Sun, 12 Feb 2023 15:17:56 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id n16-20020a6b8b10000000b006dfbd35e995sm3627849iod.21.2023.02.12.15.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 15:17:56 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH v3 55/95] fixdep: Add some tests for parse_config_line() Date: Sun, 12 Feb 2023 16:15:58 -0700 Message-Id: <20230212231638.1134219-56-sjg@chromium.org> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog In-Reply-To: <20230212231638.1134219-1-sjg@chromium.org> References: <20230212231638.1134219-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 --- (no changes since v1) 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();