All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>
Subject: [PATCH 17/32] fixdep: Add some tests for parse_config_line()
Date: Tue, 31 Jan 2023 08:26:47 -0700	[thread overview]
Message-ID: <20230131152702.249197-18-sjg@chromium.org> (raw)
In-Reply-To: <20230131152702.249197-1-sjg@chromium.org>

Add tests for this code to cover the basic cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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.1.456.gfc5497dd1b-goog


  parent reply	other threads:[~2023-01-31 15:32 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31 15:26 [PATCH 00/32] RFC: Migrate to split config Simon Glass
2023-01-31 15:26 ` [PATCH 01/32] fixup: Bugfix for moveconfig Simon Glass
2023-01-31 15:26 ` [PATCH 02/32] event: Add Kconfig options for SPL Simon Glass
2023-01-31 15:26 ` [PATCH 03/32] bootstd: " Simon Glass
2023-01-31 15:26 ` [PATCH 04/32] cmd: Add an SPL Kconfig for CMDLINE and HUSH Simon Glass
2023-01-31 15:26 ` [PATCH 05/32] boot: Add a Kconfig for SPL_QCOM_PMIC_GPIO Simon Glass
2023-01-31 15:26 ` [PATCH 06/32] cros_ec: Add SPL Kconfigs for cros_ec features Simon Glass
2023-01-31 15:26 ` [PATCH 07/32] boot: Add a Kconfig for SPL_UT_COMPRESSION Simon Glass
2023-01-31 15:26 ` [PATCH 08/32] env: Avoid checking ENV_IS_IN when env disabled Simon Glass
2023-01-31 15:26 ` [PATCH 09/32] boot: Add a Kconfig for SPL_AVB_VERIFY Simon Glass
2023-01-31 15:26 ` [PATCH 10/32] env: Allow VPL environment to be nowhere Simon Glass
2023-01-31 15:26 ` [PATCH 11/32] lib: Add VPL options for SHA1 and SHA256 Simon Glass
2023-01-31 15:26 ` [PATCH 12/32] sandbox: Tidy up RTC options Simon Glass
2023-01-31 15:26 ` [PATCH 13/32] sandbox: Use the generic VPL option to enable VPL Simon Glass
2023-01-31 15:26 ` [PATCH 14/32] sandbox: Tidy up I2C options Simon Glass
2023-01-31 15:26 ` [PATCH 15/32] fixdep: Add support for VPL Simon Glass
2023-01-31 15:26 ` [PATCH 16/32] fixdep: Refactor to make testing easier Simon Glass
2023-01-31 15:26 ` Simon Glass [this message]
2023-01-31 15:26 ` [PATCH 18/32] test: Add SPL versions of the TEST_KCONFIG options Simon Glass
2023-01-31 15:26 ` [PATCH 19/32] kconfig: Add configuration files for noproper and nospl Simon Glass
2023-01-31 15:26 ` [PATCH 20/32] kconfig: Refactor code into separate writer functions Simon Glass
2023-01-31 15:26 ` [PATCH 21/32] kconfig: Support writing separate SPL files Simon Glass
2023-01-31 15:26 ` [PATCH 22/32] Makefile: Include the config for the phase being built Simon Glass
2023-01-31 15:26 ` [PATCH 23/32] kconfig: Update CONFIG_IS_ENABLED() for split files Simon Glass
2023-01-31 15:26 ` [PATCH 24/32] Makefile: Use empty SPL_ and SPL_TPL_ vars Simon Glass
2023-01-31 15:26 ` [PATCH 25/32] Drop use of CONFIG_IS_ENABLED() Simon Glass
2023-01-31 15:26 ` [PATCH 26/32] kconfig: Adjust the meaning " Simon Glass
2023-01-31 15:26 ` [PATCH 27/32] kconfig: Drop CONFIG_IF_ENABLED_INT() Simon Glass
2023-01-31 15:26 ` [PATCH 28/32] kconfig: Drop CONFIG_IS_ENABLED() Simon Glass
2023-01-31 15:26 ` [PATCH 29/32] kconfig: drop config_opt_enabled() Simon Glass
2023-01-31 15:27 ` [PATCH 30/32] kconfig: Drop CONFIG_VAL() Simon Glass
2023-01-31 15:27 ` [PATCH 31/32] kconfig: Move closer to the Linux version Simon Glass
2023-01-31 15:27 ` [PATCH 32/32] Makefile: Drop SPL_ and SPL_TPL_ macros Simon Glass
2023-01-31 21:57 ` [PATCH 00/32] RFC: Migrate to split config Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230131152702.249197-18-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.