diff options
| author | [email protected] <[email protected]> | 2010-11-18 11:31:54 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2010-11-18 11:31:54 +0000 |
| commit | d9cb84f4840c49993cfbcc80057488c50eae60cb (patch) | |
| tree | 9077055207bb6faa59cd565d37a77aa12e39b53c /examples/libc/memory.c | |
| parent | 019b6542012115190cfbde415532c8940cc47500 (diff) | |
add libc testcase.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1061 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples/libc/memory.c')
| -rw-r--r-- | examples/libc/memory.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/libc/memory.c b/examples/libc/memory.c new file mode 100644 index 0000000000..0a0bfecd80 --- /dev/null +++ b/examples/libc/memory.c @@ -0,0 +1,54 @@ +/*
+ * memory.c
+ *
+ * Created on: 2010-11-17
+ * Author: bernard
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <finsh.h>
+#include <errno.h>
+
+static int errors = 0;
+static void merror(const char *msg)
+{
+ ++errors;
+ printf("Error: %s\n", msg);
+}
+
+int libc_mem(void)
+{
+ void *p;
+ int save;
+
+ errno = 0;
+
+ p = malloc(-1);
+ save = errno;
+
+ if (p != NULL)
+ merror("malloc (-1) succeeded.");
+
+ if (p == NULL && save != ENOMEM)
+ merror("errno is not set correctly");
+
+ p = malloc(10);
+ if (p == NULL)
+ merror("malloc (10) failed.");
+
+ /* realloc (p, 0) == free (p). */
+ p = realloc(p, 0);
+ if (p != NULL)
+ merror("realloc (p, 0) failed.");
+
+ p = malloc(0);
+ if (p == NULL)
+ merror("malloc (0) failed.");
+
+ p = realloc(p, 0);
+ if (p != NULL)
+ merror("realloc (p, 0) failed.");
+
+ return errors != 0;
+}
+FINSH_FUNCTION_EXPORT(libc_mem, memory test for libc);
|
