Changeset a35b458 in mainline for uspace/app/tester/mm
- 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/mm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.