From mboxrd@z Thu Jan 1 00:00:00 1970 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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAF67C61DA4 for ; Wed, 22 Feb 2023 16:42:12 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C24FE85B66; Wed, 22 Feb 2023 17:37:07 +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="KjJMG4CQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3DED985B1F; Wed, 22 Feb 2023 17:35:56 +0100 (CET) Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (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 2182385B2B for ; Wed, 22 Feb 2023 17:35:14 +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-xd2b.google.com with SMTP id bf15so3791384iob.7 for ; Wed, 22 Feb 2023 08:35:06 -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=ahPcI4M52ikgyXyBAKDm3ry3dFlAgpde2RK1n9tew+8=; b=KjJMG4CQvwyTGync87ZjflzAqgtVbkrZQV284wcSFCt9jUfyboBMarJxRcpVu/mSEL +JgQHSrFZyZxN6cy2/t6fzv8tJpnCKnvGIR3q36jLRaTqXivSaVpZ58awAncVFv0Djbo VIwhdEsvqEOZaI1V1He3DthYAREejDCWdLIGs= 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=ahPcI4M52ikgyXyBAKDm3ry3dFlAgpde2RK1n9tew+8=; b=PHJz8+HFI5dka6qzF8xoKXNv0fG+1XlSq1H4UzKI6TItaNPwEJB8IUxE0pyl8s6X70 mh4nVN4enXrG4PAaPg1QSVUVo1+J8i7Qxof2kv9KIgq+i3eDTnNaC0gk4lhujFgci8Ap PoQ9XklWuWNQYgUgzQ0JH1LmrHjg0cuWogfUOmUmo1OelH+GqcjmEEc5iT+/eEFPDF2D rA2pfyYO1aoEKK7Xm66uQ7pDOdqynH0S631XqI8CU/mB7YbrSbp/OZs96mnFsnVXZ8NK LjpEePnowrcaZeptTtn23d4gmYgBBRTZhNTMMTkoQuEo1x2d368xuD9DPW2RSorVJAXL KUcA== X-Gm-Message-State: AO0yUKX6Hj7LWFod+BZJgr/nSteDEbtgZ0XCrdORqqXizxLubLQ+IQ3y Nk98LKgN1J/97KQvgMoPPOsocfxSWQEvIDO0 X-Google-Smtp-Source: AK7set+YssnkYkBzfRHYopPz4L89QXUrybVRNEETgV9gcIPaSQV+0FWHhOUHp5zuDIyrsREFKOqjdA== X-Received: by 2002:a5d:87d4:0:b0:74c:91c7:8794 with SMTP id q20-20020a5d87d4000000b0074c91c78794mr2493276ios.21.1677083705763; Wed, 22 Feb 2023 08:35:05 -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 z26-20020a056602005a00b00716eb44b97esm2164541ioz.27.2023.02.22.08.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 08:35:05 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH v5 28/44] fixdep: Add some tests for parse_config_line() Date: Wed, 22 Feb 2023 09:34:09 -0700 Message-Id: <20230222163425.2043934-29-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog In-Reply-To: <20230222163425.2043934-1-sjg@chromium.org> References: <20230222163425.2043934-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(); -- 2.39.2.637.g21b0678d19-goog