H8/300: sim: testsuite: Use the correct file descriptor for stdout.

Message ID 20260822104502.1569137-1-jdx@o2.pl
State New
Headers
Series H8/300: sim: testsuite: Use the correct file descriptor for stdout. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Jan Dubiec Aug. 22, 2026, 10:44 a.m. UTC
  This is obviously a typo, because the file descriptor for stdout is 1 on
both Linux and Windows. As a result, the test cases returned nothing
on Windows, i.e. neither "pass" nor "fail". Which, BTW, raises the
question of why 0 works on Linux. For over 20 years...

Signed-off-by: Jan Dubiec <jdx@o2.pl>
---
 sim/testsuite/h8300/testutils.inc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Andrew Burgess Aug. 24, 2026, 10:47 a.m. UTC | #1
Hi Jan,

Thanks for fixing this.

Note: your subject lines ends with a period.  The GDB/sim style is to
drop the period from the subject line.

Jan Dubiec <jdx@o2.pl> writes:

> This is obviously a typo, because the file descriptor for stdout is 1 on
> both Linux and Windows. As a result, the test cases returned nothing
> on Windows, i.e. neither "pass" nor "fail". Which, BTW, raises the
> question of why 0 works on Linux. For over 20 years...

On Linux, FDs 0, 1, and 2 are usually all pointing at the same
underlying device which is opened for bi-directional I/O.  FD 1 might
get line or block buffering from libc, but once the write actually goes
out to the kernel, it's all going to the same underlying pseudo-terminal
device which is bi-directional.

As a result, writing to stdin will work just fine.

Obviously none of this is true if the parent process goes out of its way
to adjust 0, 1, and 2 prior to exec-ing the simulator.  But for normal
use, that's why this is working on Linux.

>
> Signed-off-by: Jan Dubiec <jdx@o2.pl>

Please remove this tag.  This has no meaning for GDB/simulator right
now, but might in the future, in which case it would be good to keep the
commit history free of these tags.

You might want to update the commit message to mention why this was
working fine on Linux.  But with the subject line period removed, and
the Signed-off-by tag removed:

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


> ---
>  sim/testsuite/h8300/testutils.inc | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sim/testsuite/h8300/testutils.inc b/sim/testsuite/h8300/testutils.inc
> index 63d27d45c14..1e2c7c31c7b 100644
> --- a/sim/testsuite/h8300/testutils.inc
> +++ b/sim/testsuite/h8300/testutils.inc
> @@ -85,7 +85,7 @@ _main:
>  
>  ; Output "pass\n"
>  	.macro pass
> -	mov.w	#0, r0		; fd == stdout
> +	mov.w	#1, r0		; fd == stdout
>  .if (sim_cpu == h8300)
>  	mov.w	#pass_str, r1	; buf == "pass\n"
>  	mov.w	#5, r2		; len == 5
> @@ -98,7 +98,7 @@ _main:
>  
>  ; Output "fail\n"
>  	.macro fail
> -	mov.w	#0, r0		; fd == stdout
> +	mov.w	#1, r0		; fd == stdout
>  .if (sim_cpu == h8300)
>  	mov.w	#fail_str, r1	; buf == "fail\n"
>  	mov.w	#5, r2		; len == 5
> -- 
> 2.55.0
  

Patch

diff --git a/sim/testsuite/h8300/testutils.inc b/sim/testsuite/h8300/testutils.inc
index 63d27d45c14..1e2c7c31c7b 100644
--- a/sim/testsuite/h8300/testutils.inc
+++ b/sim/testsuite/h8300/testutils.inc
@@ -85,7 +85,7 @@  _main:
 
 ; Output "pass\n"
 	.macro pass
-	mov.w	#0, r0		; fd == stdout
+	mov.w	#1, r0		; fd == stdout
 .if (sim_cpu == h8300)
 	mov.w	#pass_str, r1	; buf == "pass\n"
 	mov.w	#5, r2		; len == 5
@@ -98,7 +98,7 @@  _main:
 
 ; Output "fail\n"
 	.macro fail
-	mov.w	#0, r0		; fd == stdout
+	mov.w	#1, r0		; fd == stdout
 .if (sim_cpu == h8300)
 	mov.w	#fail_str, r1	; buf == "fail\n"
 	mov.w	#5, r2		; len == 5