[PATCH i-g-t 13/15] igt_comms_decoder for helping with debugging
Petri Latvala
petri.latvala at intel.com
Mon Mar 1 11:32:56 UTC 2021
---
runner/decoder.c | 157 +++++++++++++++++++++++++++++++++++++++++++++
runner/meson.build | 8 +++
2 files changed, 165 insertions(+)
create mode 100644 runner/decoder.c
diff --git a/runner/decoder.c b/runner/decoder.c
new file mode 100644
index 00000000..d328d49f
--- /dev/null
+++ b/runner/decoder.c
@@ -0,0 +1,157 @@
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "runnercomms.h"
+
+int main(int argc, char **argv)
+{
+ struct stat statbuf;
+ char *buf, *bufend, *p;
+ int fd;
+
+ if (argc < 2) {
+ printf("Usage: %s igt-comms-data-file\n", argv[0]);
+ return 2;
+ }
+
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failure opening %s: %m\n", argv[1]);
+ return 1;
+ }
+
+ if (fstat(fd, &statbuf)) {
+ fprintf(stderr, "Cannot stat %s: %m\n", argv[1]);
+ return 1;
+ }
+
+ buf = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (buf == MAP_FAILED) {
+ fprintf(stderr, "Failure reading %s: %m\n", argv[1]);
+ return 1;
+ }
+
+ bufend = buf + statbuf.st_size;
+ p = buf;
+
+ while (p != NULL && p != bufend) {
+ const struct runnerpacket *packet;
+ union runnerpacket_read_helper helper;
+
+ if (bufend - p >= sizeof(uint32_t)) {
+ uint32_t canary;
+
+ memcpy(&canary, p, sizeof(canary));
+ if (canary != socket_dump_canary()) {
+ fprintf(stderr,
+ "Invalid canary: %"PRIu32", expected %"PRIu32"\n",
+ canary, socket_dump_canary());
+ munmap(buf, statbuf.st_size);
+ return 1;
+ }
+ }
+ p += sizeof(uint32_t);
+
+ if (bufend - p < sizeof(struct runnerpacket)) {
+ fprintf(stderr,
+ "Error parsing comms.txt: Expected runnerpacket after canary, truncated file?\n");
+ munmap(buf, statbuf.st_size);
+ return 1;
+ }
+
+ packet = (struct runnerpacket *)p;
+ if (bufend - p < packet->size) {
+ fprintf(stderr,
+ "Error parsing comms.txt: Unexpected end of file, truncated file?\n");
+ munmap(buf, statbuf.st_size);
+ return 1;
+ }
+ p += packet->size;
+
+ helper = read_runnerpacket(packet);
+
+ switch (helper.type) {
+ case PACKETTYPE_INVALID:
+ fprintf(stderr, "Error parsing runnerpacket (type=%"PRIu32")\n", packet->type);
+ munmap(buf, statbuf.st_size);
+ return 1;
+
+ case PACKETTYPE_LOG:
+ printf("(pid=%d tid=%d) LOG\tstream=%d,text=%s",
+ packet->senderpid, packet->sendertid,
+ helper.log.stream, helper.log.text);
+ if (strlen(helper.log.text) == 0 || helper.log.text[strlen(helper.log.text) - 1] != '\n')
+ printf("\n");
+ break;
+
+ case PACKETTYPE_EXEC:
+ printf("(pid=%d tid=%d) EXEC\tcmdline=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.exec.cmdline);
+ break;
+
+ case PACKETTYPE_EXIT:
+ printf("(pid=%d tid=%d) EXIT\texitcode=%d,timeused=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.exit.exitcode, helper.exit.timeused);
+ break;
+
+ case PACKETTYPE_SUBTEST_START:
+ printf("(pid=%d tid=%d) SUBTEST_START\tname=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.subteststart.name);
+ break;
+
+ case PACKETTYPE_SUBTEST_RESULT:
+ printf("(pid=%d tid=%d) SUBTEST_RESULT\tname=%s,result=%s,timeused=%s,reason=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.subtestresult.name,
+ helper.subtestresult.result,
+ helper.subtestresult.timeused,
+ helper.subtestresult.reason ?: "<null>");
+ break;
+
+ case PACKETTYPE_DYNAMIC_SUBTEST_START:
+ printf("(pid=%d tid=%d) DYNAMIC_SUBTEST_START\tname=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.dynamicsubteststart.name);
+ break;
+
+ case PACKETTYPE_DYNAMIC_SUBTEST_RESULT:
+ printf("(pid=%d tid=%d) DYNAMIC_SUBTEST_RESULT\tname=%s,result=%s,timeused=%s,reason=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.dynamicsubtestresult.name,
+ helper.dynamicsubtestresult.result,
+ helper.dynamicsubtestresult.timeused,
+ helper.dynamicsubtestresult.reason ?: "<null>");
+ break;
+
+ case PACKETTYPE_VERSIONSTRING:
+ printf("(pid=%d tid=%d) VERSIONSTRING\ttext=%s",
+ packet->senderpid, packet->sendertid,
+ helper.versionstring.text);
+ if (strlen(helper.versionstring.text) == 0 || helper.versionstring.text[strlen(helper.versionstring.text) - 1] != '\n')
+ printf("\n");
+ break;
+
+ case PACKETTYPE_RESULT_OVERRIDE:
+ printf("pid=%d tid=%d) RESULT_OVERRIDE\tresult=%s\n",
+ packet->senderpid, packet->sendertid,
+ helper.resultoverride.result);
+ break;
+
+ default:
+ printf("Warning: Unknown packet type %"PRIu32"\n", helper.type);
+ break;
+ }
+ }
+
+
+ return 0;
+}
diff --git a/runner/meson.build b/runner/meson.build
index c3927af5..dadfc75f 100644
--- a/runner/meson.build
+++ b/runner/meson.build
@@ -10,6 +10,7 @@ runnerlib_sources = [ 'settings.c',
runner_sources = [ 'runner.c' ]
resume_sources = [ 'resume.c' ]
results_sources = [ 'results.c' ]
+decoder_sources = [ 'decoder.c' ]
runner_test_sources = [ 'runner_tests.c' ]
runner_json_test_sources = [ 'runner_json_tests.c' ]
@@ -56,6 +57,13 @@ if jsonc.found()
install_rpath : bindir_rpathdir,
dependencies : igt_deps)
+ decoder = executable('igt_comms_decoder', decoder_sources,
+ link_with : runnerlib,
+ install : true,
+ install_dir : bindir,
+ install_rpath : bindir_rpathdir,
+ dependencies : igt_deps)
+
runner_test = executable('runner_test', runner_test_sources,
c_args : '-DTESTDATA_DIRECTORY="@0@"'.format(testdata_dir),
link_with : runnerlib,
--
2.29.2
More information about the Intel-gfx-trybot
mailing list