summaryrefslogtreecommitdiff
path: root/test/stdio
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@uclibc-ng.org>2016-10-24 20:22:12 +0200
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2016-10-24 20:22:12 +0200
commit7988979a722b4cdf287b2093956a76a3f19b9897 (patch)
treed35e251d0472ceca55a2eef61cff261c8ee68fab /test/stdio
add uClibc-ng test directory
Diffstat (limited to 'test/stdio')
-rw-r--r--test/stdio/64bit.c12
-rw-r--r--test/stdio/Makefile8
-rw-r--r--test/stdio/Makefile.in8
-rw-r--r--test/stdio/fclose-loop.c21
-rw-r--r--test/stdio/lseek_no_lfs.c22
-rw-r--r--test/stdio/scanf_m.c27
-rw-r--r--test/stdio/tst-fmemopen.c53
7 files changed, 151 insertions, 0 deletions
diff --git a/test/stdio/64bit.c b/test/stdio/64bit.c
new file mode 100644
index 0000000..9b94dd8
--- /dev/null
+++ b/test/stdio/64bit.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int main(void)
+{
+ unsigned long long val = -1;
+ void *ptr = (void *)-1;
+ printf("%p\n", ptr);
+
+ sscanf("123456789", "%Lx", &val);
+ printf("val = %Lx\n", val);
+ return 0;
+}
diff --git a/test/stdio/Makefile b/test/stdio/Makefile
new file mode 100644
index 0000000..95b930b
--- /dev/null
+++ b/test/stdio/Makefile
@@ -0,0 +1,8 @@
+# uClibc stdio tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+top_srcdir=../../
+include ../Rules.mak
+-include Makefile.in
+include ../Test.mak
diff --git a/test/stdio/Makefile.in b/test/stdio/Makefile.in
new file mode 100644
index 0000000..14b5f19
--- /dev/null
+++ b/test/stdio/Makefile.in
@@ -0,0 +1,8 @@
+# uClibc stdio tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+DODIFF_64bit := 1
+
+ifeq ($(UCLIBC_HAS_GLIBC_CUSTOM_STREAMS),)
+TESTS_DISABLED += tst-fmemopen
+endif
diff --git a/test/stdio/fclose-loop.c b/test/stdio/fclose-loop.c
new file mode 100644
index 0000000..fc0cc42
--- /dev/null
+++ b/test/stdio/fclose-loop.c
@@ -0,0 +1,21 @@
+/* From: Denis Vlasenko <vda.linux@googlemail.com>
+ * With certain combination of .config options fclose() does not
+ * remove FILE* pointer from _stdio_openlist. As a result, subsequent
+ * fopen() may allocate new FILE structure exactly in place of one
+ * freed by previous fclose(), which then makes _stdio_openlist
+ * circularlt looped. The following program will enter infinite loop
+ * trying to walk _stdio_openlist in exit():
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ FILE* fp;
+ fp = fopen("/dev/null", "r");
+ fclose(fp);
+ fp = fopen("/dev/zero", "r");
+ fclose(fp);
+ return 0;
+}
diff --git a/test/stdio/lseek_no_lfs.c b/test/stdio/lseek_no_lfs.c
new file mode 100644
index 0000000..54daf6b
--- /dev/null
+++ b/test/stdio/lseek_no_lfs.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+int main(int argc, char *argv[])
+{
+ FILE * f = fopen(argv[0], "rb");
+ if (!f)
+ {
+ printf("Error: Can't open %s, reason: %s\n", argv[0], strerror(errno));
+ return 1;
+ }
+
+ if (fseek(f, (unsigned)4096, (int)SEEK_SET) == -1)
+ {
+ printf("Test failed, fseek return fail code. errno=%u (%s)\n", errno, strerror(errno));
+ return 1;
+ }
+
+ fclose(f);
+ return 0;
+}
diff --git a/test/stdio/scanf_m.c b/test/stdio/scanf_m.c
new file mode 100644
index 0000000..e1dde27
--- /dev/null
+++ b/test/stdio/scanf_m.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(void)
+{
+ const char *buf = "hello world";
+ char *ps = NULL, *pc = NULL, *ps2 = NULL;
+ char s[6], c, s2[5];
+
+ /* Check that %[...]/%c/%s work. */
+ sscanf(buf, "%[a-z] %c %s", s, &c, s2);
+ /* Check that %m[...]/%mc/%ms work. */
+ sscanf(buf, "%m[a-z] %mc %ms", &ps, &pc, &ps2);
+
+ if (strcmp(ps, "hello") != 0 || *pc != 'w' ||
+ strcmp(ps2, "orld") != 0 ||
+ strcmp(s, "hello") != 0 || c != 'w' ||
+ strcmp(s2, "orld") != 0)
+ return 1;
+
+ free(ps);
+ free(pc);
+ free(ps2);
+
+ return 0;
+}
diff --git a/test/stdio/tst-fmemopen.c b/test/stdio/tst-fmemopen.c
new file mode 100644
index 0000000..384faa1
--- /dev/null
+++ b/test/stdio/tst-fmemopen.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *text_input = "1 23 43";
+
+static const char *good_answer = "1 529 1849 ";
+
+
+static int
+do_test (void)
+{
+ FILE *out, *in;
+ int v, s;
+ size_t size;
+ char *ptr;
+
+ in = fmemopen(text_input, strlen(text_input), "r");
+ if (in == NULL) {
+ perror("fmemopen");
+ return 1;
+ }
+
+ out = open_memstream(&ptr, &size);
+ if (out == NULL) {
+ perror("open_memstream");
+ return 1;
+ }
+
+ for (;;) {
+ s = fscanf(in, "%d", &v);
+ if (s <= 0)
+ break;
+
+ s = fprintf(out, "%d ", v * v);
+ if (s == -1) {
+ puts("fprintf failed");
+ exit(1);
+ }
+ }
+ fclose(in);
+ fclose(out);
+
+ if (size != strlen(good_answer) || strcmp(good_answer, ptr) != 0) {
+ printf("failed: size=%zu; ptr=%s\n", size, ptr);
+ exit(1);
+ }
+ free(ptr);
+ exit(0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"