From: Florian K. <fk...@so...> - 2025-04-13 12:07:40
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=724e8e47f2be4cf92df4ce184eee784689435633 commit 724e8e47f2be4cf92df4ce184eee784689435633 Author: Florian Krohm <fl...@ei...> Date: Sun Apr 13 12:06:33 2025 +0000 s390x: Regtest integration of none/tests/s390x/disasm-test The checker requires objdump --version >= 2.44 Add command line flag --check-prereq to disasm-test and use it in disasm-test.vgtest. New file none/tests/s390x/disasm-test/disasm-test.post.exp as the checker is run in the "post" hook. Diff: --- none/tests/s390x/disasm-test/Makefile.am | 4 +- none/tests/s390x/disasm-test/disasm-test.post.exp | 4 ++ .../tests/s390x/disasm-test/disasm-test.stderr.exp | 1 - none/tests/s390x/disasm-test/disasm-test.vgtest | 11 ++-- none/tests/s390x/disasm-test/main.c | 62 +++++++++++++++++++++- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/none/tests/s390x/disasm-test/Makefile.am b/none/tests/s390x/disasm-test/Makefile.am index ce662cb860..61d4f31963 100644 --- a/none/tests/s390x/disasm-test/Makefile.am +++ b/none/tests/s390x/disasm-test/Makefile.am @@ -1,7 +1,7 @@ include $(top_srcdir)/Makefile.all.am -EXTRA_DIST = disasm-test.vgtest disasm-test.stderr.exp disasm-test.stdout.exp - +EXTRA_DIST = disasm-test.vgtest disasm-test.stderr.exp disasm-test.stdout.exp \ + disasm-test.post.exp dist_noinst_SCRIPTS = filter_stderr #---------------------------------------------------------------------------- diff --git a/none/tests/s390x/disasm-test/disasm-test.post.exp b/none/tests/s390x/disasm-test/disasm-test.post.exp new file mode 100644 index 0000000000..34722229c0 --- /dev/null +++ b/none/tests/s390x/disasm-test/disasm-test.post.exp @@ -0,0 +1,4 @@ +Total: 148751 tests generated +Total: 148659 insns verified +Total: 0 disassembly mismatches +Total: 92 specification exceptions diff --git a/none/tests/s390x/disasm-test/disasm-test.stderr.exp b/none/tests/s390x/disasm-test/disasm-test.stderr.exp index e6a4c48218..139597f9cb 100644 --- a/none/tests/s390x/disasm-test/disasm-test.stderr.exp +++ b/none/tests/s390x/disasm-test/disasm-test.stderr.exp @@ -1,3 +1,2 @@ -One of --verify, --generate, --run, --all, or --unit-test is required diff --git a/none/tests/s390x/disasm-test/disasm-test.vgtest b/none/tests/s390x/disasm-test/disasm-test.vgtest index d7a1a409c1..9f7f9997b0 100644 --- a/none/tests/s390x/disasm-test/disasm-test.vgtest +++ b/none/tests/s390x/disasm-test/disasm-test.vgtest @@ -1,6 +1,7 @@ -prog: disasm-test -# args: --all # enable this eventually # -# NOTE: there are extra newlines in the output which are *not* -# present when disasm-test is invoked by hand. -# Not sure where they are coming from. +# We do not want disasm-test to be run under the auspices of valgrind. +# Therefore the real test here is run in the "post" command. +# +prereq: ./disasm-test --check-prereq +prog: /bin/true +post: ./disasm-test --all --summary diff --git a/none/tests/s390x/disasm-test/main.c b/none/tests/s390x/disasm-test/main.c index c61ab8c681..aa362b511e 100644 --- a/none/tests/s390x/disasm-test/main.c +++ b/none/tests/s390x/disasm-test/main.c @@ -25,6 +25,7 @@ #include <stddef.h> // NULL #include <stdlib.h> // exit, malloc #include <stdio.h> // vfprintf +#include <ctype.h> // isdigit #include <stdarg.h> // va_list #include <string.h> // strchr #include <assert.h> // assert @@ -38,6 +39,8 @@ const char *gcc = "gcc"; // path to GCC const char *objdump = "objdump"; // path to objdump const char *gcc_flags = "-march=arch14"; +#define MIN_OBJDUMP_VERSION 2044000 /* 2.44 */ + #define CHECK_CLO(x, s) (strncmp(x, s, sizeof s - 1) == 0) static const char usage[] = @@ -63,10 +66,12 @@ static const char usage[] = " --unit-test - Run unit tests\n" " --show-spec-exc - Show insns causing specification exceptions\n" " --no-show-miscompares - Do not show disassembly miscompares\n" + " --check-prereq - Check prerequisites (e.g. objdump version)\n" ; static void remove_temp_files(const char *); static int opcode_has_errors(const opcode *); +static int check_objdump(void); static int keep_temp = 0; static int summary = 0; @@ -81,7 +86,7 @@ main(int argc, char *argv[]) { int all = 0, verify = 0, generate = 0, unit_test = 0; int num_clargs = 0; - int run = 0; + int run = 0, check_prereq = 0; const char *clargs[argc]; assert(sizeof(long long) == 8); @@ -118,6 +123,8 @@ main(int argc, char *argv[]) keep_temp = 1; } else if (CHECK_CLO(clo, "--run")) { run = 1; + } else if (CHECK_CLO(clo, "--check-prereq")) { + check_prereq = 1; } else if (CHECK_CLO(clo, "--help")) { printf("%s\n", usage); return 0; @@ -134,6 +141,9 @@ main(int argc, char *argv[]) } } + if (check_prereq) + return check_objdump(); + /* Check consistency of command line options */ if (verify + generate + run + all + unit_test == 0) fatal("One of --verify, --generate, --run, --all, or --unit-test " @@ -333,3 +343,53 @@ opcode_has_errors(const opcode *opc) } return 0; } + + +/* Objdump version 2.44 or later is required, Return 0, if that's + the case. */ +static int +check_objdump(void) +{ + unsigned need = strlen(objdump) + 3 + 1; + char *cmd = mallock(need); + + sprintf(cmd, "%s -V", objdump); + FILE *fp = popen(cmd, "r"); + + /* The version number is expected on the first line and its + format ought to be one of X or X.Y or X.Y.Z where X,Y,Z are + positive integers. */ + int c, rc = 1; + while ((c = fgetc(fp)) != EOF) { + if (c == '\n') break; + if (! isdigit(c)) continue; + + /* Version number is expected to be X or X.Y or X.Y.Z */ + char buf[32]; // assumed large enough + int ix = 0; + do { + buf[ix++] = c; + c = fgetc(fp); + } while (isdigit(c) || c == '.'); + buf[ix] = '\0'; + + unsigned version = 0, v1, v2, v3; + if (sscanf(buf, "%u.%u.%u", &v1,&v2,&v3) == 3) { + version = v1*1000000 + v2*1000 + v3; + } else if (sscanf(buf, "%u.%u", &v1,&v2) == 2) { + version = v1*1000000 + v2*1000; + } else if (sscanf(buf, "%u", &v1) == 1) { + version = v1*1000000; + } else { + error("Could not determine objdump version\n"); + break; + } + if (version >= MIN_OBJDUMP_VERSION) + rc = 0; + break; + } + pclose(fp); + free(cmd); + + return rc; +} |