libctf, tests: do not assume host and target have identical field offsets
authorNick Alcock <nick.alcock@oracle.com>
Wed, 5 Apr 2023 15:36:45 +0000 (16:36 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Sat, 8 Apr 2023 15:07:17 +0000 (16:07 +0100)
The newly-introduced libctf-lookup unnamed-field-info test checks
C compiler-observed field offsets against libctf-computed ones
by #including the testcase in the lookup runner as well as
generating CTF for it.  This only works if the host, on which
the lookup runner is compiled and executed, is the same architecture as
the target, for which the CTF is generated: when crossing, the trick
may fail.

So pass down an indication of whether this is a cross into the
testsuite, and add a new no_cross flag to .lk files that is used to
suppress test execution when a cross-compiler is being tested.

libctf/
* Makefile.am (check_DEJAGNU): Pass down TEST_CROSS.
* Makefile.in: Regenerated.
* testsuite/lib/ctf-lib.exp (run_lookup_test): Use it to
implement the new no_cross option.
* testsuite/libctf-lookup/unnamed-field-info.lk: Mark as
no_cross.

libctf/Makefile.am
libctf/Makefile.in
libctf/testsuite/lib/ctf-lib.exp
libctf/testsuite/libctf-lookup/unnamed-field-info.lk

index c959b09e4924b55fc4f0a4c7dea79b91e079ee58..b1dbc2f6ba4fc15a812545178a6aefc375f3a89f 100644 (file)
@@ -92,10 +92,15 @@ check-DEJAGNU: site.exp development.exp
        r=`pwd`; export r; \
        LC_ALL=C; export LC_ALL; \
        EXPECT=$(EXPECT); export EXPECT; \
+       if [ "@host@" = "@target@" ] ; then \
+         TEST_CROSS=no; \
+       else \
+         TEST_CROSS=yes; \
+       fi; \
        runtest=$(RUNTEST); \
        if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
          $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
-               CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" \
+               CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
                CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
                LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
        else echo "WARNING: could not find \`runtest'" 1>&2; :;\
index c6cb55c9768aa943ed0f585d455a0727e0ab7ad6..3d2696bcc47cadea9385d9febd0f8cb130aa4342 100644 (file)
@@ -1678,10 +1678,15 @@ check-DEJAGNU: site.exp development.exp
        r=`pwd`; export r; \
        LC_ALL=C; export LC_ALL; \
        EXPECT=$(EXPECT); export EXPECT; \
+       if [ "@host@" = "@target@" ] ; then \
+         TEST_CROSS=no; \
+       else \
+         TEST_CROSS=yes; \
+       fi; \
        runtest=$(RUNTEST); \
        if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
          $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
-               CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" \
+               CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
                CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
                LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
        else echo "WARNING: could not find \`runtest'" 1>&2; :;\
index 3ee82a00a334854f136cdba678f25891cca0981e..73b67b45e344ff4b92778cba8c131abad4deee07 100644 (file)
@@ -103,6 +103,9 @@ proc compile_link_one_host_cc { src output additional_args } {
 #   xfail: GLOB|PROC ...
 #      This test is expected to fail on a specified list of targets.
 #
+#   no_cross:
+#       If set, do not run this test when host != target.
+#
 # Each option may occur at most once unless otherwise mentioned.
 #
 # After the option lines come regexp lines.  run_lookup_test calls
@@ -110,7 +113,7 @@ proc compile_link_one_host_cc { src output additional_args } {
 # regexps in FILE.d.
 #
 proc run_lookup_test { name } {
-    global CC_FOR_TARGET CFLAGS_FOR_TARGET LIBS
+    global CC_FOR_TARGET CFLAGS_FOR_TARGET LIBS TEST_CROSS
     global copyfile env runtests srcdir subdir verbose
 
     if ![runtest_file_p $runtests $name] then {
@@ -139,6 +142,7 @@ proc run_lookup_test { name } {
     set opts(name) {}
     set opts(source) {}
     set opts(xfail) {}
+    set opts(no_cross) {}
 
     foreach i $opt_array {
        set opt_name [lindex $i 0]
@@ -156,6 +160,12 @@ proc run_lookup_test { name } {
        set opts($opt_name) [concat $opts($opt_name) $opt_val]
     }
 
+    if { [llength $opts(no_cross)] != 0
+        && "$TEST_CROSS" eq "yes" } {
+       untested "$subdir/$name not tested when cross-compiling"
+       return
+    }
+
     if { [llength $opts(lookup)] == 0 } {
        set opts(lookup) "$file.c"
     } else {
index eae6a517d50a1ce633f9f4e4170d7431f37a1300..680b8e0a4cafee91d9ae44ef3ea5a648cf7cc7ba 100644 (file)
@@ -1,2 +1,3 @@
 # source: unnamed-field-info-ctf.c
+# no_cross: yes
 Offset validation complete.