summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_mem.c57
-rw-r--r--test/test_mem_cache.c145
-rw-r--r--test/test_mem_cache_double_free.c75
-rw-r--r--test/test_mem_cache_invalid_free.c74
-rw-r--r--test/test_mem_cache_write_beyond.c90
-rw-r--r--test/test_mem_cache_write_buftag.c92
-rw-r--r--test/test_mem_cache_write_free.c106
-rw-r--r--test/test_mem_offbyone.c58
-rw-r--r--test/test_phys.c65
-rw-r--r--test/test_xprintf.c298
10 files changed, 0 insertions, 1060 deletions
diff --git a/test/test_mem.c b/test/test_mem.c
deleted file mode 100644
index eb7a56c..0000000
--- a/test/test_mem.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include "../mem.h"
-#include "../macros.h"
-
-#define STRING "This is a test string."
-#define STRING_SIZE (STRLEN(STRING) + 1)
-
-int
-main(int argc, char *argv[])
-{
- char *s;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- s = mem_alloc(STRING_SIZE);
-
- if (s == NULL) {
- fprintf(stderr, "unable to allocate memory\n");
- return 1;
- }
-
- strcpy(s, STRING);
- printf("string: '%s'\n", s);
- mem_free(s, STRING_SIZE);
-
- return 0;
-}
diff --git a/test/test_mem_cache.c b/test/test_mem_cache.c
deleted file mode 100644
index eaa043a..0000000
--- a/test/test_mem_cache.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (c) 2010, 2011 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <assert.h>
-#include <stddef.h>
-#include <pthread.h>
-
-#include <stdio.h>
-
-#include "../cpu.h"
-#include "../mem.c"
-#include "../error.c"
-#include "../avltree.c"
-
-#if CONFIG_MEM_USE_PHYS
-#include "../phys.c"
-#endif /* CONFIG_MEM_USE_PHYS */
-
-#define NTHREADS 4
-#define TEST_TIME 60
-#define OBJSPERLOOP 100
-
-struct result {
- unsigned long allocs;
- unsigned long frees;
-} __aligned(CPU_L1_SIZE);
-
-struct obj {
- unsigned long nr_refs;
- char name[16];
-};
-
-static void
-obj_ctor(void *ptr)
-{
- struct obj *obj;
-
- obj = ptr;
- obj->nr_refs = 0;
-}
-
-static struct mem_cache *obj_cache;
-static volatile int work;
-static struct result results[NTHREADS];
-
-static void *
-run(void *arg)
-{
- struct obj *objs[OBJSPERLOOP];
- struct result *result;
- int i, id;
-
- result = arg;
- id = result - results;
-
- mem_print("started");
-
- while (work) {
- for (i = 0; i < OBJSPERLOOP; i++) {
- objs[i] = mem_cache_alloc(obj_cache);
- result->allocs++;
- }
-
- for (i = 0; i < OBJSPERLOOP; i++) {
- mem_cache_free(obj_cache, objs[i]);
- result->frees++;
- }
- }
-
- return NULL;
-}
-
-int
-main(int argc, char *argv[])
-{
- pthread_t threads[NTHREADS];
- unsigned long ops;
- int i;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- mem_info();
-
- mem_print("Selected cache line size: %u", CPU_L1_SIZE);
- mem_print("sizeof(pthread_mutex_t): %zu", sizeof(pthread_mutex_t));
- mem_print("sizeof(struct mem_cpu_pool): %zu", sizeof(struct mem_cpu_pool));
- mem_print("sizeof(union mem_bufctl): %zu", sizeof(union mem_bufctl));
- mem_print("sizeof(struct mem_buftag): %zu", sizeof(struct mem_buftag));
- mem_print("sizeof(struct mem_slab): %zu", sizeof(struct mem_slab));
- mem_print("sizeof(struct mem_cache): %zu", sizeof(struct mem_cache));
- mem_print("sizeof(struct obj): %zu", sizeof(struct obj));
-
- obj_cache = mem_cache_create("obj", sizeof(struct obj), 0,
- obj_ctor, NULL, 0);
-
- memset(results, 0, sizeof(results));
- work = 1;
-
- for (i = 0; i < NTHREADS; i++)
- pthread_create(&threads[i], NULL, run, &results[i]);
-
- sleep(TEST_TIME);
- work = 0;
-
- for (i = 0; i < NTHREADS; i++)
- pthread_join(threads[i], NULL);
-
- ops = 0;
-
- for (i = 0; i < NTHREADS; i++)
- ops += results[i].allocs + results[i].frees;
-
- mem_info();
- mem_cache_info(obj_cache);
- mem_print("total: %lu ops in %d secs", ops, TEST_TIME);
-
- mem_cache_destroy(obj_cache);
-
- return 0;
-}
diff --git a/test/test_mem_cache_double_free.c b/test/test_mem_cache_double_free.c
deleted file mode 100644
index de356a3..0000000
--- a/test/test_mem_cache_double_free.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "../mem.h"
-#include "../macros.h"
-
-struct obj {
- unsigned long nr_refs;
- char name[16];
-};
-
-static void
-obj_ctor(void *ptr)
-{
- struct obj *obj;
-
- obj = ptr;
- obj->nr_refs = 0;
-}
-
-int
-main(int argc, char *argv[])
-{
- struct mem_cache *obj_cache;
- struct obj *obj;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- obj_cache = mem_cache_create("obj", sizeof(struct obj), 0,
- obj_ctor, NULL, MEM_CACHE_VERIFY);
-
- printf("trying normal alloc+free:\n");
- obj = mem_cache_alloc(obj_cache);
- mem_cache_free(obj_cache, obj);
-
- mem_cache_info(obj_cache);
-
- printf("trying alloc+double free:\n");
- obj = mem_cache_alloc(obj_cache);
- mem_cache_free(obj_cache, obj);
- mem_cache_free(obj_cache, obj);
-
- printf("done\n");
-
- return 0;
-}
diff --git a/test/test_mem_cache_invalid_free.c b/test/test_mem_cache_invalid_free.c
deleted file mode 100644
index 767ee6b..0000000
--- a/test/test_mem_cache_invalid_free.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "../mem.h"
-#include "../macros.h"
-
-struct obj {
- unsigned long nr_refs;
- char name[16];
-};
-
-static void
-obj_ctor(void *ptr)
-{
- struct obj *obj;
-
- obj = ptr;
- obj->nr_refs = 0;
-}
-
-int
-main(int argc, char *argv[])
-{
- struct mem_cache *obj_cache;
- struct obj *obj;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- obj_cache = mem_cache_create("obj", sizeof(struct obj), 0,
- obj_ctor, NULL, MEM_CACHE_VERIFY);
-
- printf("trying normal alloc+free:\n");
- obj = mem_cache_alloc(obj_cache);
- mem_cache_free(obj_cache, obj);
-
- mem_cache_info(obj_cache);
-
- printf("trying alloc+invalid free:\n");
- obj = mem_cache_alloc(obj_cache);
- mem_cache_free(obj_cache, (char *)obj + 1);
-
- printf("done\n");
-
- return 0;
-}
diff --git a/test/test_mem_cache_write_beyond.c b/test/test_mem_cache_write_beyond.c
deleted file mode 100644
index 05bea2e..0000000
--- a/test/test_mem_cache_write_beyond.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "../mem.h"
-#include "../macros.h"
-
-struct obj {
- unsigned long nr_refs;
- char name[16];
-};
-
-static void
-obj_ctor(void *ptr)
-{
- struct obj *obj;
-
- obj = ptr;
- obj->nr_refs = 0;
-}
-
-static void
-obj_print(struct obj *obj, size_t size)
-{
- unsigned char *ptr, *end;
-
- printf("buffer content: ");
-
- for (ptr = (unsigned char *)obj, end = ptr + size; ptr < end; ptr++)
- printf("%02x", *ptr);
-
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- struct mem_cache *obj_cache;
- struct obj *obj;
- size_t buf_size;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- obj_cache = mem_cache_create("obj", sizeof(struct obj), 0,
- obj_ctor, NULL, MEM_CACHE_VERIFY);
- mem_cache_info(obj_cache);
-
- printf("doing normal alloc:\n");
- obj = mem_cache_alloc(obj_cache);
-
- printf("writing beyond object boundary:\n");
- strcpy(obj->name, "invalid write 000000");
- buf_size = P2ROUND(sizeof(*obj), 8);
- obj_print(obj, buf_size + (sizeof(unsigned long) * 2));
-
- printf("doing normal free:\n");
- mem_cache_free(obj_cache, obj);
-
- printf("done\n");
-
- return 0;
-}
diff --git a/test/test_mem_cache_write_buftag.c b/test/test_mem_cache_write_buftag.c
deleted file mode 100644
index 539d399..0000000
--- a/test/test_mem_cache_write_buftag.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "../mem.h"
-#include "../macros.h"
-
-struct obj {
- unsigned long nr_refs;
- char name[16];
-};
-
-static void
-obj_ctor(void *ptr)
-{
- struct obj *obj;
-
- obj = ptr;
- obj->nr_refs = 0;
-}
-
-static void
-obj_print(struct obj *obj, size_t size)
-{
- unsigned char *ptr, *end;
-
- printf("buffer content: ");
-
- for (ptr = (unsigned char *)obj, end = ptr + size; ptr < end; ptr++)
- printf("%02x", *ptr);
-
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- struct mem_cache *obj_cache;
- struct obj *obj;
- unsigned long *ptr;
- size_t buf_size;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- obj_cache = mem_cache_create("obj", sizeof(struct obj), 0,
- obj_ctor, NULL, MEM_CACHE_VERIFY);
- mem_cache_info(obj_cache);
-
- printf("doing normal alloc:\n");
- obj = mem_cache_alloc(obj_cache);
-
- printf("writing garbage in buftag:\n");
- buf_size = P2ROUND(sizeof(*obj), 8);
- ptr = (void *)obj + buf_size + sizeof(unsigned long);
- *ptr = 0xed0000a1;
- obj_print(obj, buf_size + (sizeof(unsigned long) * 2));
-
- printf("doing normal free:\n");
- mem_cache_free(obj_cache, obj);
-
- printf("done\n");
-
- return 0;
-}
diff --git a/test/test_mem_cache_write_free.c b/test/test_mem_cache_write_free.c
deleted file mode 100644
index fd1c9db..0000000
--- a/test/test_mem_cache_write_free.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define _GNU_SOURCE
-#include <sched.h>
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "../mem.h"
-#include "../macros.h"
-
-struct obj {
- unsigned long nr_refs;
- char name[16];
-};
-
-static void
-obj_ctor(void *ptr)
-{
- struct obj *obj;
-
- obj = ptr;
- obj->nr_refs = 0;
-}
-
-static void
-obj_print(struct obj *obj)
-{
- unsigned char *ptr, *end;
-
- printf("buffer content: ");
-
- for (ptr = (unsigned char *)obj, end = ptr + sizeof(*obj);
- ptr < end;
- ptr++)
- printf("%02x", *ptr);
-
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- struct mem_cache *obj_cache;
- struct obj *obj;
- cpu_set_t cpu_set;
-
- (void)argc;
- (void)argv;
-
- printf("binding to CPU 0\n");
- CPU_ZERO(&cpu_set);
- CPU_SET(0, &cpu_set);
- sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
-
- mem_setup();
-
- obj_cache = mem_cache_create("obj", sizeof(struct obj), 0,
- obj_ctor, NULL, MEM_CACHE_VERIFY);
-
- printf("doing normal alloc+free:\n");
- obj = mem_cache_alloc(obj_cache);
- mem_cache_free(obj_cache, obj);
-
- mem_cache_info(obj_cache);
-
- obj_print(obj);
-
- printf("doing write on free object:\n");
- memset((void *)obj + 3, 0x89, 5);
-
- obj_print(obj);
-
- printf("trying normal alloc+free on same CPU (should fail):\n");
-
- obj = mem_cache_alloc(obj_cache);
- mem_cache_free(obj_cache, obj);
-
- printf("done\n");
-
- return 0;
-}
diff --git a/test/test_mem_offbyone.c b/test/test_mem_offbyone.c
deleted file mode 100644
index b9e7d75..0000000
--- a/test/test_mem_offbyone.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include "../mem.h"
-
-#define BUFSIZE 200
-
-int
-main(int argc, char *argv[])
-{
- char *s;
-
- (void)argc;
- (void)argv;
-
- mem_setup();
-
- printf("allocating memory:\n");
- s = mem_alloc(BUFSIZE);
-
- if (s == NULL) {
- fprintf(stderr, "unable to allocate memory\n");
- return 1;
- }
-
- printf("writing beyond end of buffer:\n");
- memset(s, 'a', BUFSIZE + 1);
-
- printf("releasing buffer, should fail if CONFIG_MEM_VERIFY defined\n");
- mem_free(s, BUFSIZE);
-
- return 0;
-}
diff --git a/test/test_phys.c b/test/test_phys.c
deleted file mode 100644
index 5ded8d5..0000000
--- a/test/test_phys.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2011 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stddef.h>
-#include <string.h>
-
-#include "../error.c"
-#include "../phys.c"
-
-int
-main(int argc, char *argv[])
-{
- struct phys_page *page;
-
- (void)argc;
- (void)argv;
-
- phys_setup();
-
- phys_info();
- printf("sizeof(struct phys_cpu_pool) = %zu\n",
- sizeof(struct phys_cpu_pool));
- printf("sizeof(struct phys_free_list) = %zu\n",
- sizeof(struct phys_free_list));
- printf("sizeof(struct phys_page): %zu\n", sizeof(struct phys_page));
- printf("sizeof(struct phys_seg): %zu\n", sizeof(struct phys_seg));
- printf("allocating two pages\n");
- page = phys_alloc_pages(PAGE_SIZE * 2);
-
- if (page == NULL) {
- fprintf(stderr, "unable to allocate memory\n");
- return 1;
- }
-
- phys_info();
-
- printf("freeing the allocated pages\n");
- phys_free_pages(page, PAGE_SIZE * 2);
- phys_info();
-
- return 0;
-}
diff --git a/test/test_xprintf.c b/test/test_xprintf.c
deleted file mode 100644
index ff157b8..0000000
--- a/test/test_xprintf.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (c) 2010 Richard Braun.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <string.h>
-
-#include "../macros.h"
-#include "../xprintf.h"
-
-#define TEST_PRINTF(format, ...) \
-MACRO_BEGIN \
- char stra[256], strb[256]; \
- int la, lb; \
- la = snprintf(stra, 256, format, ## __VA_ARGS__); \
- printf(" printf: %s", stra); \
- lb = xsnprintf(strb, 256, format, ## __VA_ARGS__); \
- xprintf("xprintf: %s", stra); \
- assert(la == lb); \
- assert(strcmp(stra, strb) == 0); \
-MACRO_END
-
-int
-main(int argc, char *argv[])
-{
- (void)argc;
- (void)argv;
-
-#define FORMAT "%c"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 'a');
-#undef FORMAT
-
-#define FORMAT "%8c"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 'a');
-#undef FORMAT
-
-#define FORMAT "%-8c"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 'a');
-#undef FORMAT
-
-#define FORMAT "%.s"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "12345");
-#undef FORMAT
-
-#define FORMAT "%.3s"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "12345");
-#undef FORMAT
-
-#define FORMAT "%4.3s"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "12345");
-#undef FORMAT
-
-#define FORMAT "%-4.3s"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "12345");
-#undef FORMAT
-
-#define FORMAT "%3.4s"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "12345");
-#undef FORMAT
-
-#define FORMAT "%-3.4s"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "12345");
-#undef FORMAT
-
-#define FORMAT "%#o"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%#x"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%#X"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%08d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%-8d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%-08d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%0-8d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "% d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%+d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%+ d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%12d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%*d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 12, 123);
-#undef FORMAT
-
-#define FORMAT "%.12d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%.012d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%.*d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 12, 123);
-#undef FORMAT
-
-#define FORMAT "%.d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%.*d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -12, 123);
-#undef FORMAT
-
-#define FORMAT "%.4d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%5.4d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%4.5d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0);
-#undef FORMAT
-
-#define FORMAT "%.0d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0);
-#undef FORMAT
-
-#define FORMAT "%.0o"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0);
-#undef FORMAT
-
-#define FORMAT "%.0x"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0);
-#undef FORMAT
-
-#define FORMAT "%1.0d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0);
-#undef FORMAT
-
-#define FORMAT "%08.0d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%08d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%08d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%8d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%8d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%.8d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%.80d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%-80d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%80d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%80.40d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%-+80.40d"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%+x"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, -123);
-#undef FORMAT
-
-#define FORMAT "%#x"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%#o"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 123);
-#undef FORMAT
-
-#define FORMAT "%p"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, "123");
-#undef FORMAT
-
-#define FORMAT "%#lx"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0xdeadbeefL);
-#undef FORMAT
-
-#define FORMAT "%zd"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, (size_t)-123);
-#undef FORMAT
-
-#define FORMAT "%#llx"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0xdeadbeefbadcafeLL);
-#undef FORMAT
-
-#define FORMAT "%llo"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT, 0xffffffffffffffffLL);
-#undef FORMAT
-
-#define FORMAT "%%"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT);
-#undef FORMAT
-
-#define FORMAT "%y"
- TEST_PRINTF("%s: '" FORMAT "'\n", FORMAT);
-#undef FORMAT
-
- char stra[10], strb[10];
- int la, lb;
- la = snprintf(stra, sizeof(stra), "%s", "123456789a");
- printf(" printf: %s\n", stra);
- lb = xsnprintf(strb, sizeof(strb), "%s", "123456789a");
- xprintf("xprintf: %s\n", stra);
- assert(la == lb);
- assert(strncmp(stra, strb, 10) == 0);
-
-#define FORMAT "12%n3%#08x4%n5"
- int lc, ld;
- sprintf(stra, FORMAT, &la, 123, &lb);
- printf(" printf: la: %d, lb: %d\n", la, lb);
- xsprintf(strb, FORMAT, &lc, 123, &ld);
- xprintf("xprintf: lc: %d, ld: %d\n", lc, ld);
- assert(la == lc);
- assert(lb == ld);
-#undef FORMAT
-
- la = snprintf(NULL, 0, "%s", "123");
- printf(" printf: %d\n", la);
- lb = xsnprintf(NULL, 0, "%s", "123");
- xprintf("xprintf: %d\n", lb);
- assert(la == lb);
-
- return 0;
-}