Add strings -n option test case

Message ID 20260929065048.445169-2-pengxu@kylinos.cn
State New
Headers
Series Add strings -n option test case |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

pengxu@kylinos.cn Sept. 29, 2026, 6:50 a.m. UTC
  From: pengxu <pengxu@kylinos.cn>

Signed-off-by: pengxu <pengxu@kylinos.cn>
---
 binutils/testsuite/binutils-all/strings-len.d | 9 +++++++++
 binutils/testsuite/binutils-all/strings-len.s | 6 ++++++
 binutils/testsuite/binutils-all/strings.exp   | 8 ++++++++
 binutils/testsuite/lib/binutils-common.exp    | 8 +++++---
 4 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 binutils/testsuite/binutils-all/strings-len.d
 create mode 100644 binutils/testsuite/binutils-all/strings-len.s
  

Comments

Jan Beulich Sept. 29, 2026, 7 a.m. UTC | #1
On 29.09.2026 08:50, pengxu@kylinos.cn wrote:
> From: pengxu <pengxu@kylinos.cn>
> 
> Signed-off-by: pengxu <pengxu@kylinos.cn>

Please can we have a non-empty description at least in cases where the
subject ...

> ---
>  binutils/testsuite/binutils-all/strings-len.d | 9 +++++++++
>  binutils/testsuite/binutils-all/strings-len.s | 6 ++++++
>  binutils/testsuite/binutils-all/strings.exp   | 8 ++++++++
>  binutils/testsuite/lib/binutils-common.exp    | 8 +++++---
>  4 files changed, 28 insertions(+), 3 deletions(-)

... does not cover all of the changes made?

> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/strings-len.d
> @@ -0,0 +1,9 @@
> +#name: strings default minimum length (4)
> +#source: strings-len.s
> +#DUMPPROG: strings
> +#strings: -d

The subject says -n, yet you use -d here?

> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/strings-len.s
> @@ -0,0 +1,6 @@
> +.data
> +.asciz "aaa"
> +.asciz "bbbb"
> +.asciz "ccccc"
> +.asciz "dddddddd"
> +.asciz "eeeeeeeeeee"

Directives want to be indented.

> --- a/binutils/testsuite/binutils-all/strings.exp
> +++ b/binutils/testsuite/binutils-all/strings.exp
> @@ -48,3 +48,11 @@ proc test_print_file_name {testfile} {
>  }
>  
>  test_print_file_name $srcdir/$subdir/strings-1.bin
> +
> +set strings_len_tests {
> +    strings-len
> +}
> +
> +foreach t $strings_len_tests {
> +    run_dump_test $t
> +}

Why a loop, when a simple run_dump_test will do?

