Skip to contentSkip to conversation

Two more metadata parser fixes

PATCH Superseded Cyril Hrubis 2 participants 10 messages Jun 20, 2025 – Jul 11, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Two more metadata parser fixes

This series fixes a metadata parser for the ".filesystems" entry of the tst_test structure. First patch fixes the data storage to JSON serialization and second patch changes the parser to convert structure intialization with only designated initializers into a hash (object) rather than an arrray.

@Andrea I suppose that the documentation generator needs a fix after
this is applied.

Cyril Hrubis (2):
metadata: data_storage: Fix hash to json object serialization
metaparse: Map arrays with designated initializers to JSON objects

 metadata/data_storage.h |  28 +++++++--
 metadata/metaparse.c    | 134 +++++++++++++++++++++++++++++++++-------
 2 files changed, 135 insertions(+), 27 deletions(-)
Signature · 5 lines
2.49.0


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

PATCH 1/2 metadata: data_storage: Fix hash to json object serialization

We have to move the curly braces into the switch() that prints the JSON values otherwise inner object will not have curly braces around them and the resulting JSON is not valid.

The changes between the old generated metadata and new metadata are only in the whitespaces:

diff -w ltp-prev.json ltp.json
7c7
< "version": "20250530-41-g080ced081"
---

Quoted 1 line

"version": "20250530-42-g73a97b583"

---
 metadata/data_storage.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
metadata/data_storage.h +4 -4
index 82d67b829..f837feec8 100644
@@ -396,14 +396,16 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int p
 		data_fprintf(f, padd, "null");
 	break;
 	case DATA_HASH:
+		data_fprintf(f, do_padd ? padd : 0, "{\n");
 		for (i = 0; i < self->hash.elems_used; i++) {
-			data_fprintf(f, padd, "\"%s\": ", self->hash.elems[i].id);
+			data_fprintf(f, padd+1, "\"%s\": ", self->hash.elems[i].id);
 			data_to_json_(self->hash.elems[i].node, f, padd+1, 0);
 			if (i < self->hash.elems_used - 1)
 				fprintf(f, ",\n");
 			else
 				fprintf(f, "\n");
 		}
+		data_fprintf(f, padd, "}");
 	break;
 	case DATA_ARRAY:
 		data_fprintf(f, do_padd ? padd : 0, "[\n");
@@ -421,9 +423,7 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int p
 
 static inline void data_to_json(struct data_node *self, FILE *f, unsigned int padd)
 {
-	fprintf(f, "{\n");
-	data_to_json_(self, f, padd + 1, 1);
-	data_fprintf(f, padd, "}");
+	data_to_json_(self, f, padd, 0);
 }
 
 #endif /* DATA_STORAGE_H__ */
Signature · 5 lines
2.49.0


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

PATCH 2/2 metaparse: Map arrays with designated initializers to JSON objects

In reply to Cyril Hrubis

The parser now scans array declarations and if it finds out that complete initialization is using designated initializers the result is mapped into a JSON object instead of an arrray.

A diff snippet looks like:

--------------------------
"filesystems": [
- [
- ".type=btrfs"
- ],
- [
- ".type=bcachefs"
- ],
- [

-     ".type=xfs",
-     ".min_kver=4.16",
-     ".mkfs_ver=mkfs.xfs >= 1.5.0",
-     [

+ {
+ "type": "btrfs"
+ },
+ {
+ "type": "bcachefs"
+ },
+ {

+     "type": "xfs",
+     "min_kver": "4.16",
+     "mkfs_ver": "mkfs.xfs >= 1.5.0",
+     "mkfs_opts": [
       "-m",
       "reflink=1"

- ],
- ".mkfs_opts=(constchar*const[])"
- ]
+ ]
+ }

    ],

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

---
 metadata/data_storage.h |  20 ++++++
 metadata/metaparse.c    | 134 +++++++++++++++++++++++++++++++++-------
 2 files changed, 131 insertions(+), 23 deletions(-)
