public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hp@axis.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 11/12] sim/testsuite/cris: Remove faulty use of basename in C tests
Date: Tue, 15 Feb 2022 00:07:24 +0100	[thread overview]
Message-ID: <20220214230724.2C0AA20439@pchp3.se.axis.com> (raw)

Calls to basename were added here as part of commit
e1e1ae6e9b5e "sim: testsuite: fix objdir handling", but that
commit missed adding "#include <libgen.h>" or the equivalent
GNU extension, see basename(3).  Fixing that shows a logical
error in the change to openpf1.c; the non-/-prefixed
code-path was changed instead of the "/"-prefixed code-path,
which is the one executed after that commit.

For "newlib" these tests failed linking after that commit.
Recent newlib has the (asm-renamed) GNU-extension-variant of
basename, but we're better off not using it at all.

Unfortunately, compilation failures for C tests run by the
machinery in c.exp are currently just marked "unresolved",
in contrast to C and assembler tests run by calling
run_sim_test.

The interaction of calling with the full program-path vs.
use of --sysroot exposes a consistency problem: when
--sysroot is used, argv[0] isn't the path by which the
program can find itself.  It's undecided whether argv[0] for
the program running in the simulator should be edited
(related to the naked argument to the simulator before
passing on to the simulated program) to remove a leading
--sysroot.  Either way, such a change would be out of scope
for this commit.

	* c/stat3.c (mybasename): New macro.  Use it instead of basename.
	* c/openpf1.c: Correct basename-related change and update related
	comment.
---
 sim/testsuite/cris/c/openpf1.c | 8 +++++---
 sim/testsuite/cris/c/stat3.c   | 3 ++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/sim/testsuite/cris/c/openpf1.c b/sim/testsuite/cris/c/openpf1.c
index 92d12bfc4371..37940d709fbb 100644
--- a/sim/testsuite/cris/c/openpf1.c
+++ b/sim/testsuite/cris/c/openpf1.c
@@ -3,8 +3,8 @@
 
    We assume, with EXE being the name of the executable:
    - The simulator executes with cwd the same directory where the executable
-     is located (so argv[0] contains a plain filename without directory
-     components).
+     is located (also argv[0] contains a plain filename without directory
+     components -or- argv[0] contains the full non-sysroot path to EXE).
    - There's no /EXE on the host file system.  */
 
 #include <stdio.h>
@@ -21,8 +21,10 @@ int main (int argc, char *argv[])
       if (fnam == NULL)
 	abort ();
       strcpy (fnam, "/");
-      strcat (fnam, basename (argv[0]));
+      strcat (fnam, argv[0]);
     }
+  else
+    fnam = strrchr (argv[0], '/');
 
   f = fopen (fnam, "rb");
   if (f == NULL)
diff --git a/sim/testsuite/cris/c/stat3.c b/sim/testsuite/cris/c/stat3.c
index eac4da9ea8d9..c44143d353e6 100644
--- a/sim/testsuite/cris/c/stat3.c
+++ b/sim/testsuite/cris/c/stat3.c
@@ -7,13 +7,14 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#define mybasename(x) ({ const char *x_ = (x), *y_ = strrchr (x_, '/'); y_ != NULL ? y_ + 1 : x_; })
 
 int main (int argc, char *argv[])
 {
   char path[1024] = "/";
   struct stat buf;
 
-  strcat (path, basename (argv[0]));
+  strcat (path, mybasename(argv[0]));
   if (stat (".", &buf) != 0
       || !S_ISDIR (buf.st_mode))
     abort ();
-- 
2.30.2


         reply	other threads:[~2022-02-14 23:07 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14 22:58 [PATCH 00/12] A little TLC for the simulators (in particular CRIS) Hans-Peter Nilsson
2022-02-14 22:59 ` [PATCH 01/12] sim cris: Correct PRIu32 to PRIx32 Hans-Peter Nilsson
2022-02-16  4:43   ` Mike Frysinger
2022-02-14 23:02 ` [PATCH 03/12] sim/testsuite: Set global_cc_os also when no compiler is found Hans-Peter Nilsson
2022-02-16  4:42   ` Mike Frysinger
2022-02-14 23:02 ` [PATCH 04/12] sim/testsuite/cris/c: Use -sim3 but only for newlib targets Hans-Peter Nilsson
2022-02-15 17:43   ` Dimitar Dimitrov
2022-02-15 22:49     ` Hans-Peter Nilsson
2022-02-16  5:25   ` Mike Frysinger
2022-02-16  6:07     ` Hans-Peter Nilsson
2022-02-16  7:34       ` Mike Frysinger
2022-02-16  5:39   ` Mike Frysinger
2022-02-16  6:09     ` Hans-Peter Nilsson
2022-02-16  7:17       ` Mike Frysinger
2022-02-16 15:27         ` Hans-Peter Nilsson
2022-02-14 23:03 ` [PATCH 06/12] sim/testsuite: Support "requires: simoption <--name-of-option>" Hans-Peter Nilsson
2022-02-16  4:49   ` Mike Frysinger
2022-02-16  6:24     ` Hans-Peter Nilsson
2022-02-16  7:09       ` Mike Frysinger
2022-02-16 15:25         ` Hans-Peter Nilsson
2022-02-14 23:05 ` [PATCH 08/12] sim cris: Unbreak --disable-sim-hardware builds Hans-Peter Nilsson
2022-02-16  4:51   ` Mike Frysinger
2022-02-16  5:54     ` Hans-Peter Nilsson
2022-02-16  6:48       ` Hans-Peter Nilsson
2022-02-16  7:15       ` Mike Frysinger
2022-02-14 23:05 ` [PATCH 09/12] sim: Fix use of out-of-tree assembler and linker when testing Hans-Peter Nilsson
2022-02-16  5:03   ` Mike Frysinger
2022-02-14 23:06 ` [PATCH 10/12] sim: Add sim_dump_memory for debugging Hans-Peter Nilsson
2022-02-16  5:02   ` Mike Frysinger
2022-02-16  6:10     ` Hans-Peter Nilsson
2022-02-16  6:41     ` Hans-Peter Nilsson
2022-02-17  2:05     ` Hans-Peter Nilsson
2022-02-17  5:30       ` Mike Frysinger
2022-02-14 23:07 ` Hans-Peter Nilsson [this message]
2022-02-16  4:57   ` [PATCH 11/12] sim/testsuite/cris: Remove faulty use of basename in C tests Mike Frysinger
2022-02-16  6:44     ` Hans-Peter Nilsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220214230724.2C0AA20439@pchp3.se.axis.com \
    --to=hp@axis.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).