Skip to contentSkip to conversation

Another attempt at hardware discovery

PATCH Superseded Cyril Hrubis 5 participants 15 messages Feb 24, 2021 – Nov 5, 2021 Library code

lore
Share & tools
lore
#0 lore raw

v2 cover Another attempt at hardware discovery

This is a second attempt on hardware discovery LTP support. The main difference between the previous attempts is that this version uses JSON, which allows us propagate structured data to the test.

This is still an early protototype but I'm seding it out to get more feedback before I continue to work on it.

So how is this supposed to work:

* Test that needs particular hardware sets the needs_hardware filed in the test test structure. This is a free form string, in the uart example it's called 'UART-loopback'. If we ever add a test for i2c eeprom it would be probably called 'I2C-eeprom', etc.

* The test library takes this and passes it to the hardware discovery script/binary. The example scipt that is included in this patchset just hardcodes configuration for a usb-to-serial cable. In real world lab this would be either prepared for each board specifically and injected to the filesystem before the test happens, or may be a simple script that calls curl with a request to a lab sever, etc.

* The output from the script is a JSON object. If there is a need to reconfigure lab hardware before the test, the JSON contains a path to a script/binary that has to be called to do so. Again this may be a script that calls curl with a request to a lab sever which would, for example, interconnect different serial ports with relays.

The parameter to that script is an unique ID for the hardware configuration that is listed in each hardware configuration in the hwconfs array of objects that follows.

I'm not sure if this actually belongs there, maybe it would be cleaner to have one reconfigure script for the whole LTP and we would pass the needs_hardware content as well as the unique ID, e.g.

'hardware-reconfigure.sh UART-loopback ttyUSB0-ttyS0'

but that is a minor detail that could be easily sorted out later.

The most important part of the JSON is the hwconfs array, which consists of hardware description objects, which, apart form the uid, are not interpreted by the library, but rather passed to the test. The test library loops over the array and forks a testrun for each entry in the array.

Each iteration of the test then gets it's parameters as a JSON object. In the case of the UART one of the objects in the array looks like:

  {
    "uid": "ttyUSB0-ttyUSB0-01",
    "rx": "ttyUSB0",
    "tx": "ttyUSB0",
    "hwflow": 0,
    "baud_rates": [
     9600,
     19200
    ]
  }

Which is mostly self-explanatory, the test then parses the structure and executes one test per each baud rate.

What is still missing is the ability to pass the JSON hardware description directly to the test, so that we can execute the test manually, but that would be fairly easy to add.

Cyril Hrubis (5):
lib: tst_cmd: Make tst_cmd() usable for global paths
lib: Add minimalistic json parser
lib: Add hardware discovery code
Sample hardware discovery and reconfigure scripts
testcases: uart01: Add.

 hardware-discovery.sh                         |  36 +
 hardware-reconfigure.sh                       |   3 +
 include/tst_hwconf.h                          |  13 +
 include/tst_json.h                            | 177 +++++
 include/tst_test.h                            |   3 +
 lib/tst_cmd.c                                 |   2 +-
 lib/tst_hardware.c                            | 218 ++++++
 lib/tst_hardware.h                            |  83 +++
 lib/tst_json.c                                | 679 ++++++++++++++++++
 lib/tst_test.c                                |  30 +
 runtest/device_drivers                        |   2 +
 testcases/kernel/device-drivers/Makefile      |   1 +
 .../kernel/device-drivers/uart/.gitignore     |   1 +
 testcases/kernel/device-drivers/uart/Makefile |   3 +
 testcases/kernel/device-drivers/uart/uart01.c | 620 ++++++++++++++++
 15 files changed, 1870 insertions(+), 1 deletion(-)
 create mode 100755 hardware-discovery.sh
 create mode 100755 hardware-reconfigure.sh
 create mode 100644 include/tst_hwconf.h
 create mode 100644 include/tst_json.h
 create mode 100644 lib/tst_hardware.c
 create mode 100644 lib/tst_hardware.h
 create mode 100644 lib/tst_json.c
 create mode 100644 runtest/device_drivers
 create mode 100644 testcases/kernel/device-drivers/uart/.gitignore
 create mode 100644 testcases/kernel/device-drivers/uart/Makefile
 create mode 100644 testcases/kernel/device-drivers/uart/uart01.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/5 lib: tst_cmd: Make tst_cmd() usable for global paths

We need to skip the check if the path to the binary starts with '/'.

---
 lib/tst_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_cmd.c +1 -1