metadata/data_storage.h +20 -0
index f837feec8..6ca5d7d90 100644
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 
 enum data_type {
 	DATA_ARRAY,
@@ -228,6 +229,13 @@ static inline struct data_node *data_node_hash_get(struct data_node *self, const
 	return hash->elems[i].node;
 }
 
+static inline unsigned int data_node_hash_len(struct data_node *self)
+{
+	struct data_node_hash *hash = &self->hash;
+
+	return hash->elems_used;
+}
+
 static inline int data_node_array_add(struct data_node *self, struct data_node *payload)
 {
 	if (self->type != DATA_ARRAY)
@@ -285,6 +293,18 @@ static inline void data_print_padd(unsigned int i)
 		putchar(' ');
 }
 
+static inline bool data_node_is_empty(struct data_node *self)
+{
+	switch (self->type) {
+	case DATA_ARRAY:
+		return data_node_array_len(self) == 0;
+	case DATA_HASH:
+		return data_node_hash_len(self) == 0;
+	default:
+		return false;
+	}
+}
+
 static inline void data_node_print_(struct data_node *self, unsigned int padd)
 {
 	unsigned int i;
metadata/metaparse.c +111 -23

188 lines not on this page · raw message

Signature · 5 lines
2.49.0


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

Re: [LTP] [PATCH 2/2] metaparse: Map arrays with designated initializers to JSON objects

Hi!

This patch is actually causing documentation build failure due to the way we are defining .hugepages as:

    .hugepages = {TST_NO_HUGEPAGES},

The shmget02 metadata (for instance) will have an empty hugepages dictionary:

  "shmget02": {
   "needs_tmpdir": "1",
   "needs_root": "1",
   "forks_child": "1",
   "save_restore": [
    [
     "/proc/sys/kernel/shmmax",
     "8192",
     "TCONF_MISSING|TBROK_RO"
    ]
   ],
   "doc": [
    "Test for ENOENT, EEXIST, EINVAL, EACCES, EPERM errors.",
    "",
    "- ENOENT - No segment exists for the given key and IPC_CREAT was not specified.", "- EEXIST - the segment exists and IPC_CREAT | IPC_EXCL is given.",
    "- EINVAL - A new segment was to be created and size is less than SHMMIN or", "  greater than SHMMAX. Or a segment for the given key exists, but size is", "  gran eater than the size of that segment.",
    "- EACCES - The user does not have permission to access the shared memory segment.", "- EPERM - The SHM_HUGETLB flag was specified, but the caller was not", "  privileged (did not have the CAP_IPC_LOCK capability) and is not a member", "  of the sysctl_hugetlb_shm_group group.",
    "- ENOMEM - The SHM_HUGETLB flag was specified, the caller was privileged but", "  not have enough hugepage memory space."
   ],
   "hugepages": {
   },
   "fname": "testcases/kernel/syscalls/ipc/shmget/shmget02.c"
  }

Which will cause the following error in the documentation build:

Traceback (most recent call last):
  File "/home/acer/Projects/ltp/doc/.venv/lib/python3.12/site-packages/sphinx/events.py", line 98, in emit results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acer/Projects/ltp/doc/conf.py", line 518, in generate_test_catalog text.extend(_generate_setup_table(conf))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acer/Projects/ltp/doc/conf.py", line 407, in _generate_setup_table values.append(f'{value[0]}, {value[1]}')
                     ~~~~~^^^
KeyError: 0

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH 2/2] metaparse: Map arrays with designated initializers to JSON objects

Hi!

Quoted 7 lines

This patch is actually causing documentation build failure due to the way we are defining .hugepages as:

    .hugepages = {TST_NO_HUGEPAGES},

The shmget02 metadata (for instance) will have an empty hugepages dictionary:

Ah, right, I've missed a special case in the C structure parsing.

This on the top of the patchset fixes the problem:

metadata/metaparse.c +9 -1
index e9e9aee10..36736ac06 100644
@@ -379,13 +379,17 @@ static int array_is_hash(FILE *f)
        long pos = ftell(f);
        int has_ids = 1;
        int elem_seen = 0;
+       int comma_last = 0;
        int in_id = 1;
        char *token;
 
        while ((token = next_token(f, NULL))) {
 
-               if (!strcmp(token, "}"))
+               if (!strcmp(token, "}")) {
+                       if (in_id && !comma_last)
+                               has_ids = 0;
                        goto ret;
+               }
 
                elem_seen = 1;
 
@@ -419,8 +423,12 @@ static int array_is_hash(FILE *f)
                        }
 
                        in_id = 1;
+
+                       comma_last = 1;
                } else if (!strcmp(token, "=")) {
                        in_id = 0;
+               } else {
+                       comma_last = 0;
                }
        }
 

