public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] tst_test: Add support for needs_devices
Date: Fri, 27 Mar 2020 14:47:06 +0100	[thread overview]
Message-ID: <20200327134707.4532-2-chrubis@suse.cz> (raw)
In-Reply-To: <20200327134707.4532-1-chrubis@suse.cz>

Which is a list of environment variables needed for a test.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_test.h |  3 +++
 lib/tst_test.c     | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/tst_test.h b/include/tst_test.h
index 84b6a940f..75d6632a2 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -213,6 +213,9 @@ struct tst_test {
 	/* NULL terminated array of needed kernel drivers */
 	const char * const *needs_drivers;
 
+	/* NULL terminated array of devices */
+	const char *const *needs_devices;
+
 	/*
 	 * NULL terminated array of (/proc, /sys) files to save
 	 * before setup and restore after cleanup
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9479264b2..da7324b78 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -464,6 +464,22 @@ static void print_test_tags(void)
 	printf("\n");
 }
 
+static void print_test_devices(void)
+{
+	const char *const *devices = tst_test->needs_devices;
+	int i;
+
+	if (!devices)
+		return;
+
+	printf("\nNeeded devices\n--------------\n");
+
+	for (i = 0; devices[i]; i++)
+		printf("%s\n", devices[i]);
+
+	printf("\n");
+}
+
 static void check_option_collision(void)
 {
 	unsigned int i, j;
@@ -543,6 +559,7 @@ static void parse_opts(int argc, char *argv[])
 		case 'h':
 			print_help();
 			print_test_tags();
+			print_test_devices();
 			exit(0);
 		case 'i':
 			iterations = atoi(optarg);
@@ -890,6 +907,21 @@ static void do_setup(int argc, char *argv[])
 				tst_brk(TCONF, "%s driver not available", name);
 	}
 
+	if (tst_test->needs_devices) {
+		int i;
+		const char *name;
+		int exit = 0;
+
+		for (i = 0; (name = tst_test->needs_devices[i]); i++) {
+			if (!getenv(name)) {
+				tst_res(TINFO, "%s device env variable mising", name);
+				exit = 1;
+			}
+		}
+		if (exit)
+			tst_brk(TCONF, "Device(s) not passed to the test");
+	}
+
 	if (tst_test->format_device)
 		tst_test->needs_device = 1;
 
-- 
2.24.1


  reply	other threads:[~2020-03-27 13:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-27 13:47 [LTP] [PATCH 0/2] [RFC] Add needs_devices && basic uart test Cyril Hrubis
2020-03-27 13:47 ` Cyril Hrubis [this message]
2020-03-27 13:47 ` [LTP] [PATCH 2/2] device_drivers/uart01: Add uart01 test Cyril Hrubis
2020-03-27 15:11   ` Petr Vorel
2020-03-28  8:27   ` Cixi Geng
2020-03-30 15:21     ` Cyril Hrubis
2020-03-31 18:08       ` Cyril Hrubis
2020-04-01 11:57         ` Cixi Geng
2020-04-01 13:12           ` Cyril Hrubis
2020-04-02  1:30             ` Cixi Geng
2020-04-02  9:31               ` Cyril Hrubis
2020-04-02 11:16                 ` Cixi Geng
2020-04-02 11:23                   ` Cyril Hrubis
2020-04-03  1:50                     ` Cixi Geng
2020-04-08  4:15                       ` Cixi Geng
2020-04-08 14:18                         ` Cyril Hrubis
2020-05-11  9:12                           ` Cixi Geng
2020-05-11  9:37                             ` Cyril Hrubis
2020-05-12  2:32                               ` Cixi Geng

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=20200327134707.4532-2-chrubis@suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox