Skip to contentSkip to conversation

Use Jansson instead of json-c in igt_runner

PATCH In review Ryszard Knop 3 participants 6 messages Aug 10, 2022 – Aug 11, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover Use Jansson instead of json-c in igt_runner

The json-c library has a hard limit of 2GB of its output. While normally it's not a problem, some very verbose edge cases make the results.json output go past that limit.

This series converts igt_runner's json-c usage to Jansson.

#1 lore raw

PATCH 1/3 runner: Use Jansson in resultgen instead of json-c

The json-c library has a hard limit of 2GB of its output. While normally it's not a problem, some very verbose edge cases make the results.json output go past that limit.

Jansson has a similar API, can work with files over 2GB and, according to JSON library and benchmarks, is slightly slower but uses less RAM to serialize its output. Jansson 2.12+ (released in 2018) is required.

This commit also updates tests to use Jansson, but they need data fixups to pass (in the next commit).

---
 runner/meson.build         |  12 +-
 runner/resultgen.c         | 349 +++++++++++++++++--------------------
 runner/resultgen.h         |   2 +-
 runner/runner_json_tests.c | 129 +++++---------
 runner/runner_tests.c      |  60 +++----
 5 files changed, 247 insertions(+), 305 deletions(-)
runner/meson.build +6 -6
index c3927af5..4e25f70a 100644
@@ -13,8 +13,8 @@ results_sources = [ 'results.c' ]
 runner_test_sources = [ 'runner_tests.c' ]
 runner_json_test_sources = [ 'runner_json_tests.c' ]
 
-jsonc = dependency('json-c', required: build_runner)
-runner_deps = [jsonc, glib]
+jansson = dependency('jansson', required: build_runner, version: '>=2.12')
+runner_deps = [jansson, glib]
 runner_c_args = []
 
 liboping = dependency('liboping', required: get_option('oping'))
@@ -23,11 +23,11 @@ if liboping.found()
 	runner_c_args += '-DHAVE_OPING=1'
 endif
 
-if not build_tests and jsonc.found()
+if not build_tests and jansson.found()
 	error('Building test runner requires building tests')
 endif
 
-if jsonc.found()
+if jansson.found()
 	subdir('testdata')
 
 	runnerlib = static_library('igt_runner', runnerlib_sources,
@@ -60,14 +60,14 @@ if jsonc.found()
 				 c_args : '-DTESTDATA_DIRECTORY="@0@"'.format(testdata_dir),
 				 link_with : runnerlib,
 				 install : false,
-				 dependencies : [igt_deps, jsonc])
+				 dependencies : [igt_deps, jansson])
 	test('runner', runner_test, timeout : 300)
 
 	runner_json_test = executable('runner_json_test', runner_json_test_sources,
 				      c_args : '-DJSON_TESTS_DIRECTORY="@0@"'.format(join_paths(meson.current_source_dir(), 'json_tests_data')),
 				      link_with : runnerlib,
 				      install : false,
-				      dependencies : [igt_deps, jsonc])
+				      dependencies : [igt_deps, jansson])
 	test('runner_json', runner_json_test, timeout : 300)
 
 	build_info += 'Build test runner: true'
runner/resultgen.c +163 -186

742 lines not on this page · raw message

runner/resultgen.h +1 -1
index ab0bf108..3bc3bafe 100644
@@ -6,6 +6,6 @@
 bool generate_results(int dirfd);
 bool generate_results_path(char *resultspath);
 
-struct json_object *generate_results_json(int dirfd);
+struct json_t *generate_results_json(int dirfd);
 
 #endif
runner/runner_json_tests.c +47 -82

190 lines not on this page · raw message

runner/runner_tests.c +30 -30

198 lines not on this page · raw message

Signature · 1 line
2.37.1
#2 lore raw

PATCH 2/3 runner/tests: Fix JSON test data

In reply to Ryszard Knop

JSON files contained extra (invalid) commas which json-c was able to handle, but Jansson, Firefox and Python parsers are unhappy with.

---
 .../json_tests_data/aborted-after-a-test/reference.json   | 6 +++---
 runner/json_tests_data/aborted-on-boot/reference.json     | 4 ++--
 runner/json_tests_data/dmesg-escapes/reference.json       | 8 ++++----
 runner/json_tests_data/empty-result-files/reference.json  | 4 ++--
 runner/json_tests_data/graceful-notrun/reference.json     | 6 +++---
 .../incomplete-before-any-subtests/reference.json         | 2 +-
 .../notrun-results-multiple-mode/reference.json           | 2 +-
 runner/json_tests_data/notrun-results/reference.json      | 2 +-
 8 files changed, 17 insertions(+), 17 deletions(-)
runner/json_tests_data/aborted-after-a-test/reference.json +3 -3
index 0776f758..3f4a3fc0 100644
@@ -49,7 +49,7 @@
 	"out":"Aborted after: successtest (first-subtest)\n\nKernel tainted (0x200)\n",
 	"result":"fail",
 	"err":"",
-	"dmesg":"",
+	"dmesg":""
     }
   },
   "totals":{
@@ -130,7 +130,7 @@
       "notrun":0,
       "fail":1,
       "warn":0
-    },
+    }
   },
   "runtimes":{
     "igt@successtest":{
@@ -139,6 +139,6 @@
         "start":0,
         "end":0.014
       }
-    },
+    }
   }
 }
runner/json_tests_data/aborted-on-boot/reference.json +2 -2
index 75f19466..5e9b905a 100644
@@ -43,7 +43,7 @@
 	"out":"Aborted after: startup\n\nKernel tainted (0x200)\n",
 	"result":"fail",
 	"err":"",
-	"dmesg":"",
+	"dmesg":""
     }
   },
   "totals":{
@@ -124,7 +124,7 @@
       "notrun":0,
       "fail":1,
       "warn":0
-    },
+    }
   },
   "runtimes":{
   }
runner/json_tests_data/dmesg-escapes/reference.json +4 -4
index 91c57310..4798db52 100644
@@ -19,8 +19,8 @@
         "end":0
       },
       "err":"Starting subtest: first-subtest\nSubtest first-subtest: SUCCESS (0.000s)\n",
-	"dmesg":"<6> [3216186.095083] Console: switching to colour dummy device 80x25\n<6> [3216186.095097] [IGT] successtest: executing\n<6> [3216186.101115] [IGT] successtest: starting subtest first-subtest\n<6> [3216186.101159] String with a\nnewline\n<6> [3216186.101159] String with a\ttab\n<6> [3216186.101159] String with an explicit\\x00NUL\n<6> [3216186.101159] The character \\x13 should be nonprintable\n<6> [3216186.101159] Escaped backslash is \\\n<6> [3216186.101159] Kernel shouldn't output this but cutoff escape \\x1\n<6> [3216186.101159] More cutoff \\x\n<6> [3216186.101159] One more \\\n<6> [3216186.101160] [IGT] successtest: exiting, ret=0\n<6> [3216186.101299] Console: switching to colour frame buffer device 240x75\n",
-    },
+	"dmesg":"<6> [3216186.095083] Console: switching to colour dummy device 80x25\n<6> [3216186.095097] [IGT] successtest: executing\n<6> [3216186.101115] [IGT] successtest: starting subtest first-subtest\n<6> [3216186.101159] String with a\nnewline\n<6> [3216186.101159] String with a\ttab\n<6> [3216186.101159] String with an explicit\\x00NUL\n<6> [3216186.101159] The character \\x13 should be nonprintable\n<6> [3216186.101159] Escaped backslash is \\\n<6> [3216186.101159] Kernel shouldn't output this but cutoff escape \\x1\n<6> [3216186.101159] More cutoff \\x\n<6> [3216186.101159] One more \\\n<6> [3216186.101160] [IGT] successtest: exiting, ret=0\n<6> [3216186.101299] Console: switching to colour frame buffer device 240x75\n"
+    }
   },
   "totals":{
     "":{
@@ -61,7 +61,7 @@
       "notrun":0,
       "fail":0,
       "warn":0
-    },
+    }
   },
   "runtimes":{
     "igt@successtest":{
@@ -70,6 +70,6 @@
         "start":0,
         "end":0.014
       }
-    },
+    }
   }
 }
runner/json_tests_data/empty-result-files/reference.json +2 -2
index f81ffb81..7c3a052a 100644
@@ -14,7 +14,7 @@
 	"err":"",
 	"dmesg":"",
 	"result":"incomplete"
-    },
+    }
   },
   "totals":{
     "":{
@@ -55,7 +55,7 @@
       "notrun":0,
       "fail":0,
       "warn":0
-    },
+    }
   },
   "runtimes":{
   }
runner/json_tests_data/graceful-notrun/reference.json +3 -3
index c95bdfec..2c9888e4 100644
@@ -39,7 +39,7 @@
 	"err":"",
 	"dmesg":"",
 	"result":"notrun"
-    },
+    }
   },
   "totals":{
     "":{
@@ -106,7 +106,7 @@
       "notrun":2,
       "fail":0,
       "warn":0
-    },
+    }
   },
   "runtimes":{
     "igt@successtest":{
@@ -115,6 +115,6 @@
         "start":0,
         "end":0.014
       }
-    },
+    }
   }
 }
runner/json_tests_data/incomplete-before-any-subtests/reference.json +1 -1
index 2a4bd456..ed2a3753 100644
@@ -39,7 +39,7 @@
 	"err":"",
 	"dmesg":"",
 	"result":"notrun"
-    },
+    }
   },
   "totals":{
     "":{
runner/json_tests_data/notrun-results-multiple-mode/reference.json +1 -1
index 3f8b7fb0..9820ecae 100644
@@ -101,6 +101,6 @@
         "start":0,
         "end":0.014
       }
-    },
+    }
   }
 }
runner/json_tests_data/notrun-results/reference.json +1 -1
index 800de38c..f419f7a1 100644
@@ -120,6 +120,6 @@
         "start":0,
         "end":0.014
       }
-    },
+    }
   }
 }
Signature · 1 line
2.37.1
#3 lore raw

PATCH 3/3 runner: Add an on-demand test for large files

In reply to Ryszard Knop

The test in question does not carry large files, as that would require adding massive files to Git. The tested logic is not any different for large files, it's just a check if the JSON library can handle them.

To run this test, use generate_data.py. You'll need around 13GB of free space and 10+ minutes to run this test successfully. The test will be skipped by default if the SKIP_ME marker exists.

---
 .../really-large-files/.gitignore             |  3 +
 .../really-large-files/0/dmesg.txt            |  0
 .../really-large-files/0/err.txt              |  0
 .../really-large-files/0/journal.txt          |  0
 .../really-large-files/0/out.txt              |  1 +
 .../really-large-files/README.txt             |  7 +++
 .../really-large-files/SKIP_ME                |  1 +
 .../really-large-files/endtime.txt            |  1 +
 .../really-large-files/generate_data.py       | 20 ++++++
 .../really-large-files/joblist.txt            |  1 +
 .../really-large-files/metadata.txt           | 12 ++++
 .../really-large-files/reference.json         | 62 +++++++++++++++++++
 .../really-large-files/starttime.txt          |  1 +
 .../really-large-files/uname.txt              |  1 +
 runner/runner_json_tests.c                    |  8 ++-
 15 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 runner/json_tests_data/really-large-files/.gitignore
 create mode 100644 runner/json_tests_data/really-large-files/0/dmesg.txt
 create mode 100644 runner/json_tests_data/really-large-files/0/err.txt
 create mode 100644 runner/json_tests_data/really-large-files/0/journal.txt
 create mode 100644 runner/json_tests_data/really-large-files/0/out.txt
 create mode 100644 runner/json_tests_data/really-large-files/README.txt
 create mode 100644 runner/json_tests_data/really-large-files/SKIP_ME
 create mode 100644 runner/json_tests_data/really-large-files/endtime.txt
 create mode 100644 runner/json_tests_data/really-large-files/generate_data.py
 create mode 100644 runner/json_tests_data/really-large-files/joblist.txt
 create mode 100644 runner/json_tests_data/really-large-files/metadata.txt
 create mode 100644 runner/json_tests_data/really-large-files/reference.json
 create mode 100644 runner/json_tests_data/really-large-files/starttime.txt
 create mode 100644 runner/json_tests_data/really-large-files/uname.txt
runner/json_tests_data/really-large-files/.gitignore new file +3 -0
new file mode 100644
index 00000000..6a445ba9
@@ -0,0 +1,3 @@
+reference.json
+0/out.txt
+SKIP_ME
\ No newline at end of file
runner/json_tests_data/really-large-files/0/dmesg.txt new file +0 -0
new file mode 100644
index 00000000..e69de29b
runner/json_tests_data/really-large-files/0/err.txt new file +0 -0
new file mode 100644
index 00000000..e69de29b
runner/json_tests_data/really-large-files/0/journal.txt new file +0 -0
new file mode 100644
index 00000000..e69de29b
runner/json_tests_data/really-large-files/0/out.txt new file +1 -0
new file mode 100644
index 00000000..e85778cd
@@ -0,0 +1 @@
+This test requires massive files generated with generate_data.py to actually test stuff.
\ No newline at end of file
runner/json_tests_data/really-large-files/README.txt new file +7 -0
new file mode 100644
index 00000000..20f6f3b2
@@ -0,0 +1,7 @@
+Check if an incredibly large JSON is generated and tested properly.
+This requires a large out.txt file to be available - it's not in
+the repo directly, run generate_data.py to test that properly.
+The SKIP_ME marker file exists to skip this test by default.
+
+The logic for small/large files does not change, testing this for each
+commit takes a long time and does not really check anything special.
runner/json_tests_data/really-large-files/SKIP_ME new file +1 -0
new file mode 100644
index 00000000..c76d0b57
@@ -0,0 +1 @@
+This marker file exists to skip this test by default.
\ No newline at end of file
runner/json_tests_data/really-large-files/endtime.txt new file +1 -0
new file mode 100644
index 00000000..635f6ae9
@@ -0,0 +1 @@
+1539953735.172373
runner/json_tests_data/really-large-files/generate_data.py new file +20 -0
new file mode 100644
index 00000000..d3852c6b
@@ -0,0 +1,20 @@
+import json
+
+print("Hope you've got enough memory for this! Generating text...")
+PREFIX = "it's time for " + ("A" * 1024 * 1024 * 1024 * 4)
+
+print("Writing to out.txt...")
+with open('0/out.txt', 'w') as f:
+	f.write(PREFIX)
+
+print("Loading reference.json...")
+with open('reference.json', 'r') as f:
+	data = json.load(f)
+
+print("Writing new reference.json...")
+with open('reference.json', 'w') as f:
+	data['tests']['igt@successtest@first-subtest']['out'] = PREFIX
+	json.dump(data, f)
+
+print("Removing SKIP_ME...")
+os.unlink("SKIP_ME")
runner/json_tests_data/really-large-files/joblist.txt new file +1 -0
new file mode 100644
index 00000000..81f914a7
@@ -0,0 +1 @@
+successtest first-subtest
runner/json_tests_data/really-large-files/metadata.txt new file +12 -0
new file mode 100644
index 00000000..08db4cc0
@@ -0,0 +1,12 @@
+abort_mask : 0
+name : really-large-files
+dry_run : 0
+sync : 0
+log_level : 0
+overwrite : 0
+multiple_mode : 0
+inactivity_timeout : 0
+use_watchdog : 0
+piglit_style_dmesg : 0
+test_root : /path/does/not/exist
+results_path : /path/does/not/exist
runner/json_tests_data/really-large-files/reference.json new file +62 -0

