Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4226 → Rev 4227

/trunk/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>
/trunk/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;
/trunk/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, count_t node_count)
{
unsigned int i;
avltree_node_t *newnode;
 
avltree_create(tree);
if (!quiet)
printf("Inserting %" PRIc " nodes...", node_count);
 
TPRINTF("Inserting %" PRIc " 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)
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, count_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;
}
 
/trunk/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);
/trunk/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);
/trunk/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);
}
/trunk/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);
}
}
/trunk/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,8 → 56,8
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;
spinlock_unlock(&rw_lock);
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=%" PRIc "\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);
}
/trunk/kernel/test/synch/semaphore2.c
50,8 → 50,8
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;
spinlock_unlock(&sem_lock);
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);
/trunk/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);
}
}
/trunk/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,33 → 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_print2(bool quiet);
extern char *test_print3(bool quiet);
extern char *test_print4(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[];
 
/trunk/kernel/test/debug/mips1_skip.c
28,7 → 28,7
 
#include <test.h>
 
char *test_mips1(bool quiet)
char *test_mips1(void)
{
return NULL;
}
/trunk/kernel/test/debug/mips1.c
36,10 → 36,9
 
#include <arch.h>
 
char *test_mips1(bool quiet)
char *test_mips1(void)
{
if (!quiet)
printf("If kconsole is compiled in, you should enter debug mode now.\n");
TPRINTF("If kconsole is compiled in, you should enter debug mode now.\n");
asm volatile (
"break\n"
/trunk/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);
}
/trunk/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;
/trunk/kernel/test/mm/falloc2.c
39,17 → 39,16
#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;
57,8 → 56,7
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++) {
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 %#" PRIi "\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);
}
/trunk/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;
}
/trunk/kernel/test/mm/purge1.c
39,7 → 39,7
extern void tlb_invalidate_all(void);
extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt);
 
char * test_purge1(bool quiet)
char *test_purge1(void)
{
tlb_entry_t entryi;
tlb_entry_t entryd;
/trunk/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,11 → 117,10
olddata1 = data1;
}
if (!quiet) {
printf("done.\n");
slab_print_list();
}
TPRINTF("done.\n");
slab_print_list();
slab_cache_destroy(cache1);
slab_cache_destroy(cache2);
}
135,9 → 129,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 → 142,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 → 156,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 → 165,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 → 176,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 → 185,13
data = new;
}
if (!sh_quiet)
printf("Thread #%" PRIu64 " finished\n", THREAD->tid);
TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid);
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 → 199,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;
}
/trunk/kernel/test/mm/purge1_skip.c
28,7 → 28,7
 
#include <test.h>
 
char *test_purge1(bool quiet)
char *test_purge1(void)
{
return NULL;
}
/trunk/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;
}
/trunk/kernel/test/fpu/fpu1_ia64.c
63,7 → 63,6
static atomic_t threads_ok;
static atomic_t threads_fault;
static waitq_t can_start;
static bool sh_quiet;
 
static void e(void *data)
{
85,8 → 84,7
}
if ((int) (100000000 * e) != E_10e8) {
if (!sh_quiet)
printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) 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;
}
119,8 → 117,7
}
if ((int) (1000000 * pi) != PI_10e8) {
if (!sh_quiet)
printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
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;
}
128,24 → 125,21
atomic_inc(&threads_ok);
}
 
char * test_fpu1(bool quiet)
char *test_fpu1(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++) {
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(e, NULL, TASK, 0, "e", 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);
152,8 → 146,7
total++;
if (!(t = thread_create(pi, NULL, TASK, 0, "pi", 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);
160,15 → 153,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);
}
/trunk/kernel/test/fpu/fpu1_x86.c
60,7 → 60,6
static atomic_t threads_ok;
static atomic_t threads_fault;
static waitq_t can_start;
static bool sh_quiet;
 
static void e(void *data)
{
82,8 → 81,7
}
if ((int) (100000000 * e) != E_10e8) {
if (!sh_quiet)
printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) 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;
}
116,8 → 114,7
}
if ((int) (100000000 * pi) != PI_10e8) {
if (!sh_quiet)
printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) 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;
}
125,24 → 122,21
atomic_inc(&threads_ok);
}
 
char * test_fpu1(bool quiet)
char *test_fpu1(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++) {
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(e, NULL, TASK, 0, "e", 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);
149,8 → 143,7
total++;
if (!(t = thread_create(pi, NULL, TASK, 0, "pi", 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);
157,15 → 150,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);
}
/trunk/kernel/test/fpu/mips2_skip.c
28,7 → 28,7
 
#include <test.h>
 
char * test_mips2(bool quiet)
char *test_mips2(void)
{
return NULL;
}
/trunk/kernel/test/fpu/fpu1_skip.c
28,7 → 28,7
 
#include <test.h>
 
char * test_fpu1(bool quiet)
char *test_fpu1(void)
{
return NULL;
}
/trunk/kernel/test/fpu/sse1_skip.c
28,7 → 28,7
 
#include <test.h>
 
char * test_sse1(bool quiet)
char *test_sse1(void)
{
return NULL;
}
/trunk/kernel/test/fpu/mips2.c
43,7 → 43,6
static atomic_t threads_ok;
static atomic_t threads_fault;
static waitq_t can_start;
static bool sh_quiet;
 
static void testit1(void *data)
{
69,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;
}
101,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;
}
111,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);
135,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);
143,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);
}
/trunk/kernel/test/fpu/sse1.c
43,25 → 43,23
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 %[arg], %%xmm2\n"
: [arg] "=m" (arg)
);
 
delay(DELAY);
asm volatile (
"movlpd %%xmm2, %[after_arg]\n"
69,8 → 67,7
);
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;
}
87,13 → 84,13
thread_detach(THREAD);
waitq_sleep(&can_start);
 
for (i = 0; i < ATTEMPTS; i++) {
asm volatile (
"movlpd %[arg], %%xmm2\n"
: [arg] "=m" (arg)
);
 
scheduler();
asm volatile (
"movlpd %%xmm2, %[after_arg]\n"
101,8 → 98,7
);
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;
}
110,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);
135,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);
143,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);
}
/trunk/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;
}
/trunk/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;
/trunk/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;
/trunk/kernel/test/print/print2.c
29,31 → 29,29
#include <print.h>
#include <test.h>
 
char *test_print2(bool quiet)
char *test_print2(void)
{
if (!quiet) {
printf("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
printf("Expected output: [a] [ b] [c ] [ d] [e ]\n");
printf("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');
printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n");
printf("Expected output: [1] [ 02] [03 ] [004] [005]\n");
printf("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5);
printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n");
printf("Expected output: [-1] [-02] [-03] [-004] [-005]\n");
printf("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5);
printf("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n");
printf("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n");
printf("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21);
unative_t nat = 0x12345678u;
printf("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n");
printf("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n");
printf("Real output: [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string");
}
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;
}
/trunk/kernel/test/print/print3.c
32,32 → 32,30
 
#define BUFFER_SIZE 32
 
char *test_print3(bool quiet)
char *test_print3(void)
{
if (!quiet) {
char buffer[BUFFER_SIZE];
int retval;
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n");
printf("Expected result: retval=30 buffer=\"Short text without parameters.\"\n");
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n");
printf("Expected result: retval=44 buffer=\"Very very very long text withou\"\n");
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n");
printf("Expected result: retval=11 buffer=\"Short text.\"\n");
retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text");
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
printf("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");
printf("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);
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
}
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;
}
/trunk/kernel/test/print/print4.c
29,56 → 29,54
#include <print.h>
#include <test.h>
 
char *test_print4(bool quiet)
char *test_print4(void)
{
if (!quiet) {
printf("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
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 group;
for (group = 1; group < 4; group++) {
printf("%#" PRIx8 ": ", group << 5);
uint8_t index;
for (index = 0; index < 32; index++)
printf("%c", (char) ((group << 5) + index));
printf(" ");
for (index = 0; index < 32; index++)
printf("%lc", (wchar_t) ((group << 5) + index));
printf("\n");
}
uint8_t index;
for (index = 0; index < 32; index++)
TPRINTF("%c", (char) ((group << 5) + index));
printf("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n");
TPRINTF(" ");
for (index = 0; index < 32; index++)
TPRINTF("%lc", (wchar_t) ((group << 5) + index));
for (group = 4; group < 8; group++) {
printf("%#" PRIx8 ": ", group << 5);
uint8_t index;
for (index = 0; index < 32; index++)
printf("%lc", (wchar_t) ((group << 5) + index));
printf("\n");
}
TPRINTF("\n");
}
TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n");
for (group = 4; group < 8; group++) {
TPRINTF("%#" PRIx8 ": ", group << 5);
printf("\nUTF-8 strings using printf(\"%%s\"):\n");
printf("English: %s\n", "Quick brown fox jumps over the lazy dog");
printf("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy");
printf("Greek: %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
printf("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה");
printf("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي");
printf("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой");
printf("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական");
uint8_t index;
for (index = 0; index < 32; index++)
TPRINTF("%lc", (wchar_t) ((group << 5) + index));
printf("\nUTF-32 strings using printf(\"%%ls\"):\n");
printf("English: %ls\n", L"Quick brown fox jumps over the lazy dog");
printf("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy");
printf("Greek: %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
printf("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה");
printf("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي");
printf("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой");
printf("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական");
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;
}
/trunk/kernel/test/print/print1.c
29,29 → 29,27
#include <print.h>
#include <test.h>
 
char *test_print1(bool quiet)
char *test_print1(void)
{
if (!quiet) {
printf("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n");
printf("Expected output: \" tex\"\n");
printf("Real output: \"%*.*s\"\n\n", 5, 3, "text");
printf("Testing printf(\"%%10.8s\", \"very long text\"):\n");
printf("Expected output: \" very lon\"\n");
printf("Real output: \"%10.8s\"\n\n", "very long text");
printf("Testing printf(\"%%8.10s\", \"text\"):\n");
printf("Expected output: \"text\"\n");
printf("Real output: \"%8.10s\"\n\n", "text");
printf("Testing printf(\"%%8.10s\", \"very long text\"):\n");
printf("Expected output: \"very long \"\n");
printf("Real output: \"%8.10s\"\n\n", "very long text");
printf("Testing printf(\"%%s\", NULL):\n");
printf("Expected output: \"(NULL)\"\n");
printf("Real output: \"%s\"\n\n", NULL);
}
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;
}