I will send a new version.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Cyril Hrubis

Hi!

Quoted 8 lines · Cyril Hrubis

This series fixes a metadata parser for the ".filesystems" entry of the tst_test structure. First patch fixes the data storage to JSON serialization and second patch changes the parser to convert structure intialization with only designated initializers into a hash (object) rather than an arrray.

@Andrea I suppose that the documentation generator needs a fix after
this is applied.

I will take a look once is merged. In general, I like the idea of this patch-set.

Quoted 8 lines

Cyril Hrubis (2):
metadata: data_storage: Fix hash to json object serialization
metaparse: Map arrays with designated initializers to JSON objects

  metadata/data_storage.h |  28 +++++++--
  metadata/metaparse.c    | 134 +++++++++++++++++++++++++++++++++-------
  2 files changed, 135 insertions(+), 27 deletions(-)

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by Andrea Cervesato on the v1 series
#6 lore raw
In reply to Cyril Hrubis

Hi!

Feel free to merge, I will fix kirk later on.

- Andrea

Quoted 17 lines · Cyril Hrubis

This series fixes a metadata parser for the ".filesystems" entry of the tst_test structure. First patch fixes the data storage to JSON serialization and second patch changes the parser to convert structure intialization with only designated initializers into a hash (object) rather than an arrray.

@Andrea I suppose that the documentation generator needs a fix after
this is applied.

Cyril Hrubis (2):
metadata: data_storage: Fix hash to json object serialization
metaparse: Map arrays with designated initializers to JSON objects

  metadata/data_storage.h |  28 +++++++--
  metadata/metaparse.c    | 134 +++++++++++++++++++++++++++++++++-------
  2 files changed, 135 insertions(+), 27 deletions(-)
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi!

Quoted 1 line

Feel free to merge, I will fix kirk later on.

These changes also crash doc generator since the format of the metadata has changed:

Traceback (most recent call last):
File "/home/metan/Work/ltp/doc/.venv/lib/python3.12/site-packages/sphinx/events.py", line 97, in emit

    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/metan/Work/ltp/doc/conf.py", line 517, in generate_test_catalog
    text.extend(_generate_setup_table(conf))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/metan/Work/ltp/doc/conf.py", line 407, in _generate_setup_table
    values.append(f'{value[0]}, {value[1]}')
                     ~~~~~^^^

KeyError: 0

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw
Quoted 15 lines · Cyril Hrubis

Hi!

Quoted 1 line

Feel free to merge, I will fix kirk later on.

These changes also crash doc generator since the format of the metadata has changed:

Traceback (most recent call last):

   File "/home/metan/Work/ltp/doc/.venv/lib/python3.12/site-packages/sphinx/events.py", line 97, in emit
     results.append(listener.handler(self.app, *args))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/home/metan/Work/ltp/doc/conf.py", line 517, in generate_test_catalog
     text.extend(_generate_setup_table(conf))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/home/metan/Work/ltp/doc/conf.py", line 407, in _generate_setup_table
     values.append(f'{value[0]}, {value[1]}')
                      ~~~~~^^^
Quoted 2 lines

KeyError: 0

Sigh, we need a patch to include in this patch series then..

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by Andrea Cervesato on the v1 series
#9 lore raw
In reply to Cyril Hrubis
Quoted 17 lines · Cyril Hrubis

This series fixes a metadata parser for the ".filesystems" entry of the tst_test structure. First patch fixes the data storage to JSON serialization and second patch changes the parser to convert structure intialization with only designated initializers into a hash (object) rather than an arrray.

@Andrea I suppose that the documentation generator needs a fix after
this is applied.

Cyril Hrubis (2):
metadata: data_storage: Fix hash to json object serialization
metaparse: Map arrays with designated initializers to JSON objects

  metadata/data_storage.h |  28 +++++++--
  metadata/metaparse.c    | 134 +++++++++++++++++++++++++++++++++-------
  2 files changed, 135 insertions(+), 27 deletions(-)
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp