Commit Graph

4471 Commits

Author SHA1 Message Date
Mike Frysinger
c0d6a6e582 sim: testsuite: rework sim_init usage
The sim_init function was called by runtest for each test when --tool
was set to sim.  When we changed to --tool '' to collapse the testsuite
dir, the init function was no longer called on every test.  However, it
was still being called explicitly by config/default.exp.  It's not clear
why that explicit call ever existed since, in the past, it meant it was
redundant.

Lets drop the single sim_init call in config/default.exp and move it out
to all our tests.  This replicates the runtest behavior so we can setup
variables on a per-test basis which allows us to recollapse the sim_path
logic back.  We'll also leverage this in the future for toolchain setup.

Also add a few comments clarifying the overall runtime behavior.
2021-11-26 19:48:05 -05:00
Mike Frysinger
4c721b266f sim: cris: fix testsuite hang when sim is missing
If the cris sim hasn't been built yet, trying to run its testsuite
will hang indefinitely.  The common sim APIs already have this, so
copy it over to the cris forks of the test+run functions.
2021-11-26 19:37:31 -05:00
Mike Frysinger
e1e1ae6e9b sim: testsuite: fix objdir handling
The tests assume that the cwd is the objdir directory and write its
intermediates to there all the time.  When using runtest's --objdir
setting though, this puts the files in the wrong place.  This isn't
a big problem currently as we never change --objdir, but in order to
support parallel test execution, we're going to start setting that
option, so clean up the code ahead of time.

We also have to tweak some of the cris tests which were making
assumptions about the argv[0] value.
2021-11-26 19:27:21 -05:00
Mike Frysinger
03c0f9c205 sim: testsuite: rename global_sim_options to SIMFLAGS_FOR_TARGET
Now that all the other toolchain settings have been renamed to match
the dejagnu settings of XXX_FOR_TARGET, rename global_sim_options to
SIMFLAGS_FOR_TARGET too.
2021-11-26 19:17:59 -05:00
Mike Frysinger
d07ada6f5a sim: testsuite: replace global_ld_options with LDFLAGS_FOR_TARGET
Only a few tests actually use global_ld_options, but we can replace the
sim-specific settings with the dejagnu common LDFLAGS_FOR_TARGET and get
the same result.
2021-11-26 19:03:13 -05:00
Mike Frysinger
0e87783408 sim: testsuite: replace global_as_options with ASFLAGS_FOR_TARGET
Only a few tests actually use global_as_options, but we can replace the
sim-specific settings with the dejagnu common ASFLAGS_FOR_TARGET and get
the same result.
2021-11-26 15:07:04 -05:00
Mike Frysinger
c099934746 sim: testsuite: drop unused global_cc_options
Nothing in the testsuite is using this setting, so let's drop it.
Any code that wants to set compiler flags can use CFLAGS_FOR_TARGET
instead to get the same effect.
2021-11-26 13:28:15 -05:00
Mike Frysinger
aa1b9bdef2 sim: testsuite: punt unused toolchain variables
These haven't been used in over 20 years.  The sim testsuite used to
run these tools itself directly, but back in ~1999 it switched to the
dejagnu helpers (e.g. target_assemble & target_link), and the dejagnu
logic only utilizes XXX_FOR_TARGET variables.  Punt them here to avoid
confusion with dead code.
2021-11-26 13:27:34 -05:00
Mike Frysinger
c0f9d65827 sim: mips: avoid _ namespace
Some C libraries export _P symbols in their headers (like older
newlib and its ctype.h), so use P_ instead to avoid conflicts.
2021-11-25 23:48:45 -05:00
Mike Frysinger
bbda248c50 sim: v850: fix cpu_option testsuite handling
The v850 testsuite code has been testing the $opt variable, but this
was never actually set anywhere globally or v850-specific.  Instead,
this was a random variable leaking out of the sh testsuite code.  As
far as I can tell, it has always been this way.  That means the code
only ever tested the v850 cpu target (which is the default).

This failure can be easily seen in practice by running the v850 code
in isolation and seeing it crash:
$ runtest v850/allinsns.exp
...
Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using ../../../sim/testsuite/config/default.exp as tool-and-target-specific interface file.
WARNING: Assuming target board is the local machine (which is probably wrong).
You may need to set your DEJAGNU environment variable.
Running ../../../sim/testsuite/v850/allinsns.exp ...
ERROR: tcl error sourcing ../../../sim/testsuite/v850/allinsns.exp.
ERROR: tcl error code TCL LOOKUP VARNAME opt
ERROR: can't read "opt": no such variable
    while executing
"switch -regexp -- $opt {