62 lines not on this page · raw message

runner/json_tests_data/really-large-files/starttime.txt new file +1 -0
new file mode 100644
index 00000000..ae038f18
@@ -0,0 +1 @@
+1539953735.111039
runner/json_tests_data/really-large-files/uname.txt new file +1 -0
new file mode 100644
index 00000000..a7aef6f7
@@ -0,0 +1 @@
+Linux hostname 4.18.0-1-amd64 #1 SMP Debian 4.18.6-1 (2018-09-06) x86_64
runner/runner_json_tests.c +7 -1
index 9f487855..6bb1eb9f 100644
@@ -89,12 +89,17 @@ static void compare(struct json_t *one,
 static void run_results_and_compare(int dirfd, const char *dirname)
 {
 	int testdirfd = openat(dirfd, dirname, O_RDONLY | O_DIRECTORY);
-	int reference;
+	int skipfd, reference;
 	struct json_t *resultsobj, *referenceobj;
 	struct json_error_t error;
 
 	igt_assert_fd(testdirfd);
 
+	skipfd = openat(testdirfd, "SKIP_ME", O_RDONLY);
+	igt_skip_on_f(skipfd != -1, "SKIP_ME marker exists - see the README "
+				    "for this test for more information.\n");
+	close(skipfd);
+
 	igt_assert((resultsobj = generate_results_json(testdirfd)) != NULL);
 
 	reference = openat(testdirfd, "reference.json", O_RDONLY);
@@ -134,6 +139,7 @@ static const char *dirnames[] = {
 	"dynamic-subtest-name-in-multiple-subtests",
 	"unprintable-characters",
 	"empty-result-files",
+	"really-large-files",
 	"graceful-notrun",
 };
 
Signature · 1 line
2.37.1
#4 lore raw

[igt-dev] ✗ Fi.CI.BUILD: failure for Use Jansson instead of json-c in igt_runner

In reply to Ryszard Knop
== Series Details ==

== Series Details ==

Series: Use Jansson instead of json-c in igt_runner
URL : https://patchwork.freedesktop.org/series/107123/
State : failure

== Summary ==

Applying: runner: Use Jansson in resultgen instead of json-c Using index info to reconstruct a base tree...
M runner/resultgen.c
Falling back to patching base and 3-way merge... Auto-merging runner/resultgen.c
CONFLICT (content): Merge conflict in runner/resultgen.c Patch failed at 0001 runner: Use Jansson in resultgen instead of json-c When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

#5 lore raw
In reply to Ryszard Knop
Quoted 7 lines · Ryszard Knop

The json-c library has a hard limit of 2GB of its output. While normally it's not a problem, some very verbose edge cases make the results.json output go past that limit.

This series converts igt_runner's json-c usage to Jansson.

I haven't been able to review this thoroughly yet, but an initial comment can be made:

Absolute blockers for this series are having gitlab CI correctly set up so it builds there (should be just a matter of adding the packages to the dockerfiles), and having the required libs installed in our CI. Latter we're able to see fully done by having a successful premerge on this series.

Signature · 1 line
Petri Latvala