summaryrefslogtreecommitdiff
path: root/test/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'test/malloc')
-rw-r--r--test/malloc/Makefile6
-rw-r--r--test/malloc/Makefile.in18
-rw-r--r--test/malloc/tst-asprintf.c27
-rw-r--r--test/malloc/tst-calloc.c23
-rw-r--r--test/malloc/tst-malloc.c5
-rw-r--r--test/malloc/tst-mcheck.c5
-rw-r--r--test/malloc/tst-obstack.c44
7 files changed, 107 insertions, 21 deletions
diff --git a/test/malloc/Makefile b/test/malloc/Makefile
index 3e92e6cdb..97c424be6 100644
--- a/test/malloc/Makefile
+++ b/test/malloc/Makefile
@@ -1,6 +1,8 @@
# uClibc malloc tests
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
-TESTS_DISABLED := time_malloc
-
+top_builddir=../../
+top_srcdir=../../
+include ../Rules.mak
+-include Makefile.in
include ../Test.mak
diff --git a/test/malloc/Makefile.in b/test/malloc/Makefile.in
new file mode 100644
index 000000000..9e7cac9f0
--- /dev/null
+++ b/test/malloc/Makefile.in
@@ -0,0 +1,18 @@
+# uClibc malloc tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+TESTS_DISABLED := time_malloc
+
+ifneq ($(UCLIBC_SUSV2_LEGACY),y)
+TESTS_DISABLED += tst-valloc
+endif
+
+ifneq ($(UCLIBC_HAS_OBSTACK),y)
+TESTS_DISABLED += tst-obstack
+endif
+
+ifneq ($(MALLOC_STANDARD),y)
+TESTS_DISABLED += tst-asprintf
+endif
+
+CFLAGS_tst-mallocfork = -fPIC
diff --git a/test/malloc/tst-asprintf.c b/test/malloc/tst-asprintf.c
new file mode 100644
index 000000000..d4c3f7676
--- /dev/null
+++ b/test/malloc/tst-asprintf.c
@@ -0,0 +1,27 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <malloc.h>
+
+static void my_stats(void)
+{
+ malloc_stats();
+ fprintf(stderr, "\n");
+}
+
+int main(int argc, char *argv[])
+{
+ char *a, *b;
+
+ my_stats();
+ asprintf(&b, "asdsadasd %ssdf\n", "AAAA");
+ my_stats();
+ asprintf(&a, "asdsadasd %ssdf\n", "AAAA");
+ my_stats();
+ free(a);
+ free(b);
+ my_stats();
+
+ return 0;
+}
diff --git a/test/malloc/tst-calloc.c b/test/malloc/tst-calloc.c
index b3594c937..b7b6d2bd2 100644
--- a/test/malloc/tst-calloc.c
+++ b/test/malloc/tst-calloc.c
@@ -13,17 +13,16 @@
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/>. */
#include <errno.h>
-#include <error.h>
#include <limits.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
+static int errors = 0;
/* Number of samples per size. */
#define N 50000
@@ -46,10 +45,11 @@ fixed_test (int size)
for (j = 0; j < size; ++j)
{
- if (ptrs[i][j] != '\0')
- error (EXIT_FAILURE, 0,
- "byte not cleared (size %d, element %d, byte %d)",
+ if (ptrs[i][j] != '\0') {
+ ++errors;
+ printf("byte not cleared (size %d, element %d, byte %d)",
size, i, j);
+ }
ptrs[i][j] = '\xff';
}
}
@@ -79,10 +79,11 @@ random_test (void)
for (j = 0; j < size; ++j)
{
- if (ptrs[i][j] != '\0')
- error (EXIT_FAILURE, 0,
- "byte not cleared (size %d, element %d, byte %d)",
+ if (ptrs[i][j] != '\0') {
+ ++errors;
+ printf("byte not cleared (size %d, element %d, byte %d)",
size, i, j);
+ }
ptrs[i][j] = '\xff';
}
}
@@ -122,5 +123,5 @@ main (void)
null_test ();
- return 0;
+ return errors != 0;
}
diff --git a/test/malloc/tst-malloc.c b/test/malloc/tst-malloc.c
index 468e1d4ba..2d3bcce17 100644
--- a/test/malloc/tst-malloc.c
+++ b/test/malloc/tst-malloc.c
@@ -13,9 +13,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/>. */
#include <errno.h>
#include <malloc.h>
diff --git a/test/malloc/tst-mcheck.c b/test/malloc/tst-mcheck.c
index af72c042b..9297d7994 100644
--- a/test/malloc/tst-mcheck.c
+++ b/test/malloc/tst-mcheck.c
@@ -13,9 +13,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/>. */
#include <errno.h>
#include <stdio.h>
diff --git a/test/malloc/tst-obstack.c b/test/malloc/tst-obstack.c
index 769697f18..1841946c3 100644
--- a/test/malloc/tst-obstack.c
+++ b/test/malloc/tst-obstack.c
@@ -1,4 +1,8 @@
-/* Test case by Alexandre Duret-Lutz <duret_g@epita.fr>. */
+/* Test case by Alexandre Duret-Lutz <duret_g@epita.fr>.
+ * test_obstack_printf() added by Anthony G. Basile <blueness.gentoo.org>.
+ */
+
+#include <features.h>
#include <obstack.h>
#include <stdint.h>
#include <stdio.h>
@@ -26,7 +30,7 @@ verbose_free (void *buf)
}
int
-main (void)
+test_obstack_alloc (void)
{
int result = 0;
int align = 2;
@@ -62,3 +66,39 @@ main (void)
return result;
}
+
+int
+test_obstack_printf (void)
+{
+ int result = 0;
+ int n;
+ char *s;
+ struct obstack ob;
+
+ obstack_init (&ob);
+
+ n = obstack_printf (&ob, "%s%d%c", "testing 1 ... 2 ... ", 3, '\n');
+ result |= (n != 22);
+ printf("obstack_printf => %d\n", n);
+
+ n = obstack_printf (&ob, "%s%d%c", "testing 3 ... 2 ... ", 1, '\0');
+ result |= (n != 22);
+ printf("obstack_printf => %d\n", n);
+
+ s = obstack_finish (&ob);
+ printf("obstack_printf => %s\n", s);
+ obstack_free (&ob, NULL);
+
+ return result;
+}
+
+int
+main (void)
+{
+ int result = 0;
+
+ result |= test_obstack_alloc();
+ result |= test_obstack_printf();
+
+ return result;
+}