Backing up a bit, the reason for this logic in the first place is
because the common sim testsuite code makes an assumption about the
assembler options with cpu_option -- the option and its value are
always separated by an =.  This is not the case with v850.  So tweak
the core sim logic a bit to support omitting the = so that we can
switch v850 to the standard all_machs setting and avoid opt entirely.
2021-11-20 23:13:50 -05:00
Jeff Law
dbf98db6f0 Fix intermittent failures on the H8, particularly H8/SX tests.
The upstream GCC tester has  showed spurious execution failures on the
    H8 target for the H8/SX multilibs. I suspected memory corruption or an
    uninitialized variable early as the same binary would sometimes work and
    sometimes it got the wrong result. Worse yet, the point where the test
    determined it was getting the wrong result would change.

    Because it only happened on the H8/SX variant I was able to zero in on
    the "mova" support and the "short form" of those instructions in particular.

    As the code stands it checks if code->op3.type == 0 to try and identify cases
    where op3 wasn't filled in and thus we've got the short form of the mova
    instruction.

    But for the short-form of those instructions we never set any of the "op3"
    data structure. We get whatever was lying around -- it's usually zero and
     thus things usually work, but if the stale data was nonzero, then we'd
    fail to recognize the instruction as a short-form and fail to set up the
    various fields appropriately.

    I initially initialized the op3.type field to zero, but didn't like that
     because it was inconsistent with how other operands were initialized.
    Bringing consistency meant using -1 as the initializer value and adjusting
    the check for short form mova appropriately.

    I've had this in the upstream GCC tester for perhaps a year at this point
    and haven't seen any of the intermittent failures again.
2021-11-20 13:06:15 -05:00
Mike Frysinger
6e3e76d17b sim: bfin: fix short --env usage in testsuite
Now that we have more than one option that matches "--env", the test
config here doesn't work.  Use the explicit --environment.
2021-11-19 21:27:50 -05:00
Mike Frysinger
ed939535e2 sim: install various doc files 2021-11-19 03:36:45 -05:00
Mike Frysinger
fccf4ba5ad sim: use program_transform_name for libsim
Instead of always using target_alias as a prefix on the name, use
program_transform_name instead so that the library is scoped in the
same way as the run program.
2021-11-18 19:56:45 -05:00
Mike Frysinger
fb2c495f94 sim: avoid installing headers when there is no sim
If we aren't building any sims, don't install the sim headers as they
won't be useful to anyone.
2021-11-18 19:45:54 -05:00
Mike Frysinger
c2aad00a74 sim: testsuite: add support for $pwd replacements
Extend the common test framework to support $pwd replacements in
settings.  This allows replacing the custom cris @exedir@ with it.
2021-11-16 20:21:59 -05:00
Mike Frysinger
927f25ebac sim: cris: replace @srcdir@ test extension with $srcdir/$subdir
The common framework supports $srcdir & $subdir replacements already,
so replace the custom @srcdir@ logic with those.  Since the replace
happens in slurp_options that cris already uses, we don't have any
logic to port over there.  We have to duplicate that into the cris
slurp_rv helper though.
2021-11-16 20:16:18 -05:00
Mike Frysinger
b31ff1f79b sim: cris: drop custom "dynamic" test field
This tag is used to force tests to be built dynamically (i.e. without
-static linking).  This is because cris-sim.exp in dejagnu turns on
static linking in ldflags.

The default configs and runtest flags shouldn't load these boards.
If these settings are still needed, we should figure out a different
way of suppressing the stock settings wholesale.  We want these to
all pass out of the box with little to no configuration so that they
can run in a multitarget build.

