Changeset a35b458 in mainline for uspace/app/tester
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/app/tester
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/console/console1.c
r3061bc1 ra35b458 51 51 if (!test_quiet) { 52 52 console_ctrl_t *console = console_init(stdin, stdout); 53 53 54 54 printf("Style test: "); 55 55 console_flush(console); … … 68 68 console_set_style(console, STYLE_NORMAL); 69 69 printf("\n"); 70 70 71 71 unsigned int i; 72 72 unsigned int j; 73 73 74 74 printf("\nForeground color test:\n"); 75 75 for (j = 0; j < 2; j++) { … … 84 84 putchar('\n'); 85 85 } 86 86 87 87 printf("\nBackground color test:\n"); 88 88 for (j = 0; j < 2; j++) { … … 97 97 putchar('\n'); 98 98 } 99 99 100 100 printf("\nRGB colors test:\n"); 101 101 102 102 for (i = 0; i < 255; i += 16) { 103 103 console_flush(console); … … 108 108 console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0); 109 109 putchar('\n'); 110 110 111 111 for (i = 0; i < 255; i += 16) { 112 112 console_flush(console); … … 117 117 console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0); 118 118 putchar('\n'); 119 119 120 120 for (i = 0; i < 255; i += 16) { 121 121 console_flush(console); … … 127 127 putchar('\n'); 128 128 } 129 129 130 130 return NULL; 131 131 } -
uspace/app/tester/fault/fault1.c
r3061bc1 ra35b458 33 33 { 34 34 ((int *)(0))[1] = 0; 35 35 36 36 return "Survived write to NULL"; 37 37 } -
uspace/app/tester/fault/fault2.c
r3061bc1 ra35b458 38 38 volatile int var1 = *((aliasing_int *) (((char *) (&var)) + 1)); 39 39 printf("Read %d\n", var1); 40 40 41 41 return "Survived unaligned read"; 42 42 } -
uspace/app/tester/float/float1.c
r3061bc1 ra35b458 52 52 double e = 0; 53 53 double f = 1; 54 54 55 55 for (double d = 1; e != le; d *= f, f += 1) { 56 56 le = e; 57 57 e = e + 1 / d; 58 58 } 59 59 60 60 if ((uint32_t) (e * PRECISION) != E_10E8) { 61 61 atomic_inc(&threads_fault); … … 63 63 } 64 64 } 65 65 66 66 atomic_inc(&threads_finished); 67 67 } … … 70 70 { 71 71 atomic_count_t total = 0; 72 72 73 73 atomic_set(&threads_finished, 0); 74 74 atomic_set(&threads_fault, 0); 75 75 76 76 TPRINTF("Creating threads"); 77 77 for (unsigned int i = 0; i < THREADS; i++) { … … 80 80 break; 81 81 } 82 82 83 83 TPRINTF("."); 84 84 total++; 85 85 } 86 86 87 87 TPRINTF("\n"); 88 88 89 89 while (atomic_get(&threads_finished) < total) { 90 90 TPRINTF("Threads left: %" PRIua "\n", … … 92 92 thread_sleep(1); 93 93 } 94 94 95 95 if (atomic_get(&threads_fault) == 0) 96 96 return NULL; 97 97 98 98 return "Test failed"; 99 99 } -
uspace/app/tester/float/softfloat1.c
r3061bc1 ra35b458 100 100 if (a < b) 101 101 return -1; 102 102 103 103 if (a > b) 104 104 return 1; 105 105 106 106 return 0; 107 107 } … … 111 111 if (a < b) 112 112 return -1; 113 113 114 114 if (a > b) 115 115 return 1; 116 116 117 117 return 0; 118 118 } … … 122 122 { 123 123 uint_to_double_op_t op = (uint_to_double_op_t) f; 124 124 125 125 double c; 126 126 double sc; 127 127 op(uop_a[i], &c, &sc); 128 128 129 129 *pic = (cmptype_t) (c * PRECISION); 130 130 *pisc = (cmptype_t) (sc * PRECISION); … … 135 135 { 136 136 double_to_uint_op_t op = (double_to_uint_op_t) f; 137 137 138 138 unsigned int c; 139 139 unsigned int sc; 140 140 op(dop_a[i], &c, &sc); 141 141 142 142 *pic = (cmptype_t) c; 143 143 *pisc = (cmptype_t) sc; … … 148 148 { 149 149 float_binary_op_t op = (float_binary_op_t) f; 150 150 151 151 float c; 152 152 float sc; 153 153 op(fop_a[i], fop_a[j], &c, &sc); 154 154 155 155 *pic = (cmptype_t) (c * PRECISION); 156 156 *pisc = (cmptype_t) (sc * PRECISION); … … 161 161 { 162 162 float_cmp_op_t op = (float_cmp_op_t) f; 163 163 164 164 op(dop_a[i], dop_a[j], pis, piss); 165 165 } … … 169 169 { 170 170 double_binary_op_t op = (double_binary_op_t) f; 171 171 172 172 double c; 173 173 double sc; 174 174 op(dop_a[i], dop_a[j], &c, &sc); 175 175 176 176 *pic = (cmptype_t) (c * PRECISION); 177 177 *pisc = (cmptype_t) (sc * PRECISION); … … 182 182 { 183 183 double_cmp_op_t op = (double_cmp_op_t) f; 184 184 185 185 op(dop_a[i], dop_a[j], pis, piss); 186 186 } … … 189 189 { 190 190 bool correct = true; 191 191 192 192 for (unsigned int i = 0; i < OPERANDS; i++) { 193 193 cmptype_t ic; 194 194 cmptype_t isc; 195 195 196 196 template(f, i, &ic, &isc); 197 197 cmptype_t diff = ic - isc; 198 198 199 199 if (diff != 0) { 200 200 TPRINTF("i=%u ic=%" PRIdCMPTYPE " isc=%" PRIdCMPTYPE "\n", … … 203 203 } 204 204 } 205 205 206 206 return correct; 207 207 } … … 210 210 { 211 211 bool correct = true; 212 212 213 213 for (unsigned int i = 0; i < OPERANDS; i++) { 214 214 for (unsigned int j = 0; j < OPERANDS; j++) { 215 215 cmptype_t ic; 216 216 cmptype_t isc; 217 217 218 218 template(f, i, j, &ic, &isc); 219 219 cmptype_t diff = ic - isc; 220 220 221 221 if (diff != 0) { 222 222 TPRINTF("i=%u, j=%u ic=%" PRIdCMPTYPE … … 226 226 } 227 227 } 228 228 229 229 return correct; 230 230 } … … 275 275 return; 276 276 } 277 277 278 278 *pc = a / b; 279 279 *psc = div_float(a, b); … … 284 284 { 285 285 *pis = fcmp(a, b); 286 286 287 287 if (is_float_lt(a, b) == -1) 288 288 *piss = -1; … … 320 320 return; 321 321 } 322 322 323 323 *pc = a / b; 324 324 *psc = div_double(a, b); … … 329 329 { 330 330 *pis = dcmp(a, b); 331 331 332 332 if (is_double_lt(a, b) == -1) 333 333 *piss = -1; … … 343 343 { 344 344 bool err = false; 345 345 346 346 if (!test_template_binary(float_template_binary, float_add_operator)) { 347 347 err = true; 348 348 TPRINTF("%s\n", "Float addition failed"); 349 349 } 350 350 351 351 if (!test_template_binary(float_template_binary, float_sub_operator)) { 352 352 err = true; 353 353 TPRINTF("%s\n", "Float addition failed"); 354 354 } 355 355 356 356 if (!test_template_binary(float_template_binary, float_mul_operator)) { 357 357 err = true; 358 358 TPRINTF("%s\n", "Float multiplication failed"); 359 359 } 360 360 361 361 if (!test_template_binary(float_template_binary, float_div_operator)) { 362 362 err = true; 363 363 TPRINTF("%s\n", "Float division failed"); 364 364 } 365 365 366 366 if (!test_template_binary(float_compare_template, float_cmp_operator)) { 367 367 err = true; 368 368 TPRINTF("%s\n", "Float comparison failed"); 369 369 } 370 370 371 371 if (!test_template_binary(double_template_binary, double_add_operator)) { 372 372 err = true; 373 373 TPRINTF("%s\n", "Double addition failed"); 374 374 } 375 375 376 376 if (!test_template_binary(double_template_binary, double_sub_operator)) { 377 377 err = true; 378 378 TPRINTF("%s\n", "Double addition failed"); 379 379 } 380 380 381 381 if (!test_template_binary(double_template_binary, double_mul_operator)) { 382 382 err = true; 383 383 TPRINTF("%s\n", "Double multiplication failed"); 384 384 } 385 385 386 386 if (!test_template_binary(double_template_binary, double_div_operator)) { 387 387 err = true; 388 388 TPRINTF("%s\n", "Double division failed"); 389 389 } 390 390 391 391 if (!test_template_binary(double_compare_template, double_cmp_operator)) { 392 392 err = true; 393 393 TPRINTF("%s\n", "Double comparison failed"); 394 394 } 395 395 396 396 if (!test_template_unary(uint_to_double_template, 397 397 uint_to_double_operator)) { … … 399 399 TPRINTF("%s\n", "Conversion from unsigned int to double failed"); 400 400 } 401 401 402 402 if (!test_template_unary(double_to_uint_template, 403 403 double_to_uint_operator)) { … … 405 405 TPRINTF("%s\n", "Conversion from double to unsigned int failed"); 406 406 } 407 407 408 408 if (!test_template_unary(double_to_uint_template, 409 409 double_to_int_operator)) { … … 411 411 TPRINTF("%s\n", "Conversion from double to signed int failed"); 412 412 } 413 413 414 414 if (err) 415 415 return "Software floating point imprecision"; 416 416 417 417 return NULL; 418 418 } -
uspace/app/tester/hw/serial/serial1.c
r3061bc1 ra35b458 59 59 size_t nread; 60 60 size_t nwritten; 61 61 62 62 if (test_argc < 1) 63 63 cnt = DEFAULT_COUNT; … … 73 73 return "Unexpected argument error"; 74 74 } 75 75 76 76 service_id_t svc_id; 77 77 errno_t res = loc_service_get_id("devices/\\hw\\pci0\\00:01.0\\com1\\a", … … 79 79 if (res != EOK) 80 80 return "Failed getting serial port service ID"; 81 81 82 82 async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF, 83 83 IPC_FLAG_BLOCKING); 84 84 if (sess == NULL) 85 85 return "Failed connecting to serial device"; 86 86 87 87 res = chardev_open(sess, &chardev); 88 88 if (res != EOK) { … … 90 90 return "Failed opening serial port"; 91 91 } 92 92 93 93 res = serial_open(sess, &serial); 94 94 if (res != EOK) { … … 97 97 return "Failed opening serial port"; 98 98 } 99 99 100 100 char *buf = (char *) malloc(cnt + 1); 101 101 if (buf == NULL) { … … 105 105 return "Failed allocating input buffer"; 106 106 } 107 107 108 108 unsigned old_baud; 109 109 serial_parity_t old_par; 110 110 unsigned old_stop; 111 111 unsigned old_word_size; 112 112 113 113 res = serial_get_comm_props(serial, &old_baud, &old_par, 114 114 &old_word_size, &old_stop); … … 120 120 return "Failed to get old serial communication parameters"; 121 121 } 122 122 123 123 res = serial_set_comm_props(serial, 1200, SERIAL_NO_PARITY, 8, 1); 124 124 if (EOK != res) { … … 129 129 return "Failed setting serial communication parameters"; 130 130 } 131 131 132 132 TPRINTF("Trying reading %zu characters from serial device " 133 133 "(svc_id=%" PRIun ")\n", cnt, svc_id); 134 134 135 135 size_t total = 0; 136 136 while (total < cnt) { 137 137 138 138 rc = chardev_read(chardev, buf, cnt - total, &nread); 139 139 if (rc != EOK) { 140 140 (void) serial_set_comm_props(serial, old_baud, 141 141 old_par, old_word_size, old_stop); 142 142 143 143 free(buf); 144 144 chardev_close(chardev); … … 147 147 return "Failed reading from serial device"; 148 148 } 149 149 150 150 if (nread > cnt - total) { 151 151 (void) serial_set_comm_props(serial, old_baud, 152 152 old_par, old_word_size, old_stop); 153 153 154 154 free(buf); 155 155 chardev_close(chardev); … … 158 158 return "Read more data than expected"; 159 159 } 160 160 161 161 TPRINTF("Read %zd bytes\n", nread); 162 162 163 163 buf[nread] = 0; 164 164 165 165 /* 166 166 * Write data back to the device to test the opposite … … 171 171 (void) serial_set_comm_props(serial, old_baud, 172 172 old_par, old_word_size, old_stop); 173 173 174 174 free(buf); 175 175 chardev_close(chardev); … … 178 178 return "Failed writing to serial device"; 179 179 } 180 180 181 181 if (nwritten != nread) { 182 182 (void) serial_set_comm_props(serial, old_baud, 183 183 old_par, old_word_size, old_stop); 184 184 185 185 free(buf); 186 186 chardev_close(chardev); … … 189 189 return "Written less data than read from serial device"; 190 190 } 191 191 192 192 TPRINTF("Written %zd bytes\n", nwritten); 193 193 194 194 total += nread; 195 195 } 196 196 197 197 TPRINTF("Trying to write EOT banner to the serial device\n"); 198 198 199 199 size_t eot_size = str_size(EOT); 200 200 rc = chardev_write(chardev, (void *) EOT, eot_size, &nwritten); 201 201 202 202 (void) serial_set_comm_props(serial, old_baud, old_par, old_word_size, 203 203 old_stop); 204 204 205 205 free(buf); 206 206 chardev_close(chardev); 207 207 serial_close(serial); 208 208 async_hangup(sess); 209 209 210 210 if (rc != EOK) 211 211 return "Failed to write EOT banner to serial device"; 212 212 213 213 if (nwritten != eot_size) 214 214 return "Written less data than the size of the EOT banner " 215 215 "to serial device"; 216 216 217 217 return NULL; 218 218 } -
uspace/app/tester/ipc/ping_pong.c
r3061bc1 ra35b458 41 41 { 42 42 TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS); 43 43 44 44 struct timeval start; 45 45 gettimeofday(&start, NULL); 46 46 47 47 uint64_t count = 0; 48 48 while (true) { 49 49 struct timeval now; 50 50 gettimeofday(&now, NULL); 51 51 52 52 if (tv_sub_diff(&now, &start) >= DURATION_SECS * 1000000L) 53 53 break; 54 54 55 55 size_t i; 56 56 for (i = 0; i < COUNT_GRANULARITY; i++) { 57 57 errno_t retval = ns_ping(); 58 58 59 59 if (retval != EOK) { 60 60 TPRINTF("\n"); … … 62 62 } 63 63 } 64 64 65 65 count += COUNT_GRANULARITY; 66 66 } 67 67 68 68 TPRINTF("OK\nCompleted %" PRIu64 " round trips in %u seconds, %" PRIu64 " rt/s.\n", 69 69 count, DURATION_SECS, count / DURATION_SECS); 70 70 71 71 return NULL; 72 72 } -
uspace/app/tester/ipc/starve.c
r3061bc1 ra35b458 42 42 if (console == NULL) 43 43 return "Failed to init connection with console."; 44 44 45 45 struct timeval start; 46 46 gettimeofday(&start, NULL); 47 47 48 48 TPRINTF("Intensive computation shall be imagined (for %ds)...\n", DURATION_SECS); 49 49 TPRINTF("Press a key to terminate prematurely...\n"); … … 51 51 struct timeval now; 52 52 gettimeofday(&now, NULL); 53 53 54 54 if (tv_sub_diff(&now, &start) >= DURATION_SECS * 1000000L) 55 55 break; 56 56 57 57 cons_event_t ev; 58 58 suseconds_t timeout = 0; … … 63 63 } 64 64 } 65 65 66 66 // FIXME - unless a key was pressed, the answer leaked as no one 67 67 // will wait for it. 68 68 // We cannot use async_forget() directly, though. Something like 69 69 // console_forget_pending_kbd_event() shall come here. 70 70 71 71 TPRINTF("Terminating...\n"); 72 72 73 73 console_done(console); 74 74 75 75 return err; 76 76 } -
uspace/app/tester/loop/loop1.c
r3061bc1 ra35b458 36 36 while (true); 37 37 TPRINTF("\n"); 38 38 39 39 return "Survived endless loop"; 40 40 } -
uspace/app/tester/mm/common.c
r3061bc1 ra35b458 72 72 { 73 73 link_t *link; 74 74 75 75 while ((link = list_first(&mem_blocks)) != NULL) { 76 76 mem_block_t *block = list_get_instance(link, mem_block_t, link); 77 77 free_block(block); 78 78 } 79 79 80 80 while ((link = list_first(&mem_areas)) != NULL) { 81 81 mem_area_t *area = list_get_instance(link, mem_area_t, link); … … 89 89 uint8_t *mbeg = (uint8_t *) block; 90 90 uint8_t *mend = (uint8_t *) block + sizeof(mem_block_t); 91 91 92 92 /* Entry block memory <bbeg, bend) */ 93 93 uint8_t *bbeg = (uint8_t *) block->addr; 94 94 uint8_t *bend = (uint8_t *) block->addr + block->size; 95 95 96 96 /* Data block <dbeg, dend) */ 97 97 uint8_t *dbeg = (uint8_t *) addr; 98 98 uint8_t *dend = (uint8_t *) addr + size; 99 99 100 100 /* Check for overlaps */ 101 101 if (((mbeg >= dbeg) && (mbeg < dend)) || … … 104 104 ((bend > dbeg) && (bend <= dend))) 105 105 return true; 106 106 107 107 return false; 108 108 } … … 122 122 { 123 123 bool fnd = false; 124 124 125 125 list_foreach(mem_blocks, link, mem_block_t, block) { 126 126 if (overlap_match(block, addr, size)) { … … 129 129 } 130 130 } 131 131 132 132 return fnd; 133 133 } … … 160 160 { 161 161 void *data; 162 162 163 163 /* Allocate the chunk of memory */ 164 164 data = malloc(size); … … 166 166 if (data == NULL) 167 167 return NULL; 168 168 169 169 /* Check for overlaps with other chunks */ 170 170 if (test_overlap(data, size)) { … … 174 174 error_flag = true; 175 175 } 176 176 177 177 return data; 178 178 } … … 197 197 if (mem_allocated >= MAX_ALLOC) 198 198 return NULL; 199 199 200 200 /* Allocate the block holder */ 201 201 mem_block_t *block = … … 203 203 if (block == NULL) 204 204 return NULL; 205 205 206 206 link_initialize(&block->link); 207 207 208 208 /* Allocate the block memory */ 209 209 block->addr = checked_malloc(size); … … 213 213 return NULL; 214 214 } 215 215 216 216 block->size = size; 217 217 218 218 /* Register the allocated block */ 219 219 list_append(&block->link, &mem_blocks); 220 220 mem_allocated += size + sizeof(mem_block_t); 221 221 mem_blocks_count++; 222 222 223 223 return block; 224 224 } … … 238 238 mem_allocated -= block->size + sizeof(mem_block_t); 239 239 mem_blocks_count--; 240 240 241 241 /* Free the memory */ 242 242 free(block->addr); … … 272 272 pos < end; pos++) 273 273 *pos = block_expected_value(block, pos); 274 274 275 275 check_consistency("fill_block"); 276 276 } … … 308 308 if (mem_blocks_count == 0) 309 309 return NULL; 310 310 311 311 unsigned long idx = rand() % mem_blocks_count; 312 312 link_t *entry = list_nth(&mem_blocks, idx); 313 313 314 314 if (entry == NULL) { 315 315 TPRINTF("\nError: Corrupted list of allocated memory blocks.\n"); … … 317 317 error_flag = true; 318 318 } 319 319 320 320 return list_get_instance(entry, mem_block_t, link); 321 321 } … … 337 337 if (area == NULL) 338 338 return NULL; 339 339 340 340 link_initialize(&area->link); 341 341 342 342 area->addr = as_area_create(AS_AREA_ANY, size, 343 343 AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE, … … 348 348 return NULL; 349 349 } 350 350 351 351 area->size = size; 352 352 353 353 /* Register the allocated area */ 354 354 list_append(&area->link, &mem_areas); 355 355 356 356 return area; 357 357 } … … 369 369 /* Unregister the area */ 370 370 list_remove(&area->link); 371 371 372 372 /* Free the memory */ 373 373 errno_t ret = as_area_destroy(area->addr); 374 374 if (ret != EOK) 375 375 error_flag = true; 376 376 377 377 free(area); 378 378 check_consistency("unmap_area"); … … 405 405 pos < end; pos++) 406 406 *pos = area_expected_value(area, pos); 407 407 408 408 check_consistency("fill_area"); 409 409 } -
uspace/app/tester/mm/common.h
r3061bc1 ra35b458 48 48 /* Address of the start of the block */ 49 49 void *addr; 50 50 51 51 /* Size of the memory block */ 52 52 size_t size; 53 53 54 54 /* Link to other blocks */ 55 55 link_t link; … … 59 59 /* Address of the start of the area */ 60 60 void *addr; 61 61 62 62 /* Size of the memory area */ 63 63 size_t size; -
uspace/app/tester/mm/malloc1.c
r3061bc1 ra35b458 208 208 { 209 209 for (unsigned int cycles = 0; /* always */; cycles++) { 210 210 211 211 if ((subphase->cond.max_cycles) && 212 212 (cycles >= subphase->cond.max_cycles)) { … … 217 217 break; 218 218 } 219 219 220 220 /* 221 221 * Decide whether we alloc or free memory in this step. … … 229 229 int alloc = phase->alloc.min_block_size + 230 230 (rand() % (phase->alloc.max_block_size - phase->alloc.min_block_size + 1)); 231 231 232 232 mem_block_t *blk = alloc_block(alloc); 233 233 RETURN_IF_ERROR; 234 234 235 235 if (blk == NULL) { 236 236 TPRINTF("F(A)"); … … 244 244 RETURN_IF_ERROR; 245 245 } 246 246 247 247 } else if (rnd < subphase->prob.free) { 248 248 mem_block_t *blk = get_random_block(); … … 257 257 check_block(blk); 258 258 RETURN_IF_ERROR; 259 259 260 260 free_block(blk); 261 261 RETURN_IF_ERROR; … … 263 263 } 264 264 } 265 265 266 266 TPRINTF("\n.. finished.\n"); 267 267 } … … 271 271 for (unsigned int subno = 0; subno < 3; subno++) { 272 272 subphase_t *subphase = &phase->subphases[subno]; 273 273 274 274 TPRINTF(".. Sub-phase %u (%s)\n", subno + 1, subphase->name); 275 275 do_subphase(phase, subphase); … … 281 281 { 282 282 init_mem(); 283 283 284 284 for (unsigned int phaseno = 0; phaseno < sizeof_array(phases); 285 285 phaseno++) { 286 286 phase_t *phase = &phases[phaseno]; 287 287 288 288 TPRINTF("Entering phase %u (%s)\n", phaseno + 1, phase->name); 289 289 290 290 do_phase(phase); 291 291 if (error_flag) 292 292 break; 293 293 294 294 TPRINTF("Phase finished.\n"); 295 295 } 296 296 297 297 TPRINTF("Cleaning up.\n"); 298 298 done_mem(); 299 299 if (error_flag) 300 300 return "Test failed"; 301 301 302 302 return NULL; 303 303 } -
uspace/app/tester/mm/malloc3.c
r3061bc1 ra35b458 200 200 { 201 201 for (unsigned int cycles = 0; /* always */; cycles++) { 202 202 203 203 if ((subphase->cond.max_cycles) && 204 204 (cycles >= subphase->cond.max_cycles)) { … … 209 209 break; 210 210 } 211 211 212 212 /* 213 213 * Decide whether we alloc or free memory in this step. … … 221 221 int alloc = phase->alloc.min_block_size + 222 222 (rand() % (phase->alloc.max_block_size - phase->alloc.min_block_size + 1)); 223 223 224 224 mem_block_t *blk = alloc_block(alloc); 225 225 RETURN_IF_ERROR; 226 226 227 227 if (blk == NULL) { 228 228 TPRINTF("F(A)"); … … 235 235 fill_block(blk); 236 236 RETURN_IF_ERROR; 237 237 238 238 if ((mem_blocks_count % AREA_GRANULARITY) == 0) { 239 239 mem_area_t *area = map_area(AREA_SIZE); 240 240 RETURN_IF_ERROR; 241 241 242 242 if (area != NULL) { 243 243 TPRINTF("*"); … … 248 248 } 249 249 } 250 250 251 251 } else if (rnd < subphase->prob.free) { 252 252 mem_block_t *blk = get_random_block(); … … 261 261 check_block(blk); 262 262 RETURN_IF_ERROR; 263 263 264 264 free_block(blk); 265 265 RETURN_IF_ERROR; … … 267 267 } 268 268 } 269 269 270 270 TPRINTF("\n.. finished.\n"); 271 271 } … … 275 275 for (unsigned int subno = 0; subno < 3; subno++) { 276 276 subphase_t *subphase = &phase->subphases[subno]; 277 277 278 278 TPRINTF(".. Sub-phase %u (%s)\n", subno + 1, subphase->name); 279 279 do_subphase(phase, subphase); … … 285 285 { 286 286 init_mem(); 287 287 288 288 for (unsigned int phaseno = 0; phaseno < sizeof_array(phases); 289 289 phaseno++) { 290 290 phase_t *phase = &phases[phaseno]; 291 291 292 292 TPRINTF("Entering phase %u (%s)\n", phaseno + 1, phase->name); 293 293 294 294 do_phase(phase); 295 295 if (error_flag) 296 296 break; 297 297 298 298 TPRINTF("Phase finished.\n"); 299 299 } 300 300 301 301 TPRINTF("Cleaning up.\n"); 302 302 done_mem(); 303 303 if (error_flag) 304 304 return "Test failed"; 305 305 306 306 return NULL; 307 307 } -
uspace/app/tester/mm/mapping1.c
r3061bc1 ra35b458 41 41 { 42 42 TPRINTF("Creating AS area...\n"); 43 43 44 44 void *result = as_area_create(AS_AREA_ANY, size, 45 45 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED); 46 46 if (result == AS_MAP_FAILED) 47 47 return NULL; 48 48 49 49 return result; 50 50 } … … 53 53 { 54 54 TPRINTF("Touching (faulting-in) AS area...\n"); 55 55 56 56 char *ptr = (char *)area; 57 57 58 58 while (size > 0) { 59 59 *ptr = 0; … … 86 86 { 87 87 errno_t rc; 88 88 89 89 size_t buffer1_len = BUFFER1_PAGES * PAGE_SIZE; 90 90 size_t buffer2_len = BUFFER2_PAGES * PAGE_SIZE; … … 94 94 return "Cannot allocate memory"; 95 95 } 96 96 97 97 touch_area(buffer1, buffer1_len); 98 98 touch_area(buffer2, buffer2_len); 99 99 100 100 /* Now verify that mapping to physical frames exist. */ 101 101 if (!VERIFY_MAPPING(buffer1, BUFFER1_PAGES, EOK)) { … … 105 105 return "Failed to find mapping (buffer2)"; 106 106 } 107 107 108 108 /* Let's destroy the buffer1 area and access it again. */ 109 109 rc = as_area_destroy(buffer1); … … 114 114 return "Mapping of destroyed area still exists"; 115 115 } 116 116 117 117 /* clean-up */ 118 118 rc = as_area_destroy(buffer2); … … 120 120 return "Failed to destroy AS area"; 121 121 } 122 122 123 123 return NULL; 124 124 } -
uspace/app/tester/mm/pager1.c
r3061bc1 ra35b458 71 71 return NULL; 72 72 } 73 73 74 74 TPRINTF("Creating AS area...\n"); 75 75 76 76 void *result = async_as_area_create(AS_AREA_ANY, size, 77 77 AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, fd, 0, 0); … … 80 80 return NULL; 81 81 } 82 82 83 83 return result; 84 84 } … … 87 87 { 88 88 TPRINTF("Touching (faulting-in) AS area...\n"); 89 89 90 90 volatile char *ptr = (char *) area; 91 91 92 92 char ch; 93 93 while ((ch = *ptr++)) … … 101 101 if (!buffer) 102 102 return "Cannot allocate memory"; 103 103 104 104 touch_area(buffer, buffer_len); 105 105 106 106 as_area_destroy(buffer); 107 107 vfs_put(fd); 108 108 109 109 return NULL; 110 110 } -
uspace/app/tester/print/print1.c
r3061bc1 ra35b458 36 36 TPRINTF("Expected output: \" tex\"\n"); 37 37 TPRINTF("Real output: \"%*.*s\"\n\n", 5, 3, "text"); 38 38 39 39 TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n"); 40 40 TPRINTF("Expected output: \" very lon\"\n"); 41 41 TPRINTF("Real output: \"%10.8s\"\n\n", "very long text"); 42 42 43 43 TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); 44 44 TPRINTF("Expected output: \" text\"\n"); 45 45 TPRINTF("Real output: \"%8.10s\"\n\n", "text"); 46 46 47 47 TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n"); 48 48 TPRINTF("Expected output: \"very long \"\n"); 49 49 TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); 50 50 51 51 TPRINTF("Testing printf(\"%%-*.*s\", 7, 7, \"text\"):\n"); 52 52 TPRINTF("Expected output: \"text \"\n"); 53 53 TPRINTF("Real output: \"%-*.*s\"\n\n", 7, 7, "text"); 54 54 55 55 return NULL; 56 56 } -
uspace/app/tester/print/print2.c
r3061bc1 ra35b458 36 36 TPRINTF("Expected output: [a]\n"); 37 37 TPRINTF("Real output: [%c]\n\n", 'a'); 38 38 39 39 TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n"); 40 40 TPRINTF("Expected output: [1] [ 02] [03 ] [004] [005]\n"); 41 41 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5); 42 42 43 43 TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n"); 44 44 TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 45 45 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); 46 46 47 47 TPRINTF("Testing printf(\"%%lld %%3.2lld %%-3.2lld %%2.3lld %%-2.3lld\", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5):\n"); 48 48 TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 49 49 TPRINTF("Real output: [%lld] [%3.2lld] [%-3.2lld] [%2.3lld] [%-2.3lld]\n\n", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5); 50 50 51 51 TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); 52 52 TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); 53 53 TPRINTF("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21); 54 54 55 55 char ch[12]; 56 56 ptrdiff_t d, neg_d; 57 57 58 58 d = &ch[0] - &ch[12]; 59 59 neg_d = (unsigned)(-d); … … 61 61 TPRINTF("Expected output: [-12] [12] [c] [-12] [14]\n"); 62 62 TPRINTF("Real output: [%td] [%tu] [%tx] [%ti] [%to]\n\n", d, neg_d, neg_d, d, neg_d); 63 63 64 64 return NULL; 65 65 } -
uspace/app/tester/print/print3.c
r3061bc1 ra35b458 38 38 char buffer[BUFFER_SIZE]; 39 39 int retval; 40 40 41 41 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n"); 42 42 TPRINTF("Expected result: retval=30 buffer=\"Short text without parameters.\"\n"); 43 43 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); 44 44 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 45 45 46 46 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n"); 47 47 TPRINTF("Expected result: retval=44 buffer=\"Very very very long text withou\"\n"); 48 48 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); 49 49 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 50 50 51 51 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n"); 52 52 TPRINTF("Expected result: retval=11 buffer=\"Short text.\"\n"); 53 53 retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text"); 54 54 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 55 55 56 56 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"); 57 57 TPRINTF("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n"); 58 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 59 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); 60 60 61 61 return NULL; 62 62 } -
uspace/app/tester/print/print4.c
r3061bc1 ra35b458 35 35 { 36 36 TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); 37 37 38 38 uint8_t group; 39 39 for (group = 1; group < 4; group++) { 40 40 TPRINTF("%#x: ", group << 5); 41 41 42 42 uint8_t index; 43 43 for (index = 0; index < 32; index++) 44 44 TPRINTF("%c", (char) ((group << 5) + index)); 45 45 46 46 TPRINTF(" "); 47 47 for (index = 0; index < 32; index++) 48 48 TPRINTF("%lc", (wint_t) ((group << 5) + index)); 49 49 50 50 TPRINTF("\n"); 51 51 } 52 52 53 53 TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); 54 54 55 55 for (group = 4; group < 8; group++) { 56 56 TPRINTF("%#x: ", group << 5); 57 57 58 58 uint8_t index; 59 59 for (index = 0; index < 32; index++) 60 60 TPRINTF("%lc", (wint_t) ((group << 5) + index)); 61 61 62 62 TPRINTF("\n"); 63 63 } 64 64 65 65 TPRINTF("\nUTF-8 strings using printf(\"%%s\"):\n"); 66 66 TPRINTF("English: %s\n", "Quick brown fox jumps over the lazy dog"); … … 71 71 TPRINTF("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); 72 72 TPRINTF("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական"); 73 73 74 74 TPRINTF("\nUTF-32 strings using printf(\"%%ls\"):\n"); 75 75 TPRINTF("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); … … 80 80 TPRINTF("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); 81 81 TPRINTF("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական"); 82 82 83 83 return NULL; 84 84 } -
uspace/app/tester/print/print5.c
r3061bc1 ra35b458 48 48 TPRINTF("Expected output: \"(NULL)\"\n"); 49 49 TPRINTF("Real output: \"%s\"\n\n", (char *) NULL); 50 50 51 51 TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n"); 52 52 TPRINTF("Expected output: [a] [ b] [c ] [ d] [e ]\n"); 53 53 TPRINTF("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e'); 54 54 55 55 return NULL; 56 56 } -
uspace/app/tester/print/print6.c
r3061bc1 ra35b458 126 126 /* __PRINTF_FLAG_DECIMALPT */ 127 127 { -1.23450067995e+231, "%#10.10e", "-1.2345006800e+231", 0 }, 128 128 129 129 /* special */ 130 130 … … 139 139 * Fixed 140 140 */ 141 141 142 142 /* padding */ 143 143 … … 181 181 const int buf_size = 256; 182 182 char buf[256 + 1] = { 0 }; 183 183 184 184 TPRINTF("Test printing of floating point numbers via " 185 185 "printf(\"%%f\"):\n"); 186 186 187 187 for (int i = 0; i < patterns_len; ++i) { 188 188 189 189 snprintf(buf, buf_size, pat[i].fmt, pat[i].val); 190 190 191 191 if (!str_cmp(buf, pat[i].exp_str)) { 192 192 TPRINTF("ok: %s |%s| == |%s|\n", … … 203 203 } 204 204 } 205 205 206 206 if (failed) { 207 207 return "Unexpectedly misprinted floating point numbers."; -
uspace/app/tester/stdio/stdio1.c
r3061bc1 ra35b458 42 42 FILE *file; 43 43 const char *file_name = "/textdemo"; 44 44 45 45 TPRINTF("Open file \"%s\"...", file_name); 46 46 errno = 0; … … 51 51 } else 52 52 TPRINTF("OK\n"); 53 53 54 54 TPRINTF("Read file..."); 55 55 size_t cnt = fread(buf, 1, BUF_SIZE, file); … … 60 60 } else 61 61 TPRINTF("OK\n"); 62 62 63 63 buf[cnt] = '\0'; 64 64 TPRINTF("Read %zu bytes, string \"%s\"\n", cnt, buf); 65 65 66 66 TPRINTF("Seek to beginning..."); 67 67 if (fseek(file, 0, SEEK_SET) != 0) { … … 71 71 } else 72 72 TPRINTF("OK\n"); 73 73 74 74 TPRINTF("Read using fgetc()..."); 75 75 while (true) { … … 77 77 if (c == EOF) 78 78 break; 79 79 80 80 TPRINTF("."); 81 81 } 82 82 TPRINTF("[EOF]\n"); 83 83 84 84 TPRINTF("Close..."); 85 85 if (fclose(file) != 0) { … … 88 88 } else 89 89 TPRINTF("OK\n"); 90 90 91 91 return NULL; 92 92 } -
uspace/app/tester/stdio/stdio2.c
r3061bc1 ra35b458 38 38 FILE *file; 39 39 const char *file_name = "/test"; 40 40 41 41 TPRINTF("Open file \"%s\" for writing...", file_name); 42 42 errno = 0; … … 47 47 } else 48 48 TPRINTF("OK\n"); 49 49 50 50 TPRINTF("Write to file..."); 51 51 fprintf(file, "integer: %u, string: \"%s\"", 42, "Hello!"); 52 52 TPRINTF("OK\n"); 53 53 54 54 TPRINTF("Close..."); 55 55 if (fclose(file) != 0) { … … 58 58 } else 59 59 TPRINTF("OK\n"); 60 60 61 61 TPRINTF("Open file \"%s\" for reading...", file_name); 62 62 file = fopen(file_name, "rt"); … … 66 66 } else 67 67 TPRINTF("OK\n"); 68 68 69 69 TPRINTF("File contains:\n"); 70 70 while (true) { … … 74 74 TPRINTF("%c", c); 75 75 } 76 76 77 77 TPRINTF("\nClose..."); 78 78 if (fclose(file) != 0) { … … 81 81 } else 82 82 TPRINTF("OK\n"); 83 83 84 84 return NULL; 85 85 } -
uspace/app/tester/tester.c
r3061bc1 ra35b458 84 84 /* Execute the test */ 85 85 const char *ret = test->entry(); 86 86 87 87 if (ret == NULL) { 88 88 printf("\nTest passed\n"); 89 89 return true; 90 90 } 91 91 92 92 printf("\n%s\n", ret); 93 93 return false; … … 99 99 unsigned int i = 0; 100 100 unsigned int n = 0; 101 101 102 102 printf("\n*** Running all safe tests ***\n\n"); 103 103 104 104 for (test = tests; test->name != NULL; test++) { 105 105 if (test->safe) { … … 111 111 } 112 112 } 113 113 114 114 printf("\nCompleted, %u tests run, %u passed.\n", i + n, i); 115 115 } … … 123 123 len = str_length(test->name); 124 124 } 125 125 126 126 unsigned int _len = (unsigned int) len; 127 127 if ((_len != len) || (((int) _len) < 0)) { … … 129 129 return; 130 130 } 131 131 132 132 for (test = tests; test->name != NULL; test++) 133 133 printf("%-*s %s%s\n", _len, test->name, test->desc, 134 134 (test->safe ? "" : " (unsafe)")); 135 135 136 136 printf("%-*s Run all safe tests\n", _len, "*"); 137 137 } … … 145 145 return 0; 146 146 } 147 147 148 148 log_init("tester"); 149 149 … … 151 151 test_argc = argc - 2; 152 152 test_argv = argv + 2; 153 153 154 154 if (str_cmp(argv[1], "*") == 0) { 155 155 run_safe_tests(); 156 156 return 0; 157 157 } 158 158 159 159 test_t *test; 160 160 for (test = tests; test->name != NULL; test++) { … … 163 163 } 164 164 } 165 165 166 166 printf("Unknown test \"%s\"\n", argv[1]); 167 167 return -2; -
uspace/app/tester/thread/setjmp1.c
r3061bc1 ra35b458 64 64 { 65 65 counter = 0; 66 66 67 67 const char *err_msg = test_it(); 68 68 69 69 return err_msg; 70 70 } -
uspace/app/tester/thread/thread1.c
r3061bc1 ra35b458 45 45 { 46 46 thread_detach(thread_get_id()); 47 47 48 48 while (atomic_get(&finish)) 49 49 thread_usleep(100000); 50 50 51 51 atomic_inc(&threads_finished); 52 52 } … … 56 56 unsigned int i; 57 57 atomic_count_t total = 0; 58 58 59 59 atomic_set(&finish, 1); 60 60 atomic_set(&threads_finished, 0); 61 61 62 62 TPRINTF("Creating threads"); 63 63 for (i = 0; i < THREADS; i++) { … … 69 69 total++; 70 70 } 71 71 72 72 TPRINTF("\nRunning threads for %u seconds...", DELAY); 73 73 thread_sleep(DELAY); 74 74 TPRINTF("\n"); 75 75 76 76 atomic_set(&finish, 0); 77 77 while (atomic_get(&threads_finished) < total) { … … 80 80 thread_sleep(1); 81 81 } 82 82 83 83 return NULL; 84 84 } -
uspace/app/tester/vfs/vfs1.c
r3061bc1 ra35b458 50 50 { 51 51 TPRINTF("Opening the root directory..."); 52 52 53 53 DIR *dirp = opendir("/"); 54 54 if (!dirp) { … … 57 57 } else 58 58 TPRINTF("OK\n"); 59 59 60 60 struct dirent *dp; 61 61 while ((dp = readdir(dirp))) 62 62 TPRINTF(" node \"%s\"\n", dp->d_name); 63 63 closedir(dirp); 64 64 65 65 return NULL; 66 66 } … … 77 77 } 78 78 TPRINTF("Created directory %s\n", TEST_DIRECTORY); 79 79 80 80 int fd0; 81 81 rc = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, … … 84 84 return "vfs_lookup_open() failed"; 85 85 TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0); 86 86 87 87 size_t size = sizeof(text); 88 88 size_t cnt; … … 93 93 94 94 pos = 0; 95 95 96 96 char buf[BUF_SIZE]; 97 97 TPRINTF("read..\n"); … … 100 100 if (rc != EOK) 101 101 return "read() failed"; 102 102 103 103 int icnt = (int) cnt; 104 104 if ((size_t) icnt != cnt) { … … 109 109 } 110 110 } 111 111 112 112 vfs_put(fd0); 113 113 114 114 const char *rv = read_root(); 115 115 if (rv != NULL) 116 116 return rv; 117 117 118 118 if (vfs_rename_path(TEST_FILE, TEST_FILE2) != EOK) 119 119 return "vfs_rename_path() failed"; 120 120 TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2); 121 121 122 122 if (vfs_unlink_path(TEST_FILE2) != EOK) 123 123 return "vfs_unlink_path() failed"; 124 124 TPRINTF("Unlinked %s\n", TEST_FILE2); 125 125 126 126 if (vfs_unlink_path(TEST_DIRECTORY) != EOK) 127 127 return "vfs_unlink_path() failed"; 128 128 TPRINTF("Removed directory %s\n", TEST_DIRECTORY); 129 129 130 130 rv = read_root(); 131 131 if (rv != NULL) 132 132 return rv; 133 133 134 134 return NULL; 135 135 }
Note:
See TracChangeset
for help on using the changeset viewer.