/branches/arm/kernel/test/avltree/avltree1.c |
---|
41,7 → 41,7 |
*/ |
static avltree_node_t avltree_nodes[NODE_COUNT]; |
/* |
/* |
* head of free nodes' list: |
*/ |
static avltree_node_t *first_free_node = NULL; |
58,11 → 58,11 |
if (!node) |
return NULL; |
if (node->lft) { |
tmp = test_tree_parents(node->lft); |
if (tmp != node) { |
printf("Bad parent pointer key: %" PRIu64 |
TPRINTF("Bad parent pointer key: %" PRIu64 |
", address: %p\n", tmp->key, node->lft); |
} |
} |
69,7 → 69,7 |
if (node->rgt) { |
tmp = test_tree_parents(node->rgt); |
if (tmp != node) { |
printf("Bad parent pointer key: %" PRIu64 |
TPRINTF("Bad parent pointer key: %" PRIu64 |
", address: %p\n", |
tmp->key,node->rgt); |
} |
80,49 → 80,50 |
int test_tree_balance(avltree_node_t *node) |
{ |
int h1, h2, diff; |
if (!node) |
return 0; |
h1 = test_tree_balance(node->lft); |
h2 = test_tree_balance(node->rgt); |
diff = h2 - h1; |
if (diff != node->balance || (diff != -1 && diff != 0 && diff != 1)) { |
printf("Bad balance\n"); |
} |
return h1 > h2 ? h1 + 1 : h2 + 1; |
if ((diff != node->balance) || ((diff != -1) && (diff != 0) && (diff != 1))) |
TPRINTF("Bad balance\n"); |
return ((h1 > h2) ? (h1 + 1) : (h2 + 1)); |
} |
/** |
* Prints the structure of the node, which is level levels from the top of the |
* tree. |
* tree. |
*/ |
static void |
print_tree_structure_flat(avltree_node_t *node, int level) |
static void print_tree_structure_flat(avltree_node_t *node, int level) |
{ |
/* |
* You can set the maximum level as high as you like. |
* Most of the time, you'll want to debug code using small trees, |
* so that a large level indicates a loop, which is a bug. |
* Most of the time, you'll want to debug code using small trees, |
* so that a large level indicates a loop, which is a bug. |
*/ |
if (level > 16) { |
printf("[...]"); |
TPRINTF("[...]"); |
return; |
} |
if (node == NULL) |
return; |
printf("%" PRIu64 "[%" PRIu8 "]", node->key, node->balance); |
TPRINTF("%" PRIu64 "[%" PRIu8 "]", node->key, node->balance); |
if (node->lft != NULL || node->rgt != NULL) { |
printf("("); |
TPRINTF("("); |
print_tree_structure_flat(node->lft, level + 1); |
if (node->rgt != NULL) { |
printf(","); |
TPRINTF(","); |
print_tree_structure_flat(node->rgt, level + 1); |
} |
printf(")"); |
TPRINTF(")"); |
} |
} |
129,10 → 130,10 |
static void alloc_avltree_node_prepare(void) |
{ |
int i; |
for (i = 0; i < NODE_COUNT - 1; i++) { |
for (i = 0; i < NODE_COUNT - 1; i++) |
avltree_nodes[i].par = &avltree_nodes[i + 1]; |
} |
avltree_nodes[i].par = NULL; |
/* |
139,37 → 140,44 |
* Node keys which will be used for insertion. Up to NODE_COUNT size of |
* array. |
*/ |
/* First tree node and same key */ |
avltree_nodes[0].key = 60; |
avltree_nodes[1].key = 60; |
avltree_nodes[2].key = 60; |
/* LL rotation */ |
avltree_nodes[3].key = 50; |
avltree_nodes[4].key = 40; |
avltree_nodes[5].key = 30; |
/* LR rotation */ |
avltree_nodes[6].key = 20; |
avltree_nodes[7].key = 20; |
avltree_nodes[8].key = 25; |
avltree_nodes[9].key = 25; |
/* LL rotation in lower floor */ |
avltree_nodes[10].key = 35; |
/* RR rotation */ |
avltree_nodes[11].key = 70; |
avltree_nodes[12].key = 80; |
/* RL rotation */ |
avltree_nodes[13].key = 90; |
avltree_nodes[14].key = 85; |
/* Insert 0 key */ |
avltree_nodes[15].key = 0; |
avltree_nodes[16].key = 0; |
/* Insert reverse */ |
avltree_nodes[17].key = 600; |
avltree_nodes[18].key = 500; |
avltree_nodes[19].key = 400; |
avltree_nodes[20].key = 300; |
for (i = 21; i < NODE_COUNT; i++) |
avltree_nodes[i].key = i * 3; |
179,40 → 187,35 |
static avltree_node_t *alloc_avltree_node(void) |
{ |
avltree_node_t *node; |
node = first_free_node; |
first_free_node = first_free_node->par; |
return node; |
} |
static void test_tree_insert(avltree_t *tree, count_t node_count, bool quiet) |
static void test_tree_insert(avltree_t *tree, size_t node_count) |
{ |
unsigned int i; |
avltree_node_t *newnode; |
avltree_create(tree); |
if (!quiet) |
printf("Inserting %" PRIc " nodes...", node_count); |
TPRINTF("Inserting %" PRIs " nodes...", node_count); |
for (i = 0; i < node_count; i++) { |
newnode = alloc_avltree_node(); |
avltree_insert(tree, newnode); |
if (!quiet) { |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
if (!quiet) |
printf("done.\n"); |
TPRINTF("done.\n"); |
} |
static void test_tree_delete(avltree_t *tree, count_t node_count, |
int node_position, bool quiet) |
static void test_tree_delete(avltree_t *tree, size_t node_count, |
int node_position) |
{ |
avltree_node_t *delnode; |
unsigned int i; |
219,71 → 222,61 |
switch (node_position) { |
case 0: |
if (!quiet) |
printf("Deleting root nodes..."); |
TPRINTF("Deleting root nodes..."); |
while (tree->root != NULL) { |
delnode = tree->root; |
avltree_delete(tree, delnode); |
if (!quiet) { |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
} |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
break; |
case 1: |
if (!quiet) |
printf("Deleting nodes according to creation time..."); |
TPRINTF("Deleting nodes according to creation time..."); |
for (i = 0; i < node_count; i++) { |
avltree_delete(tree, &avltree_nodes[i]); |
if (!quiet) { |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
break; |
break; |
} |
if (!quiet) |
printf("done.\n"); |
TPRINTF("done.\n"); |
} |
static void test_tree_delmin(avltree_t *tree, count_t node_count, bool quiet) |
static void test_tree_delmin(avltree_t *tree, size_t node_count) |
{ |
unsigned int i = 0; |
if (!quiet) |
printf("Deleting minimum nodes..."); |
TPRINTF("Deleting minimum nodes..."); |
while (tree->root != NULL) { |
i++; |
avltree_delete_min(tree); |
if (!quiet) { |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
test_tree_parents(tree->root); |
test_tree_balance(tree->root); |
} |
if (!quiet && (i != node_count)) |
printf("Bad node count. Some nodes have been lost!\n"); |
if (!quiet) |
printf("done.\n"); |
if (i != node_count) |
TPRINTF("Bad node count. Some nodes have been lost!\n"); |
TPRINTF("done.\n"); |
} |
char *test_avltree1(bool quiet) |
char *test_avltree1(void) |
{ |
alloc_avltree_node_prepare(); |
test_tree_insert(&avltree, NODE_COUNT, quiet); |
test_tree_delete(&avltree, NODE_COUNT, 0, quiet); |
test_tree_insert(&avltree, NODE_COUNT); |
test_tree_delete(&avltree, NODE_COUNT, 0); |
alloc_avltree_node_prepare(); |
test_tree_insert(&avltree, NODE_COUNT, quiet); |
test_tree_delete(&avltree, NODE_COUNT, 1, quiet); |
test_tree_insert(&avltree, NODE_COUNT); |
test_tree_delete(&avltree, NODE_COUNT, 1); |
alloc_avltree_node_prepare(); |
test_tree_insert(&avltree, NODE_COUNT, quiet); |
test_tree_delmin(&avltree, NODE_COUNT, quiet); |
test_tree_insert(&avltree, NODE_COUNT); |
test_tree_delmin(&avltree, NODE_COUNT); |
return NULL; |
} |
/branches/arm/kernel/test/avltree/avltree1.def |
---|
1,6 → 1,6 |
{ |
"avltree1", |
"Test Avl tree operations", |
"Test AVL tree operations", |
&test_avltree1, |
true |
}, |
/branches/arm/kernel/test/synch/rwlock4.c |
---|
40,13 → 40,12 |
#include <synch/synch.h> |
#include <synch/spinlock.h> |
#define READERS 50 |
#define WRITERS 50 |
#define READERS 50 |
#define WRITERS 50 |
static atomic_t thread_count; |
static rwlock_t rwlock; |
static atomic_t threads_fault; |
static bool sh_quiet; |
SPINLOCK_INITIALIZE(rw_lock); |
57,10 → 56,10 |
static uint32_t random(uint32_t max) |
{ |
uint32_t rc; |
spinlock_lock(&rw_lock); |
spinlock_lock(&rw_lock); |
rc = seed % max; |
seed = (((seed<<2) ^ (seed>>2)) * 487) + rc; |
seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc; |
spinlock_unlock(&rw_lock); |
return rc; |
} |
70,43 → 69,39 |
int rc, to; |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
to = random(40000); |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); |
TPRINTF("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); |
rc = rwlock_write_lock_timeout(&rwlock, to); |
if (SYNCH_FAILED(rc)) { |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); |
atomic_dec(&thread_count); |
return; |
} |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); |
if (rwlock.readers_in) { |
if (!sh_quiet) |
printf("Oops."); |
TPRINTF("Oops.\n"); |
atomic_inc(&threads_fault); |
atomic_dec(&thread_count); |
return; |
} |
thread_usleep(random(1000000)); |
if (rwlock.readers_in) { |
if (!sh_quiet) |
printf("Oops."); |
TPRINTF("Oops.\n"); |
atomic_inc(&threads_fault); |
atomic_dec(&thread_count); |
return; |
} |
rwlock_write_unlock(&rwlock); |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); |
atomic_dec(&thread_count); |
} |
118,33 → 113,28 |
to = random(2000); |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); |
TPRINTF("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); |
rc = rwlock_read_lock_timeout(&rwlock, to); |
if (SYNCH_FAILED(rc)) { |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); |
atomic_dec(&thread_count); |
return; |
} |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); |
thread_usleep(30000); |
rwlock_read_unlock(&rwlock); |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); |
atomic_dec(&thread_count); |
} |
char * test_rwlock4(bool quiet) |
char *test_rwlock4(void) |
{ |
context_t ctx; |
uint32_t i; |
sh_quiet = quiet; |
waitq_initialize(&can_start); |
rwlock_initialize(&rwlock); |
158,28 → 148,25 |
thread_t *thrd; |
context_save(&ctx); |
if (!quiet) { |
printf("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in); |
printf("Creating %" PRIu32 " readers\n", rd); |
} |
TPRINTF("sp=%#x, readers_in=%" PRIs "\n", ctx.sp, rwlock.readers_in); |
TPRINTF("Creating %" PRIu32 " readers\n", rd); |
for (i = 0; i < rd; i++) { |
thrd = thread_create(reader, NULL, TASK, 0, "reader", false); |
if (thrd) |
thread_ready(thrd); |
else if (!quiet) |
printf("Could not create reader %" PRIu32 "\n", i); |
else |
TPRINTF("Could not create reader %" PRIu32 "\n", i); |
} |
if (!quiet) |
printf("Creating %" PRIu32 " writers\n", wr); |
TPRINTF("Creating %" PRIu32 " writers\n", wr); |
for (i = 0; i < wr; i++) { |
thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
if (thrd) |
thread_ready(thrd); |
else if (!quiet) |
printf("Could not create writer %" PRIu32 "\n", i); |
else |
TPRINTF("Could not create writer %" PRIu32 "\n", i); |
} |
thread_usleep(20000); |
186,8 → 173,7 |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while (atomic_get(&thread_count) > 0) { |
if (!quiet) |
printf("Threads left: %ld\n", atomic_get(&thread_count)); |
TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); |
thread_sleep(1); |
} |
/branches/arm/kernel/test/synch/rwlock1.c |
---|
35,39 → 35,39 |
#include <synch/waitq.h> |
#include <synch/rwlock.h> |
#define READERS 50 |
#define WRITERS 50 |
#define READERS 50 |
#define WRITERS 50 |
static rwlock_t rwlock; |
char * test_rwlock1(bool quiet) |
char *test_rwlock1(void) |
{ |
rwlock_initialize(&rwlock); |
rwlock_write_lock(&rwlock); |
rwlock_write_unlock(&rwlock); |
rwlock_write_unlock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_write_lock(&rwlock); |
rwlock_write_unlock(&rwlock); |
rwlock_write_unlock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_write_lock(&rwlock); |
rwlock_write_unlock(&rwlock); |
rwlock_write_unlock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_unlock(&rwlock); |
/branches/arm/kernel/test/synch/rwlock2.c |
---|
34,38 → 34,34 |
#include <synch/rwlock.h> |
#define READERS 50 |
#define WRITERS 50 |
#define READERS 50 |
#define WRITERS 50 |
static rwlock_t rwlock; |
static bool sh_quiet; |
static void writer(void *arg) |
{ |
if (!sh_quiet) |
printf("Trying to lock rwlock for writing....\n"); |
TPRINTF("Trying to lock rwlock for writing....\n"); |
rwlock_write_lock(&rwlock); |
rwlock_write_unlock(&rwlock); |
if (!sh_quiet) |
printf("Trying to lock rwlock for reading....\n"); |
TPRINTF("Trying to lock rwlock for reading....\n"); |
rwlock_read_lock(&rwlock); |
rwlock_read_unlock(&rwlock); |
rwlock_read_unlock(&rwlock); |
} |
char * test_rwlock2(bool quiet) |
char *test_rwlock2(void) |
{ |
thread_t *thrd; |
sh_quiet = quiet; |
rwlock_initialize(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
rwlock_read_lock(&rwlock); |
thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
if (thrd) |
72,7 → 68,7 |
thread_ready(thrd); |
else |
return "Could not create thread"; |
thread_sleep(1); |
rwlock_read_unlock(&rwlock); |
/branches/arm/kernel/test/synch/rwlock3.c |
---|
34,41 → 34,35 |
#include <synch/rwlock.h> |
#define THREADS 4 |
#define THREADS 4 |
static atomic_t thread_count; |
static rwlock_t rwlock; |
static bool sh_quiet; |
static void reader(void *arg) |
{ |
thread_detach(THREAD); |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 ": trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 ": trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); |
rwlock_read_lock(&rwlock); |
rwlock_read_unlock(&rwlock); |
if (!sh_quiet) { |
printf("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); |
printf("cpu%u, tid %" PRIu64 ": trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); |
} |
TPRINTF("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 ": trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); |
rwlock_write_lock(&rwlock); |
rwlock_write_unlock(&rwlock); |
if (!sh_quiet) |
printf("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); |
atomic_dec(&thread_count); |
} |
char * test_rwlock3(bool quiet) |
char *test_rwlock3(void) |
{ |
int i; |
thread_t *thrd; |
sh_quiet = quiet; |
atomic_set(&thread_count, THREADS); |
79,16 → 73,15 |
thrd = thread_create(reader, NULL, TASK, 0, "reader", false); |
if (thrd) |
thread_ready(thrd); |
else if (!quiet) |
printf("Could not create reader %d\n", i); |
else |
TPRINTF("Could not create reader %d\n", i); |
} |
thread_sleep(1); |
rwlock_write_unlock(&rwlock); |
while (atomic_get(&thread_count) > 0) { |
if (!quiet) |
printf("Threads left: %ld\n", atomic_get(&thread_count)); |
TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); |
thread_sleep(1); |
} |
/branches/arm/kernel/test/synch/semaphore1.c |
---|
35,9 → 35,9 |
#include <synch/waitq.h> |
#include <synch/semaphore.h> |
#define AT_ONCE 3 |
#define PRODUCERS 50 |
#define CONSUMERS 50 |
#define AT_ONCE 3 |
#define PRODUCERS 50 |
#define CONSUMERS 50 |
static semaphore_t sem; |
47,10 → 47,10 |
static void producer(void *arg) |
{ |
thread_detach(THREAD); |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
semaphore_down(&sem); |
atomic_inc(&items_produced); |
thread_usleep(250); |
59,7 → 59,7 |
static void consumer(void *arg) |
{ |
thread_detach(THREAD); |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
69,7 → 69,7 |
semaphore_up(&sem); |
} |
char * test_semaphore1(bool quiet) |
char *test_semaphore1(void) |
{ |
int i, j, k; |
int consumers, producers; |
76,10 → 76,10 |
waitq_initialize(&can_start); |
semaphore_initialize(&sem, AT_ONCE); |
for (i = 1; i <= 3; i++) { |
thread_t *thrd; |
atomic_set(&items_produced, 0); |
atomic_set(&items_consumed, 0); |
86,8 → 86,8 |
consumers = i * CONSUMERS; |
producers = (4 - i) * PRODUCERS; |
printf("Creating %d consumers and %d producers...", consumers, producers); |
TPRINTF("Creating %d consumers and %d producers...", consumers, producers); |
for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) { |
for (k = 0; k < i; k++) { |
thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false); |
94,7 → 94,7 |
if (thrd) |
thread_ready(thrd); |
else |
printf("could not create consumer %d\n", i); |
TPRINTF("could not create consumer %d\n", i); |
} |
for (k = 0; k < (4 - i); k++) { |
thrd = thread_create(producer, NULL, TASK, 0, "producer", false); |
101,17 → 101,17 |
if (thrd) |
thread_ready(thrd); |
else |
printf("could not create producer %d\n", i); |
TPRINTF("could not create producer %d\n", i); |
} |
} |
printf("ok\n"); |
TPRINTF("ok\n"); |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while ((items_consumed.count != consumers) || (items_produced.count != producers)) { |
printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); |
TPRINTF("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); |
thread_sleep(1); |
} |
} |
/branches/arm/kernel/test/synch/semaphore2.c |
---|
50,10 → 50,10 |
static uint32_t random(uint32_t max) |
{ |
uint32_t rc; |
spinlock_lock(&sem_lock); |
spinlock_lock(&sem_lock); |
rc = seed % max; |
seed = (((seed<<2) ^ (seed>>2)) * 487) + rc; |
seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc; |
spinlock_unlock(&sem_lock); |
return rc; |
} |
67,21 → 67,21 |
waitq_sleep(&can_start); |
to = random(20000); |
printf("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to); |
TPRINTF("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to); |
rc = semaphore_down_timeout(&sem, to); |
if (SYNCH_FAILED(rc)) { |
printf("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid); |
return; |
} |
printf("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid); |
thread_usleep(random(30000)); |
semaphore_up(&sem); |
printf("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid); |
TPRINTF("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid); |
} |
char * test_semaphore2(bool quiet) |
char *test_semaphore2(void) |
{ |
uint32_t i, k; |
91,13 → 91,13 |
thread_t *thrd; |
k = random(7) + 1; |
printf("Creating %" PRIu32 " consumers\n", k); |
TPRINTF("Creating %" PRIu32 " consumers\n", k); |
for (i = 0; i < k; i++) { |
thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false); |
if (thrd) |
thread_ready(thrd); |
else |
printf("Error creating thread\n"); |
TPRINTF("Error creating thread\n"); |
} |
thread_usleep(20000); |
/branches/arm/kernel/test/synch/rwlock5.c |
---|
35,8 → 35,8 |
#include <synch/waitq.h> |
#include <synch/rwlock.h> |
#define READERS 50 |
#define WRITERS 50 |
#define READERS 50 |
#define WRITERS 50 |
static rwlock_t rwlock; |
47,9 → 47,9 |
static void writer(void *arg) |
{ |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
rwlock_write_lock(&rwlock); |
atomic_inc(&items_written); |
rwlock_write_unlock(&rwlock); |
58,7 → 58,7 |
static void reader(void *arg) |
{ |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
rwlock_read_lock(&rwlock); |
66,7 → 66,7 |
rwlock_read_unlock(&rwlock); |
} |
char * test_rwlock5(bool quiet) |
char *test_rwlock5(void) |
{ |
int i, j, k; |
long readers, writers; |
76,15 → 76,15 |
for (i = 1; i <= 3; i++) { |
thread_t *thrd; |
atomic_set(&items_read, 0); |
atomic_set(&items_written, 0); |
readers = i * READERS; |
writers = (4 - i) * WRITERS; |
printf("Creating %ld readers and %ld writers...", readers, writers); |
TPRINTF("Creating %ld readers and %ld writers...", readers, writers); |
for (j = 0; j < (READERS + WRITERS) / 2; j++) { |
for (k = 0; k < i; k++) { |
thrd = thread_create(reader, NULL, TASK, 0, "reader", false); |
91,7 → 91,7 |
if (thrd) |
thread_ready(thrd); |
else |
printf("Could not create reader %d\n", k); |
TPRINTF("Could not create reader %d\n", k); |
} |
for (k = 0; k < (4 - i); k++) { |
thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
98,17 → 98,17 |
if (thrd) |
thread_ready(thrd); |
else |
printf("Could not create writer %d\n", k); |
TPRINTF("Could not create writer %d\n", k); |
} |
} |
printf("ok\n"); |
TPRINTF("ok\n"); |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while ((items_read.count != readers) || (items_written.count != writers)) { |
printf("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in); |
TPRINTF("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in); |
thread_usleep(100000); |
} |
} |
/branches/arm/kernel/test/mm/falloc2.c |
---|
39,26 → 39,24 |
#include <memstr.h> |
#include <arch.h> |
#define MAX_FRAMES 256 |
#define MAX_ORDER 8 |
#define MAX_FRAMES 256 |
#define MAX_ORDER 8 |
#define THREAD_RUNS 1 |
#define THREADS 8 |
#define THREAD_RUNS 1 |
#define THREADS 8 |
static atomic_t thread_count; |
static atomic_t thread_fail; |
static bool sh_quiet; |
static void falloc(void * arg) |
static void falloc(void *arg) |
{ |
int order, run, allocated, i; |
uint8_t val = THREAD->tid % THREADS; |
index_t k; |
size_t k; |
void **frames = (void **) malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC); |
if (frames == NULL) { |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id); |
atomic_inc(&thread_fail); |
atomic_dec(&thread_count); |
return; |
65,11 → 63,10 |
} |
thread_detach(THREAD); |
for (run = 0; run < THREAD_RUNS; run++) { |
for (order = 0; order <= MAX_ORDER; order++) { |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); |
allocated = 0; |
for (i = 0; i < (MAX_FRAMES >> order); i++) { |
81,17 → 78,13 |
break; |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id); |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id); |
for (i = 0; i < allocated; i++) { |
for (k = 0; k <= (((index_t) FRAME_SIZE << order) - 1); k++) { |
for (k = 0; k <= (((size_t) FRAME_SIZE << order) - 1); k++) { |
if (((uint8_t *) frames[i])[k] != val) { |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Unexpected data (%c) in block %p offset %#" PRIi "\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Unexpected data (%c) in block %p offset %#" PRIs "\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); |
atomic_inc(&thread_fail); |
goto cleanup; |
} |
99,32 → 92,28 |
frame_free(KA2PA(frames[i])); |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id); |
} |
} |
cleanup: |
cleanup: |
free(frames); |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id); |
TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id); |
atomic_dec(&thread_count); |
} |
char * test_falloc2(bool quiet) |
char *test_falloc2(void) |
{ |
unsigned int i; |
sh_quiet = quiet; |
atomic_set(&thread_count, THREADS); |
atomic_set(&thread_fail, 0); |
for (i = 0; i < THREADS; i++) { |
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false); |
if (!thrd) { |
if (!quiet) |
printf("Could not create thread %u\n", i); |
TPRINTF("Could not create thread %u\n", i); |
break; |
} |
thread_ready(thrd); |
131,8 → 120,7 |
} |
while (atomic_get(&thread_count) > 0) { |
if (!quiet) |
printf("Threads left: %ld\n", atomic_get(&thread_count)); |
TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); |
thread_sleep(1); |
} |
/branches/arm/kernel/test/mm/purge1.c |
---|
26,8 → 26,6 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifdef ia64 |
#include <print.h> |
#include <test.h> |
#include <mm/page.h> |
39,18 → 37,18 |
#include <debug.h> |
extern void tlb_invalidate_all(void); |
extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt); |
extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, size_t cnt); |
char * test_purge1(bool quiet) |
char *test_purge1(void) |
{ |
tlb_entry_t entryi; |
tlb_entry_t entryd; |
int i; |
entryd.word[0] = 0; |
entryd.word[1] = 0; |
entryd.p = true; /* present */ |
entryd.ma = MA_WRITEBACK; |
entryd.a = true; /* already accessed */ |
77,11 → 75,9 |
dtc_mapping_insert(0 + i * (1 << PAGE_WIDTH), 9, entryd); |
} |
tlb_invalidate_pages(8,0x0c000,14); |
tlb_invalidate_pages(8, 0x0c000, 14); |
/*tlb_invalidate_all();*/ |
/* tlb_invalidate_all(); */ |
return NULL; |
} |
#endif |
/branches/arm/kernel/test/mm/slab2.c |
---|
36,18 → 36,18 |
#include <synch/condvar.h> |
#include <synch/mutex.h> |
#define ITEM_SIZE 256 |
#define ITEM_SIZE 256 |
/** Fill memory with 2 caches, when allocation fails, |
* free one of the caches. We should have everything in magazines, |
* now allocation should clean magazines and allow for full allocation. |
*/ |
static void totalmemtest(bool quiet) |
static void totalmemtest(void) |
{ |
slab_cache_t *cache1; |
slab_cache_t *cache2; |
int i; |
void *data1, *data2; |
void *olddata1 = NULL, *olddata2 = NULL; |
54,8 → 54,7 |
cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
if (!quiet) |
printf("Allocating..."); |
TPRINTF("Allocating..."); |
/* Use atomic alloc, so that we find end of memory */ |
do { |
74,13 → 73,12 |
*((void **) data2) = olddata2; |
olddata1 = data1; |
olddata2 = data2; |
} while (1); |
} while (true); |
if (!quiet) { |
printf("done.\n"); |
printf("Deallocating cache2..."); |
} |
TPRINTF("done.\n"); |
TPRINTF("Deallocating cache2..."); |
/* We do not have memory - now deallocate cache2 */ |
while (olddata2) { |
data2 = *((void **) olddata2); |
88,16 → 86,14 |
olddata2 = data2; |
} |
if (!quiet) { |
printf("done.\n"); |
printf("Allocating to cache1...\n"); |
} |
TPRINTF("done.\n"); |
TPRINTF("Allocating to cache1...\n"); |
for (i = 0; i < 30; i++) { |
data1 = slab_alloc(cache1, FRAME_ATOMIC); |
if (!data1) { |
if (!quiet) |
printf("Incorrect memory size - use another test."); |
TPRINTF("Incorrect memory size - use another test."); |
return; |
} |
memsetb(data1, ITEM_SIZE, 0); |
104,7 → 100,7 |
*((void **) data1) = olddata1; |
olddata1 = data1; |
} |
while (1) { |
while (true) { |
data1 = slab_alloc(cache1, FRAME_ATOMIC); |
if (!data1) |
break; |
113,8 → 109,7 |
olddata1 = data1; |
} |
if (!quiet) |
printf("Deallocating cache1..."); |
TPRINTF("Deallocating cache1..."); |
while (olddata1) { |
data1 = *((void **) olddata1); |
122,10 → 117,10 |
olddata1 = data1; |
} |
if (!quiet) { |
printf("done.\n"); |
TPRINTF("done.\n"); |
if (!test_quiet) |
slab_print_list(); |
} |
slab_cache_destroy(cache1); |
slab_cache_destroy(cache2); |
135,9 → 130,8 |
static semaphore_t thr_sem; |
static condvar_t thread_starter; |
static mutex_t starter_mutex; |
static bool sh_quiet; |
#define THREADS 8 |
#define THREADS 8 |
static void slabtest(void *priv) |
{ |
149,14 → 143,12 |
condvar_wait(&thread_starter,&starter_mutex); |
mutex_unlock(&starter_mutex); |
if (!sh_quiet) |
printf("Starting thread #%" PRIu64 "...\n", THREAD->tid); |
TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); |
/* Alloc all */ |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid); |
TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); |
while (1) { |
while (true) { |
/* Call with atomic to detect end of memory */ |
new = slab_alloc(thr_cache, FRAME_ATOMIC); |
if (!new) |
165,8 → 157,7 |
data = new; |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid); |
TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); |
while (data) { |
new = *((void **)data); |
175,10 → 166,9 |
data = new; |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid); |
TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); |
while (1) { |
while (true) { |
/* Call with atomic to detect end of memory */ |
new = slab_alloc(thr_cache, FRAME_ATOMIC); |
if (!new) |
187,8 → 177,7 |
data = new; |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid); |
TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); |
while (data) { |
new = *((void **)data); |
197,14 → 186,15 |
data = new; |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " finished\n", THREAD->tid); |
TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); |
slab_print_list(); |
if (!test_quiet) |
slab_print_list(); |
semaphore_up(&thr_sem); |
} |
static void multitest(int size, bool quiet) |
static void multitest(int size) |
{ |
/* Start 8 threads that just allocate as much as possible, |
* then release everything, then again allocate, then release |
212,48 → 202,42 |
thread_t *t; |
int i; |
if (!quiet) |
printf("Running stress test with size %d\n", size); |
TPRINTF("Running stress test with size %d\n", size); |
condvar_initialize(&thread_starter); |
mutex_initialize(&starter_mutex, MUTEX_PASSIVE); |
thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); |
semaphore_initialize(&thr_sem,0); |
for (i = 0; i < THREADS; i++) { |
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) { |
if (!quiet) |
printf("Could not create thread %d\n", i); |
TPRINTF("Could not create thread %d\n", i); |
} else |
thread_ready(t); |
} |
thread_sleep(1); |
condvar_broadcast(&thread_starter); |
for (i = 0; i < THREADS; i++) |
semaphore_down(&thr_sem); |
slab_cache_destroy(thr_cache); |
if (!quiet) |
printf("Stress test complete.\n"); |
TPRINTF("Stress test complete.\n"); |
} |
char * test_slab2(bool quiet) |
char *test_slab2(void) |
{ |
sh_quiet = quiet; |
TPRINTF("Running reclaim single-thread test .. pass 1\n"); |
totalmemtest(); |
if (!quiet) |
printf("Running reclaim single-thread test .. pass 1\n"); |
totalmemtest(quiet); |
if (!quiet) |
printf("Running reclaim single-thread test .. pass 2\n"); |
totalmemtest(quiet); |
if (!quiet) |
printf("Reclaim test OK.\n"); |
TPRINTF("Running reclaim single-thread test .. pass 2\n"); |
totalmemtest(); |
multitest(128, quiet); |
multitest(2048, quiet); |
multitest(8192, quiet); |
TPRINTF("Reclaim test OK.\n"); |
multitest(128); |
multitest(2048); |
multitest(8192); |
return NULL; |
} |
/branches/arm/kernel/test/mm/falloc1.c |
---|
36,12 → 36,13 |
#include <debug.h> |
#include <align.h> |
#define MAX_FRAMES 1024 |
#define MAX_ORDER 8 |
#define TEST_RUNS 2 |
#define MAX_FRAMES 1024 |
#define MAX_ORDER 8 |
#define TEST_RUNS 2 |
char * test_falloc1(bool quiet) { |
uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0); |
char *test_falloc1(void) { |
uintptr_t *frames |
= (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0); |
int results[MAX_ORDER + 1]; |
int i, order, run; |
52,11 → 53,10 |
if (frames == NULL) |
return "Unable to allocate frames"; |
for (run = 0; run < TEST_RUNS; run++) { |
for (order = 0; order <= MAX_ORDER; order++) { |
if (!quiet) |
printf("Allocating %d frames blocks ... ", 1 << order); |
TPRINTF("Allocating %d frames blocks ... ", 1 << order); |
allocated = 0; |
for (i = 0; i < MAX_FRAMES >> order; i++) { |
63,8 → 63,7 |
frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { |
if (!quiet) |
printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); |
TPRINTF("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); |
return "Test failed"; |
} |
71,15 → 70,13 |
if (frames[allocated]) |
allocated++; |
else { |
if (!quiet) |
printf("done. "); |
TPRINTF("done. "); |
break; |
} |
} |
if (!quiet) |
printf("%d blocks allocated.\n", allocated); |
TPRINTF("%d blocks allocated.\n", allocated); |
if (run) { |
if (results[order] != allocated) |
return "Possible frame leak"; |
86,17 → 83,15 |
} else |
results[order] = allocated; |
if (!quiet) |
printf("Deallocating ... "); |
TPRINTF("Deallocating ... "); |
for (i = 0; i < allocated; i++) |
frame_free(KA2PA(frames[i])); |
if (!quiet) |
printf("done.\n"); |
TPRINTF("done.\n"); |
} |
} |
free(frames); |
return NULL; |
/branches/arm/kernel/test/mm/slab1.c |
---|
33,23 → 33,21 |
#include <arch.h> |
#include <memstr.h> |
#define VAL_COUNT 1024 |
#define VAL_COUNT 1024 |
static void * data[VAL_COUNT]; |
static void *data[VAL_COUNT]; |
static void testit(int size, int count, bool quiet) |
static void testit(int size, int count) |
{ |
slab_cache_t *cache; |
int i; |
if (!quiet) |
printf("Creating cache, object size: %d.\n", size); |
TPRINTF("Creating cache, object size: %d.\n", size); |
cache = slab_cache_create("test_cache", size, 0, NULL, NULL, |
SLAB_CACHE_NOMAGAZINE); |
SLAB_CACHE_NOMAGAZINE); |
if (!quiet) |
printf("Allocating %d items...", count); |
TPRINTF("Allocating %d items...", count); |
for (i = 0; i < count; i++) { |
data[i] = slab_alloc(cache, 0); |
56,78 → 54,71 |
memsetb(data[i], size, 0); |
} |
if (!quiet) { |
printf("done.\n"); |
printf("Freeing %d items...", count); |
} |
TPRINTF("done.\n"); |
TPRINTF("Freeing %d items...", count); |
for (i = 0; i < count; i++) |
slab_free(cache, data[i]); |
if (!quiet) { |
printf("done.\n"); |
printf("Allocating %d items...", count); |
} |
TPRINTF("done.\n"); |
TPRINTF("Allocating %d items...", count); |
for (i = 0; i < count; i++) { |
data[i] = slab_alloc(cache, 0); |
memsetb(data[i], size, 0); |
} |
if (!quiet) { |
printf("done.\n"); |
printf("Freeing %d items...", count / 2); |
} |
TPRINTF("done.\n"); |
TPRINTF("Freeing %d items...", count / 2); |
for (i = count - 1; i >= count / 2; i--) |
slab_free(cache, data[i]); |
if (!quiet) { |
printf("done.\n"); |
printf("Allocating %d items...", count / 2); |
} |
TPRINTF("done.\n"); |
TPRINTF("Allocating %d items...", count / 2); |
for (i = count / 2; i < count; i++) { |
data[i] = slab_alloc(cache, 0); |
memsetb(data[i], size, 0); |
} |
if (!quiet) { |
printf("done.\n"); |
printf("Freeing %d items...", count); |
} |
TPRINTF("done.\n"); |
TPRINTF("Freeing %d items...", count); |
for (i = 0; i < count; i++) |
slab_free(cache, data[i]); |
if (!quiet) |
printf("done.\n"); |
TPRINTF("done.\n"); |
slab_cache_destroy(cache); |
if (!quiet) |
printf("Test complete.\n"); |
TPRINTF("Test complete.\n"); |
} |
static void testsimple(bool quiet) |
static void testsimple(void) |
{ |
testit(100, VAL_COUNT, quiet); |
testit(200, VAL_COUNT, quiet); |
testit(1024, VAL_COUNT, quiet); |
testit(2048, 512, quiet); |
testit(4000, 128, quiet); |
testit(8192, 128, quiet); |
testit(16384, 128, quiet); |
testit(16385, 128, quiet); |
testit(100, VAL_COUNT); |
testit(200, VAL_COUNT); |
testit(1024, VAL_COUNT); |
testit(2048, 512); |
testit(4000, 128); |
testit(8192, 128); |
testit(16384, 128); |
testit(16385, 128); |
} |
#define THREADS 6 |
#define THR_MEM_COUNT 1024 |
#define THR_MEM_SIZE 128 |
#define THREADS 6 |
#define THR_MEM_COUNT 1024 |
#define THR_MEM_SIZE 128 |
static void * thr_data[THREADS][THR_MEM_COUNT]; |
static void *thr_data[THREADS][THR_MEM_COUNT]; |
static slab_cache_t *thr_cache; |
static semaphore_t thr_sem; |
static bool sh_quiet; |
static void slabtest(void *data) |
{ |
136,8 → 127,7 |
thread_detach(THREAD); |
if (!sh_quiet) |
printf("Starting thread #%" PRIu64 "...\n", THREAD->tid); |
TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); |
for (j = 0; j < 10; j++) { |
for (i = 0; i < THR_MEM_COUNT; i++) |
150,24 → 140,23 |
slab_free(thr_cache, thr_data[offs][i]); |
} |
if (!sh_quiet) |
printf("Thread #%" PRIu64 " finished\n", THREAD->tid); |
TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); |
semaphore_up(&thr_sem); |
} |
static void testthreads(bool quiet) |
static void testthreads(void) |
{ |
thread_t *t; |
int i; |
thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, |
SLAB_CACHE_NOMAGAZINE); |
SLAB_CACHE_NOMAGAZINE); |
semaphore_initialize(&thr_sem, 0); |
for (i = 0; i < THREADS; i++) { |
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { |
if (!quiet) |
printf("Could not create thread %d\n", i); |
TPRINTF("Could not create thread %d\n", i); |
} else |
thread_ready(t); |
} |
177,16 → 166,13 |
slab_cache_destroy(thr_cache); |
if (!quiet) |
printf("Test complete.\n"); |
TPRINTF("Test complete.\n"); |
} |
char * test_slab1(bool quiet) |
char *test_slab1(void) |
{ |
sh_quiet = quiet; |
testsimple(); |
testthreads(); |
testsimple(quiet); |
testthreads(quiet); |
return NULL; |
} |
/branches/arm/kernel/test/mm/purge1_skip.c |
---|
0,0 → 1,34 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <test.h> |
char *test_purge1(void) |
{ |
return NULL; |
} |
/branches/arm/kernel/test/mm/mapping1.c |
---|
35,40 → 35,36 |
#include <arch/types.h> |
#include <debug.h> |
#define PAGE0 0x10000000 |
#define PAGE1 (PAGE0+PAGE_SIZE) |
#define PAGE0 0x10000000 |
#define PAGE1 (PAGE0 + PAGE_SIZE) |
#define VALUE0 0x01234567 |
#define VALUE1 0x89abcdef |
#define VALUE0 0x01234567 |
#define VALUE1 0x89abcdef |
char * test_mapping1(bool quiet) |
char *test_mapping1(void) |
{ |
uintptr_t frame0, frame1; |
uint32_t v0, v1; |
frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); |
frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); |
if (!quiet) |
printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); |
TPRINTF("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); |
*((uint32_t *) frame0) = VALUE0; |
if (!quiet) |
printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); |
TPRINTF("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); |
*((uint32_t *) frame1) = VALUE1; |
if (!quiet) |
printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); |
TPRINTF("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); |
page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); |
if (!quiet) |
printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); |
TPRINTF("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); |
page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); |
v0 = *((uint32_t *) PAGE0); |
v1 = *((uint32_t *) PAGE1); |
if (!quiet) { |
printf("Value at virtual address %p is %#x.\n", PAGE0, v0); |
printf("Value at virtual address %p is %#x.\n", PAGE1, v1); |
} |
TPRINTF("Value at virtual address %p is %#x.\n", PAGE0, v0); |
TPRINTF("Value at virtual address %p is %#x.\n", PAGE1, v1); |
if (v0 != VALUE0) |
return "Value at v0 not equal to VALUE0"; |
75,25 → 71,22 |
if (v1 != VALUE1) |
return "Value at v1 not equal to VALUE1"; |
if (!quiet) |
printf("Writing %#x to virtual address %p.\n", 0, PAGE0); |
TPRINTF("Writing %#x to virtual address %p.\n", 0, PAGE0); |
*((uint32_t *) PAGE0) = 0; |
if (!quiet) |
printf("Writing %#x to virtual address %p.\n", 0, PAGE1); |
*((uint32_t *) PAGE1) = 0; |
TPRINTF("Writing %#x to virtual address %p.\n", 0, PAGE1); |
*((uint32_t *) PAGE1) = 0; |
v0 = *((uint32_t *) PAGE0); |
v1 = *((uint32_t *) PAGE1); |
if (!quiet) { |
printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); |
printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); |
} |
TPRINTF("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); |
TPRINTF("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); |
if (v0 != 0) |
return "Value at v0 not equal to 0"; |
if (v1 != 0) |
return "Value at v1 not equal to 0"; |
return NULL; |
return NULL; |
} |
/branches/arm/kernel/test/mm/purge1.def |
---|
1,4 → 1,3 |
#ifdef ia64 |
{ |
"purge1", |
"Itanium TLB purge test", |
5,4 → 4,3 |
&test_purge1, |
true |
}, |
#endif |
/branches/arm/kernel/test/test.c |
---|
34,6 → 34,8 |
#include <test.h> |
bool test_quiet; |
test_t tests[] = { |
#include <atomic/atomic1.def> |
#include <avltree/avltree1.def> |
56,11 → 58,14 |
#include <synch/semaphore1.def> |
#include <synch/semaphore2.def> |
#include <print/print1.def> |
#include <print/print2.def> |
#include <print/print3.def> |
#include <print/print4.def> |
#include <thread/thread1.def> |
#include <sysinfo/sysinfo1.def> |
{ |
.name = NULL, |
.desc = NULL, |
.desc = NULL, |
.entry = NULL |
} |
}; |
/branches/arm/kernel/test/btree/btree1.c |
---|
33,15 → 33,14 |
static void *data = (void *) 0xdeadbeef; |
char * test_btree1(bool quiet) |
char *test_btree1(void) |
{ |
btree_t t; |
int i; |
btree_create(&t); |
if (!quiet) |
printf("Inserting keys.\n"); |
TPRINTF("Inserting keys.\n"); |
btree_insert(&t, 19, data, NULL); |
btree_insert(&t, 20, data, NULL); |
btree_insert(&t, 21, data, NULL); |
78,11 → 77,10 |
for (i = 100; i >= 50; i--) |
btree_insert(&t, i, data, NULL); |
if (!quiet) |
if (!test_quiet) |
btree_print(&t); |
if (!quiet) |
printf("Removing keys.\n"); |
TPRINTF("Removing keys.\n"); |
btree_remove(&t, 50, NULL); |
btree_remove(&t, 49, NULL); |
btree_remove(&t, 51, NULL); |
158,7 → 156,7 |
btree_remove(&t, 35, NULL); |
btree_remove(&t, 36, NULL); |
if (!quiet) |
if (!test_quiet) |
btree_print(&t); |
return NULL; |
/branches/arm/kernel/test/test.h |
---|
38,8 → 38,17 |
#include <arch/types.h> |
#include <typedefs.h> |
typedef char *(*test_entry_t)(bool); |
extern bool test_quiet; |
#define TPRINTF(format, ...) \ |
{ \ |
if (!test_quiet) { \ |
printf(format, ##__VA_ARGS__); \ |
} \ |
} |
typedef char *(*test_entry_t)(void); |
typedef struct { |
char *name; |
char *desc; |
47,30 → 56,33 |
bool safe; |
} test_t; |
extern char * test_atomic1(bool quiet); |
extern char * test_avltree1(bool quiet); |
extern char * test_btree1(bool quiet); |
extern char * test_mips1(bool quiet); |
extern char * test_fault1(bool quiet); |
extern char * test_fpu1(bool quiet); |
extern char * test_sse1(bool quiet); |
extern char * test_mips2(bool quiet); |
extern char * test_falloc1(bool quiet); |
extern char * test_falloc2(bool quiet); |
extern char * test_mapping1(bool quiet); |
extern char * test_purge1(bool quiet); |
extern char * test_slab1(bool quiet); |
extern char * test_slab2(bool quiet); |
extern char * test_rwlock1(bool quiet); |
extern char * test_rwlock2(bool quiet); |
extern char * test_rwlock3(bool quiet); |
extern char * test_rwlock4(bool quiet); |
extern char * test_rwlock5(bool quiet); |
extern char * test_semaphore1(bool quiet); |
extern char * test_semaphore2(bool quiet); |
extern char * test_print1(bool quiet); |
extern char * test_thread1(bool quiet); |
extern char * test_sysinfo1(bool quiet); |
extern char *test_atomic1(void); |
extern char *test_avltree1(void); |
extern char *test_btree1(void); |
extern char *test_mips1(void); |
extern char *test_fault1(void); |
extern char *test_fpu1(void); |
extern char *test_sse1(void); |
extern char *test_mips2(void); |
extern char *test_falloc1(void); |
extern char *test_falloc2(void); |
extern char *test_mapping1(void); |
extern char *test_purge1(void); |
extern char *test_slab1(void); |
extern char *test_slab2(void); |
extern char *test_rwlock1(void); |
extern char *test_rwlock2(void); |
extern char *test_rwlock3(void); |
extern char *test_rwlock4(void); |
extern char *test_rwlock5(void); |
extern char *test_semaphore1(void); |
extern char *test_semaphore2(void); |
extern char *test_print1(void); |
extern char *test_print2(void); |
extern char *test_print3(void); |
extern char *test_print4(void); |
extern char *test_thread1(void); |
extern char *test_sysinfo1(void); |
extern test_t tests[]; |
/branches/arm/kernel/test/debug/mips1_skip.c |
---|
0,0 → 1,34 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <test.h> |
char *test_mips1(void) |
{ |
return NULL; |
} |
/branches/arm/kernel/test/debug/mips1.c |
---|
25,8 → 25,6 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifdef mips32 |
#include <print.h> |
#include <debug.h> |
38,10 → 36,9 |
#include <arch.h> |
char * test_mips1(bool quiet) |
char *test_mips1(void) |
{ |
if (!quiet) |
printf("You should enter kconsole debug mode now.\n"); |
TPRINTF("If kconsole is compiled in, you should enter debug mode now.\n"); |
asm volatile ( |
"break\n" |
49,5 → 46,3 |
return "Back from debug mode"; |
} |
#endif |
/branches/arm/kernel/test/debug/mips1.def |
---|
1,4 → 1,3 |
#ifdef mips32 |
{ |
"mips1", |
"MIPS debug test", |
5,4 → 4,3 |
&test_mips1, |
false |
}, |
#endif |
/branches/arm/kernel/test/thread/thread1.c |
---|
36,37 → 36,33 |
#include <arch.h> |
#define THREADS 5 |
#define THREADS 5 |
static atomic_t finish; |
static atomic_t threads_finished; |
static bool sh_quiet; |
static void threadtest(void *data) |
{ |
thread_detach(THREAD); |
thread_detach(THREAD); |
while (atomic_get(&finish)) { |
if (!sh_quiet) |
printf("%" PRIu64 " ", THREAD->tid); |
TPRINTF("%" PRIu64 " ", THREAD->tid); |
thread_usleep(100000); |
} |
atomic_inc(&threads_finished); |
} |
char * test_thread1(bool quiet) |
char *test_thread1(void) |
{ |
unsigned int i, total = 0; |
sh_quiet = quiet; |
atomic_set(&finish, 1); |
atomic_set(&threads_finished, 0); |
for (i = 0; i < THREADS; i++) { |
thread_t *t; |
if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) { |
if (!quiet) |
printf("Could not create thread %d\n", i); |
TPRINTF("Could not create thread %d\n", i); |
break; |
} |
thread_ready(t); |
73,14 → 69,12 |
total++; |
} |
if (!quiet) |
printf("Running threads for 10 seconds...\n"); |
TPRINTF("Running threads for 10 seconds...\n"); |
thread_sleep(10); |
atomic_set(&finish, 0); |
while (atomic_get(&threads_finished) < ((long) total)) { |
if (!quiet) |
printf("Threads left: %d\n", total - atomic_get(&threads_finished)); |
TPRINTF("Threads left: %d\n", total - atomic_get(&threads_finished)); |
thread_sleep(1); |
} |
/branches/arm/kernel/test/fpu/fpu1.c |
---|
File deleted |
/branches/arm/kernel/test/fpu/fpu1_ia64.c |
---|
0,0 → 1,170 |
/* |
* Copyright (c) 2005 Jakub Vana |
* Copyright (c) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <print.h> |
#include <debug.h> |
#include <test.h> |
#include <atomic.h> |
#include <proc/thread.h> |
#include <arch.h> |
#include <arch/arch.h> |
#define THREADS 150 |
#define ATTEMPTS 100 |
#define E_10e8 271828182 |
#define PI_10e8 3141592 |
static inline long double sqrt(long double a) |
{ |
long double x = 1; |
long double lx = 0; |
if (a < 0.00000000000000001) |
return 0; |
while (x != lx) { |
lx = x; |
x = (x + (a / x)) / 2; |
} |
return x; |
} |
static atomic_t threads_ok; |
static atomic_t threads_fault; |
static waitq_t can_start; |
static void e(void *data) |
{ |
int i; |
double e, d, le, f; |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i<ATTEMPTS; i++) { |
le = -1; |
e = 0; |
f = 1; |
for (d = 1; e != le; d *= f, f += 1) { |
le = e; |
e = e + 1 / d; |
} |
if ((int) (100000000 * e) != E_10e8) { |
TPRINTF("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
atomic_inc(&threads_fault); |
break; |
} |
} |
atomic_inc(&threads_ok); |
} |
static void pi(void *data) |
{ |
int i; |
double lpi, pi; |
double n, ab, ad; |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i < ATTEMPTS; i++) { |
lpi = -1; |
pi = 0; |
for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
double sc, cd; |
sc = sqrt(1 - (ab * ab / 4)); |
cd = 1 - sc; |
ad = sqrt(ab * ab / 4 + cd * cd); |
lpi = pi; |
pi = 2 * n * ad; |
} |
if ((int) (1000000 * pi) != PI_10e8) { |
TPRINTF("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); |
atomic_inc(&threads_fault); |
break; |
} |
} |
atomic_inc(&threads_ok); |
} |
char *test_fpu1(void) |
{ |
unsigned int i, total = 0; |
waitq_initialize(&can_start); |
atomic_set(&threads_ok, 0); |
atomic_set(&threads_fault, 0); |
TPRINTF("Creating %u threads... ", 2 * THREADS); |
for (i = 0; i < THREADS; i++) { |
thread_t *t; |
if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
TPRINTF("could not create thread %u\n", 2 * i); |
break; |
} |
thread_ready(t); |
total++; |
if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { |
TPRINTF("could not create thread %u\n", 2 * i + 1); |
break; |
} |
thread_ready(t); |
total++; |
} |
TPRINTF("ok\n"); |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while (atomic_get(&threads_ok) != (long) total) { |
TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); |
thread_sleep(1); |
} |
if (atomic_get(&threads_fault) == 0) |
return NULL; |
return "Test failed"; |
} |
/branches/arm/kernel/test/fpu/fpu1_x86.c |
---|
0,0 → 1,167 |
/* |
* Copyright (c) 2005 Jakub Vana |
* Copyright (c) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <print.h> |
#include <debug.h> |
#include <test.h> |
#include <atomic.h> |
#include <proc/thread.h> |
#include <arch.h> |
#include <arch/arch.h> |
#define THREADS 150 |
#define ATTEMPTS 100 |
#define E_10e8 271828182 |
#define PI_10e8 314159265 |
static inline double sqrt(double x) |
{ |
double v; |
asm ( |
"fsqrt\n" |
: "=t" (v) |
: "0" (x) |
); |
return v; |
} |
static atomic_t threads_ok; |
static atomic_t threads_fault; |
static waitq_t can_start; |
static void e(void *data) |
{ |
int i; |
double e, d, le, f; |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i<ATTEMPTS; i++) { |
le = -1; |
e = 0; |
f = 1; |
for (d = 1; e != le; d *= f, f += 1) { |
le = e; |
e = e + 1 / d; |
} |
if ((int) (100000000 * e) != E_10e8) { |
TPRINTF("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
atomic_inc(&threads_fault); |
break; |
} |
} |
atomic_inc(&threads_ok); |
} |
static void pi(void *data) |
{ |
int i; |
double lpi, pi; |
double n, ab, ad; |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i < ATTEMPTS; i++) { |
lpi = -1; |
pi = 0; |
for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
double sc, cd; |
sc = sqrt(1 - (ab * ab / 4)); |
cd = 1 - sc; |
ad = sqrt(ab * ab / 4 + cd * cd); |
lpi = pi; |
pi = 2 * n * ad; |
} |
if ((int) (100000000 * pi) != PI_10e8) { |
TPRINTF("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); |
atomic_inc(&threads_fault); |
break; |
} |
} |
atomic_inc(&threads_ok); |
} |
char *test_fpu1(void) |
{ |
unsigned int i, total = 0; |
waitq_initialize(&can_start); |
atomic_set(&threads_ok, 0); |
atomic_set(&threads_fault, 0); |
TPRINTF("Creating %u threads... ", 2 * THREADS); |
for (i = 0; i < THREADS; i++) { |
thread_t *t; |
if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
TPRINTF("could not create thread %u\n", 2 * i); |
break; |
} |
thread_ready(t); |
total++; |
if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { |
TPRINTF("could not create thread %u\n", 2 * i + 1); |
break; |
} |
thread_ready(t); |
total++; |
} |
TPRINTF("ok\n"); |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while (atomic_get(&threads_ok) != (long) total) { |
TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); |
thread_sleep(1); |
} |
if (atomic_get(&threads_fault) == 0) |
return NULL; |
return "Test failed"; |
} |
/branches/arm/kernel/test/fpu/mips2_skip.c |
---|
0,0 → 1,34 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <test.h> |
char *test_mips2(void) |
{ |
return NULL; |
} |
/branches/arm/kernel/test/fpu/fpu1_skip.c |
---|
0,0 → 1,34 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <test.h> |
char *test_fpu1(void) |
{ |
return NULL; |
} |
/branches/arm/kernel/test/fpu/sse1_skip.c |
---|
0,0 → 1,34 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <test.h> |
char *test_sse1(void) |
{ |
return NULL; |
} |
/branches/arm/kernel/test/fpu/mips2.c |
---|
26,8 → 26,6 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifdef mips32 |
#include <print.h> |
#include <debug.h> |
38,14 → 36,13 |
#include <arch.h> |
#define THREADS 50 |
#define DELAY 10000L |
#define ATTEMPTS 5 |
#define THREADS 50 |
#define DELAY 10000L |
#define ATTEMPTS 5 |
static atomic_t threads_ok; |
static atomic_t threads_fault; |
static waitq_t can_start; |
static bool sh_quiet; |
static void testit1(void *data) |
{ |
56,7 → 53,7 |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i < ATTEMPTS; i++) { |
asm volatile ( |
"mtc1 %0,$1" |
71,8 → 68,7 |
); |
if (arg != after_arg) { |
if (!sh_quiet) |
printf("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
atomic_inc(&threads_fault); |
break; |
} |
89,13 → 85,13 |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i < ATTEMPTS; i++) { |
asm volatile ( |
"mtc1 %0,$1" |
: "=r" (arg) |
); |
scheduler(); |
asm volatile ( |
"mfc1 %0,$1" |
103,8 → 99,7 |
); |
if (arg != after_arg) { |
if (!sh_quiet) |
printf("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
atomic_inc(&threads_fault); |
break; |
} |
113,24 → 108,21 |
} |
char * test_mips2(bool quiet) |
char *test_mips2(void) |
{ |
unsigned int i, total = 0; |
sh_quiet = quiet; |
waitq_initialize(&can_start); |
atomic_set(&threads_ok, 0); |
atomic_set(&threads_fault, 0); |
if (!quiet) |
printf("Creating %u threads... ", 2 * THREADS); |
TPRINTF("Creating %u threads... ", 2 * THREADS); |
for (i = 0; i < THREADS; i++) { |
thread_t *t; |
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { |
if (!quiet) |
printf("could not create thread %u\n", 2 * i); |
TPRINTF("could not create thread %u\n", 2 * i); |
break; |
} |
thread_ready(t); |
137,8 → 129,7 |
total++; |
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { |
if (!quiet) |
printf("could not create thread %u\n", 2 * i + 1); |
TPRINTF("could not create thread %u\n", 2 * i + 1); |
break; |
} |
thread_ready(t); |
145,15 → 136,13 |
total++; |
} |
if (!quiet) |
printf("ok\n"); |
TPRINTF("ok\n"); |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while (atomic_get(&threads_ok) != (long) total) { |
if (!quiet) |
printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); |
thread_sleep(1); |
} |
162,5 → 151,3 |
return "Test failed"; |
} |
#endif |
/branches/arm/kernel/test/fpu/sse1.c |
---|
26,8 → 26,6 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#if (defined(ia32) || defined(amd64) || defined(ia32xen)) |
#include <print.h> |
#include <debug.h> |
38,41 → 36,38 |
#include <arch.h> |
#define THREADS 25 |
#define DELAY 10000L |
#define ATTEMPTS 5 |
#define THREADS 25 |
#define DELAY 10000L |
#define ATTEMPTS 5 |
static atomic_t threads_ok; |
static atomic_t threads_fault; |
static waitq_t can_start; |
static bool sh_quiet; |
static void testit1(void *data) |
{ |
int i; |
int arg __attribute__((aligned(16))) = (int) ((unative_t) data); |
int after_arg __attribute__((aligned(16))); |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i < ATTEMPTS; i++) { |
asm volatile ( |
"movlpd %0, %%xmm2\n" |
: "=m" (arg) |
"movlpd %[arg], %%xmm2\n" |
: [arg] "=m" (arg) |
); |
delay(DELAY); |
asm volatile ( |
"movlpd %%xmm2, %0\n" |
: "=m" (after_arg) |
"movlpd %%xmm2, %[after_arg]\n" |
: [after_arg] "=m" (after_arg) |
); |
if (arg != after_arg) { |
if (!sh_quiet) |
printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
TPRINTF("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
atomic_inc(&threads_fault); |
break; |
} |
89,22 → 84,21 |
thread_detach(THREAD); |
waitq_sleep(&can_start); |
for (i = 0; i < ATTEMPTS; i++) { |
asm volatile ( |
"movlpd %0, %%xmm2\n" |
: "=m" (arg) |
"movlpd %[arg], %%xmm2\n" |
: [arg] "=m" (arg) |
); |
scheduler(); |
asm volatile ( |
"movlpd %%xmm2, %0\n" |
: "=m" (after_arg) |
"movlpd %%xmm2, %[after_arg]\n" |
: [after_arg] "=m" (after_arg) |
); |
if (arg != after_arg) { |
if (!sh_quiet) |
printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
TPRINTF("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); |
atomic_inc(&threads_fault); |
break; |
} |
112,25 → 106,21 |
atomic_inc(&threads_ok); |
} |
char * test_sse1(bool quiet) |
char *test_sse1(void) |
{ |
unsigned int i, total = 0; |
sh_quiet = quiet; |
waitq_initialize(&can_start); |
atomic_set(&threads_ok, 0); |
atomic_set(&threads_fault, 0); |
if (!quiet) |
printf("Creating %u threads... ", 2 * THREADS); |
TPRINTF("Creating %u threads... ", 2 * THREADS); |
for (i = 0; i < THREADS; i++) { |
thread_t *t; |
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { |
if (!quiet) |
printf("could not create thread %u\n", 2 * i); |
TPRINTF("could not create thread %u\n", 2 * i); |
break; |
} |
thread_ready(t); |
137,8 → 127,7 |
total++; |
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { |
if (!quiet) |
printf("could not create thread %u\n", 2 * i + 1); |
TPRINTF("could not create thread %u\n", 2 * i + 1); |
break; |
} |
thread_ready(t); |
145,15 → 134,13 |
total++; |
} |
if (!quiet) |
printf("ok\n"); |
TPRINTF("ok\n"); |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
while (atomic_get(&threads_ok) != (long) total) { |
if (!quiet) |
printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); |
thread_sleep(1); |
} |
162,5 → 149,3 |
return "Test failed"; |
} |
#endif |
/branches/arm/kernel/test/fpu/mips2.def |
---|
1,4 → 1,3 |
#ifdef mips32 |
{ |
"mips2", |
"MIPS FPU test", |
5,4 → 4,3 |
&test_mips2, |
true |
}, |
#endif |
/branches/arm/kernel/test/fpu/fpu1.def |
---|
1,4 → 1,3 |
#if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen)) |
{ |
"fpu1", |
"Intel FPU test", |
5,4 → 4,3 |
&test_fpu1, |
true |
}, |
#endif |
/branches/arm/kernel/test/fpu/sse1.def |
---|
1,4 → 1,3 |
#if (defined(ia32) || defined(amd64) || defined(ia32xen)) |
{ |
"sse1", |
"Intel SEE test", |
5,4 → 4,3 |
&test_sse1, |
true |
}, |
#endif |
/branches/arm/kernel/test/sysinfo/sysinfo1.c |
---|
32,9 → 32,9 |
#include <test.h> |
#include <sysinfo/sysinfo.h> |
char * test_sysinfo1(bool quiet) |
char *test_sysinfo1(void) |
{ |
if (!quiet) |
if (!test_quiet) |
sysinfo_dump(NULL, 0); |
return NULL; |
} |
/branches/arm/kernel/test/fault/fault1.c |
---|
36,8 → 36,7 |
#include <arch.h> |
char * test_fault1(bool quiet) |
char *test_fault1(void) |
{ |
((int *)(0))[1] = 0; |
/branches/arm/kernel/test/atomic/atomic1.c |
---|
31,7 → 31,7 |
#include <atomic.h> |
#include <debug.h> |
char * test_atomic1(bool quiet) |
char *test_atomic1(void) |
{ |
atomic_t a; |
/branches/arm/kernel/test/print/print2.c |
---|
0,0 → 1,57 |
/* |
* Copyright (c) 2005 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <print.h> |
#include <test.h> |
char *test_print2(void) |
{ |
TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n"); |
TPRINTF("Expected output: [a] [ b] [c ] [ d] [e ]\n"); |
TPRINTF("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e'); |
TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n"); |
TPRINTF("Expected output: [1] [ 02] [03 ] [004] [005]\n"); |
TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5); |
TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n"); |
TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); |
TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); |
TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); |
TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); |
TPRINTF("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21); |
unative_t nat = 0x12345678u; |
TPRINTF("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n"); |
TPRINTF("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n"); |
TPRINTF("Real output: [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string"); |
return NULL; |
} |
/branches/arm/kernel/test/print/print3.c |
---|
0,0 → 1,61 |
/* |
* Copyright (c) 2005 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <print.h> |
#include <macros.h> |
#include <test.h> |
#define BUFFER_SIZE 32 |
char *test_print3(void) |
{ |
char buffer[BUFFER_SIZE]; |
int retval; |
TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n"); |
TPRINTF("Expected result: retval=30 buffer=\"Short text without parameters.\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n"); |
TPRINTF("Expected result: retval=44 buffer=\"Very very very long text withou\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n"); |
TPRINTF("Expected result: retval=11 buffer=\"Short text.\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text"); |
TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very long %%s. This text's length is more than %%d. We are interested in the result.\", \"text\", " STRING(BUFFER_SIZE) "):\n"); |
TPRINTF("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text's length is more than %d. We are interested in the result.", "text", BUFFER_SIZE); |
TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
return NULL; |
} |
/branches/arm/kernel/test/print/print4.c |
---|
0,0 → 1,82 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* 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 <print.h> |
#include <test.h> |
char *test_print4(void) |
{ |
TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); |
uint8_t group; |
for (group = 1; group < 4; group++) { |
TPRINTF("%#" PRIx8 ": ", group << 5); |
uint8_t index; |
for (index = 0; index < 32; index++) |
TPRINTF("%c", (char) ((group << 5) + index)); |
TPRINTF(" "); |
for (index = 0; index < 32; index++) |
TPRINTF("%lc", (wchar_t) ((group << 5) + index)); |
TPRINTF("\n"); |
} |
TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); |
for (group = 4; group < 8; group++) { |
TPRINTF("%#" PRIx8 ": ", group << 5); |
uint8_t index; |
for (index = 0; index < 32; index++) |
TPRINTF("%lc", (wchar_t) ((group << 5) + index)); |
TPRINTF("\n"); |
} |
TPRINTF("\nUTF-8 strings using printf(\"%%s\"):\n"); |
TPRINTF("English: %s\n", "Quick brown fox jumps over the lazy dog"); |
TPRINTF("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy"); |
TPRINTF("Greek: %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
TPRINTF("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה"); |
TPRINTF("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي"); |
TPRINTF("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); |
TPRINTF("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական"); |
TPRINTF("\nUTF-32 strings using printf(\"%%ls\"):\n"); |
TPRINTF("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); |
TPRINTF("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy"); |
TPRINTF("Greek: %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
TPRINTF("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה"); |
TPRINTF("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي"); |
TPRINTF("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); |
TPRINTF("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական"); |
return NULL; |
} |
/branches/arm/kernel/test/print/print1.c |
---|
29,44 → 29,27 |
#include <print.h> |
#include <test.h> |
#define BUFFER_SIZE 32 |
char * test_print1(bool quiet) |
char *test_print1(void) |
{ |
if (!quiet) { |
int retval; |
unative_t nat = 0x12345678u; |
char buffer[BUFFER_SIZE]; |
printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
printf(" very long text 10.8s %10.8s \n", "very long text"); |
printf(" text 8.10s %8.10s \n", "text"); |
printf(" very long text 8.10s %8.10s \n", "very long text"); |
printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n", 'a', 'b', 'c', 'd', 'e'); |
printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n", 1, 1, 1, 1, 1); |
printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n", -1, -1, -1, -1, -1); |
printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n", 17, 17, 17, 17, 17); |
printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#" PRIxn "'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); |
printf(" Print to NULL '%s'\n", NULL); |
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
} |
TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); |
TPRINTF("Expected output: \" tex\"\n"); |
TPRINTF("Real output: \"%*.*s\"\n\n", 5, 3, "text"); |
TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n"); |
TPRINTF("Expected output: \" very lon\"\n"); |
TPRINTF("Real output: \"%10.8s\"\n\n", "very long text"); |
TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); |
TPRINTF("Expected output: \"text\"\n"); |
TPRINTF("Real output: \"%8.10s\"\n\n", "text"); |
TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n"); |
TPRINTF("Expected output: \"very long \"\n"); |
TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); |
TPRINTF("Testing printf(\"%%s\", NULL):\n"); |
TPRINTF("Expected output: \"(NULL)\"\n"); |
TPRINTF("Real output: \"%s\"\n\n", NULL); |
return NULL; |
} |
/branches/arm/kernel/test/print/print1.def |
---|
1,6 → 1,6 |
{ |
"print1", |
"Printf test", |
"String printf test", |
&test_print1, |
true |
}, |
/branches/arm/kernel/test/print/print2.def |
---|
0,0 → 1,6 |
{ |
"print2", |
"Numeric printf test", |
&test_print2, |
true |
}, |
/branches/arm/kernel/test/print/print3.def |
---|
0,0 → 1,6 |
{ |
"print3", |
"Buffered printf test", |
&test_print3, |
true |
}, |
/branches/arm/kernel/test/print/print4.def |
---|
0,0 → 1,6 |
{ |
"print4", |
"Unicode test", |
&test_print4, |
true |
}, |