With dropping "dynamic", it'll be easier to merge the custom cris
test logic with the common sim test logic.
2021-11-16 20:06:44 -05:00
Mike Frysinger
5ec501b574 sim: testsuite: add more silent build rules
site.exp is still verbose, but that comes from automake, so have
to get it fixed upstream.
2021-11-16 19:33:57 -05:00
Sergei Trofimovich
e97436b1b7 sim: cr16: fix build on gcc-12 (NULL comparison)
On gcc-12 build fails as:

    sim/cr16/interp.c: In function 'lookup_hash':
    sim/cr16/interp.c:89:25: error:
      the comparison will always evaluate as 'true'
      for the address of 'mnimonic' will never be NULL [-Werror=address]
       89 |   if ((h->ops->mnimonic != NULL) &&
          |                         ^~

'mnimonic' is a sharr array within ops. It can never be NULL.

While at it renamed 'mnimonic' to 'mnemonic'.
2021-11-16 23:32:00 +00:00
Mike Frysinger
3b2934856f sim: run: support concise env var settings
Support the same syntax as other common utilities where env vars can
be specified before the program to be run without an explicit option.

This behavior can be suppressed by using the -- marker.
2021-11-16 03:34:28 -05:00
Mike Frysinger
35818ade96 sim: nrun: add --env-{set,unset,clear} command line options
Provide explicit control over the program's environment with the
basic set/unset/clear options.  These are a bit clunky to use,
but they're functional.

The env set operation is split out into a separate function as it'll
be used in the next commit.

With these in place, we can adjust the custom cris testsuite to use
the now standard options and not its one-off hack.
2021-11-16 03:34:00 -05:00
Mike Frysinger
85588c9ab9 sim: syscall: hoist argc/argn/argnlen to common code
Now that the callback framework supports argv & envp, we can move
the Blackfin implementation of these syscalls to the common code.
2021-11-16 02:13:42 -05:00
Mike Frysinger
fab6939b01 sim: syscall: fix argvlen & argv implementation
Now that we have access to the argv & envp strings, finish implementing
these syscalls.  Delete unused variables, fix tbuf by incrementing the
pointer instead of setting to the length, and make sure we don't write
more data than the bufsize says is available.
2021-11-16 02:09:46 -05:00
Mike Frysinger
8cfc9a1895 sim: callback: expose argv & environ
Pass the existing strings data to the callbacks so that common
libgloss syscalls can be implemented (which we'll do shortly).
2021-11-16 01:13:39 -05:00
Mike Frysinger
54f7a83a62 sim: keep track of program environment strings
We've been passing the environment strings to sim_create_inferior,
but most ports don't do anything with them.  A few will use ad-hoc
logic to stuff the stack for user-mode programs, but that's it.

Let's formalize this across the board by storing the strings in the
normal sim state.  This will allow (in future commits) supporting
more functionality in the run interface, and to unify some of the
libgloss syscalls.
2021-11-16 00:58:41 -05:00
Mike Frysinger
38f9e52086 sim: iq2000: fix some missing prototypes warnings
Turns out some of these were hiding real bugs like not passing the
pc variable down.
2021-11-16 00:49:13 -05:00
Mike Frysinger
e6c46d0772 sim: cris: make error message test a little more flexible
The point of this test is to just make sure the usage text is shown,
not the exact details of the usage text.  So shorten the output test
to match the beginning.  This fixes breakage when the output changed
slightly to include [--].
2021-11-15 03:34:36 -05:00
Mike Frysinger
7770da9714 sim: run: fix crash in argc==0 error situation
The new argv processing code assumed that we were always passed a
command line.  If we weren't, make sure we don't crash before we
get a chance to output an error message about incorrect usage.
2021-11-15 03:32:26 -05:00
Mike Frysinger
145a603abc sim: cris: touch up rvdummy handling
Add quiet build support and make sure it's removed with `make clean`.
2021-11-15 03:00:05 -05:00
Mike Frysinger
565cbe4b91 sim: cris: replace custom "dest" test field with new --argv0
The #dest field used in the cris testsuite is a bit of hack to set the
argv[0] for the tests to read out later on.  Now that the sim has an
option to set argv[0] explicitly, we don't need this custom field, so
let's drop it to harmonize the testsuites a little.
2021-11-15 02:53:31 -05:00
Mike Frysinger
852016f921 sim: run: add --argv0 option to control argv[0]
We default argv[0] to the program we run which is a standard *NIX
convention, but sometimes we want to be able to control the argv[0]
setting independently (especially for programs that inspect argv[0]
to change their behavior or output).  Add an option to control it.
2021-11-15 02:53:31 -05:00
Mike Frysinger
e8f20a28b1 sim: split program path out of argv vector
We use the program argv to both find the program to run (argv[0]) and
to hold the arguments to the program.  Most of the time this is fine,
but if we want to let programs specify argv[0] independently (which is
possible in standard *NIX programs), this double duty doesn't work.

So let's split the path to the program to run out into a separate
field by itself.  This simplifies the various sim_open funcs too.

By itself, this code is more of a logical cleanup than something that
is super useful.  But it will open up customization of argv[0] in a
follow up commit.  Split the changes to make it easier to review.
2021-11-15 02:53:29 -05:00
Mike Frysinger
7b2ec4e46f sim: bfin: fix mach/xfail usage in tests
Set the mach to the right value all the time, and update xfail to
say the test fails on all targets.  WIth multitarget testing, the
idea of target here doesn't make much sense.
2021-11-15 01:35:49 -05:00
Mike Frysinger
35f7d33dd9 sim: sh: fix switch-bool warnings
This code triggers -Werror=switch-bool warnings with <=gcc-5 versions.
Rework it to use if statements instead as it also simplifies a bit.
2021-11-13 00:57:00 -05:00
Mike Frysinger
dc5a462160 sim: sh: rework carry checks to not rely on integer overflows
In <=gcc-7 versions, -fstrict-overflow is enabled by default, and that
triggers warnings in this code that relies on integer overflows to test
for carries.  Change the logic to test against the limit directly.
2021-11-13 00:57:00 -05:00
Mike Frysinger
efe113047d sim: testsuite: drop sim_compile cover function
Most code isn't using this, and the only call site (in one cris file)
can use target_compile directly.  So switch it over to simplify.
2021-11-11 02:07:10 -05:00
Mike Frysinger
f0f2906ca0 sim: cris: stop testing a.out explicitly [ld/13900]
Since gcc dropped support for a.out starting with 4.4.0 in 2009, it's
been impossible to verify this code actually still works.  Since it
crashes in ld, and it uses a config option that no other tests uses
and we want to remove, drop the test to avoid all the trouble.
2021-11-11 00:38:53 -05:00
Mike Frysinger
40f6466678 sim: io: tweak compiler workaround with error output
Outputting an extra space broke a cris test.  Change the workaround
to use %s with an empty string to avoid the compiler warning but not
output an extra space.
2021-11-11 00:16:33 -05:00
Mike Frysinger
bebe33486c sim: testsuite: delete unused arm remote host logic
There's no need to sync testutils.inc with remote hosts.  The one
we have in the source tree is all we need and only thing we test.
Delete it to simplify.
2021-11-10 21:58:08 -05:00
Mike Frysinger
23ec4a527d sim: synacor: simplify test generation
Objcopy was used to create a binary file of just the executable code
since the environment requires code to based at address 0.  We can
accomplish the same thing with the -Ttext=0 flag, so switch to that
to get rid of custom logic.
2021-11-10 21:45:43 -05:00
Mike Frysinger
1ee4d0e313 sim: frv: flip trapdump default back to off
When I refactored this by scoping it to sim-frv-xxx in commit
e7954ef5e5 ("sim: frv: scope the
unique configure flag"), I changed the default from off to on.
While the feature is nice for developers, it breaks a bunch of
tests which aren't expecting this extra output.  So flip it back
to off by default.
2021-11-10 05:19:03 -05:00
Mike Frysinger
024120b6ee sim: sh: simplify testsuite a bit
Switch from the centralized list in the exp file to each test declaring
its own requirements which they're already (mostly) doing.  This will
increase coverage slightly by running more tests in more configurations
since the hardcoded exp list was a little out of date.

We have to mark the psh* tests as shdsp only (to match what the exp
file was doing), mark the fsca & fsrra tests as failing (since they
weren't even being run by the exp file), and to fix the expected
output & status of the fail test.
2021-11-09 01:22:06 -05:00
Mike Frysinger
4e6e8ba7c5 sim: cris: clean up missing func prototype warnings
Move some unused funcs under existing #if 0 protection, mark a few
local funcs as static, and add missing prototypes for the rest which
are used from other files.  This fixes all the fatal warnings in the
mloop files so we can turn -Werror on here fully.
2021-11-08 22:48:55 -05:00
Mike Frysinger
81817dacd6 sim: sh: fix conversion of PC to an integer
On LLP64 targets where sizeof(long) != sizeof(void*), this code fails:
sim/sh/interp.c:704:24: error: cast from pointer to integer of different size  -Werror=pointer-to-int-cast]
  704 |   do { memstalls += ((((long) PC & 3) != 0) ? (n) : ((n) - 1)); } while (0)
      |                        ^

Since this code simply needs to check alignment, cast it using uintptr_t
which is the right type for this.
2021-11-06 21:09:08 -04:00
Mike Frysinger
a11cd3ddb2 sim: sh: clean up time(NULL) call
Casting 0 to a pointer via (long *) doesn't work on LLP64 targets:
error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

It's also unnecessary here.  We can simply pass NULL like every other
bit of code does.
2021-11-06 21:06:47 -04:00
Mike Frysinger
4a0bb487b8 sim: sh: break utime logic out of _WIN32 check
Some _WIN32 targets provide utime (like mingw), so move the header
include out from _WIN32 and under the specific HAVE_UTIME_H check.
2021-11-06 21:03:01 -04:00
Mike Frysinger
73eef3fc38 sim: sh: drop errno extern
This isn't needed on any reasonable target nowadays, and no other
source does this, and breaks with some mingw targets, so punt the
extern entirely.
2021-11-06 20:59:17 -04:00
Mike Frysinger
697fa6fe67 sim: sh: fix isnan redefinition with mingw targets
The code assumes that all _WIN32 targets are the same and can
define isnan to _isnan.  For mingw targets, they provide an isnan
define already, so no need for the fallback here.
2021-11-06 20:57:32 -04:00
Mike Frysinger
fd0975b96b sim: arm/bfin/rx: undefine page size from system headers
Some targets (like cygwin) will export page size defines that clash
with our local usage here.  Undefine the system one to fix building
for these targets.
2021-11-06 20:40:20 -04:00