> --- a/binutils/testsuite/lib/binutils-common.exp
> +++ b/binutils/testsuite/lib/binutils-common.exp
> @@ -945,11 +945,12 @@ proc prune_dump_output { output } {
>  #   objdump: FLAGS
>  #   readelf: FLAGS
>  #   size: FLAGS
> +#   strings: FLAGS
>  #	Use the specified program to analyze the output file, and pass it
>  #	FLAGS, in addition to the output name.  Note that they are run
>  #	with LC_ALL=C in the environment to give consistent sorting of
>  #	symbols.  If no FLAGS are needed then you can use:
> -#	    DUMPPROG: [nm objdump readelf addr2line]
> +#	    DUMPPROG: [nm objdump readelf addr2line strings]
>  #	instead, or just pass a flag that happens to be the default.
>  #	If objdump is the dump tool and we're not dumping binary, nor
>  #	have run ld, then the standard section names (.text, .data and
> @@ -1051,7 +1052,7 @@ proc run_dump_test { name {extra_options {}} } {
>      global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS CC_FOR_TARGET CFLAGS_FOR_TARGET
>      global ELFEDIT ELFEDITFLAGS LD LDFLAGS NM NMFLAGS OBJCOPY OBJCOPYFLAGS
>      global OBJDUMP OBJDUMPFLAGS READELF READELFFLAGS STRIP STRIPFLAGS
> -    global SIZE SIZEFLAGS
> +    global SIZE SIZEFLAGS STRINGS STRINGS STRINGSFLAGS

STRINGS occurring twice?

Jan
  
pengxu@kylinos.cn Sept. 29, 2026, 9:06 a.m. UTC | #2
I have updated the patch:
1.Add some description for this patch
2.Correct changed files list
3.This case is for "string -n", I used "string -d -n" to avoid non-data
symbols, only show data symbols
4.Change dirctives format
5.I used loop to test 3 cases
6.Correct STRINGS in binutils-common.exp

Now "make check-binutils RUNTESTFLAGS="binutils-all/strings.exp" shows
result:
# of expected passes    5


Thanks!
  

Patch

diff --git a/binutils/testsuite/binutils-all/strings-len.d b/binutils/testsuite/binutils-all/strings-len.d
new file mode 100644
index 00000000000..e971e3898c7
--- /dev/null
+++ b/binutils/testsuite/binutils-all/strings-len.d
@@ -0,0 +1,9 @@ 
+#name: strings default minimum length (4)
+#source: strings-len.s
+#DUMPPROG: strings
+#strings: -d
+
+bbbb
+ccccc
+dddddddd
+eeeeeeeeeee
diff --git a/binutils/testsuite/binutils-all/strings-len.s b/binutils/testsuite/binutils-all/strings-len.s
new file mode 100644
index 00000000000..b23cd1173d3
--- /dev/null
+++ b/binutils/testsuite/binutils-all/strings-len.s
@@ -0,0 +1,6 @@ 
+.data
+.asciz "aaa"
+.asciz "bbbb"
+.asciz "ccccc"
+.asciz "dddddddd"
+.asciz "eeeeeeeeeee"
diff --git a/binutils/testsuite/binutils-all/strings.exp b/binutils/testsuite/binutils-all/strings.exp
index 1a317e1022c..5a28ea1973e 100644
--- a/binutils/testsuite/binutils-all/strings.exp
+++ b/binutils/testsuite/binutils-all/strings.exp
@@ -48,3 +48,11 @@  proc test_print_file_name {testfile} {
 }
 
 test_print_file_name $srcdir/$subdir/strings-1.bin
+
+set strings_len_tests {
+    strings-len
+}
+
+foreach t $strings_len_tests {
+    run_dump_test $t
+}
diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
index e7e8c223389..4ac3b01a40d 100644
--- a/binutils/testsuite/lib/binutils-common.exp
+++ b/binutils/testsuite/lib/binutils-common.exp
@@ -945,11 +945,12 @@  proc prune_dump_output { output } {
 #   objdump: FLAGS
 #   readelf: FLAGS
 #   size: FLAGS
+#   strings: FLAGS
 #	Use the specified program to analyze the output file, and pass it
 #	FLAGS, in addition to the output name.  Note that they are run
 #	with LC_ALL=C in the environment to give consistent sorting of
 #	symbols.  If no FLAGS are needed then you can use:
-#	    DUMPPROG: [nm objdump readelf addr2line]
+#	    DUMPPROG: [nm objdump readelf addr2line strings]
 #	instead, or just pass a flag that happens to be the default.
 #	If objdump is the dump tool and we're not dumping binary, nor
 #	have run ld, then the standard section names (.text, .data and
@@ -1051,7 +1052,7 @@  proc run_dump_test { name {extra_options {}} } {
     global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS CC_FOR_TARGET CFLAGS_FOR_TARGET
     global ELFEDIT ELFEDITFLAGS LD LDFLAGS NM NMFLAGS OBJCOPY OBJCOPYFLAGS
     global OBJDUMP OBJDUMPFLAGS READELF READELFFLAGS STRIP STRIPFLAGS
-    global SIZE SIZEFLAGS
+    global SIZE SIZEFLAGS STRINGS STRINGS STRINGSFLAGS
     global copyfile env runtests srcdir subdir verbose base_dir
     global DT_RELR_LDFLAGS NO_DT_RELR_LDFLAGS
     global NO_ROSEGMENT_LDFLAGS
@@ -1314,6 +1315,7 @@  proc run_dump_test { name {extra_options {}} } {
 		objdump		{ set dumpprogram objdump }
 		readelf		{ set dumpprogram readelf }
 		size		{ set dumpprogram size }
+		strings         { set dumpprogram strings }
 		default		{
 		    perror "unrecognized DUMPPROG option $opts(DUMPPROG) in $file.d"
 		    unresolved $base_testname
@@ -1322,7 +1324,7 @@  proc run_dump_test { name {extra_options {}} } {
 	    }
 	} else {
 	    # Guess which program to run, by seeing which option was specified.
-	    foreach p {addr2line nm objdump readelf size} {
+	    foreach p {addr2line nm objdump readelf size strings} {
 		if {$opts($p) != ""} {
 		    if {$dumpprogram != ""} {
 			perror "ambiguous dump program in $file.d"