Changeset 96348adc in mainline for kernel/test/mm/falloc2.c
- Timestamp:
- 2006-12-12T17:24:58Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e13972
- Parents:
- 34db7fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/falloc2.c
r34db7fa r96348adc 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include <print.h> 29 30 #include <test.h> … … 39 40 #include <arch.h> 40 41 41 #ifdef CONFIG_BENCH42 #include <arch/cycle.h>43 #endif44 45 42 #define MAX_FRAMES 256 46 43 #define MAX_ORDER 8 … … 49 46 #define THREADS 8 50 47 51 static void falloc(void * arg);52 static void failed(void);48 static atomic_t thread_count; 49 static atomic_t thread_fail; 53 50 54 static atomic_t thread_count; 55 56 void falloc(void * arg) 51 static void falloc(void * arg) 57 52 { 58 53 int order, run, allocated, i; … … 61 56 62 57 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC); 63 ASSERT(frames != NULL); 58 if (frames == NULL) { 59 printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); 60 atomic_inc(&thread_fail); 61 atomic_dec(&thread_count); 62 return; 63 } 64 64 65 65 thread_detach(THREAD); … … 74 74 memsetb(frames[allocated], FRAME_SIZE << order, val); 75 75 allocated++; 76 } else {76 } else 77 77 break; 78 }79 78 } 80 79 printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); … … 85 84 if (((uint8_t *) frames[i])[k] != val) { 86 85 printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); 87 failed(); 86 atomic_inc(&thread_fail); 87 goto cleanup; 88 88 } 89 89 } … … 93 93 } 94 94 } 95 95 96 cleanup: 96 97 free(frames); 97 98 printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); … … 99 100 } 100 101 101 102 void failed(void) 102 char * test_falloc2(void) 103 103 { 104 panic("Test failed.\n"); 105 } 106 107 108 void test_falloc2(void) 109 { 110 #ifdef CONFIG_BENCH 111 uint64_t t0 = get_cycle(); 112 #endif 113 int i; 104 unsigned int i; 114 105 115 106 atomic_set(&thread_count, THREADS); 107 atomic_set(&thread_fail, 0); 116 108 117 109 for (i = 0; i < THREADS; i++) { 118 thread_t * thrd ;119 thrd = thread_create(falloc, NULL, TASK, 0, "falloc");120 if (thrd)121 thread_ready(thrd);122 else123 failed();110 thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc"); 111 if (!thrd) { 112 printf("Could not create thread %d\n", i); 113 break; 114 } 115 thread_ready(thrd); 124 116 } 125 117 126 while (thread_count.count) 127 ; 128 129 printf("Test passed.\n"); 130 #ifdef CONFIG_BENCH 131 uint64_t dt = get_cycle() - t0; 132 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 133 #endif 118 while (atomic_get(&thread_count) > 0) { 119 printf("Threads left: %d\n", atomic_get(&thread_count)); 120 thread_sleep(1); 121 } 122 123 if (atomic_get(&thread_fail) == 0) 124 return NULL; 125 126 return "Test failed"; 134 127 }
Note:
See TracChangeset
for help on using the changeset viewer.