aboutsummaryrefslogtreecommitdiff
path: root/stdio-common
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@redhat.com>2025-03-25 09:40:20 +0000
committerMaciej W. Rozycki <macro@redhat.com>2025-03-25 09:40:20 +0000
commitd1a621b735247ba0f7bf288e35a1b172cb6803f6 (patch)
treeb0c065b660221ecbb445d6a9220c31a98d25349a /stdio-common
parent0544df4f4a9c6ce72de589e95f5bdadce8f103d0 (diff)
downloadglibc-d1a621b735247ba0f7bf288e35a1b172cb6803f6.tar.xz
glibc-d1a621b735247ba0f7bf288e35a1b172cb6803f6.zip
stdio-common: Add tests for formatted scanf input specifiers
Add a collection of tests for formatted scanf input specifiers covering the b, d, i, o, u, x, and X integer conversions, the a, A, e, E, f, F, g, and G floating-point conversions, and the [, c, and s character conversions. Also the hh, h, l, and ll length modifiers are covered with the integer conversions as are the l and L length modifier with the floating-point conversions. The tests cover assignment suppressing and the field width as well, verifying the number of assignments made, the number of characters consumed and the value assigned. Add the common test code here as well as test cases for scanf, and then base Makefile infrastructure plus target-agnostic input data, for the character conversions and the `char', `short', and `long long' integer ones, signed and unsigned, with remaining input data and other functions from the scanf family deferred to subsequent additions. Keep input data disabled and referring to BZ #12701 for entries that are currently incorrectly accepted as valid data, such as '0b' or '0x' with the relevant integer conversions or sequences of an insufficient number of characters with the c conversion. Reviewed-by: Joseph Myers <josmyers@redhat.com>
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/Makefile60
-rw-r--r--stdio-common/tst-scanf-format-c-b.input90
-rw-r--r--stdio-common/tst-scanf-format-c-c.input64
-rw-r--r--stdio-common/tst-scanf-format-c-s.input64
-rw-r--r--stdio-common/tst-scanf-format-char-d.input266
-rw-r--r--stdio-common/tst-scanf-format-char-i.input1526
-rw-r--r--stdio-common/tst-scanf-format-character.h130
-rw-r--r--stdio-common/tst-scanf-format-integer.h51
-rw-r--r--stdio-common/tst-scanf-format-llong-d.input266
-rw-r--r--stdio-common/tst-scanf-format-llong-i.input1526
-rw-r--r--stdio-common/tst-scanf-format-real.h363
-rw-r--r--stdio-common/tst-scanf-format-s-c.c22
-rw-r--r--stdio-common/tst-scanf-format-s-char.c22
-rw-r--r--stdio-common/tst-scanf-format-s-double.c22
-rw-r--r--stdio-common/tst-scanf-format-s-float.c22
-rw-r--r--stdio-common/tst-scanf-format-s-int.c22
-rw-r--r--stdio-common/tst-scanf-format-s-ldouble.c22
-rw-r--r--stdio-common/tst-scanf-format-s-llong.c22
-rw-r--r--stdio-common/tst-scanf-format-s-long.c22
-rw-r--r--stdio-common/tst-scanf-format-s-short.c22
-rw-r--r--stdio-common/tst-scanf-format-s-uchar.c22
-rw-r--r--stdio-common/tst-scanf-format-s-uint.c22
-rw-r--r--stdio-common/tst-scanf-format-s-ullong.c22
-rw-r--r--stdio-common/tst-scanf-format-s-ulong.c22
-rw-r--r--stdio-common/tst-scanf-format-s-ushort.c22
-rw-r--r--stdio-common/tst-scanf-format-s.h29
-rw-r--r--stdio-common/tst-scanf-format-short-d.input266
-rw-r--r--stdio-common/tst-scanf-format-short-i.input1526
-rw-r--r--stdio-common/tst-scanf-format-skeleton-c.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-char.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-double.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-float.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-int.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-ldouble.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-llong.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-long.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-short.c21
-rw-r--r--stdio-common/tst-scanf-format-skeleton-uchar.c22
-rw-r--r--stdio-common/tst-scanf-format-skeleton-uint.c22
-rw-r--r--stdio-common/tst-scanf-format-skeleton-ullong.c22
-rw-r--r--stdio-common/tst-scanf-format-skeleton-ulong.c22
-rw-r--r--stdio-common/tst-scanf-format-skeleton-ushort.c22
-rw-r--r--stdio-common/tst-scanf-format-skeleton.c373
-rw-r--r--stdio-common/tst-scanf-format-skeleton.h40
-rw-r--r--stdio-common/tst-scanf-format-uchar-b.input644
-rw-r--r--stdio-common/tst-scanf-format-uchar-o.input434
-rw-r--r--stdio-common/tst-scanf-format-uchar-u.input224
-rw-r--r--stdio-common/tst-scanf-format-uchar-x.input710
-rw-r--r--stdio-common/tst-scanf-format-uchar-xx.input710
-rw-r--r--stdio-common/tst-scanf-format-ullong-b.input644
-rw-r--r--stdio-common/tst-scanf-format-ullong-o.input434
-rw-r--r--stdio-common/tst-scanf-format-ullong-u.input224
-rw-r--r--stdio-common/tst-scanf-format-ullong-x.input742
-rw-r--r--stdio-common/tst-scanf-format-ullong-xx.input742
-rw-r--r--stdio-common/tst-scanf-format-ushort-b.input644
-rw-r--r--stdio-common/tst-scanf-format-ushort-o.input434
-rw-r--r--stdio-common/tst-scanf-format-ushort-u.input224
-rw-r--r--stdio-common/tst-scanf-format-ushort-x.input714
-rw-r--r--stdio-common/tst-scanf-format-ushort-xx.input714
59 files changed, 15485 insertions, 0 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index d3733d0c3d..9cf037e23c 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -51,6 +51,33 @@ nonfmt-xprintf-stems := \
xprintf-stems := $(sort $(fmt-xprintf-stems) $(nonfmt-xprintf-stems))
+# List of markers for scanf family function tests.
+xscanf-funcs := s
+
+# List of data types and formats for individual per-conversion scanf tests.
+# Further conversions are provided by sysdeps.
+xscanf-kinds := char int real uint
+fmt-xscanf-char-convs := c
+fmts-xscanf-char := b c s
+fmt-xscanf-int-convs := char llong short
+fmts-xscanf-int := d i
+fmt-xscanf-real-convs :=
+fmts-xscanf-real := aa a ee e ff f gg g
+fmt-xscanf-uint-convs := uchar ullong ushort
+fmts-xscanf-uint := b o u xx x
+
+xscanf-convs = $(sort $(fmt-xscanf-char-convs) $(fmt-xscanf-int-convs) \
+ $(fmt-xscanf-real-convs) $(fmt-xscanf-uint-convs))
+
+xscanf-srcs = $(foreach p,$(xscanf-funcs), \
+ $(foreach c,$(xscanf-convs),tst-scanf-format-$(p)-$(c)))
+
+xscanf-stems = $(sort $(foreach k,$(xscanf-kinds), \
+ $(foreach f,$(fmts-xscanf-$(k)), \
+ $(foreach p,$(xscanf-funcs), \
+ $(foreach c,$(fmt-xscanf-$(k)-convs), \
+ tst-scanf-format-$(p)-$(c)-$(f))))))
+
headers := \
bits/printf-ldbl.h \
bits/stdio_lim.h \
@@ -367,6 +394,7 @@ tests-internal = \
test-srcs = \
$(xprintf-srcs) \
+ $(xscanf-srcs) \
tst-fwrite-bz29459 \
tst-printf \
tst-printfsz-islongdouble \
@@ -376,6 +404,7 @@ test-srcs = \
ifeq ($(run-built-tests),yes)
tests-special += \
$(foreach f,$(xprintf-stems),$(objpfx)$(f).out) \
+ $(foreach f,$(xscanf-stems),$(objpfx)$(f).out) \
$(objpfx)tst-fwrite-bz29459.out \
$(objpfx)tst-printf.out \
$(objpfx)tst-printfsz-islongdouble.out \
@@ -387,6 +416,7 @@ ifeq (yes,$(build-shared))
ifneq ($(PERL),no)
tests-special += \
$(foreach f,$(xprintf-stems),$(objpfx)$(f)-mem.out) \
+ $(foreach f,$(xscanf-stems),$(objpfx)$(f)-mem.out) \
$(objpfx)tst-freopen2-mem.out \
$(objpfx)tst-freopen3-mem.out \
$(objpfx)tst-freopen4-mem.out \
@@ -409,6 +439,8 @@ tests-special += \
generated += \
$(foreach f,$(xprintf-stems),$(f)-mem.out) \
$(foreach f,$(xprintf-stems),$(f).mtrace) \
+ $(foreach f,$(xscanf-stems),$(f)-mem.out) \
+ $(foreach f,$(xscanf-stems),$(f).mtrace) \
tst-freopen2-mem.out \
tst-freopen2.mtrace \
tst-freopen3-mem.out \
@@ -601,6 +633,26 @@ $(objpfx)tst-printf-format-%.out: \
$(make-tst-printf-format-out) > $@; \
$(evaluate-test)
+# With scanf format tests reuse the same executable for all the inputs
+# of the same data type that use a different conversion specifier each.
+define tst-scanf-format-rule
+$$(objpfx)tst-scanf-format-$(1)-$(2)-$(3).out: \
+ tst-scanf-format-$(2)-$(3).input $$(objpfx)tst-scanf-format-$(1)-$(2)
+ $$(make-tst-scanf-format-out) > $$@ < $$<; \
+ $$(evaluate-test)
+endef
+make-tst-scanf-format-out = \
+ $(test-wrapper-env) \
+ $(run-program-env) \
+ MALLOC_TRACE=$(@:.out=.mtrace) \
+ LD_PRELOAD=$(common-objpfx)malloc/libc_malloc_debug.so \
+ $(host-test-program-cmd)
+$(foreach k,$(xscanf-kinds), \
+ $(foreach f,$(fmts-xscanf-$(k)), \
+ $(foreach p,$(xscanf-funcs), \
+ $(foreach c,$(fmt-xscanf-$(k)-convs), \
+ $(eval $(call tst-scanf-format-rule,$(p),$(c),$(f)))))))
+
$(objpfx)tst-printfsz-islongdouble.out: \
tst-printfsz-islongdouble.sh $(objpfx)tst-printfsz-islongdouble
$(SHELL) $^ '$(test-program-prefix)' $@; \
@@ -713,5 +765,13 @@ $(objpfx)tst-setvbuf1-cmp.out: tst-setvbuf1.expect $(objpfx)tst-setvbuf1.out
$(objpfx)tst-printf-round: $(libm)
$(objpfx)tst-scanf-round: $(libm)
+# With scanf format tests real conversions depend on libm.
+define tst-scanf-format-libm-dep
+$$(objpfx)tst-scanf-format-$(1)-$(2): $$(libm)
+endef
+$(foreach p,$(xscanf-funcs), \
+ $(foreach c,$(fmt-xscanf-real-convs), \
+ $(eval $(call tst-scanf-format-libm-dep,$(p),$(c)))))
+
$(objpfx)tst-freopen7: $(shared-thread-library)
$(objpfx)tst-freopen64-7: $(shared-thread-library)
diff --git a/stdio-common/tst-scanf-format-c-b.input b/stdio-common/tst-scanf-format-c-b.input
new file mode 100644
index 0000000000..52b2dc1a4c
--- /dev/null
+++ b/stdio-common/tst-scanf-format-c-b.input
@@ -0,0 +1,90 @@
+%[bcdefghijklmnopqrstuvw]::0:-1:
+%*[bcdefghijklmnopqrstuvw]::0:-1:
+%[bcdefghijklmnopqrstuvw]:The:0:-1:
+%*[bcdefghijklmnopqrstuvw]:The:0:-1:
+%[bcdefghijklmnopqrstuvw]:quick:1:5:quick:
+%*[bcdefghijklmnopqrstuvw]:quick:0:5:
+%[bcdefghijklmnopqrstuvw]:brown fox:1:5:brown:
+%*[bcdefghijklmnopqrstuvw]:brown fox:0:5:
+%[bcdefghijklmnopqrstuvw]:jumps over the lazy dog:1:5:jumps:
+%*[bcdefghijklmnopqrstuvw]:jumps over the lazy dog:0:5:
+%[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%*[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%[ Tabcdefghijklmnopqrstuvwxyz]:The:1:3:The:
+%*[ Tabcdefghijklmnopqrstuvwxyz]:The:0:3:
+%[ Tabcdefghijklmnopqrstuvwxyz]:quick:1:5:quick:
+%*[ Tabcdefghijklmnopqrstuvwxyz]:quick:0:5:
+%[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:1:9:brown fox:
+%*[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:0:9:
+%[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:1:23:jumps over the lazy dog:
+%*[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:0:23:
+%1[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%*1[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%1[ Tabcdefghijklmnopqrstuvwxyz]:The:1:1:T:
+%*1[ Tabcdefghijklmnopqrstuvwxyz]:The:0:1:
+%1[ Tabcdefghijklmnopqrstuvwxyz]:quick:1:1:q:
+%*1[ Tabcdefghijklmnopqrstuvwxyz]:quick:0:1:
+%1[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:1:1:b:
+%*1[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:0:1:
+%1[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:1:1:j:
+%*1[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:0:1:
+%2[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%*2[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%2[ Tabcdefghijklmnopqrstuvwxyz]:The:1:2:Th:
+%*2[ Tabcdefghijklmnopqrstuvwxyz]:The:0:2:
+%2[ Tabcdefghijklmnopqrstuvwxyz]:quick:1:2:qu:
+%*2[ Tabcdefghijklmnopqrstuvwxyz]:quick:0:2:
+%2[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:1:2:br:
+%*2[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:0:2:
+%2[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:1:2:ju:
+%*2[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:0:2:
+%5[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%*5[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%5[ Tabcdefghijklmnopqrstuvwxyz]:The:1:3:The:
+%*5[ Tabcdefghijklmnopqrstuvwxyz]:The:0:3:
+%5[ Tabcdefghijklmnopqrstuvwxyz]:quick:1:5:quick:
+%*5[ Tabcdefghijklmnopqrstuvwxyz]:quick:0:5:
+%5[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:1:5:brown:
+%*5[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:0:5:
+%5[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:1:5:jumps:
+%*5[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:0:5:
+%10[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%*10[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%10[ Tabcdefghijklmnopqrstuvwxyz]:The:1:3:The:
+%*10[ Tabcdefghijklmnopqrstuvwxyz]:The:0:3:
+%10[ Tabcdefghijklmnopqrstuvwxyz]:quick:1:5:quick:
+%*10[ Tabcdefghijklmnopqrstuvwxyz]:quick:0:5:
+%10[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:1:9:brown fox:
+%*10[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:0:9:
+%10[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:1:10:jumps over:
+%*10[ Tabcdefghijklmnopqrstuvwxyz]:jumps over the lazy dog:0:10:
+%25[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%*25[ Tabcdefghijklmnopqrstuvwxyz]::0:-1:
+%25[ Tabcdefghijklmnopqrstuvwxyz]:The:1:3:The:
+%*25[ Tabcdefghijklmnopqrstuvwxyz]:The:0:3:
+%25[ Tabcdefghijklmnopqrstuvwxyz]:quick:1:5:quick:
+%*25[ Tabcdefghijklmnopqrstuvwxyz]:quick:0:5:
+%25[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:1:9:brown fox:
+%*25[ Tabcdefghijklmnopqrstuvwxyz]:brown fox:0:9: