Changeset cb01e1e in mainline
- Timestamp:
- 2009-04-04T00:26:27Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a85aebd
- Parents:
- 171f9a1
- Location:
- kernel
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/cmd.c
r171f9a1 rcb01e1e 32 32 33 33 /** 34 * @file 35 * @brief 34 * @file cmd.c 35 * @brief Kernel console command wrappers. 36 36 * 37 37 * This file is meant to contain all wrapper functions for … … 997 997 998 998 /* Execute the test */ 999 char * ret = test->entry(false); 999 test_quiet = false; 1000 char *ret = test->entry(); 1000 1001 1001 1002 /* Update and read thread accounting */ … … 1049 1050 1050 1051 /* Execute the test */ 1051 char * ret = test->entry(true); 1052 test_quiet = true; 1053 char * ret = test->entry(); 1052 1054 1053 1055 /* Update and read thread accounting */ … … 1151 1153 if (!fnd) 1152 1154 printf("Unknown test\n"); 1153 1155 1154 1156 return 1; 1155 1157 } -
kernel/test/atomic/atomic1.c
r171f9a1 rcb01e1e 32 32 #include <debug.h> 33 33 34 char * test_atomic1(bool quiet)34 char *test_atomic1(void) 35 35 { 36 36 atomic_t a; -
kernel/test/avltree/avltree1.c
r171f9a1 rcb01e1e 42 42 static avltree_node_t avltree_nodes[NODE_COUNT]; 43 43 44 /* 44 /* 45 45 * head of free nodes' list: 46 46 */ … … 59 59 if (!node) 60 60 return NULL; 61 61 62 62 if (node->lft) { 63 63 tmp = test_tree_parents(node->lft); 64 64 if (tmp != node) { 65 printf("Bad parent pointer key: %" PRIu6465 TPRINTF("Bad parent pointer key: %" PRIu64 66 66 ", address: %p\n", tmp->key, node->lft); 67 67 } … … 70 70 tmp = test_tree_parents(node->rgt); 71 71 if (tmp != node) { 72 printf("Bad parent pointer key: %" PRIu6472 TPRINTF("Bad parent pointer key: %" PRIu64 73 73 ", address: %p\n", 74 74 tmp->key,node->rgt); … … 81 81 { 82 82 int h1, h2, diff; 83 83 84 84 if (!node) 85 85 return 0; 86 86 87 h1 = test_tree_balance(node->lft); 87 88 h2 = test_tree_balance(node->rgt); 88 89 diff = h2 - h1; 89 if (diff != node->balance || (diff != -1 && diff != 0 && diff != 1)) { 90 printf("Bad balance\n"); 91 } 92 return h1 > h2 ? h1 + 1 : h2 + 1; 90 91 if ((diff != node->balance) || ((diff != -1) && (diff != 0) && (diff != 1))) 92 TPRINTF("Bad balance\n"); 93 94 return ((h1 > h2) ? (h1 + 1) : (h2 + 1)); 93 95 } 94 96 95 97 /** 96 98 * Prints the structure of the node, which is level levels from the top of the 97 * tree. 98 */ 99 static void 100 print_tree_structure_flat(avltree_node_t *node, int level) 99 * tree. 100 */ 101 static void print_tree_structure_flat(avltree_node_t *node, int level) 101 102 { 102 103 /* 103 104 * You can set the maximum level as high as you like. 104 105 105 * Most of the time, you'll want to debug code using small trees, 106 * so that a large level indicates a loop, which is a bug. 106 107 */ 107 108 if (level > 16) { 108 printf("[...]");109 TPRINTF("[...]"); 109 110 return; 110 111 } 111 112 112 113 if (node == NULL) 113 114 return; 114 115 printf("%" PRIu64 "[%" PRIu8 "]", node->key, node->balance);115 116 TPRINTF("%" PRIu64 "[%" PRIu8 "]", node->key, node->balance); 116 117 if (node->lft != NULL || node->rgt != NULL) { 117 printf("(");118 118 TPRINTF("("); 119 119 120 print_tree_structure_flat(node->lft, level + 1); 120 121 if (node->rgt != NULL) { 121 printf(",");122 TPRINTF(","); 122 123 print_tree_structure_flat(node->rgt, level + 1); 123 124 } 124 125 printf(")");125 126 TPRINTF(")"); 126 127 } 127 128 } … … 130 131 { 131 132 int i; 132 133 for (i = 0; i < NODE_COUNT - 1; i++) {133 134 for (i = 0; i < NODE_COUNT - 1; i++) 134 135 avltree_nodes[i].par = &avltree_nodes[i + 1]; 135 }136 136 137 avltree_nodes[i].par = NULL; 137 138 … … 140 141 * array. 141 142 */ 142 143 143 144 /* First tree node and same key */ 144 145 avltree_nodes[0].key = 60; 145 146 avltree_nodes[1].key = 60; 146 147 avltree_nodes[2].key = 60; 148 147 149 /* LL rotation */ 148 150 avltree_nodes[3].key = 50; 149 151 avltree_nodes[4].key = 40; 150 152 avltree_nodes[5].key = 30; 153 151 154 /* LR rotation */ 152 155 avltree_nodes[6].key = 20; … … 154 157 avltree_nodes[8].key = 25; 155 158 avltree_nodes[9].key = 25; 159 156 160 /* LL rotation in lower floor */ 157 161 avltree_nodes[10].key = 35; 162 158 163 /* RR rotation */ 159 164 avltree_nodes[11].key = 70; 160 165 avltree_nodes[12].key = 80; 166 161 167 /* RL rotation */ 162 168 avltree_nodes[13].key = 90; 163 169 avltree_nodes[14].key = 85; 170 164 171 /* Insert 0 key */ 165 172 avltree_nodes[15].key = 0; 166 173 avltree_nodes[16].key = 0; 174 167 175 /* Insert reverse */ 168 176 avltree_nodes[17].key = 600; … … 170 178 avltree_nodes[19].key = 400; 171 179 avltree_nodes[20].key = 300; 172 180 173 181 for (i = 21; i < NODE_COUNT; i++) 174 182 avltree_nodes[i].key = i * 3; … … 180 188 { 181 189 avltree_node_t *node; 182 190 183 191 node = first_free_node; 184 192 first_free_node = first_free_node->par; 185 193 186 194 return node; 187 195 } 188 196 189 static void test_tree_insert(avltree_t *tree, count_t node_count , bool quiet)197 static void test_tree_insert(avltree_t *tree, count_t node_count) 190 198 { 191 199 unsigned int i; 192 200 avltree_node_t *newnode; 193 201 194 202 avltree_create(tree); 195 203 196 if (!quiet) 197 printf("Inserting %" PRIc " nodes...", node_count); 198 204 TPRINTF("Inserting %" PRIc " nodes...", node_count); 205 199 206 for (i = 0; i < node_count; i++) { 200 207 newnode = alloc_avltree_node(); 201 208 202 209 avltree_insert(tree, newnode); 203 if (!quiet) { 204 test_tree_parents(tree->root); 205 test_tree_balance(tree->root); 206 } 207 } 208 209 if (!quiet) 210 printf("done.\n"); 211 } 212 210 test_tree_parents(tree->root); 211 test_tree_balance(tree->root); 212 } 213 214 TPRINTF("done.\n"); 215 } 213 216 214 217 static void test_tree_delete(avltree_t *tree, count_t node_count, 215 int node_position , bool quiet)218 int node_position) 216 219 { 217 220 avltree_node_t *delnode; … … 220 223 switch (node_position) { 221 224 case 0: 222 if (!quiet)223 printf("Deleting root nodes...");225 TPRINTF("Deleting root nodes..."); 226 224 227 while (tree->root != NULL) { 225 228 delnode = tree->root; 226 229 avltree_delete(tree, delnode); 227 if (!quiet) { 228 test_tree_parents(tree->root); 229 test_tree_balance(tree->root); 230 } 231 } 230 test_tree_parents(tree->root); 231 test_tree_balance(tree->root); 232 } 232 233 break; 233 234 case 1: 234 if (!quiet)235 printf("Deleting nodes according to creation time...");235 TPRINTF("Deleting nodes according to creation time..."); 236 236 237 for (i = 0; i < node_count; i++) { 237 238 avltree_delete(tree, &avltree_nodes[i]); 238 if (!quiet) { 239 test_tree_parents(tree->root); 240 test_tree_balance(tree->root); 241 } 242 } 243 break; 244 } 245 246 if (!quiet) 247 printf("done.\n"); 248 } 249 250 static void test_tree_delmin(avltree_t *tree, count_t node_count, bool quiet) 239 test_tree_parents(tree->root); 240 test_tree_balance(tree->root); 241 } 242 break; 243 } 244 245 TPRINTF("done.\n"); 246 } 247 248 static void test_tree_delmin(avltree_t *tree, count_t node_count) 251 249 { 252 250 unsigned int i = 0; 253 251 254 if (!quiet) 255 printf("Deleting minimum nodes..."); 252 TPRINTF("Deleting minimum nodes..."); 256 253 257 254 while (tree->root != NULL) { 258 255 i++; 259 256 avltree_delete_min(tree); 260 if (!quiet) { 261 test_tree_parents(tree->root); 262 test_tree_balance(tree->root); 263 } 264 } 265 266 if (!quiet && (i != node_count)) 267 printf("Bad node count. Some nodes have been lost!\n"); 268 269 if (!quiet) 270 printf("done.\n"); 271 } 272 273 char *test_avltree1(bool quiet) 257 test_tree_parents(tree->root); 258 test_tree_balance(tree->root); 259 } 260 261 if (i != node_count) 262 TPRINTF("Bad node count. Some nodes have been lost!\n"); 263 264 TPRINTF("done.\n"); 265 } 266 267 char *test_avltree1(void) 274 268 { 275 269 alloc_avltree_node_prepare(); 276 test_tree_insert(&avltree, NODE_COUNT , quiet);277 test_tree_delete(&avltree, NODE_COUNT, 0 , quiet);278 270 test_tree_insert(&avltree, NODE_COUNT); 271 test_tree_delete(&avltree, NODE_COUNT, 0); 272 279 273 alloc_avltree_node_prepare(); 280 test_tree_insert(&avltree, NODE_COUNT , quiet);281 test_tree_delete(&avltree, NODE_COUNT, 1 , quiet);282 274 test_tree_insert(&avltree, NODE_COUNT); 275 test_tree_delete(&avltree, NODE_COUNT, 1); 276 283 277 alloc_avltree_node_prepare(); 284 test_tree_insert(&avltree, NODE_COUNT , quiet);285 test_tree_delmin(&avltree, NODE_COUNT , quiet);286 278 test_tree_insert(&avltree, NODE_COUNT); 279 test_tree_delmin(&avltree, NODE_COUNT); 280 287 281 return NULL; 288 282 } 289 -
kernel/test/btree/btree1.c
r171f9a1 rcb01e1e 34 34 static void *data = (void *) 0xdeadbeef; 35 35 36 char * test_btree1(bool quiet)36 char *test_btree1(void) 37 37 { 38 38 btree_t t; 39 39 int i; 40 40 41 41 btree_create(&t); 42 42 43 if (!quiet) 44 printf("Inserting keys.\n"); 43 TPRINTF("Inserting keys.\n"); 45 44 btree_insert(&t, 19, data, NULL); 46 45 btree_insert(&t, 20, data, NULL); … … 79 78 btree_insert(&t, i, data, NULL); 80 79 81 if (! quiet)80 if (!test_quiet) 82 81 btree_print(&t); 83 82 84 if (!quiet) 85 printf("Removing keys.\n"); 83 TPRINTF("Removing keys.\n"); 86 84 btree_remove(&t, 50, NULL); 87 85 btree_remove(&t, 49, NULL); … … 159 157 btree_remove(&t, 36, NULL); 160 158 161 if (! quiet)159 if (!test_quiet) 162 160 btree_print(&t); 163 161 -
kernel/test/debug/mips1.c
r171f9a1 rcb01e1e 37 37 #include <arch.h> 38 38 39 char *test_mips1( bool quiet)39 char *test_mips1(void) 40 40 { 41 if (!quiet) 42 printf("If kconsole is compiled in, you should enter debug mode now.\n"); 41 TPRINTF("If kconsole is compiled in, you should enter debug mode now.\n"); 43 42 44 43 asm volatile ( -
kernel/test/debug/mips1_skip.c
r171f9a1 rcb01e1e 29 29 #include <test.h> 30 30 31 char *test_mips1( bool quiet)31 char *test_mips1(void) 32 32 { 33 33 return NULL; -
kernel/test/fault/fault1.c
r171f9a1 rcb01e1e 37 37 #include <arch.h> 38 38 39 40 char * test_fault1(bool quiet) 39 char *test_fault1(void) 41 40 { 42 41 ((int *)(0))[1] = 0; -
kernel/test/fpu/fpu1_ia64.c
r171f9a1 rcb01e1e 64 64 static atomic_t threads_fault; 65 65 static waitq_t can_start; 66 static bool sh_quiet;67 66 68 67 static void e(void *data) … … 86 85 87 86 if ((int) (100000000 * e) != E_10e8) { 88 if (!sh_quiet) 89 printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); 87 TPRINTF("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); 90 88 atomic_inc(&threads_fault); 91 89 break; … … 120 118 121 119 if ((int) (1000000 * pi) != PI_10e8) { 122 if (!sh_quiet) 123 printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); 120 TPRINTF("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); 124 121 atomic_inc(&threads_fault); 125 122 break; … … 129 126 } 130 127 131 char * test_fpu1(bool quiet)128 char *test_fpu1(void) 132 129 { 133 130 unsigned int i, total = 0; 134 sh_quiet = quiet;135 131 136 132 waitq_initialize(&can_start); … … 138 134 atomic_set(&threads_fault, 0); 139 135 140 if (!quiet) 141 printf("Creating %u threads... ", 2 * THREADS); 136 TPRINTF("Creating %u threads... ", 2 * THREADS); 142 137 143 for (i = 0; i < THREADS; i++) { 138 for (i = 0; i < THREADS; i++) { 144 139 thread_t *t; 145 140 146 141 if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { 147 if (!quiet) 148 printf("could not create thread %u\n", 2 * i); 142 TPRINTF("could not create thread %u\n", 2 * i); 149 143 break; 150 144 } … … 153 147 154 148 if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { 155 if (!quiet) 156 printf("could not create thread %u\n", 2 * i + 1); 149 TPRINTF("could not create thread %u\n", 2 * i + 1); 157 150 break; 158 151 } … … 161 154 } 162 155 163 if (!quiet) 164 printf("ok\n"); 156 TPRINTF("ok\n"); 165 157 166 158 thread_sleep(1); … … 168 160 169 161 while (atomic_get(&threads_ok) != (long) total) { 170 if (!quiet) 171 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 162 TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); 172 163 thread_sleep(1); 173 164 } -
kernel/test/fpu/fpu1_skip.c
r171f9a1 rcb01e1e 29 29 #include <test.h> 30 30 31 char * test_fpu1(bool quiet)31 char *test_fpu1(void) 32 32 { 33 33 return NULL; -
kernel/test/fpu/fpu1_x86.c
r171f9a1 rcb01e1e 61 61 static atomic_t threads_fault; 62 62 static waitq_t can_start; 63 static bool sh_quiet;64 63 65 64 static void e(void *data) … … 83 82 84 83 if ((int) (100000000 * e) != E_10e8) { 85 if (!sh_quiet) 86 printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); 84 TPRINTF("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); 87 85 atomic_inc(&threads_fault); 88 86 break; … … 117 115 118 116 if ((int) (100000000 * pi) != PI_10e8) { 119 if (!sh_quiet) 120 printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); 117 TPRINTF("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); 121 118 atomic_inc(&threads_fault); 122 119 break; … … 126 123 } 127 124 128 char * test_fpu1(bool quiet)125 char *test_fpu1(void) 129 126 { 130 127 unsigned int i, total = 0; 131 sh_quiet = quiet;132 128 133 129 waitq_initialize(&can_start); … … 135 131 atomic_set(&threads_fault, 0); 136 132 137 if (!quiet) 138 printf("Creating %u threads... ", 2 * THREADS); 133 TPRINTF("Creating %u threads... ", 2 * THREADS); 139 134 140 for (i = 0; i < THREADS; i++) { 135 for (i = 0; i < THREADS; i++) { 141 136 thread_t *t; 142 137 143 138 if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { 144 if (!quiet) 145 printf("could not create thread %u\n", 2 * i); 139 TPRINTF("could not create thread %u\n", 2 * i); 146 140 break; 147 141 } … … 150 144 151 145 if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { 152 if (!quiet) 153 printf("could not create thread %u\n", 2 * i + 1); 146 TPRINTF("could not create thread %u\n", 2 * i + 1); 154 147 break; 155 148 } … … 158 151 } 159 152 160 if (!quiet) 161 printf("ok\n"); 153 TPRINTF("ok\n"); 162 154 163 155 thread_sleep(1); … … 165 157 166 158 while (atomic_get(&threads_ok) != (long) total) { 167 if (!quiet) 168 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 159 TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); 169 160 thread_sleep(1); 170 161 } -
kernel/test/fpu/mips2.c
r171f9a1 rcb01e1e 44 44 static atomic_t threads_fault; 45 45 static waitq_t can_start; 46 static bool sh_quiet;47 46 48 47 static void testit1(void *data) … … 70 69 71 70 if (arg != after_arg) { 72 if (!sh_quiet) 73 printf("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 71 TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 74 72 atomic_inc(&threads_fault); 75 73 break; … … 102 100 103 101 if (arg != after_arg) { 104 if (!sh_quiet) 105 printf("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 102 TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 106 103 atomic_inc(&threads_fault); 107 104 break; … … 112 109 113 110 114 char * test_mips2(bool quiet)111 char *test_mips2(void) 115 112 { 116 113 unsigned int i, total = 0; 117 sh_quiet = quiet;118 114 119 115 waitq_initialize(&can_start); … … 121 117 atomic_set(&threads_fault, 0); 122 118 123 if (!quiet) 124 printf("Creating %u threads... ", 2 * THREADS); 119 TPRINTF("Creating %u threads... ", 2 * THREADS); 125 120 126 121 for (i = 0; i < THREADS; i++) { … … 128 123 129 124 if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { 130 if (!quiet) 131 printf("could not create thread %u\n", 2 * i); 125 TPRINTF("could not create thread %u\n", 2 * i); 132 126 break; 133 127 } … … 136 130 137 131 if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { 138 if (!quiet) 139 printf("could not create thread %u\n", 2 * i + 1); 132 TPRINTF("could not create thread %u\n", 2 * i + 1); 140 133 break; 141 134 } … … 144 137 } 145 138 146 if (!quiet) 147 printf("ok\n"); 139 TPRINTF("ok\n"); 148 140 149 141 thread_sleep(1); … … 151 143 152 144 while (atomic_get(&threads_ok) != (long) total) { 153 if (!quiet) 154 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 145 TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); 155 146 thread_sleep(1); 156 147 } -
kernel/test/fpu/mips2_skip.c
r171f9a1 rcb01e1e 29 29 #include <test.h> 30 30 31 char * test_mips2(bool quiet)31 char *test_mips2(void) 32 32 { 33 33 return NULL; -
kernel/test/fpu/sse1.c
r171f9a1 rcb01e1e 44 44 static atomic_t threads_fault; 45 45 static waitq_t can_start; 46 static bool sh_quiet;47 48 46 49 47 static void testit1(void *data) … … 52 50 int arg __attribute__((aligned(16))) = (int) ((unative_t) data); 53 51 int after_arg __attribute__((aligned(16))); 54 52 55 53 thread_detach(THREAD); 56 54 57 55 waitq_sleep(&can_start); 58 56 59 57 for (i = 0; i < ATTEMPTS; i++) { 60 58 asm volatile ( … … 62 60 : [arg] "=m" (arg) 63 61 ); 64 62 65 63 delay(DELAY); 66 64 asm volatile ( … … 70 68 71 69 if (arg != after_arg) { 72 if (!sh_quiet) 73 printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 70 TPRINTF("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 74 71 atomic_inc(&threads_fault); 75 72 break; … … 88 85 89 86 waitq_sleep(&can_start); 90 87 91 88 for (i = 0; i < ATTEMPTS; i++) { 92 89 asm volatile ( … … 94 91 : [arg] "=m" (arg) 95 92 ); 96 93 97 94 scheduler(); 98 95 asm volatile ( … … 102 99 103 100 if (arg != after_arg) { 104 if (!sh_quiet) 105 printf("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 101 TPRINTF("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg); 106 102 atomic_inc(&threads_fault); 107 103 break; … … 111 107 } 112 108 113 114 char * test_sse1(bool quiet) 109 char *test_sse1(void) 115 110 { 116 111 unsigned int i, total = 0; 117 sh_quiet = quiet;118 112 119 113 waitq_initialize(&can_start); … … 121 115 atomic_set(&threads_fault, 0); 122 116 123 if (!quiet) 124 printf("Creating %u threads... ", 2 * THREADS); 125 117 TPRINTF("Creating %u threads... ", 2 * THREADS); 118 126 119 for (i = 0; i < THREADS; i++) { 127 120 thread_t *t; 128 121 129 122 if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { 130 if (!quiet) 131 printf("could not create thread %u\n", 2 * i); 123 TPRINTF("could not create thread %u\n", 2 * i); 132 124 break; 133 125 } … … 136 128 137 129 if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { 138 if (!quiet) 139 printf("could not create thread %u\n", 2 * i + 1); 130 TPRINTF("could not create thread %u\n", 2 * i + 1); 140 131 break; 141 132 } … … 144 135 } 145 136 146 if (!quiet) 147 printf("ok\n"); 148 137 TPRINTF("ok\n"); 138 149 139 thread_sleep(1); 150 140 waitq_wakeup(&can_start, WAKEUP_ALL); 151 141 152 142 while (atomic_get(&threads_ok) != (long) total) { 153 if (!quiet) 154 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 143 TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok)); 155 144 thread_sleep(1); 156 145 } -
kernel/test/fpu/sse1_skip.c
r171f9a1 rcb01e1e 29 29 #include <test.h> 30 30 31 char * test_sse1(bool quiet)31 char *test_sse1(void) 32 32 { 33 33 return NULL; -
kernel/test/mm/falloc1.c
r171f9a1 rcb01e1e 37 37 #include <align.h> 38 38 39 #define MAX_FRAMES 102440 #define MAX_ORDER 841 #define TEST_RUNS 239 #define MAX_FRAMES 1024 40 #define MAX_ORDER 8 41 #define TEST_RUNS 2 42 42 43 char * test_falloc1(bool quiet) { 44 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0); 43 char *test_falloc1(void) { 44 uintptr_t *frames 45 = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0); 45 46 int results[MAX_ORDER + 1]; 46 47 … … 53 54 if (frames == NULL) 54 55 return "Unable to allocate frames"; 55 56 56 57 for (run = 0; run < TEST_RUNS; run++) { 57 58 for (order = 0; order <= MAX_ORDER; order++) { 58 if (!quiet) 59 printf("Allocating %d frames blocks ... ", 1 << order); 59 TPRINTF("Allocating %d frames blocks ... ", 1 << order); 60 60 61 61 allocated = 0; … … 64 64 65 65 if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { 66 if (!quiet) 67 printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 66 TPRINTF("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 68 67 return "Test failed"; 69 68 } … … 72 71 allocated++; 73 72 else { 74 if (!quiet) 75 printf("done. "); 73 TPRINTF("done. "); 76 74 break; 77 75 } 78 76 } 79 77 80 if (!quiet) 81 printf("%d blocks allocated.\n", allocated); 82 78 TPRINTF("%d blocks allocated.\n", allocated); 79 83 80 if (run) { 84 81 if (results[order] != allocated) … … 87 84 results[order] = allocated; 88 85 89 if (!quiet) 90 printf("Deallocating ... "); 86 TPRINTF("Deallocating ... "); 91 87 92 88 for (i = 0; i < allocated; i++) 93 89 frame_free(KA2PA(frames[i])); 94 90 95 if (!quiet) 96 printf("done.\n"); 91 TPRINTF("done.\n"); 97 92 } 98 93 } 99 94 100 95 free(frames); 101 96 -
kernel/test/mm/falloc2.c
r171f9a1 rcb01e1e 40 40 #include <arch.h> 41 41 42 #define MAX_FRAMES 25643 #define MAX_ORDER 842 #define MAX_FRAMES 256 43 #define MAX_ORDER 8 44 44 45 #define THREAD_RUNS 146 #define THREADS 845 #define THREAD_RUNS 1 46 #define THREADS 8 47 47 48 48 static atomic_t thread_count; 49 49 static atomic_t thread_fail; 50 static bool sh_quiet;51 50 52 static void falloc(void * 51 static void falloc(void *arg) 53 52 { 54 53 int order, run, allocated, i; … … 58 57 void **frames = (void **) malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC); 59 58 if (frames == NULL) { 60 if (!sh_quiet) 61 printf("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id); 59 TPRINTF("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id); 62 60 atomic_inc(&thread_fail); 63 61 atomic_dec(&thread_count); … … 66 64 67 65 thread_detach(THREAD); 68 66 69 67 for (run = 0; run < THREAD_RUNS; run++) { 70 68 for (order = 0; order <= MAX_ORDER; order++) { 71 if (!sh_quiet) 72 printf("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); 69 TPRINTF("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); 73 70 74 71 allocated = 0; … … 82 79 } 83 80 84 if (!sh_quiet) 85 printf("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); 86 87 if (!sh_quiet) 88 printf("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id); 81 TPRINTF("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); 82 TPRINTF("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id); 89 83 90 84 for (i = 0; i < allocated; i++) { 91 85 for (k = 0; k <= (((index_t) FRAME_SIZE << order) - 1); k++) { 92 86 if (((uint8_t *) frames[i])[k] != val) { 93 if (!sh_quiet) 94 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); 87 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); 95 88 atomic_inc(&thread_fail); 96 89 goto cleanup; … … 100 93 } 101 94 102 if (!sh_quiet) 103 printf("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id); 95 TPRINTF("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id); 104 96 } 105 97 } 106 107 cleanup: 98 99 cleanup: 108 100 free(frames); 109 101 110 if (!sh_quiet) 111 printf("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id); 102 TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id); 112 103 atomic_dec(&thread_count); 113 104 } 114 105 115 char * test_falloc2(bool quiet)106 char *test_falloc2(void) 116 107 { 117 108 unsigned int i; 118 sh_quiet = quiet; 119 109 120 110 atomic_set(&thread_count, THREADS); 121 111 atomic_set(&thread_fail, 0); 122 112 123 113 for (i = 0; i < THREADS; i++) { 124 114 thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false); 125 115 if (!thrd) { 126 if (!quiet) 127 printf("Could not create thread %u\n", i); 116 TPRINTF("Could not create thread %u\n", i); 128 117 break; 129 118 } … … 132 121 133 122 while (atomic_get(&thread_count) > 0) { 134 if (!quiet) 135 printf("Threads left: %ld\n", atomic_get(&thread_count)); 123 TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); 136 124 thread_sleep(1); 137 125 } -
kernel/test/mm/mapping1.c
r171f9a1 rcb01e1e 36 36 #include <debug.h> 37 37 38 #define PAGE0 39 #define PAGE1 (PAGE0+PAGE_SIZE)38 #define PAGE0 0x10000000 39 #define PAGE1 (PAGE0 + PAGE_SIZE) 40 40 41 #define VALUE0 42 #define VALUE1 41 #define VALUE0 0x01234567 42 #define VALUE1 0x89abcdef 43 43 44 char * test_mapping1(bool quiet)44 char *test_mapping1(void) 45 45 { 46 46 uintptr_t frame0, frame1; 47 47 uint32_t v0, v1; 48 48 49 49 frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 50 50 frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 51 51 52 if (!quiet) 53 printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); 52 TPRINTF("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); 54 53 *((uint32_t *) frame0) = VALUE0; 55 if (!quiet)56 printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1));54 55 TPRINTF("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); 57 56 *((uint32_t *) frame1) = VALUE1; 58 57 59 if (!quiet) 60 printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); 58 TPRINTF("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); 61 59 page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); 62 if (!quiet)63 printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1));60 61 TPRINTF("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); 64 62 page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); 65 63 66 64 v0 = *((uint32_t *) PAGE0); 67 65 v1 = *((uint32_t *) PAGE1); 68 if (!quiet) { 69 printf("Value at virtual address %p is %#x.\n", PAGE0, v0); 70 printf("Value at virtual address %p is %#x.\n", PAGE1, v1); 71 } 66 TPRINTF("Value at virtual address %p is %#x.\n", PAGE0, v0); 67 TPRINTF("Value at virtual address %p is %#x.\n", PAGE1, v1); 72 68 73 69 if (v0 != VALUE0) … … 76 72 return "Value at v1 not equal to VALUE1"; 77 73 78 if (!quiet) 79 printf("Writing %#x to virtual address %p.\n", 0, PAGE0); 74 TPRINTF("Writing %#x to virtual address %p.\n", 0, PAGE0); 80 75 *((uint32_t *) PAGE0) = 0; 81 if (!quiet)82 printf("Writing %#x to virtual address %p.\n", 0, PAGE1);83 *((uint32_t *) PAGE1) = 0; 84 76 77 TPRINTF("Writing %#x to virtual address %p.\n", 0, PAGE1); 78 *((uint32_t *) PAGE1) = 0; 79 85 80 v0 = *((uint32_t *) PAGE0); 86 81 v1 = *((uint32_t *) PAGE1); 87 82 88 if (!quiet) { 89 printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); 90 printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); 91 } 92 83 TPRINTF("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); 84 TPRINTF("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); 85 93 86 if (v0 != 0) 94 87 return "Value at v0 not equal to 0"; … … 96 89 return "Value at v1 not equal to 0"; 97 90 98 return NULL; 91 return NULL; 99 92 } -
kernel/test/mm/purge1.c
r171f9a1 rcb01e1e 40 40 extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt); 41 41 42 char * test_purge1(bool quiet)42 char *test_purge1(void) 43 43 { 44 44 tlb_entry_t entryi; -
kernel/test/mm/purge1_skip.c
r171f9a1 rcb01e1e 29 29 #include <test.h> 30 30 31 char *test_purge1( bool quiet)31 char *test_purge1(void) 32 32 { 33 33 return NULL; -
kernel/test/mm/slab1.c
r171f9a1 rcb01e1e 34 34 #include <memstr.h> 35 35 36 #define VAL_COUNT 36 #define VAL_COUNT 1024 37 37 38 static void * 38 static void *data[VAL_COUNT]; 39 39 40 static void testit(int size, int count , bool quiet)40 static void testit(int size, int count) 41 41 { 42 42 slab_cache_t *cache; 43 43 int i; 44 44 45 if (!quiet) 46 printf("Creating cache, object size: %d.\n", size); 45 TPRINTF("Creating cache, object size: %d.\n", size); 47 46 48 47 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 49 48 SLAB_CACHE_NOMAGAZINE); 50 49 51 if (!quiet) 52 printf("Allocating %d items...", count); 50 TPRINTF("Allocating %d items...", count); 53 51 54 52 for (i = 0; i < count; i++) { … … 57 55 } 58 56 59 if (!quiet) { 60 printf("done.\n"); 61 printf("Freeing %d items...", count); 62 } 57 TPRINTF("done.\n"); 58 59 TPRINTF("Freeing %d items...", count); 63 60 64 61 for (i = 0; i < count; i++) 65 62 slab_free(cache, data[i]); 66 63 67 if (!quiet) { 68 printf("done.\n"); 69 printf("Allocating %d items...", count); 70 } 64 TPRINTF("done.\n"); 65 66 TPRINTF("Allocating %d items...", count); 71 67 72 68 for (i = 0; i < count; i++) { … … 75 71 } 76 72 77 if (!quiet) { 78 printf("done.\n"); 79 printf("Freeing %d items...", count / 2); 80 } 73 TPRINTF("done.\n"); 74 75 TPRINTF("Freeing %d items...", count / 2); 81 76 82 77 for (i = count - 1; i >= count / 2; i--) 83 78 slab_free(cache, data[i]); 84 79 85 if (!quiet) { 86 printf("done.\n"); 87 printf("Allocating %d items...", count / 2); 88 } 80 TPRINTF("done.\n"); 81 82 TPRINTF("Allocating %d items...", count / 2); 89 83 90 84 for (i = count / 2; i < count; i++) { … … 93 87 } 94 88 95 if (!quiet) { 96 printf("done.\n"); 97 printf("Freeing %d items...", count); 98 } 89 TPRINTF("done.\n"); 90 91 TPRINTF("Freeing %d items...", count); 99 92 100 93 for (i = 0; i < count; i++) 101 94 slab_free(cache, data[i]); 102 95 103 if (!quiet)104 printf("done.\n");96 TPRINTF("done.\n"); 97 105 98 slab_cache_destroy(cache); 106 99 107 if (!quiet) 108 printf("Test complete.\n"); 100 TPRINTF("Test complete.\n"); 109 101 } 110 102 111 static void testsimple( bool quiet)103 static void testsimple(void) 112 104 { 113 testit(100, VAL_COUNT , quiet);114 testit(200, VAL_COUNT , quiet);115 testit(1024, VAL_COUNT , quiet);116 testit(2048, 512 , quiet);117 testit(4000, 128 , quiet);118 testit(8192, 128 , quiet);119 testit(16384, 128 , quiet);120 testit(16385, 128 , quiet);105 testit(100, VAL_COUNT); 106 testit(200, VAL_COUNT); 107 testit(1024, VAL_COUNT); 108 testit(2048, 512); 109 testit(4000, 128); 110 testit(8192, 128); 111 testit(16384, 128); 112 testit(16385, 128); 121 113 } 122 114 123 #define THREADS 6124 #define THR_MEM_COUNT 125 #define THR_MEM_SIZE 115 #define THREADS 6 116 #define THR_MEM_COUNT 1024 117 #define THR_MEM_SIZE 128 126 118 127 static void * 119 static void *thr_data[THREADS][THR_MEM_COUNT]; 128 120 static slab_cache_t *thr_cache; 129 121 static semaphore_t thr_sem; 130 static bool sh_quiet;131 122 132 123 static void slabtest(void *data) … … 137 128 thread_detach(THREAD); 138 129 139 if (!sh_quiet) 140 printf("Starting thread #%" PRIu64 "...\n", THREAD->tid); 130 TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); 141 131 142 132 for (j = 0; j < 10; j++) { … … 151 141 } 152 142 153 if (!sh_quiet) 154 printf("Thread #%" PRIu64 " finished\n", THREAD->tid); 143 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); 155 144 156 145 semaphore_up(&thr_sem); 157 146 } 158 147 159 static void testthreads( bool quiet)148 static void testthreads(void) 160 149 { 161 150 thread_t *t; 162 151 int i; 163 152 164 153 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, 165 SLAB_CACHE_NOMAGAZINE); 154 SLAB_CACHE_NOMAGAZINE); 155 166 156 semaphore_initialize(&thr_sem, 0); 167 157 for (i = 0; i < THREADS; i++) { 168 158 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { 169 if (!quiet) 170 printf("Could not create thread %d\n", i); 159 TPRINTF("Could not create thread %d\n", i); 171 160 } else 172 161 thread_ready(t); … … 178 167 slab_cache_destroy(thr_cache); 179 168 180 if (!quiet) 181 printf("Test complete.\n"); 169 TPRINTF("Test complete.\n"); 182 170 } 183 171 184 char * test_slab1(bool quiet)172 char *test_slab1(void) 185 173 { 186 sh_quiet = quiet; 187 188 testsimple(quiet); 189 testthreads(quiet); 174 testsimple(); 175 testthreads(); 190 176 191 177 return NULL; -
kernel/test/mm/slab2.c
r171f9a1 rcb01e1e 37 37 #include <synch/mutex.h> 38 38 39 #define ITEM_SIZE 25639 #define ITEM_SIZE 256 40 40 41 41 /** Fill memory with 2 caches, when allocation fails, … … 43 43 * now allocation should clean magazines and allow for full allocation. 44 44 */ 45 static void totalmemtest( bool quiet)45 static void totalmemtest(void) 46 46 { 47 47 slab_cache_t *cache1; 48 48 slab_cache_t *cache2; 49 49 int i; 50 50 51 51 void *data1, *data2; 52 52 void *olddata1 = NULL, *olddata2 = NULL; … … 55 55 cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); 56 56 57 if (!quiet) 58 printf("Allocating..."); 57 TPRINTF("Allocating..."); 59 58 60 59 /* Use atomic alloc, so that we find end of memory */ … … 75 74 olddata1 = data1; 76 75 olddata2 = data2; 77 } while (1); 78 79 if (!quiet) { 80 printf("done.\n"); 81 printf("Deallocating cache2..."); 82 } 76 } while (true); 77 78 TPRINTF("done.\n"); 79 80 TPRINTF("Deallocating cache2..."); 83 81 84 82 /* We do not have memory - now deallocate cache2 */ … … 89 87 } 90 88 91 if (!quiet) { 92 printf("done.\n"); 93 printf("Allocating to cache1...\n"); 94 } 89 TPRINTF("done.\n"); 90 91 TPRINTF("Allocating to cache1...\n"); 95 92 96 93 for (i = 0; i < 30; i++) { 97 94 data1 = slab_alloc(cache1, FRAME_ATOMIC); 98 95 if (!data1) { 99 if (!quiet) 100 printf("Incorrect memory size - use another test."); 96 TPRINTF("Incorrect memory size - use another test."); 101 97 return; 102 98 } … … 105 101 olddata1 = data1; 106 102 } 107 while ( 1) {103 while (true) { 108 104 data1 = slab_alloc(cache1, FRAME_ATOMIC); 109 105 if (!data1) … … 114 110 } 115 111 116 if (!quiet) 117 printf("Deallocating cache1..."); 112 TPRINTF("Deallocating cache1..."); 118 113 119 114 while (olddata1) { … … 123 118 } 124 119 125 if (!quiet) { 126 printf("done.\n"); 127 slab_print_list(); 128 } 120 TPRINTF("done.\n"); 121 122 slab_print_list(); 129 123 130 124 slab_cache_destroy(cache1); … … 136 130 static condvar_t thread_starter; 137 131 static mutex_t starter_mutex; 138 static bool sh_quiet; 139 140 #define THREADS 8 132 133 #define THREADS 8 141 134 142 135 static void slabtest(void *priv) … … 150 143 mutex_unlock(&starter_mutex); 151 144 152 if (!sh_quiet) 153 printf("Starting thread #%" PRIu64 "...\n", THREAD->tid); 145 TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid); 154 146 155 147 /* Alloc all */ 156 if (!sh_quiet) 157 printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 158 159 while (1) { 148 TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 149 150 while (true) { 160 151 /* Call with atomic to detect end of memory */ 161 152 new = slab_alloc(thr_cache, FRAME_ATOMIC); … … 166 157 } 167 158 168 if (!sh_quiet) 169 printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 159 TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 170 160 171 161 while (data) { … … 176 166 } 177 167 178 if (!sh_quiet) 179 printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 180 181 while (1) { 168 TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid); 169 170 while (true) { 182 171 /* Call with atomic to detect end of memory */ 183 172 new = slab_alloc(thr_cache, FRAME_ATOMIC); … … 188 177 } 189 178 190 if (!sh_quiet) 191 printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 179 TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid); 192 180 193 181 while (data) { … … 198 186 } 199 187 200 if (!sh_quiet) 201 printf("Thread #%" PRIu64 " finished\n", THREAD->tid); 188 TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid); 202 189 203 190 slab_print_list(); … … 205 192 } 206 193 207 static void multitest(int size , bool quiet)194 static void multitest(int size) 208 195 { 209 196 /* Start 8 threads that just allocate as much as possible, … … 213 200 int i; 214 201 215 if (!quiet) 216 printf("Running stress test with size %d\n", size); 202 TPRINTF("Running stress test with size %d\n", size); 217 203 218 204 condvar_initialize(&thread_starter); 219 205 mutex_initialize(&starter_mutex, MUTEX_PASSIVE); 220 206 221 207 thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); 222 208 semaphore_initialize(&thr_sem,0); 223 209 for (i = 0; i < THREADS; i++) { 224 210 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) { 225 if (!quiet) 226 printf("Could not create thread %d\n", i); 211 TPRINTF("Could not create thread %d\n", i); 227 212 } else 228 213 thread_ready(t); … … 230 215 thread_sleep(1); 231 216 condvar_broadcast(&thread_starter); 232 217 233 218 for (i = 0; i < THREADS; i++) 234 219 semaphore_down(&thr_sem); 235 220 236 221 slab_cache_destroy(thr_cache); 237 if (!quiet) 238 printf("Stress test complete.\n"); 239 } 240 241 char * test_slab2(bool quiet) 242 { 243 sh_quiet = quiet; 244 245 if (!quiet) 246 printf("Running reclaim single-thread test .. pass 1\n"); 247 totalmemtest(quiet); 248 if (!quiet) 249 printf("Running reclaim single-thread test .. pass 2\n"); 250 totalmemtest(quiet); 251 if (!quiet) 252 printf("Reclaim test OK.\n"); 253 254 multitest(128, quiet); 255 multitest(2048, quiet); 256 multitest(8192, quiet); 222 TPRINTF("Stress test complete.\n"); 223 } 224 225 char *test_slab2(void) 226 { 227 TPRINTF("Running reclaim single-thread test .. pass 1\n"); 228 totalmemtest(); 229 230 TPRINTF("Running reclaim single-thread test .. pass 2\n"); 231 totalmemtest(); 232 233 TPRINTF("Reclaim test OK.\n"); 234 235 multitest(128); 236 multitest(2048); 237 multitest(8192); 257 238 258 239 return NULL; -
kernel/test/print/print1.c
r171f9a1 rcb01e1e 30 30 #include <test.h> 31 31 32 char *test_print1( bool quiet)32 char *test_print1(void) 33 33 { 34 if (!quiet) { 35 printf("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); 36 printf("Expected output: \" tex\"\n"); 37 printf("Real output: \"%*.*s\"\n\n", 5, 3, "text"); 38 39 printf("Testing printf(\"%%10.8s\", \"very long text\"):\n"); 40 printf("Expected output: \" very lon\"\n"); 41 printf("Real output: \"%10.8s\"\n\n", "very long text"); 42 43 printf("Testing printf(\"%%8.10s\", \"text\"):\n"); 44 printf("Expected output: \"text\"\n"); 45 printf("Real output: \"%8.10s\"\n\n", "text"); 46 47 printf("Testing printf(\"%%8.10s\", \"very long text\"):\n"); 48 printf("Expected output: \"very long \"\n"); 49 printf("Real output: \"%8.10s\"\n\n", "very long text"); 50 51 printf("Testing printf(\"%%s\", NULL):\n"); 52 printf("Expected output: \"(NULL)\"\n"); 53 printf("Real output: \"%s\"\n\n", NULL); 54 } 34 TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); 35 TPRINTF("Expected output: \" tex\"\n"); 36 TPRINTF("Real output: \"%*.*s\"\n\n", 5, 3, "text"); 37 38 TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n"); 39 TPRINTF("Expected output: \" very lon\"\n"); 40 TPRINTF("Real output: \"%10.8s\"\n\n", "very long text"); 41 42 TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); 43 TPRINTF("Expected output: \"text\"\n"); 44 TPRINTF("Real output: \"%8.10s\"\n\n", "text"); 45 46 TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n"); 47 TPRINTF("Expected output: \"very long \"\n"); 48 TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); 49 50 TPRINTF("Testing printf(\"%%s\", NULL):\n"); 51 TPRINTF("Expected output: \"(NULL)\"\n"); 52 TPRINTF("Real output: \"%s\"\n\n", NULL); 55 53 56 54 return NULL; -
kernel/test/print/print2.c
r171f9a1 rcb01e1e 30 30 #include <test.h> 31 31 32 char *test_print2( bool quiet)32 char *test_print2(void) 33 33 { 34 if (!quiet) { 35 printf("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n"); 36 printf("Expected output: [a] [ b] [c ] [ d] [e ]\n"); 37 printf("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e'); 38 39 printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n"); 40 printf("Expected output: [1] [ 02] [03 ] [004] [005]\n"); 41 printf("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5); 42 43 printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n"); 44 printf("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 45 printf("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); 46 47 printf("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); 48 printf("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); 49 printf("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21); 50 51 unative_t nat = 0x12345678u; 52 53 printf("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n"); 54 printf("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n"); 55 printf("Real output: [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string"); 56 } 34 TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n"); 35 TPRINTF("Expected output: [a] [ b] [c ] [ d] [e ]\n"); 36 TPRINTF("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e'); 37 38 TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n"); 39 TPRINTF("Expected output: [1] [ 02] [03 ] [004] [005]\n"); 40 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5); 41 42 TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n"); 43 TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 44 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); 45 46 TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); 47 TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); 48 TPRINTF("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21); 49 50 unative_t nat = 0x12345678u; 51 52 TPRINTF("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n"); 53 TPRINTF("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n"); 54 TPRINTF("Real output: [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string"); 57 55 58 56 return NULL; -
kernel/test/print/print3.c
r171f9a1 rcb01e1e 33 33 #define BUFFER_SIZE 32 34 34 35 char *test_print3( bool quiet)35 char *test_print3(void) 36 36 { 37 if (!quiet) { 38 char buffer[BUFFER_SIZE]; 39 int retval; 40 41 printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n"); 42 printf("Expected result: retval=30 buffer=\"Short text without parameters.\"\n"); 43 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); 44 printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 45 46 printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n"); 47 printf("Expected result: retval=44 buffer=\"Very very very long text withou\"\n"); 48 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); 49 printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 50 51 printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n"); 52 printf("Expected result: retval=11 buffer=\"Short text.\"\n"); 53 retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text"); 54 printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 55 56 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"); 57 printf("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n"); 58 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); 59 printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 60 } 37 char buffer[BUFFER_SIZE]; 38 int retval; 39 40 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n"); 41 TPRINTF("Expected result: retval=30 buffer=\"Short text without parameters.\"\n"); 42 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); 43 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 44 45 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n"); 46 TPRINTF("Expected result: retval=44 buffer=\"Very very very long text withou\"\n"); 47 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); 48 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 49 50 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n"); 51 TPRINTF("Expected result: retval=11 buffer=\"Short text.\"\n"); 52 retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text"); 53 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 54 55 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"); 56 TPRINTF("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n"); 57 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); 58 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 61 59 62 60 return NULL; -
kernel/test/print/print4.c
r171f9a1 rcb01e1e 30 30 #include <test.h> 31 31 32 char *test_print4( bool quiet)32 char *test_print4(void) 33 33 { 34 if (!quiet) { 35 printf("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); 34 TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); 35 36 uint8_t group; 37 for (group = 1; group < 4; group++) { 38 TPRINTF("%#" PRIx8 ": ", group << 5); 36 39 37 uint8_t group; 38 for (group = 1; group < 4; group++) { 39 printf("%#" PRIx8 ": ", group << 5); 40 41 uint8_t index; 42 for (index = 0; index < 32; index++) 43 printf("%c", (char) ((group << 5) + index)); 44 45 printf(" "); 46 for (index = 0; index < 32; index++) 47 printf("%lc", (wchar_t) ((group << 5) + index)); 48 49 printf("\n"); 50 } 40 uint8_t index; 41 for (index = 0; index < 32; index++) 42 TPRINTF("%c", (char) ((group << 5) + index)); 51 43 52 printf("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); 44 TPRINTF(" "); 45 for (index = 0; index < 32; index++) 46 TPRINTF("%lc", (wchar_t) ((group << 5) + index)); 53 47 54 for (group = 4; group < 8; group++) { 55 printf("%#" PRIx8 ": ", group << 5); 56 57 uint8_t index; 58 for (index = 0; index < 32; index++) 59 printf("%lc", (wchar_t) ((group << 5) + index)); 60 61 printf("\n"); 62 } 48 TPRINTF("\n"); 49 } 50 51 TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); 52 53 for (group = 4; group < 8; group++) { 54 TPRINTF("%#" PRIx8 ": ", group << 5); 63 55 64 printf("\nUTF-8 strings using printf(\"%%s\"):\n"); 65 printf("English: %s\n", "Quick brown fox jumps over the lazy dog"); 66 printf("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy"); 67 printf("Greek: %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε"); 68 printf("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה"); 69 printf("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي"); 70 printf("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); 71 printf("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական"); 56 uint8_t index; 57 for (index = 0; index < 32; index++) 58 TPRINTF("%lc", (wchar_t) ((group << 5) + index)); 72 59 73 printf("\nUTF-32 strings using printf(\"%%ls\"):\n"); 74 printf("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); 75 printf("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy"); 76 printf("Greek: %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε"); 77 printf("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה"); 78 printf("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي"); 79 printf("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); 80 printf("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական"); 60 TPRINTF("\n"); 81 61 } 62 63 TPRINTF("\nUTF-8 strings using printf(\"%%s\"):\n"); 64 TPRINTF("English: %s\n", "Quick brown fox jumps over the lazy dog"); 65 TPRINTF("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy"); 66 TPRINTF("Greek: %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε"); 67 TPRINTF("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה"); 68 TPRINTF("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي"); 69 TPRINTF("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); 70 TPRINTF("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական"); 71 72 TPRINTF("\nUTF-32 strings using printf(\"%%ls\"):\n"); 73 TPRINTF("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); 74 TPRINTF("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy"); 75 TPRINTF("Greek: %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε"); 76 TPRINTF("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה"); 77 TPRINTF("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي"); 78 TPRINTF("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); 79 TPRINTF("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական"); 82 80 83 81 return NULL; -
kernel/test/synch/rwlock1.c
r171f9a1 rcb01e1e 36 36 #include <synch/rwlock.h> 37 37 38 #define READERS 39 #define WRITERS 38 #define READERS 50 39 #define WRITERS 50 40 40 41 41 static rwlock_t rwlock; 42 42 43 char * test_rwlock1(bool quiet)43 char *test_rwlock1(void) 44 44 { 45 45 rwlock_initialize(&rwlock); 46 46 47 47 rwlock_write_lock(&rwlock); 48 rwlock_write_unlock(&rwlock); 49 50 rwlock_read_lock(&rwlock); 51 rwlock_read_lock(&rwlock); 48 rwlock_write_unlock(&rwlock); 49 52 50 rwlock_read_lock(&rwlock); 53 51 rwlock_read_lock(&rwlock); 54 52 rwlock_read_lock(&rwlock); 55 53 rwlock_read_lock(&rwlock); 54 rwlock_read_lock(&rwlock); 55 56 56 rwlock_read_unlock(&rwlock); 57 rwlock_read_unlock(&rwlock); 57 rwlock_read_unlock(&rwlock); 58 58 rwlock_read_unlock(&rwlock); 59 59 rwlock_read_unlock(&rwlock); … … 61 61 62 62 rwlock_write_lock(&rwlock); 63 rwlock_write_unlock(&rwlock); 64 63 rwlock_write_unlock(&rwlock); 64 65 65 rwlock_read_lock(&rwlock); 66 66 rwlock_read_unlock(&rwlock); 67 67 68 68 rwlock_write_lock(&rwlock); 69 rwlock_write_unlock(&rwlock); 70 69 rwlock_write_unlock(&rwlock); 70 71 71 rwlock_read_lock(&rwlock); 72 72 rwlock_read_unlock(&rwlock); -
kernel/test/synch/rwlock2.c
r171f9a1 rcb01e1e 35 35 #include <synch/rwlock.h> 36 36 37 #define READERS 38 #define WRITERS 37 #define READERS 50 38 #define WRITERS 50 39 39 40 40 static rwlock_t rwlock; 41 static bool sh_quiet;42 41 43 42 static void writer(void *arg) 44 43 { 45 if (!sh_quiet) 46 printf("Trying to lock rwlock for writing....\n"); 44 TPRINTF("Trying to lock rwlock for writing....\n"); 47 45 48 46 rwlock_write_lock(&rwlock); 49 47 rwlock_write_unlock(&rwlock); 50 48 51 if (!sh_quiet) 52 printf("Trying to lock rwlock for reading....\n"); 49 TPRINTF("Trying to lock rwlock for reading....\n"); 53 50 54 51 rwlock_read_lock(&rwlock); 55 rwlock_read_unlock(&rwlock); 52 rwlock_read_unlock(&rwlock); 56 53 } 57 54 58 char * test_rwlock2(bool quiet)55 char *test_rwlock2(void) 59 56 { 60 57 thread_t *thrd; 61 sh_quiet = quiet;62 58 63 59 rwlock_initialize(&rwlock); 64 60 65 61 rwlock_read_lock(&rwlock); 66 62 rwlock_read_lock(&rwlock); 67 63 rwlock_read_lock(&rwlock); 68 rwlock_read_lock(&rwlock); 64 rwlock_read_lock(&rwlock); 69 65 70 66 thrd = thread_create(writer, NULL, TASK, 0, "writer", false); … … 73 69 else 74 70 return "Could not create thread"; 75 71 76 72 thread_sleep(1); 77 73 -
kernel/test/synch/rwlock3.c
r171f9a1 rcb01e1e 35 35 #include <synch/rwlock.h> 36 36 37 #define THREADS 37 #define THREADS 4 38 38 39 39 static atomic_t thread_count; 40 40 static rwlock_t rwlock; 41 static bool sh_quiet;42 41 43 42 static void reader(void *arg) … … 45 44 thread_detach(THREAD); 46 45 47 if (!sh_quiet) 48 printf("cpu%u, tid %" PRIu64 ": trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 46 TPRINTF("cpu%u, tid %" PRIu64 ": trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 49 47 50 48 rwlock_read_lock(&rwlock); 51 49 rwlock_read_unlock(&rwlock); 52 50 53 if (!sh_quiet) { 54 printf("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); 55 printf("cpu%u, tid %" PRIu64 ": trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 56 } 57 51 TPRINTF("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); 52 TPRINTF("cpu%u, tid %" PRIu64 ": trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 53 58 54 rwlock_write_lock(&rwlock); 59 55 rwlock_write_unlock(&rwlock); 60 56 61 if (!sh_quiet) 62 printf("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); 57 TPRINTF("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid); 63 58 64 59 atomic_dec(&thread_count); 65 60 } 66 61 67 char * test_rwlock3(bool quiet)62 char *test_rwlock3(void) 68 63 { 69 64 int i; 70 65 thread_t *thrd; 71 sh_quiet = quiet;72 66 73 67 atomic_set(&thread_count, THREADS); … … 80 74 if (thrd) 81 75 thread_ready(thrd); 82 else if (!quiet)83 printf("Could not create reader %d\n", i);76 else 77 TPRINTF("Could not create reader %d\n", i); 84 78 } 85 79 86 80 thread_sleep(1); 87 81 rwlock_write_unlock(&rwlock); 88 82 89 83 while (atomic_get(&thread_count) > 0) { 90 if (!quiet) 91 printf("Threads left: %ld\n", atomic_get(&thread_count)); 84 TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); 92 85 thread_sleep(1); 93 86 } -
kernel/test/synch/rwlock4.c
r171f9a1 rcb01e1e 41 41 #include <synch/spinlock.h> 42 42 43 #define READERS 44 #define WRITERS 43 #define READERS 50 44 #define WRITERS 50 45 45 46 46 static atomic_t thread_count; 47 47 static rwlock_t rwlock; 48 48 static atomic_t threads_fault; 49 static bool sh_quiet;50 49 51 50 SPINLOCK_INITIALIZE(rw_lock); … … 58 57 { 59 58 uint32_t rc; 60 61 spinlock_lock(&rw_lock); 59 60 spinlock_lock(&rw_lock); 62 61 rc = seed % max; 63 62 seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc; … … 71 70 thread_detach(THREAD); 72 71 waitq_sleep(&can_start); 73 72 74 73 to = random(40000); 75 74 76 if (!sh_quiet) 77 printf("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); 75 TPRINTF("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to); 78 76 79 77 rc = rwlock_write_lock_timeout(&rwlock, to); 80 78 if (SYNCH_FAILED(rc)) { 81 if (!sh_quiet) 82 printf("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); 79 TPRINTF("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid); 83 80 atomic_dec(&thread_count); 84 81 return; 85 82 } 86 83 87 if (!sh_quiet) 88 printf("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); 89 84 TPRINTF("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid); 85 90 86 if (rwlock.readers_in) { 91 if (!sh_quiet) 92 printf("Oops."); 87 TPRINTF("Oops.\n"); 93 88 atomic_inc(&threads_fault); 94 89 atomic_dec(&thread_count); 95 90 return; 96 91 } 92 97 93 thread_usleep(random(1000000)); 94 98 95 if (rwlock.readers_in) { 99 if (!sh_quiet) 100 printf("Oops."); 96 TPRINTF("Oops.\n"); 101 97 atomic_inc(&threads_fault); 102 98 atomic_dec(&thread_count); 103 99 return; 104 100 } 105 101 106 102 rwlock_write_unlock(&rwlock); 107 103 108 if (!sh_quiet) 109 printf("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); 104 TPRINTF("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid); 110 105 atomic_dec(&thread_count); 111 106 } … … 119 114 to = random(2000); 120 115 121 if (!sh_quiet) 122 printf("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); 116 TPRINTF("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to); 123 117 124 118 rc = rwlock_read_lock_timeout(&rwlock, to); 125 119 if (SYNCH_FAILED(rc)) { 126 if (!sh_quiet) 127 printf("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); 120 TPRINTF("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid); 128 121 atomic_dec(&thread_count); 129 122 return; 130 123 } 131 124 132 if (!sh_quiet) 133 printf("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); 125 TPRINTF("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid); 134 126 135 127 thread_usleep(30000); 136 128 rwlock_read_unlock(&rwlock); 137 129 138 if (!sh_quiet) 139 printf("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); 130 TPRINTF("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid); 140 131 atomic_dec(&thread_count); 141 132 } 142 133 143 char * test_rwlock4(bool quiet)134 char *test_rwlock4(void) 144 135 { 145 136 context_t ctx; 146 137 uint32_t i; 147 sh_quiet = quiet;148 138 149 139 waitq_initialize(&can_start); … … 159 149 160 150 context_save(&ctx); 161 if (!quiet) { 162 printf("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in); 163 printf("Creating %" PRIu32 " readers\n", rd); 164 } 151 TPRINTF("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in); 152 TPRINTF("Creating %" PRIu32 " readers\n", rd); 165 153 166 154 for (i = 0; i < rd; i++) { … … 168 156 if (thrd) 169 157 thread_ready(thrd); 170 else if (!quiet)171 printf("Could not create reader %" PRIu32 "\n", i);158 else 159 TPRINTF("Could not create reader %" PRIu32 "\n", i); 172 160 } 173 174 if (!quiet) 175 printf("Creating %" PRIu32 " writers\n", wr); 161 162 TPRINTF("Creating %" PRIu32 " writers\n", wr); 176 163 177 164 for (i = 0; i < wr; i++) { … … 179 166 if (thrd) 180 167 thread_ready(thrd); 181 else if (!quiet)182 printf("Could not create writer %" PRIu32 "\n", i);168 else 169 TPRINTF("Could not create writer %" PRIu32 "\n", i); 183 170 } 184 171 … … 187 174 188 175 while (atomic_get(&thread_count) > 0) { 189 if (!quiet) 190 printf("Threads left: %ld\n", atomic_get(&thread_count)); 176 TPRINTF("Threads left: %ld\n", atomic_get(&thread_count)); 191 177 thread_sleep(1); 192 178 } -
kernel/test/synch/rwlock5.c
r171f9a1 rcb01e1e 36 36 #include <synch/rwlock.h> 37 37 38 #define READERS 39 #define WRITERS 38 #define READERS 50 39 #define WRITERS 50 40 40 41 41 static rwlock_t rwlock; … … 48 48 { 49 49 thread_detach(THREAD); 50 50 51 51 waitq_sleep(&can_start); 52 52 53 53 rwlock_write_lock(&rwlock); 54 54 atomic_inc(&items_written); … … 59 59 { 60 60 thread_detach(THREAD); 61 61 62 62 waitq_sleep(&can_start); 63 63 … … 67 67 } 68 68 69 char * test_rwlock5(bool quiet)69 char *test_rwlock5(void) 70 70 { 71 71 int i, j, k; … … 77 77 for (i = 1; i <= 3; i++) { 78 78 thread_t *thrd; 79 79 80 80 atomic_set(&items_read, 0); 81 81 atomic_set(&items_written, 0); 82 82 83 83 readers = i * READERS; 84 84 writers = (4 - i) * WRITERS; 85 86 printf("Creating %ld readers and %ld writers...", readers, writers);85 86 TPRINTF("Creating %ld readers and %ld writers...", readers, writers); 87 87 88 88 for (j = 0; j < (READERS + WRITERS) / 2; j++) { … … 92 92 thread_ready(thrd); 93 93 else 94 printf("Could not create reader %d\n", k);94 TPRINTF("Could not create reader %d\n", k); 95 95 } 96 96 for (k = 0; k < (4 - i); k++) { … … 99 99 thread_ready(thrd); 100 100 else 101 printf("Could not create writer %d\n", k);101 TPRINTF("Could not create writer %d\n", k); 102 102 } 103 103 } 104 105 printf("ok\n");106 104 105 TPRINTF("ok\n"); 106 107 107 thread_sleep(1); 108 108 waitq_wakeup(&can_start, WAKEUP_ALL); 109 109 110 110 while ((items_read.count != readers) || (items_written.count != writers)) { 111 printf("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);111 TPRINTF("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in); 112 112 thread_usleep(100000); 113 113 } -
kernel/test/synch/semaphore1.c
r171f9a1 rcb01e1e 36 36 #include <synch/semaphore.h> 37 37 38 #define AT_ONCE 39 #define PRODUCERS 40 #define CONSUMERS 38 #define AT_ONCE 3 39 #define PRODUCERS 50 40 #define CONSUMERS 50 41 41 42 42 static semaphore_t sem; … … 48 48 static void producer(void *arg) 49 49 { 50 thread_detach(THREAD); 51 50 thread_detach(THREAD); 51 52 52 waitq_sleep(&can_start); 53 53 54 54 semaphore_down(&sem); 55 55 atomic_inc(&items_produced); … … 60 60 static void consumer(void *arg) 61 61 { 62 thread_detach(THREAD); 62 thread_detach(THREAD); 63 63 64 64 waitq_sleep(&can_start); … … 70 70 } 71 71 72 char * test_semaphore1(bool quiet)72 char *test_semaphore1(void) 73 73 { 74 74 int i, j, k; … … 77 77 waitq_initialize(&can_start); 78 78 semaphore_initialize(&sem, AT_ONCE); 79 79 80 80 for (i = 1; i <= 3; i++) { 81 81 thread_t *thrd; 82 82 83 83 atomic_set(&items_produced, 0); 84 84 atomic_set(&items_consumed, 0); … … 87 87 producers = (4 - i) * PRODUCERS; 88 88 89 printf("Creating %d consumers and %d producers...", consumers, producers);90 89 TPRINTF("Creating %d consumers and %d producers...", consumers, producers); 90 91 91 for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) { 92 92 for (k = 0; k < i; k++) { … … 95 95 thread_ready(thrd); 96 96 else 97 printf("could not create consumer %d\n", i);97 TPRINTF("could not create consumer %d\n", i); 98 98 } 99 99 for (k = 0; k < (4 - i); k++) { … … 102 102 thread_ready(thrd); 103 103 else 104 printf("could not create producer %d\n", i);104 TPRINTF("could not create producer %d\n", i); 105 105 } 106 106 } 107 108 printf("ok\n");109 107 108 TPRINTF("ok\n"); 109 110 110 thread_sleep(1); 111 111 waitq_wakeup(&can_start, WAKEUP_ALL); 112 112 113 113 while ((items_consumed.count != consumers) || (items_produced.count != producers)) { 114 printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);114 TPRINTF("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); 115 115 thread_sleep(1); 116 116 } -
kernel/test/synch/semaphore2.c
r171f9a1 rcb01e1e 51 51 { 52 52 uint32_t rc; 53 54 spinlock_lock(&sem_lock); 53 54 spinlock_lock(&sem_lock); 55 55 rc = seed % max; 56 56 seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc; … … 68 68 69 69 to = random(20000); 70 printf("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to);70 TPRINTF("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to); 71 71 rc = semaphore_down_timeout(&sem, to); 72 72 if (SYNCH_FAILED(rc)) { 73 printf("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid);73 TPRINTF("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid); 74 74 return; 75 75 } 76 76 77 printf("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid);77 TPRINTF("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid); 78 78 thread_usleep(random(30000)); 79 79 80 80 semaphore_up(&sem); 81 printf("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid);81 TPRINTF("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid); 82 82 } 83 83 84 char * test_semaphore2(bool quiet)84 char *test_semaphore2(void) 85 85 { 86 86 uint32_t i, k; … … 92 92 93 93 k = random(7) + 1; 94 printf("Creating %" PRIu32 " consumers\n", k);94 TPRINTF("Creating %" PRIu32 " consumers\n", k); 95 95 for (i = 0; i < k; i++) { 96 96 thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false); … … 98 98 thread_ready(thrd); 99 99 else 100 printf("Error creating thread\n");100 TPRINTF("Error creating thread\n"); 101 101 } 102 102 -
kernel/test/sysinfo/sysinfo1.c
r171f9a1 rcb01e1e 33 33 #include <sysinfo/sysinfo.h> 34 34 35 char * test_sysinfo1(bool quiet)35 char *test_sysinfo1(void) 36 36 { 37 if (! quiet)37 if (!test_quiet) 38 38 sysinfo_dump(NULL, 0); 39 39 return NULL; -
kernel/test/test.c
r171f9a1 rcb01e1e 34 34 35 35 #include <test.h> 36 37 bool test_quiet; 36 38 37 39 test_t tests[] = { -
kernel/test/test.h
r171f9a1 rcb01e1e 39 39 #include <typedefs.h> 40 40 41 typedef char *(*test_entry_t)(bool); 41 extern bool test_quiet; 42 43 #define TPRINTF(format, ...) \ 44 { \ 45 if (!test_quiet) { \ 46 printf(format, ##__VA_ARGS__); \ 47 } \ 48 } 49 50 typedef char *(*test_entry_t)(void); 42 51 43 52 typedef struct { … … 48 57 } test_t; 49 58 50 extern char *test_atomic1( bool quiet);51 extern char *test_avltree1( bool quiet);52 extern char *test_btree1( bool quiet);53 extern char *test_mips1( bool quiet);54 extern char *test_fault1( bool quiet);55 extern char *test_fpu1( bool quiet);56 extern char *test_sse1( bool quiet);57 extern char *test_mips2( bool quiet);58 extern char *test_falloc1( bool quiet);59 extern char *test_falloc2( bool quiet);60 extern char *test_mapping1( bool quiet);61 extern char *test_purge1( bool quiet);62 extern char *test_slab1( bool quiet);63 extern char *test_slab2( bool quiet);64 extern char *test_rwlock1( bool quiet);65 extern char *test_rwlock2( bool quiet);66 extern char *test_rwlock3( bool quiet);67 extern char *test_rwlock4( bool quiet);68 extern char *test_rwlock5( bool quiet);69 extern char *test_semaphore1( bool quiet);70 extern char *test_semaphore2( bool quiet);71 extern char *test_print1( bool quiet);72 extern char *test_print2( bool quiet);73 extern char *test_print3( bool quiet);74 extern char *test_print4( bool quiet);75 extern char *test_thread1( bool quiet);76 extern char *test_sysinfo1( bool quiet);59 extern char *test_atomic1(void); 60 extern char *test_avltree1(void); 61 extern char *test_btree1(void); 62 extern char *test_mips1(void); 63 extern char *test_fault1(void); 64 extern char *test_fpu1(void); 65 extern char *test_sse1(void); 66 extern char *test_mips2(void); 67 extern char *test_falloc1(void); 68 extern char *test_falloc2(void); 69 extern char *test_mapping1(void); 70 extern char *test_purge1(void); 71 extern char *test_slab1(void); 72 extern char *test_slab2(void); 73 extern char *test_rwlock1(void); 74 extern char *test_rwlock2(void); 75 extern char *test_rwlock3(void); 76 extern char *test_rwlock4(void); 77 extern char *test_rwlock5(void); 78 extern char *test_semaphore1(void); 79 extern char *test_semaphore2(void); 80 extern char *test_print1(void); 81 extern char *test_print2(void); 82 extern char *test_print3(void); 83 extern char *test_print4(void); 84 extern char *test_thread1(void); 85 extern char *test_sysinfo1(void); 77 86 78 87 extern test_t tests[]; -
kernel/test/thread/thread1.c
r171f9a1 rcb01e1e 37 37 #include <arch.h> 38 38 39 #define THREADS 539 #define THREADS 5 40 40 41 41 static atomic_t finish; 42 42 static atomic_t threads_finished; 43 static bool sh_quiet;44 43 45 44 static void threadtest(void *data) 46 45 { 47 thread_detach(THREAD); 48 46 thread_detach(THREAD); 47 49 48 while (atomic_get(&finish)) { 50 if (!sh_quiet) 51 printf("%" PRIu64 " ", THREAD->tid); 49 TPRINTF("%" PRIu64 " ", THREAD->tid); 52 50 thread_usleep(100000); 53 51 } … … 55 53 } 56 54 57 char * test_thread1(bool quiet)55 char *test_thread1(void) 58 56 { 59 57 unsigned int i, total = 0; 60 sh_quiet = quiet;61 58 62 59 atomic_set(&finish, 1); 63 60 atomic_set(&threads_finished, 0); 64 61 65 62 for (i = 0; i < THREADS; i++) { 66 63 thread_t *t; 67 64 if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) { 68 if (!quiet) 69 printf("Could not create thread %d\n", i); 65 TPRINTF("Could not create thread %d\n", i); 70 66 break; 71 67 } … … 74 70 } 75 71 76 if (!quiet) 77 printf("Running threads for 10 seconds...\n"); 72 TPRINTF("Running threads for 10 seconds...\n"); 78 73 thread_sleep(10); 79 74 80 75 atomic_set(&finish, 0); 81 76 while (atomic_get(&threads_finished) < ((long) total)) { 82 if (!quiet) 83 printf("Threads left: %d\n", total - atomic_get(&threads_finished)); 77 TPRINTF("Threads left: %d\n", total - atomic_get(&threads_finished)); 84 78 thread_sleep(1); 85 79 }
Note:
See TracChangeset
for help on using the changeset viewer.