summaryrefslogtreecommitdiff
path: root/test/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'test/stdlib')
-rw-r--r--test/stdlib/Makefile9
-rw-r--r--test/stdlib/Makefile.in19
-rw-r--r--test/stdlib/qsort.c10
-rw-r--r--test/stdlib/test-canon.c8
-rw-r--r--test/stdlib/test-canon2.c86
-rw-r--r--test/stdlib/test-mkostemp-O_CLOEXEC.c45
-rw-r--r--test/stdlib/test-mkostemp-child.c22
-rw-r--r--test/stdlib/testarc4random.c10
-rw-r--r--test/stdlib/teststrtoq.c89
9 files changed, 288 insertions, 10 deletions
diff --git a/test/stdlib/Makefile b/test/stdlib/Makefile
index efec56d70..567e0e37a 100644
--- a/test/stdlib/Makefile
+++ b/test/stdlib/Makefile
@@ -1,9 +1,8 @@
# uClibc stdlib 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
-
-DODIFF_qsort := 1
-DODIFF_testatexit := 1
-DODIFF_teston_exit := 1
-DODIFF_teststrtol := 1
diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in
new file mode 100644
index 000000000..91dfde412
--- /dev/null
+++ b/test/stdlib/Makefile.in
@@ -0,0 +1,19 @@
+# uClibc stdlib tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+DODIFF_qsort := 1
+DODIFF_testatexit := 1
+DODIFF_teston_exit := 1
+DODIFF_teststrtol := 1
+
+TESTS_DISABLED :=
+ifeq ($(UCLIBC_HAS_PTY),)
+TESTS_DISABLED += ptytest
+endif
+ifeq ($(UCLIBC_HAS_ARC4RANDOM),)
+TESTS_DISABLED += testarc4random
+endif
+
+CFLAGS_test-canon = -fPIC
+CFLAGS_test-canon2 = -fPIC
+CFLAGS_testatexit = -fPIC
diff --git a/test/stdlib/qsort.c b/test/stdlib/qsort.c
index abc505e2d..74f93315f 100644
--- a/test/stdlib/qsort.c
+++ b/test/stdlib/qsort.c
@@ -34,7 +34,15 @@ int main(void)
printf("[%d] %s\n", i, dirbuf->d_name);
}
printf("\nCalling qsort()\n");
- qsort(array, numdir, sizeof(struct dirent *), alphasort);
+ /* Even though some manpages say that alphasort should be
+ * int alphasort(const void *a, const void *b),
+ * in reality glibc and uclibc have const struct dirent**
+ * instead of const void*.
+ * Therefore we get a warning here unless we use a cast,
+ * which makes people think that alphasort prototype
+ * needs to be fixed in uclibc headers.
+ */
+ qsort(array, numdir, sizeof(struct dirent *), (void*) alphasort);
for (i = 0; i < numdir; ++i) {
dirbuf = array[i];
printf("[%d] %s\n", i, dirbuf->d_name);
diff --git a/test/stdlib/test-canon.c b/test/stdlib/test-canon.c
index 9770a948d..1b43dedfb 100644
--- a/test/stdlib/test-canon.c
+++ b/test/stdlib/test-canon.c
@@ -15,9 +15,8 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
/* This file must be run from within a directory called "stdlib". */
@@ -28,10 +27,11 @@
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
+#include <sys/stat.h>
/* Prototype for our test function. */
extern int do_test (int argc, char *argv[]);
-#include <test-skeleton.c>
+#include "../test-skeleton.c"
#ifndef PATH_MAX
# define PATH_MAX 4096
diff --git a/test/stdlib/test-canon2.c b/test/stdlib/test-canon2.c
new file mode 100644
index 000000000..4a03b2d48
--- /dev/null
+++ b/test/stdlib/test-canon2.c
@@ -0,0 +1,86 @@
+/* Test for realpath/canonicalize function.
+ Copyright (C) 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <string.h>
+
+
+/* Prototype for our test function. */
+extern void do_prepare (int argc, char *argv[]);
+extern int do_test (int argc, char *argv[]);
+
+/* We have a preparation function. */
+#define PREPARE do_prepare
+
+#include <test-skeleton.c>
+
+/* Name of the temporary files we create. */
+char *name1;
+char *name2;
+
+/* Preparation. */
+void
+do_prepare (int argc, char *argv[])
+{
+ size_t test_dir_len;
+ int tfd;
+
+ test_dir_len = strlen (test_dir);
+
+ /* Generate the circular symlinks. */
+ name1 = malloc (test_dir_len + sizeof ("/canonXXXXXX"));
+ mempcpy (mempcpy (name1, test_dir, test_dir_len),
+ "/canonXXXXXX", sizeof ("/canonXXXXXX"));
+ name2 = strdup (name1);
+ tfd = mkstemp(name1);
+ if (tfd < 0) {
+ printf("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit(1);
+ }
+ close(tfd);
+ add_temp_file (name1);
+ tfd = mkstemp(name2);
+ if (tfd < 0) {
+ printf("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit(1);
+ }
+ close(tfd);
+ add_temp_file (name2);
+}
+
+
+/* Run the test. */
+int
+do_test (int argc, char *argv[])
+{
+ char *canon;
+
+ printf ("create symlinks from %s to %s and vice versa\n", name1, name2);
+ if (symlink (name1, name2) == -1
+ || symlink (name2, name1) == -1)
+ /* We cannot test this. */
+ return 0;
+
+ /* Call the function. This is equivalent the using `realpath' but the
+ function allocates the room for the result. */
+ errno = 0;
+ canon = canonicalize_file_name (name1);
+
+ return canon != NULL || errno != ELOOP;
+}
diff --git a/test/stdlib/test-mkostemp-O_CLOEXEC.c b/test/stdlib/test-mkostemp-O_CLOEXEC.c
new file mode 100644
index 000000000..9ff229af1
--- /dev/null
+++ b/test/stdlib/test-mkostemp-O_CLOEXEC.c
@@ -0,0 +1,45 @@
+#define _XOPEN_SOURCE_EXTENDED
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+#if !defined __ARCH_USE_MMU__
+# define fork vfork
+#endif
+
+int main(int argc, char *argv[]) {
+ int fd, status;
+ char buff[5];
+ char template[] = "/tmp/test-mkostemp.XXXXXX";
+
+ fd = mkostemp(template, O_CLOEXEC);
+ unlink(template);
+
+ snprintf(buff, 5, "%d", fd);
+
+ if(!fork())
+ if(execl("./test-mkostemp-child", "test-mkostemp-child", buff, NULL) == -1)
+ exit(EXIT_FAILURE);
+
+ wait(&status);
+
+ memset(buff, 0, 5);
+ lseek(fd, 0, SEEK_SET);
+ errno = 0;
+ if(read(fd, buff, 5) == -1)
+ exit(EXIT_FAILURE);
+
+ if(!strncmp(buff, "test", 5))
+ exit(EXIT_FAILURE);
+ else
+ exit(EXIT_SUCCESS);
+
+ close(fd);
+ exit(EXIT_SUCCESS);
+}
diff --git a/test/stdlib/test-mkostemp-child.c b/test/stdlib/test-mkostemp-child.c
new file mode 100644
index 000000000..708bd80a1
--- /dev/null
+++ b/test/stdlib/test-mkostemp-child.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+ int fd;
+
+ /* This file gets built and run as a test, but its
+ * really just a helper for test-mkostemp-O_CLOEXEC.c.
+ * So, we'll always return succcess.
+ */
+ if(argc != 2)
+ exit(EXIT_SUCCESS);
+
+ sscanf(argv[1], "%d", &fd);
+
+ if(write(fd, "test\0", 5) == -1)
+ ; /* Don't Panic! Failure is okay here. */
+
+ close(fd);
+ exit(EXIT_SUCCESS);
+}
diff --git a/test/stdlib/testarc4random.c b/test/stdlib/testarc4random.c
new file mode 100644
index 000000000..14ff1cc36
--- /dev/null
+++ b/test/stdlib/testarc4random.c
@@ -0,0 +1,10 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void)
+{
+ int random_number;
+ random_number = arc4random() % 65536;
+ printf("%d\n", random_number);
+ return 0;
+}
diff --git a/test/stdlib/teststrtoq.c b/test/stdlib/teststrtoq.c
new file mode 100644
index 000000000..6e1a4cbc6
--- /dev/null
+++ b/test/stdlib/teststrtoq.c
@@ -0,0 +1,89 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+
+const char *strings[]={
+ /* some simple stuff */
+ "0", "1", "10",
+ "100", "1000", "10000", "100000", "1000000",
+ "10000000", "100000000", "1000000000",
+
+ /* negative */
+ "-0", "-1", "-10",
+ "-100", "-1000", "-10000", "-100000", "-1000000",
+ "-10000000", "-100000000", "-1000000000",
+
+ /* test base>10 */
+ "a", "b", "f", "g", "z",
+
+ /* test hex */
+ "0x0", "0x1", "0xa", "0xf", "0x10",
+
+ /* test octal */
+ "00", "01", "07", "08", "0a", "010",
+
+ /* other */
+ "0x8000000",
+
+ /* check overflow cases: (for 32 bit) */
+ "2147483645",
+ "2147483646",
+ "2147483647",
+ "2147483648",
+ "2147483649",
+ "-2147483645",
+ "-2147483646",
+ "-2147483647",
+ "-2147483648",
+ "-2147483649",
+ "4294967293",
+ "4294967294",
+ "4294967295",
+ "4294967296",
+ "4294967297",
+ "-4294967293",
+ "-4294967294",
+ "-4294967295",
+ "-4294967296",
+ "-4294967297",
+
+ /* bad input tests */
+ "",
+ "00",
+ "0x",
+ "0x0",
+ "-",
+ "+",
+ " ",
+ " -",
+ " - 0",
+};
+int n_tests=sizeof(strings)/sizeof(strings[0]);
+
+
+
+void do_test(int base);
+void do_test(int base)
+{
+ int i;
+ quad_t n;
+ char *endptr;
+
+ for(i=0;i<n_tests;i++){
+ n=strtoq(strings[i],&endptr,base);
+ printf("strtoq(\"%s\",%d) len=%lu res=%qd\n",
+ strings[i],base,(unsigned long)(endptr-strings[i]),n);
+ }
+}
+
+int main(int argc,char *argv[])
+{
+ do_test(0);
+ do_test(8);
+ do_test(10);
+ do_test(16);
+ do_test(36);
+
+ return 0;
+}