index 7446249f9..b73978e20 100644
@@ -58,7 +58,7 @@ int tst_cmd_fds_(void (cleanup_fn)(void),
 
 	char path[PATH_MAX];
 
-	if (tst_get_path(argv[0], path, sizeof(path))) {
+	if (argv[0][0] != '/' && tst_get_path(argv[0], path, sizeof(path))) {
 		if (flags & TST_CMD_TCONF_ON_MISSING)
 			tst_brkm(TCONF, cleanup_fn, "Couldn't find '%s' in $PATH at %s:%d", argv[0],
 				 __FILE__, __LINE__);
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 1/5 lib: tst_cmd: Make tst_cmd() usable for global paths

Quoted 1 line

We need to skip the check if the path to the binary starts with '/'.

Good point!

Kind regards,
Petr

#3 lore raw

PATCH v2 2/5 lib: Add minimalistic json parser

In reply to Cyril Hrubis
---
 include/tst_json.h | 177 ++++++++++++
 lib/tst_json.c     | 679 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 856 insertions(+)
 create mode 100644 include/tst_json.h
 create mode 100644 lib/tst_json.c
include/tst_json.h new file +177 -0
new file mode 100644
index 000000000..4b3669824
@@ -0,0 +1,177 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2021 Cyril Hrubis <[email protected]>
+ */
+
+#ifndef TST_JSON_H
+#define TST_JSON_H
+
+#include <stdio.h>
+
+#define TST_JSON_ERR_MAX 128
+#define TST_JSON_ID_MAX 64
+
+enum tst_json_type {
+	TST_JSON_VOID = 0,
+	TST_JSON_INT,
+	TST_JSON_STR,
+	TST_JSON_OBJ,
+	TST_JSON_ARR,
+};
+
+struct tst_json_buf {
+	/** Pointer to a null terminated JSON string */
+	const char *json;
+	/** A length of the JSON string */
+	size_t len;
+	/** A current offset into the JSON string */
+	size_t off;
+	/** An offset to the start of the last array or object */
+	size_t sub_off;
+
+	char err[TST_JSON_ERR_MAX];
+	char buf[];
+};
+
+struct tst_json_val {
+	enum tst_json_type type;
+
+	/** An user supplied buffer and size to store a string values to. */
+	char *buf;
+	size_t buf_size;
+
+	/** An union to store the parsed value into. */
+	union {
+		long val_int;
+		const char *val_str;
+	};
+
+	/** An ID for object values */
+	char id[TST_JSON_ID_MAX];
+};
+
+/*
+ * @brief Resets the parser.
+ *
+ * Resets the parse offset and clears errors.
+ *
+ * @buf An tst_json buffer
+ */
+static inline void tst_json_reset(struct tst_json_buf *buf)
+{
+	buf->off = 0;
+	buf->err[0] = 0;
+}
+
+/*
+ * @brief Fills the buffer error.
+ *
+ * Once buffer error is set all parsing functions return immediatelly with type
+ * set to TST_JSON_VOID.
+ *
+ * @buf An tst_json buffer
+ * @fmt A printf like format string
+ * @... A printf like parameters
+ */
+void tst_json_err(struct tst_json_buf *buf, const char *fmt, ...)
+               __attribute__((format (printf, 2, 3)));
+
+/*
+ * @brief Prints error into a file.
+ *
+ * The error takes into consideration the current offset in the buffer and
+ * prints a few preceding lines along with the exact position of the error.
+ *
+ * @f A file to print the error to.
+ * @buf An tst_json buffer.
+ */
+void tst_json_err_print(FILE *f, struct tst_json_buf *buf);
+
+/*
+ * @brief Returns true if error was encountered.
+ *
+ * @bfu An tst_json buffer.
+ * @return True if error was encountered false otherwise.
+ */
+static inline int tst_json_is_err(struct tst_json_buf *buf)
+{
+	return !!buf->err[0];
+}
+
+/*
+ * @brief Checks is result has valid type.
+ *
+ * @res An tst_json value.
+ * @return Zero if result is not valid, non-zero otherwise.
+ */
+static inline int tst_json_valid(struct tst_json_val *res)
+{
+	return !!res->type;
+}
+
+/*
+ * @brief Returns the type of next element in buffer.
+ *
+ * @buf An tst_json buffer.
+ * @return A type of next element in the buffer.
+ */
+enum tst_json_type tst_json_next_type(struct tst_json_buf *buf);
+
+/*
+ * @brief Returns if first element in JSON is object or array.
+ *
+ * @buf An tst_json buffer.
+ * @return On success returns TST_JSON_OBJ or TST_JSON_ARR. On failure TST_JSON_VOID.
+ */
+enum tst_json_type tst_json_start(struct tst_json_buf *buf);
+
+/*
+ * @brief Starts parsing of an JSON object.
+ *
+ * @buf An tst_json buffer.
+ * @res An tst_json result.
+ */
+int tst_json_obj_first(struct tst_json_buf *buf, struct tst_json_val *res);
+int tst_json_obj_next(struct tst_json_buf *buf, struct tst_json_val *res);
+
+#define TST_JSON_OBJ_FOREACH(buf, res) \
+	for (tst_json_obj_first(buf, res); tst_json_valid(res); tst_json_obj_next(buf, res))
+
+/*
+ * @brief Skips parsing of an JSON object.
+ *
+ * @buf An tst_json buffer.
+ * @return Zero on success, non-zero otherwise.
+ */
+int tst_json_obj_skip(struct tst_json_buf *buf);
+
+int tst_json_arr_first(struct tst_json_buf *buf, struct tst_json_val *res);
+int tst_json_arr_next(struct tst_json_buf *buf, struct tst_json_val *res);
+
+#define TST_JSON_ARR_FOREACH(buf, res) \
+	for (tst_json_arr_first(buf, res); tst_json_valid(res); tst_json_arr_next(buf, res))
+
+/*
+ * @brief Skips parsing of an JSON array.
+ *
+ * @buf An tst_json buffer.
+ * @return Zero on success, non-zero otherwise.
+ */
+int tst_json_arr_skip(struct tst_json_buf *buf);
+
+/*
+ * @brief Loads a file into an tst_json buffer.
+ *
+ * @path A path to a file.
+ * @return An tst_json buffer or NULL in a case of a failure.
+ */
+struct tst_json_buf *tst_json_load(const char *path);
+
+/*
+ * @brief Frees an tst_json buffer.
+ *
+ * @buf An tst_json buffer allcated by tst_json_load() function.
+ */
+void tst_json_free(struct tst_json_buf *buf);
+
+#endif /* TST_JSON_H */
lib/tst_json.c new file +679 -0

679 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw

PATCH v2 2/5 lib: Add minimalistic json parser

Hi Cyril,

Nice work!

lib/tst_json.c line 28

Quoted 8 lines
lib/tst_json.c new file +8 -0
+static int eatws(struct tst_json_buf *buf)
+{
+	while (!buf_empty(buf)) {
+		switch (buf->json[buf->off]) {
+		case ' ':
+		case '\t':
+		case '\n':
+		case '\f':

Shouldn't there be '\r' as well? (handled at copy_str()).

lib/tst_json.c line 38

Quoted 10 lines
lib/tst_json.c new file +10 -0
+		break;
+		default:
+			goto ret;
+		}
+
+		buf->off += 1;
+	}
+ret:
+	return buf_empty(buf);
+}

Kind regards,
Petr

Reviewed-by on v2 2/5
#5 lore raw

Re: [LTP] [Automated-testing] [PATCH v2 2/5] lib: Add minimalistic json parser

Hello,

Quoted 6 lines · Petr Vorel

Hi Cyril,

Nice work!

Quoted 9 lines

lib/tst_json.c line 28

Quoted 8 lines
lib/tst_json.c new file +8 -0
+static int eatws(struct tst_json_buf *buf)
+{
+	while (!buf_empty(buf)) {
+		switch (buf->json[buf->off]) {
+		case ' ':
+		case '\t':
+		case '\n':
+		case '\f':

Shouldn't there be '\r' as well? (handled at copy_str()).

Yeah, it seems to be in the spec.

At any rate, I wouldn't mind this patch being applied immediately because there is more than one WIP it may be useful for.

Quoted 23 lines

lib/tst_json.c line 38

Quoted 10 lines
lib/tst_json.c new file +10 -0
+		break;
+		default:
+			goto ret;
+		}
+
+		buf->off += 1;
+	}
+ret:
+	return buf_empty(buf);
+}

Kind regards,
Petr

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#872): https://lists.yoctoproject.org/g/automated-testing/message/872
Mute This Topic: https://lists.yoctoproject.org/mt/80881162/3616767
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/automated-testing/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [Automated-testing] [PATCH v2 2/5] lib: Add minimalistic json parser

Hi!

Quoted 4 lines

Yeah, it seems to be in the spec.

At any rate, I wouldn't mind this patch being applied immediately because there is more than one WIP it may be useful for.

Meanwhile I did a bit more work on the parser and made sure that it passes JSONTestSuite as well.

If you need a JSON parser in LTP we should vendor the latest version at:

https://github.com/metan-ucw/ujson

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v2 3/5 lib: Add hardware discovery code

In reply to Cyril Hrubis

See lib/tst_hardware.h for details.

---
 include/tst_hwconf.h |  13 +++
 include/tst_test.h   |   3 +
 lib/tst_hardware.c   | 218 +++++++++++++++++++++++++++++++++++++++++++
 lib/tst_hardware.h   |  83 ++++++++++++++++
 lib/tst_test.c       |  30 ++++++
 5 files changed, 347 insertions(+)
 create mode 100644 include/tst_hwconf.h
 create mode 100644 lib/tst_hardware.c
 create mode 100644 lib/tst_hardware.h
include/tst_hwconf.h new file +13 -0
new file mode 100644
index 000000000..5b0b95441
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020-2021 Cyril Hrubis <[email protected]>
+ */
+
+#ifndef TST_HWCONF_H__
+#define TST_HWCONF_H__
+
+#include "tst_json.h"
+
+struct tst_json_buf *tst_hwconf_get(void);
+
+#endif	/* TST_HWCONF_H__ */
include/tst_test.h +3 -0
index 1fbebe752..bd6de601e 100644
@@ -230,6 +230,9 @@ struct tst_test {
 	/* NULL terminated array of needed kernel drivers */
 	const char * const *needs_drivers;
 
+	/* Unique hardware identifier */
+	const char *needs_hardware;
+
 	/*
 	 * NULL terminated array of (/proc, /sys) files to save
 	 * before setup and restore after cleanup
lib/tst_hardware.c new file +218 -0

218 lines not on this page · raw message

lib/tst_hardware.h new file +83 -0

83 lines not on this page · raw message

lib/tst_test.c +30 -0
index 6bbee030b..3883ce227 100644
@@ -27,6 +27,7 @@
 #include "tst_wallclock.h"
 #include "tst_sys_conf.h"
 #include "tst_kconfig.h"
+#include "tst_hardware.h"
 
 #include "old_resource.h"
 #include "old_device.h"
@@ -499,6 +500,14 @@ static void print_test_tags(void)
 	printf("\n");
 }
 
+static void print_test_hardware(void)
+{
+	if (!tst_test->needs_hardware)
+		return;
+
+	printf("\nNeeded hardware\n--------------\n%s\n\n", tst_test->needs_hardware);
+}
+
 static void check_option_collision(void)
 {
 	unsigned int i, j;
@@ -578,6 +587,7 @@ static void parse_opts(int argc, char *argv[])
 		case 'h':
 			print_help();
 			print_test_tags();
+			print_test_hardware();
 			exit(0);
 		case 'i':
 			iterations = atoi(optarg);
@@ -942,6 +952,18 @@ static void do_setup(int argc, char *argv[])
 				tst_brk(TCONF, "%s driver not available", name);
 	}
 
+	if (tst_test->needs_hardware) {
+		unsigned int cnt = tst_hwlist_discover(tst_test->needs_hardware);
+
+		if (!cnt) {
+			tst_brk(TCONF, "No hardware '%s' discovered",
+				tst_test->needs_hardware);
+		}
+
+		tst_res(TINFO, "Found %u hardware configurations for '%s'",
+			cnt, tst_test->needs_hardware);
+	}
+
 	if (tst_test->format_device)
 		tst_test->needs_device = 1;
 
@@ -1395,6 +1417,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	if (tst_test->test_variants)
 		test_variants = tst_test->test_variants;
 
+	if (tst_test->needs_hardware) {
+		test_variants = tst_hwlist_cnt();
+		tst_hwlist_reset();
+	}
+
 	for (tst_variant = 0; tst_variant < test_variants; tst_variant++) {
 		if (tst_test->all_filesystems)
 			ret |= run_tcases_per_fs();
@@ -1403,6 +1430,9 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 		if (ret & ~(TCONF))
 			goto exit;
+
+		if (tst_test->needs_hardware)
+			tst_hwlist_next();
 	}
 
 exit:
Signature · 1 line
2.26.2
#8 lore raw

PATCH v2 4/5 Sample hardware discovery and reconfigure scripts

In reply to Cyril Hrubis

This is not going to be part of the final patchset.

---
 hardware-discovery.sh   | 36 ++++++++++++++++++++++++++++++++++++
 hardware-reconfigure.sh |  3 +++
 2 files changed, 39 insertions(+)
 create mode 100755 hardware-discovery.sh
 create mode 100755 hardware-reconfigure.sh
hardware-discovery.sh new file +36 -0
new file mode 100755
index 000000000..2d1eeefaa
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+if [ "$1" = "UART-loopback" ]; then
+	echo '{'
+	echo ' "reconfigure": "hardware-reconfigure.sh",'
+	echo ' "hwconfs": ['
+	echo '  {'
+	echo '   "uid": "ttyUSB0-ttyUSB0-01",'
+	echo '   "tx": "/dev/ttyUSB0",'
+	echo '   "rx": "/dev/ttyUSB0",'
+	echo '   "hwflow": 0,'
+	echo '   "baud_rates": ['
+	echo '    4800,'
+	echo '    9600,'
+	echo '    19200'
+	echo '   ]'
+	echo '  },'
+	echo '  {'
+	echo '   "uid": "ttyUSB0-ttyUSB0-02",'
+	echo '   "tx": "/dev/ttyUSB0",'
+	echo '   "rx": "/dev/ttyUSB0",'
+	echo '   "hwflow": 1,'
+	echo '   "baud_rates": ['
+	echo '    4800,'
+	echo '    9600,'
+	echo '    19200'
+	echo '   ]'
+	echo '  }'
+	echo ' ]'
+	echo '}'
+
+	exit 0
+fi
+
+echo '{}'
+exit 0
hardware-reconfigure.sh new file +3 -0
new file mode 100755
index 000000000..079f6588a
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo "Reconfigure '$@'"
Signature · 1 line
2.26.2
#9 lore raw

PATCH v2 5/5 testcases: uart01: Add.

In reply to Cyril Hrubis

Execute from the git checkout as:

LTPROOT=~/foo/bar/ltp/ HARDWARE_DISCOVERY=${LTPROOT}hardware-discovery.sh ./uart01 -s 10240

---
 runtest/device_drivers                        |   2 +
 testcases/kernel/device-drivers/Makefile      |   1 +
 .../kernel/device-drivers/uart/.gitignore     |   1 +
 testcases/kernel/device-drivers/uart/Makefile |   3 +
 testcases/kernel/device-drivers/uart/uart01.c | 620 ++++++++++++++++++
 5 files changed, 627 insertions(+)
 create mode 100644 runtest/device_drivers
 create mode 100644 testcases/kernel/device-drivers/uart/.gitignore
 create mode 100644 testcases/kernel/device-drivers/uart/Makefile
 create mode 100644 testcases/kernel/device-drivers/uart/uart01.c
runtest/device_drivers new file +2 -0
new file mode 100644
index 000000000..9295c7a90
@@ -0,0 +1,2 @@
+uart01
+uart01 -s 10240
testcases/kernel/device-drivers/Makefile +1 -0
index 55e0d25a0..a214f211b 100644
@@ -27,6 +27,7 @@ SUBDIRS		:= acpi \
 		   rtc \
 		   tbio \
 		   uaccess \
+		   uart \
 		   zram
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/device-drivers/uart/.gitignore new file +1 -0
new file mode 100644
index 000000000..9333e8db9
@@ -0,0 +1 @@
+uart01
testcases/kernel/device-drivers/uart/Makefile new file +3 -0
new file mode 100644
index 000000000..939e433d0
@@ -0,0 +1,3 @@
+top_srcdir	?= ../../../..
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/device-drivers/uart/uart01.c new file +620 -0

620 lines not on this page · raw message

Signature · 1 line
2.26.2
#10 lore raw

v2 cover Another attempt at hardware discovery

In reply to Cyril Hrubis

Here are some questions and feedback on the proposal.

Quoted 6 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Cyril Hrubis

This is a second attempt on hardware discovery LTP support. The main difference between the previous attempts is that this version uses JSON, which allows us propagate structured data to the test.

JSON seems like a good choice. In my experience, if a test is written in a language where json-handling is not easy (e.g. shell scripts), there are options for dealing with this. For example, you could require 'jq' on the system where the shell script runs. It's not that bad of a dependency IMHO.

Quoted 10 lines

This is still an early protototype but I'm sending it out to get more feedback before I continue to work on it.

So how is this supposed to work:

* Test that needs particular hardware sets the needs_hardware filed in the test test structure. This is a free form string, in the uart example it's called 'UART-loopback'. If we ever add a test for i2c eeprom it would be probably called 'I2C-eeprom', etc.

Sounds good. It will be good to standardize on these strings in the long run. For now, just picking strings and trying to reconcile them later seems OK.

Quoted 3 lines

* The test library takes this and passes it to the hardware discovery script/binary.

This is probably in the patch set, but how is this invoked? Does the script have a well-known name or location?

Quoted 5 lines

The example script that is included in this patchset
just hardcodes configuration for a usb-to-serial cable. In real world lab this would be either prepared for each board specifically and injected to the filesystem before the test happens, or may be a simple script that calls curl with a request to a lab sever, etc.

Either of these seem like workable approaches. In the case of injecting it into the filesystem, do you have any ideas where you would inject these? For example, would they go somewhere under /etc, or in /usr/test/conf?

Is this something that only the hardware discovery program needs to know? Or do tests use this data directly?

This seems like a rendezvous point between the hardware discovery program and the lab management system, so IMHO it should be well-defined.

Quoted 4 lines

* The output from the script is a JSON object. If there is a need to reconfigure lab hardware before the test, the JSON contains a path to a script/binary that has to be called to do so.

That's interesting.

Quoted 37 lines

Again this may be a
script that calls curl with a request to a lab sever which would, for example, interconnect different serial ports with relays.

The parameter to that script is an unique ID for the hardware configuration that is listed in each hardware configuration in the hwconfs array of objects that follows.

I'm not sure if this actually belongs there, maybe it would be cleaner to have one reconfigure script for the whole LTP and we would pass the needs_hardware content as well as the unique ID, e.g.

'hardware-reconfigure.sh UART-loopback ttyUSB0-ttyS0'

but that is a minor detail that could be easily sorted out later.

The most important part of the JSON is the hwconfs array, which consists of hardware description objects, which, apart form the uid, are not interpreted by the library, but rather passed to the test. The test library loops over the array and forks a testrun for each entry in the array.

Each iteration of the test then gets it's parameters as a JSON object. In the case of the UART one of the objects in the array looks like:

  {
    "uid": "ttyUSB0-ttyUSB0-01",
    "rx": "ttyUSB0",
    "tx": "ttyUSB0",
    "hwflow": 0,
    "baud_rates": [
     9600,
     19200
    ]
  }
Quoted 6 lines

Which is mostly self-explanatory, the test then parses the structure and executes one test per each baud rate.

What is still missing is the ability to pass the JSON hardware description directly to the test, so that we can execute the test manually, but that would be fairly easy to add.

OK - let me describe what I had in mind for a test where the serial port was not in loopback mode, to see how it relates to the proposed architecture. The gpio version of this is implemented in the board farm REST API, but the serial port testing version of this is still under consideration:

Here's how the test would work, for a serial port transmission test where
the transmitting side of the serial line was on the DUT and the other side was managed by the lab hardware:
- 1) the test discovers the hardware for DUT endpoint of the serial line
using the hardware discovery program
- 2) the test discovers the hardware for the lab endpoint (receiving end)
of the serial line using the hardware discovery program
- 3) the test discovers the available baud rates from the hardware discovery program
- 4) the test configures the lab endpoint for reception
- 5) the test configures the DUT endpoint for transmission
- 6) the test loops over the baud rate values, doing the following (7-13):
- 7) use a curl interface or local program to set the receive baud rate of the lab endpoint
- 8) use a curl interface or local program to request serial capture of the lab endpoint
- 9) configure the baud rate of the DUT endpoint
- 10) send data through the DUT endpoint
- 11) use a curl interface or local program to cause the lab endpoint to stop capturing data
- 12) use a curl interface or local program to request the capture data from the lab endpoint
- 13) compare data that was received with the data that was intended to be transmitted

These roles could also be reversed (ie, have the lab endpoint be the sender and the DUT endpoint be the receiver).

The process of configuring the baud rate seems like it corresponds with the hardware_reconfigure.sh script. But maybe you were only thinking of have this actually set up physical connections, and not manage connection/bus settings.

In any event, maybe the hardware_reconfigure.sh script could know about 'start data capture', 'stop data capture', and 'get captured data' operations, or maybe this should be a separate script.

This is structured in a generic way, because I think different tests (such as audio testing, video testing, power measurement testing, CAN bus testing, i2C testing, gpio testing, etc. can all be fit into this model of testing by:
discovering bus endpoints, configuring bus parameters, transmitting or generating data, capturing data
comparing data

So far, I don't see anything in LTP proposal that precludes this model of testing. There may be more to add - either extending hardware_reconfigure.sh or adding a new command that a test would use interactively to
cause data to be exchanged and allow it to be compared.

So - it looks good to me!
-- Tim

Quoted 38 lines

Cyril Hrubis (5):
lib: tst_cmd: Make tst_cmd() usable for global paths
lib: Add minimalistic json parser
lib: Add hardware discovery code
Sample hardware discovery and reconfigure scripts
testcases: uart01: Add.

 hardware-discovery.sh                         |  36 +
 hardware-reconfigure.sh                       |   3 +
 include/tst_hwconf.h                          |  13 +
 include/tst_json.h                            | 177 +++++
 include/tst_test.h                            |   3 +
 lib/tst_cmd.c                                 |   2 +-
 lib/tst_hardware.c                            | 218 ++++++
 lib/tst_hardware.h                            |  83 +++
 lib/tst_json.c                                | 679 ++++++++++++++++++
 lib/tst_test.c                                |  30 +
 runtest/device_drivers                        |   2 +
 testcases/kernel/device-drivers/Makefile      |   1 +
 .../kernel/device-drivers/uart/.gitignore     |   1 +
 testcases/kernel/device-drivers/uart/Makefile |   3 +
 testcases/kernel/device-drivers/uart/uart01.c | 620 ++++++++++++++++
 15 files changed, 1870 insertions(+), 1 deletion(-)
 create mode 100755 hardware-discovery.sh
 create mode 100755 hardware-reconfigure.sh
 create mode 100644 include/tst_hwconf.h
 create mode 100644 include/tst_json.h
 create mode 100644 lib/tst_hardware.c
 create mode 100644 lib/tst_hardware.h
 create mode 100644 lib/tst_json.c
 create mode 100644 runtest/device_drivers
 create mode 100644 testcases/kernel/device-drivers/uart/.gitignore
 create mode 100644 testcases/kernel/device-drivers/uart/Makefile
 create mode 100644 testcases/kernel/device-drivers/uart/uart01.c

--
2.26.2

#11 lore raw

v2 cover Another attempt at hardware discovery

Hi!

Quoted 8 lines
Quoted 4 lines

* Test that needs particular hardware sets the needs_hardware filed in the test test structure. This is a free form string, in the uart example it's called 'UART-loopback'. If we ever add a test for i2c eeprom it would be probably called 'I2C-eeprom', etc.

Sounds good. It will be good to standardize on these strings in the long run. For now, just picking strings and trying to reconcile them later seems OK.

That's what I'm expecting there as well.

Quoted 6 lines
Quoted 3 lines

* The test library takes this and passes it to the hardware discovery script/binary.

This is probably in the patch set, but how is this invoked? Does the script have a well-known name or location?

There is a fallback to a well-known location that can be overrided with an environment varible. This is not well designed at this point, I just wrote a minimal amount of code for the prototype to run.

Quoted 10 lines
Quoted 5 lines

The example script that is included in this patchset
just hardcodes configuration for a usb-to-serial cable. In real world lab this would be either prepared for each board specifically and injected to the filesystem before the test happens, or may be a simple script that calls curl with a request to a lab sever, etc.

Either of these seem like workable approaches. In the case of injecting it into the filesystem, do you have any ideas where you would inject these? For example, would they go somewhere under /etc, or in /usr/test/conf?

No idea, so far my patchset just puts it into $LTPROOT, but I guess that /usr/test/ would be much better place. Do we have a proposal for the /usr/test/ hierarchy somewhere?

Quoted 2 lines

Is this something that only the hardware discovery program needs to know? Or do tests use this data directly?

Currently it's used by the LTP test library, so it's executed by the test binary before it forks a child that actually runs the test.

In the future it could be executed by the test driver (e.g. replacement for ltp-pan I'm working on), which could then pass the pieces of the JSON that describe the hardware to the test for each test invocation. This is still under development, but I do not think that these details matter at all, what we need at this point is to describe generic enough information flow.

Quoted 3 lines

This seems like a rendezvous point between the hardware discovery program and the lab management system, so IMHO it should be well-defined.

Couldn't agree more.

Quoted 89 lines
Quoted 4 lines

* The output from the script is a JSON object. If there is a need to reconfigure lab hardware before the test, the JSON contains a path to a script/binary that has to be called to do so.

That's interesting.

Quoted 37 lines

Again this may be a
script that calls curl with a request to a lab sever which would, for example, interconnect different serial ports with relays.

The parameter to that script is an unique ID for the hardware configuration that is listed in each hardware configuration in the hwconfs array of objects that follows.

I'm not sure if this actually belongs there, maybe it would be cleaner to have one reconfigure script for the whole LTP and we would pass the needs_hardware content as well as the unique ID, e.g.

'hardware-reconfigure.sh UART-loopback ttyUSB0-ttyS0'

but that is a minor detail that could be easily sorted out later.

The most important part of the JSON is the hwconfs array, which consists of hardware description objects, which, apart form the uid, are not interpreted by the library, but rather passed to the test. The test library loops over the array and forks a testrun for each entry in the array.

Each iteration of the test then gets it's parameters as a JSON object. In the case of the UART one of the objects in the array looks like:

  {
    "uid": "ttyUSB0-ttyUSB0-01",
    "rx": "ttyUSB0",
    "tx": "ttyUSB0",
    "hwflow": 0,
    "baud_rates": [
     9600,
     19200
    ]
  }
Quoted 6 lines

Which is mostly self-explanatory, the test then parses the structure and executes one test per each baud rate.

What is still missing is the ability to pass the JSON hardware description directly to the test, so that we can execute the test manually, but that would be fairly easy to add.

OK - let me describe what I had in mind for a test where the serial port was not in loopback mode, to see how it relates to the proposed architecture. The gpio version of this is implemented in the board farm REST API, but the serial port testing version of this is still under consideration:

Here's how the test would work, for a serial port transmission test where
the transmitting side of the serial line was on the DUT and the other side was managed by the lab hardware:
- 1) the test discovers the hardware for DUT endpoint of the serial line
using the hardware discovery program
- 2) the test discovers the hardware for the lab endpoint (receiving end)
of the serial line using the hardware discovery program
- 3) the test discovers the available baud rates from the hardware discovery program
- 4) the test configures the lab endpoint for reception
- 5) the test configures the DUT endpoint for transmission
- 6) the test loops over the baud rate values, doing the following (7-13):
- 7) use a curl interface or local program to set the receive baud rate of the lab endpoint
- 8) use a curl interface or local program to request serial capture of the lab endpoint
- 9) configure the baud rate of the DUT endpoint
- 10) send data through the DUT endpoint
- 11) use a curl interface or local program to cause the lab endpoint to stop capturing data
- 12) use a curl interface or local program to request the capture data from the lab endpoint
- 13) compare data that was received with the data that was intended to be transmitted

These roles could also be reversed (ie, have the lab endpoint be the sender and the DUT endpoint be the receiver).

The process of configuring the baud rate seems like it corresponds with the hardware_reconfigure.sh script. But maybe you were only thinking of have this actually set up physical connections, and not manage connection/bus settings.

In any event, maybe the hardware_reconfigure.sh script could know about 'start data capture', 'stop data capture', and 'get captured data' operations, or maybe this should be a separate script.

Quoted 7 lines

This is structured in a generic way, because I think different tests (such as audio testing, video testing, power measurement testing, CAN bus testing, i2C testing, gpio testing, etc. can all be fit into this model of testing by:
discovering bus endpoints, configuring bus parameters, transmitting or generating data, capturing data
comparing data

I guess that we need two more generic scripts in the format then, one called before the test starts and one called after the test has finished.

So something as:

{
"pre_test": "/path/to/pre_script.sh",
"post_test": "/path/to/post_script.sh",
"hwconfs": [

    ...

]
}

And these scripts would need to actually be called before each test and get JSON as a parameter as well.

e.g. for a serial port described as:

{
"uid": "ttyUSB0-ttyUSB0-01",
"rx": "ttyUSB0",
"tx": "ttyUSB0",
"hwflow": 0,
"baud_rates": [
9600,
19200
]
}

We would get following:

------------------------------

* pre_script.sh gets passed following JSON:

{
"uid": "ttyUSB0-ttyUSB0-01",
"rx": "ttyUSB0",
"tx": "ttyUSB0",
"hwflow": 0,
"baud_rate": 9600
}

* test is executed

* post_script.sh gets passed following JSON

{
"uid": "ttyUSB0-ttyUSB0-01",
}

------------------------------

* pre_script.sh gets passed following JSON

{
"uid": "ttyUSB0-ttyUSB0-01",
"rx": "ttyUSB0",
"tx": "ttyUSB0",
"hwflow": 0,
"baud_rate": 19200
}

* test is executed

* post_script.sh gets passed following JSON

{
"uid": "ttyUSB0-ttyUSB0-01",
}

------------------------------

This changes things a bit, this means that the pre_script has to be executed before each test execution and it's actually passed a JSON data rather than simple value. So the test would need to serialize the data and send the request instead.

The question is how should we propagate data to the test from a post_script.sh. I guess that the output should be JSON as well and in a case of binary data it should include a path to a file, since binary does not work well for JSON.

So in the case of UART capture test the output from post_script.sh would be something as:

{
	"capture": "/path/to/capture/file.bin"
}

Also in a case that we want the lab to send some binary data to the UART during the test the pre_script.sh would get something as:

{
"uid": "ttyUSB0-ttyUSB0-01",
"hwflow": 0,
"baud_rate": 19200,
"transmit": "/path/to/transmit/file.bin"
}

However this means that the test needs to listen even before we call this script, which again complicates things a bit.

Quoted 4 lines

So far, I don't see anything in LTP proposal that precludes this model of testing. There may be more to add - either extending hardware_reconfigure.sh or adding a new command that a test would use interactively to
cause data to be exchanged and allow it to be compared.

Indeed, this is hard to desing especially since I do have very limited set of usecases at the moment. But at least your UART case helped a lot, thanks!

Signature · 2 lines
Cyril Hrubis
[email protected]
#12 lore raw

Hello All,

Quoted 160 lines · Cyril Hrubis

Hi!

Quoted 8 lines
Quoted 4 lines

* Test that needs particular hardware sets the needs_hardware filed in the test test structure. This is a free form string, in the uart example it's called 'UART-loopback'. If we ever add a test for i2c eeprom it would be probably called 'I2C-eeprom', etc.

Sounds good. It will be good to standardize on these strings in the long run. For now, just picking strings and trying to reconcile them later seems OK.

That's what I'm expecting there as well.

Quoted 6 lines
Quoted 3 lines

* The test library takes this and passes it to the hardware discovery script/binary.

This is probably in the patch set, but how is this invoked? Does the script have a well-known name or location?

There is a fallback to a well-known location that can be overrided with an environment varible. This is not well designed at this point, I just wrote a minimal amount of code for the prototype to run.

Quoted 10 lines
Quoted 5 lines

The example script that is included in this patchset
just hardcodes configuration for a usb-to-serial cable. In real world lab this would be either prepared for each board specifically and injected to the filesystem before the test happens, or may be a simple script that calls curl with a request to a lab sever, etc.

Either of these seem like workable approaches. In the case of injecting it into the filesystem, do you have any ideas where you would inject these? For example, would they go somewhere under /etc, or in /usr/test/conf?

No idea, so far my patchset just puts it into $LTPROOT, but I guess that /usr/test/ would be much better place. Do we have a proposal for the /usr/test/ hierarchy somewhere?

Quoted 2 lines

Is this something that only the hardware discovery program needs to know? Or do tests use this data directly?

Currently it's used by the LTP test library, so it's executed by the test binary before it forks a child that actually runs the test.

In the future it could be executed by the test driver (e.g. replacement for ltp-pan I'm working on), which could then pass the pieces of the JSON that describe the hardware to the test for each test invocation. This is still under development, but I do not think that these details matter at all, what we need at this point is to describe generic enough information flow.

Quoted 3 lines

This seems like a rendezvous point between the hardware discovery program and the lab management system, so IMHO it should be well-defined.

Couldn't agree more.

Quoted 89 lines
Quoted 4 lines

* The output from the script is a JSON object. If there is a need to reconfigure lab hardware before the test, the JSON contains a path to a script/binary that has to be called to do so.

That's interesting.

Quoted 37 lines

Again this may be a
script that calls curl with a request to a lab sever which would, for example, interconnect different serial ports with relays.

The parameter to that script is an unique ID for the hardware configuration that is listed in each hardware configuration in the hwconfs array of objects that follows.

I'm not sure if this actually belongs there, maybe it would be cleaner to have one reconfigure script for the whole LTP and we would pass the needs_hardware content as well as the unique ID, e.g.

'hardware-reconfigure.sh UART-loopback ttyUSB0-ttyS0'

but that is a minor detail that could be easily sorted out later.

The most important part of the JSON is the hwconfs array, which consists of hardware description objects, which, apart form the uid, are not interpreted by the library, but rather passed to the test. The test library loops over the array and forks a testrun for each entry in the array.

Each iteration of the test then gets it's parameters as a JSON object. In the case of the UART one of the objects in the array looks like:

  {
    "uid": "ttyUSB0-ttyUSB0-01",
    "rx": "ttyUSB0",
    "tx": "ttyUSB0",
    "hwflow": 0,
    "baud_rates": [
     9600,
     19200
    ]
  }
Quoted 6 lines

Which is mostly self-explanatory, the test then parses the structure and executes one test per each baud rate.

What is still missing is the ability to pass the JSON hardware description directly to the test, so that we can execute the test manually, but that would be fairly easy to add.

OK - let me describe what I had in mind for a test where the serial port was not in loopback mode, to see how it relates to the proposed architecture. The gpio version of this is implemented in the board farm REST API, but the serial port testing version of this is still under consideration:

Here's how the test would work, for a serial port transmission test where
the transmitting side of the serial line was on the DUT and the other side was managed by the lab hardware:
- 1) the test discovers the hardware for DUT endpoint of the serial line
using the hardware discovery program
- 2) the test discovers the hardware for the lab endpoint (receiving end)
of the serial line using the hardware discovery program
- 3) the test discovers the available baud rates from the hardware discovery program
- 4) the test configures the lab endpoint for reception
- 5) the test configures the DUT endpoint for transmission
- 6) the test loops over the baud rate values, doing the following (7-13):
- 7) use a curl interface or local program to set the receive baud rate of the lab endpoint
- 8) use a curl interface or local program to request serial capture of the lab endpoint
- 9) configure the baud rate of the DUT endpoint
- 10) send data through the DUT endpoint
- 11) use a curl interface or local program to cause the lab endpoint to stop capturing data
- 12) use a curl interface or local program to request the capture data from the lab endpoint
- 13) compare data that was received with the data that was intended to be transmitted

These roles could also be reversed (ie, have the lab endpoint be the sender and the DUT endpoint be the receiver).

The process of configuring the baud rate seems like it corresponds with the hardware_reconfigure.sh script. But maybe you were only thinking of have this actually set up physical connections, and not manage connection/bus settings.

In any event, maybe the hardware_reconfigure.sh script could know about 'start data capture', 'stop data capture', and 'get captured data' operations, or maybe this should be a separate script.

Quoted 7 lines

This is structured in a generic way, because I think different tests (such as audio testing, video testing, power measurement testing, CAN bus testing, i2C testing, gpio testing, etc. can all be fit into this model of testing by:
discovering bus endpoints, configuring bus parameters, transmitting or generating data, capturing data
comparing data

I guess that we need two more generic scripts in the format then, one called before the test starts and one called after the test has finished.

So something as:

Quoted 7 lines

{
"pre_test": "/path/to/pre_script.sh",
"post_test": "/path/to/post_script.sh",
"hwconfs": [

    ...

]
}

How about we allow an arbitrary list of callbacks for the initial implementation?

e.g.

{

  "cmds" : {
    "activate-robot-1": "robocmd 1",
    "launch-missiles": "echo 'fire!' > /dev/stty1",
    ...

}
"hwconfs": [ ... ]
}

As we add tests it may turn out there are only a limited number of callbacks practically possible. Then we can standardise on those.

Quoted 71 lines

And these scripts would need to actually be called before each test and get JSON as a parameter as well.

e.g. for a serial port described as:

{
"uid": "ttyUSB0-ttyUSB0-01",
"rx": "ttyUSB0",
"tx": "ttyUSB0",
"hwflow": 0,
"baud_rates": [
9600,
19200
]
}

We would get following:

------------------------------

* pre_script.sh gets passed following JSON:

{
"uid": "ttyUSB0-ttyUSB0-01",
"rx": "ttyUSB0",
"tx": "ttyUSB0",
"hwflow": 0,
"baud_rate": 9600
}

* test is executed

* post_script.sh gets passed following JSON

{
"uid": "ttyUSB0-ttyUSB0-01",
}

------------------------------

* pre_script.sh gets passed following JSON

{
"uid": "ttyUSB0-ttyUSB0-01",
"rx": "ttyUSB0",
"tx": "ttyUSB0",
"hwflow": 0,
"baud_rate": 19200
}

* test is executed

* post_script.sh gets passed following JSON

{
"uid": "ttyUSB0-ttyUSB0-01",
}

------------------------------

This changes things a bit, this means that the pre_script has to be executed before each test execution and it's actually passed a JSON data rather than simple value. So the test would need to serialize the data and send the request instead.

The question is how should we propagate data to the test from a post_script.sh. I guess that the output should be JSON as well and in a case of binary data it should include a path to a file, since binary does not work well for JSON.

Quoted 6 lines

So in the case of UART capture test the output from post_script.sh would be something as:

{
	"capture": "/path/to/capture/file.bin"
}

Yes, or base64 encode it if the data is small. Or send

{ ...., "trailing_binary": 1 }\n

Then transmit the binary data after the '}\n'

Quoted 11 lines

Also in a case that we want the lab to send some binary data to the UART during the test the pre_script.sh would get something as:

{
"uid": "ttyUSB0-ttyUSB0-01",
"hwflow": 0,
"baud_rate": 19200,
"transmit": "/path/to/transmit/file.bin"
}

Quoted 2 lines

However this means that the test needs to listen even before we call this script, which again complicates things a bit.

Not if we make the cmds free form. Using JSON makes perfect sense IMO. I'd like to combine efforts here and use the JSON parser for the parallel test executor IPC.

Quoted 9 lines
Quoted 5 lines

So far, I don't see anything in LTP proposal that precludes this model of testing. There may be more to add - either extending hardware_reconfigure.sh or adding a new command that a test would use interactively to
cause data to be exchanged and allow it to be compared.

Indeed, this is hard to desing especially since I do have very limited set of usecases at the moment. But at least your UART case helped a lot, thanks!

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

v2 cover Another attempt at hardware discovery

In reply to Cyril Hrubis

Cyril Hrubis <[email protected]> ?2021?2?25??? ??12:49???

Quoted 8 lines

This is a second attempt on hardware discovery LTP support. The main difference between the previous attempts is that this version uses JSON, which allows us propagate structured data to the test.

This is still an early protototype but I'm seding it out to get more feedback before I continue to work on it.

Quoted 6 lines

So how is this supposed to work:

* Test that needs particular hardware sets the needs_hardware filed in the test test structure. This is a free form string, in the uart example it's called 'UART-loopback'. If we ever add a test for i2c eeprom it would be probably called 'I2C-eeprom', etc.

I think this has many advantages over the first edition, In out Internal Test? we use a similar way to define the test prerequires as JSON structor.[1] here is My opinion, In the LTP testcase framework, we can set all the prerequires
in a JSONfile, these prerquires include CONFIGS, ABIs, devices-path(sys?proc,dev etc.),
the SETUP stage to check if the machine satisfy the defined-Json. at the same time? we also need a scripts to generate a JSON-file from the current machine to collect all the prerequires list.
In this way, the benefit not just device-driver, but alse common testcase

Quoted 89 lines

* The test library takes this and passes it to the hardware discovery script/binary. The example scipt that is included in this patchset just hardcodes configuration for a usb-to-serial cable. In real world lab this would be either prepared for each board specifically and injected to the filesystem before the test happens, or may be a simple script that calls curl with a request to a lab sever, etc.

* The output from the script is a JSON object. If there is a need to reconfigure lab hardware before the test, the JSON contains a path to a script/binary that has to be called to do so. Again this may be a script that calls curl with a request to a lab sever which would, for example, interconnect different serial ports with relays.

The parameter to that script is an unique ID for the hardware configuration that is listed in each hardware configuration in the hwconfs array of objects that follows.

I'm not sure if this actually belongs there, maybe it would be cleaner to have one reconfigure script for the whole LTP and we would pass the needs_hardware content as well as the unique ID, e.g.

'hardware-reconfigure.sh UART-loopback ttyUSB0-ttyS0'

but that is a minor detail that could be easily sorted out later.

The most important part of the JSON is the hwconfs array, which consists of hardware description objects, which, apart form the uid, are not interpreted by the library, but rather passed to the test. The test library loops over the array and forks a testrun for each entry in the array.

Each iteration of the test then gets it's parameters as a JSON object. In the case of the UART one of the objects in the array looks like:

  {
    "uid": "ttyUSB0-ttyUSB0-01",
    "rx": "ttyUSB0",
    "tx": "ttyUSB0",
    "hwflow": 0,
    "baud_rates": [
     9600,
     19200
    ]
  }

Which is mostly self-explanatory, the test then parses the structure and executes one test per each baud rate.

What is still missing is the ability to pass the JSON hardware description directly to the test, so that we can execute the test manually, but that would be fairly easy to add.

Cyril Hrubis (5):
lib: tst_cmd: Make tst_cmd() usable for global paths
lib: Add minimalistic json parser
lib: Add hardware discovery code
Sample hardware discovery and reconfigure scripts
testcases: uart01: Add.

 hardware-discovery.sh                         |  36 +
 hardware-reconfigure.sh                       |   3 +
 include/tst_hwconf.h                          |  13 +
 include/tst_json.h                            | 177 +++++
 include/tst_test.h                            |   3 +
 lib/tst_cmd.c                                 |   2 +-
 lib/tst_hardware.c                            | 218 ++++++
 lib/tst_hardware.h                            |  83 +++
 lib/tst_json.c                                | 679 ++++++++++++++++++
 lib/tst_test.c                                |  30 +
 runtest/device_drivers                        |   2 +
 testcases/kernel/device-drivers/Makefile      |   1 +
 .../kernel/device-drivers/uart/.gitignore     |   1 +
 testcases/kernel/device-drivers/uart/Makefile |   3 +
 testcases/kernel/device-drivers/uart/uart01.c | 620 ++++++++++++++++
 15 files changed, 1870 insertions(+), 1 deletion(-)
 create mode 100755 hardware-discovery.sh
 create mode 100755 hardware-reconfigure.sh
 create mode 100644 include/tst_hwconf.h
 create mode 100644 include/tst_json.h
 create mode 100644 lib/tst_hardware.c
 create mode 100644 lib/tst_hardware.h
 create mode 100644 lib/tst_json.c
 create mode 100644 runtest/device_drivers
 create mode 100644 testcases/kernel/device-drivers/uart/.gitignore
 create mode 100644 testcases/kernel/device-drivers/uart/Makefile
 create mode 100644 testcases/kernel/device-drivers/uart/uart01.c
Quoted 3 lines

--
2.26.2

[1] https://github.com/gengcixi/kernel_feature_check

#14 lore raw

v2 cover Another attempt at hardware discovery

Hi!

Quoted 10 lines

I think this has many advantages over the first edition, In out Internal Test??? we use a similar way to define the test prerequires as JSON structor.[1] here is My opinion, In the LTP testcase framework, we can set all the prerequires
in a JSONfile, these prerquires include CONFIGS, ABIs, devices-path(sys???proc,dev etc.),
the SETUP stage to check if the machine satisfy the defined-Json. at the same time??? we also need a scripts to generate a JSON-file from the current machine to collect all the prerequires list.
In this way, the benefit not just device-driver, but alse common testcase

We actually have something like this implemented. We generate a big JSON file on LTP build that describes the whole testsuite, but it includes more than just pre-requisites, have a look at docparse/metadata.json that is generated in recent LTP builds.

As for kernel config dependencies we have needs_kconfigs array, which is actually an array of boolean expressions on kernel config options where each of them has to be true in order for a test to continue. So to find out if we have a suitable kernel config for a test we have to check if all are true in:

"tests": {
	"test_name": {
		"needs_kconfigs": [
			"CONFIG_FOO=y | CONFIG_BAR=m",
			"!CONFIG_DAR=y"
		]
	}
}

We do not have the "file" part that would match the functionality you have in your code but that shouldn't be hard to add.

Signature · 2 lines
Cyril Hrubis
[email protected]