sim: tests: get common tests working again

These were written with 32-bit host assumptions baked into it.
Simplify the printf formats to use ll length modifier as it's
in C11 rather than trying to manually break it up into two,
and cleanup some of the casts to stop assuming sizeof(long) is
the same as sizeof(int).

We also have to add a few more includes for the various funcs
used in here.

The tests aren't compiled automatically still.  We can figure
that out later with more work.
This commit is contained in:
Mike Frysinger
2021-01-09 17:57:48 -05:00
parent c6185dce03
commit 254c3783fe
4 changed files with 46 additions and 41 deletions

View File

@ -1,3 +1,18 @@
2021-01-11 Mike Frysinger <vapier@gentoo.org>
* common/alu-tst.c: Include stdlib.h.
(PACKAGE): Define.
(print_hex): Change printf to use %llx.
* common/bits-gen.c: Include stdlib.h, string.h, and unistd.h.
(gen_struct): Change long long to unsigned64.
(gen_bit): Change bit cast to bit mask. Change printf to use %llx.
(gen_mask): Likewise.
(usage): Delete default case.
(main): Change WITH_HOST_WORD_BITSIZE printf from %d to %zu. Emit
PACKAGE define and stdlib.h & string.h includes.
* common/bits-tst.c (calc): Change printf to use %llx.
(check_sext, check_rot, check_extract, check_bits): Likewise.
2021-01-09 Mike Frysinger <vapier@gentoo.org> 2021-01-09 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate. * configure: Regenerate.
@ -368,4 +383,3 @@ Mon Sep 1 16:43:55 1997 Andrew Cagney <cagney@b1.cygnus.com>
* configure.in (configdirs): Test for the target directory instead * configure.in (configdirs): Test for the target directory instead
of matching on a target. of matching on a target.

View File

@ -14,8 +14,11 @@
#define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE) #define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)
#include <stdlib.h>
#include <string.h> #include <string.h>
#define PACKAGE "sim"
#include "sim-basics.h" #include "sim-basics.h"
#include "sim-alu.h" #include "sim-alu.h"
@ -62,9 +65,7 @@ print_hex (unsigned64 val, int nr_bits)
printf ("0x%08lx", (long) (unsigned32) (val)); printf ("0x%08lx", (long) (unsigned32) (val));
break; break;
case 64: case 64:
printf ("0x%08lx%08lx", printf ("0x%016llx", (long long) (unsigned64) (val));
(long) (unsigned32) (val >> 32),
(long) (unsigned32) (val));
break; break;
default: default:
abort (); abort ();

View File

@ -17,9 +17,10 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void void
gen_struct (void) gen_struct (void)
@ -29,8 +30,8 @@ gen_struct (void)
printf (" int line;\n"); printf (" int line;\n");
printf (" int row;\n"); printf (" int row;\n");
printf (" int col;\n"); printf (" int col;\n");
printf (" long long val;\n"); printf (" unsigned64 val;\n");
printf (" long long check;\n"); printf (" unsigned64 check;\n");
printf ("} test_tuples;\n"); printf ("} test_tuples;\n");
printf ("\n"); printf ("\n");
printf ("typedef struct _test_spec {\n"); printf ("typedef struct _test_spec {\n");
@ -62,13 +63,12 @@ gen_bit (int bitsize,
else else
bit <<= i; bit <<= i;
if (bitsize == 32) if (bitsize == 32)
bit = (unsigned) bit; /* truncate it! */ bit &= 0xffffffff; /* truncate it! */
/* write it out */ /* write it out */
printf (" { __LINE__, "); printf (" { __LINE__, ");
printf ("%d, %2d, ", -1, i); printf ("%d, %2d, ", -1, i);
printf ("%s (%2d), ", macro, i); printf ("%s (%2d), ", macro, i);
printf ("UNSIGNED64 (0x%08lx%08lx), ", printf ("UNSIGNED64 (0x%016llx), ", bit);
(long) (bit >> 32), (long) bit);
printf ("},\n"); printf ("},\n");
} }
printf ("};\n"); printf ("};\n");
@ -141,11 +141,10 @@ gen_mask (int bitsize,
mask |= bit; mask |= bit;
} }
if (bitsize == 32) if (bitsize == 32)
mask = (unsigned long) mask; mask &= 0xffffffff;
printf ("%d, %d, ", l, h); printf ("%d, %d, ", l, h);
printf ("%s%s (%2d, %2d), ", msb, macro, l, h); printf ("%s%s (%2d, %2d), ", msb, macro, l, h);
printf ("UNSIGNED64 (0x%08lx%08lx), ", printf ("UNSIGNED64 (0x%llx), ", mask);
(long) (mask >> 32), (long) mask);
} }
else else
printf ("-1, -1, "); printf ("-1, -1, ");
@ -184,7 +183,6 @@ usage (int reason)
case 4: case 4:
fprintf (stderr, "Invalid <byte-order> argument\n"); fprintf (stderr, "Invalid <byte-order> argument\n");
break; break;
default:
} }
exit (1); exit (1);
@ -232,13 +230,16 @@ main (int argc, char *argv[])
printf ("#define WITH_TARGET_WORD_BITSIZE %d\n", bitsize); printf ("#define WITH_TARGET_WORD_BITSIZE %d\n", bitsize);
printf ("#define WITH_TARGET_WORD_MSB %d\n", msb); printf ("#define WITH_TARGET_WORD_MSB %d\n", msb);
printf ("#define WITH_HOST_WORD_BITSIZE %d\n", sizeof (int) * 8); printf ("#define WITH_HOST_WORD_BITSIZE %zu\n", sizeof (int) * 8);
printf ("#define WITH_TARGET_BYTE_ORDER %s\n", big_endian ? "BFD_ENDIAN_BIG" : "BFD_ENDIAN_LITTLE"); printf ("#define WITH_TARGET_BYTE_ORDER %s\n", big_endian ? "BFD_ENDIAN_BIG" : "BFD_ENDIAN_LITTLE");
printf ("\n"); printf ("\n");
printf ("#define SIM_BITS_INLINE (ALL_H_INLINE)\n"); printf ("#define SIM_BITS_INLINE (ALL_H_INLINE)\n");
printf ("\n"); printf ("\n");
printf ("#define ASSERT(X) do { if (!(X)) abort(); } while (0)\n"); printf ("#define ASSERT(X) do { if (!(X)) abort(); } while (0)\n");
printf ("\n"); printf ("\n");
printf ("#define PACKAGE \"sim\"\n");
printf ("#include <stdlib.h>\n");
printf ("#include <string.h>\n");
printf ("#include \"sim-basics.h\"\n"); printf ("#include \"sim-basics.h\"\n");
gen_struct (); gen_struct ();

View File

@ -153,8 +153,8 @@ calc (const char *call,
else else
{ {
fprintf (stderr, fprintf (stderr,
"Unknown call passed to calc (%s, 0x%08lx%08lx, %d, %d)\n", "Unknown call passed to calc (%s, 0x%016llx, %d, %d)\n",
call, (long)(val >> 32), (long)val, row, col); call, val, row, col);
abort (); abort ();
return val; return val;
} }
@ -185,10 +185,8 @@ check_sext (int nr_bits,
fprintf (stderr, fprintf (stderr,
"%s:%d: ", __FILE__, __LINE__); "%s:%d: ", __FILE__, __LINE__);
fprintf (stderr, fprintf (stderr,
" %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n", " %s(0x%016llx,%d) == 0x%016llx wrong, != 0x%016llx\n",
sexted, (long)(mask_0 >> 32), (long)mask_0, col, sexted, mask_0, col, sext_0, mask_1);
(long)(sext_0 >> 32), (long)sext_0,
(long)(mask_1 >> 32), (long)mask_1);
errors ++; errors ++;
} }
if (sext_1 != mask_1) if (sext_1 != mask_1)
@ -196,10 +194,8 @@ check_sext (int nr_bits,
fprintf (stderr, fprintf (stderr,
"%s:%d: ", __FILE__, __LINE__); "%s:%d: ", __FILE__, __LINE__);
fprintf (stderr, fprintf (stderr,
" %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n", " %s(0x%016llx,%d) == 0x%016llx wrong, != 0x%016llx\n",
sexted, (long)(mask_1 >> 32), (long)mask_1, col, sexted, mask_1, col, sext_1, mask_1);
(long)(sext_1 >> 32), (long)sext_1,
(long)(mask_1 >> 32), (long)mask_1);
errors ++; errors ++;
} }
if (sext != msmask) if (sext != msmask)
@ -207,10 +203,8 @@ check_sext (int nr_bits,
fprintf (stderr, fprintf (stderr,
"%s:%d: ", __FILE__, __LINE__); "%s:%d: ", __FILE__, __LINE__);
fprintf (stderr, fprintf (stderr,
" %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx (%s(%d,%d))\n", " %s(0x%016llx,%d) == 0x%016llx wrong, != 0x%016llx (%s(%d,%d))\n",
sexted, (long)(mask >> 32), (long)mask, col, sexted, mask, col, sext, msmask,
(long)(sext >> 32), (long)sext,
(long)(msmask >> 32), (long)msmask,
msmasked, 0, (msb_nr ? nr_bits - col - 1 : col)); msmasked, 0, (msb_nr ? nr_bits - col - 1 : col));
errors ++; errors ++;
} }
@ -244,10 +238,8 @@ check_rot (int nr_bits,
|| (shift != 0 && rot == mask && abs(row - col) != (nr_bits - 1))) || (shift != 0 && rot == mask && abs(row - col) != (nr_bits - 1)))
{ {
fprintf (stderr, "%s:%d: ", __FILE__, __LINE__); fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
fprintf (stderr, " %s(%s(0x%08lx%08lx,%d) == 0x%08lx%08lx, %d) failed\n", fprintf (stderr, " %s(%s(0x%016llx,%d) == 0x%016llx, %d) failed\n",
roted, roted, roted, roted, mask, shift, urot, -shift);
(long)(mask >> 32), (long)mask, shift,
(long)(urot >> 32), (long)urot, -shift);
errors ++; errors ++;
} }
} }
@ -276,10 +268,8 @@ check_extract (int nr_bits,
if (mask != inst) if (mask != inst)
{ {
fprintf (stderr, "%s:%d: ", __FILE__, __LINE__); fprintf (stderr, "%s:%d: ", __FILE__, __LINE__);
fprintf (stderr, " %s(%d,%d)=0x%08lx%08lx -> %s=0x%08lx%08lx -> %s=0x%08lx%08lx failed\n", fprintf (stderr, " %s(%d,%d)=0x%016llx -> %s=0x%016llx -> %s=0x%016llx failed\n",
masked, row, col, (long)(mask >> 32), (long)mask, masked, row, col, mask, extracted, extr, inserted, inst);
extracted, (long)(extr >> 32), (long)extr,
inserted, (long)(inst >> 32), (long)inst);
errors ++; errors ++;
} }
} }
@ -317,9 +307,8 @@ check_bits (int call,
fprintf (stderr, " (%d, %d)", tuple->row, tuple->col); fprintf (stderr, " (%d, %d)", tuple->row, tuple->col);
else else
fprintf (stderr, " (%d)", tuple->col); fprintf (stderr, " (%d)", tuple->col);
fprintf (stderr, " == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n", fprintf (stderr, " == 0x%016llx wrong, != 0x%016llx\n",
(long) (val >> 32), (long) val, val, check);
(long) (check >> 32), (long) check);
errors ++; errors ++;
} }
} }