added a new header file to encapsulate compiler-specific stuff.
[newos.git] / apps / vmtest / main.c
blob965e24b0708bbb339120e61c6655dc07481f9727
1 /*
2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #include <string.h>
6 #include <stdio.h>
7 #include <sys/types.h>
8 #include <sys/syscalls.h>
9 #include <newos/errors.h>
10 #include <unistd.h>
12 int main(void)
14 int rc = 0;
16 printf("VM test\n");
18 printf("my thread id is %d\n", _kern_get_current_thread_id());
19 #if 0
20 printf("writing to invalid page\n");
21 *(int *)0x30000000 = 5;
22 #endif
23 #if 1
24 printf("doing some region tests\n");
26 region_id region;
27 region_id region2;
28 vm_region_info info;
29 void *ptr, *ptr2;
31 region = _kern_vm_create_anonymous_region("foo", &ptr, REGION_ADDR_ANY_ADDRESS,
32 16*4096, REGION_WIRING_LAZY, LOCK_RW);
33 printf("region = 0x%x @ 0x%x\n", region, (unsigned int)ptr);
34 region2 = _kern_vm_clone_region("foo2", &ptr2, REGION_ADDR_ANY_ADDRESS,
35 region, REGION_NO_PRIVATE_MAP, LOCK_RW);
36 printf("region2 = 0x%x @ 0x%x\n", region2, (unsigned int)ptr2);
38 _kern_vm_get_region_info(region, &info);
39 printf("info.base = 0x%x info.size = 0x%x\n", (unsigned int)info.base, (unsigned int)info.size);
41 _kern_vm_delete_region(region);
42 _kern_vm_delete_region(region2);
43 printf("deleting both regions\n");
45 #endif
46 #if 1
47 printf("doing some commitment tests (will only be proper on 256MB machines)\n");
49 region_id region;
50 region_id region2;
51 void *ptr, *ptr2;
53 region = _kern_vm_create_anonymous_region("large", &ptr, REGION_ADDR_ANY_ADDRESS,
54 200*1024*1024, REGION_WIRING_LAZY, LOCK_RW);
55 if(region < 0) {
56 printf("error %d creating large region\n", region);
57 } else {
58 printf("region = 0x%x @ 0x%x\n", region, (unsigned int)ptr);
61 printf("pausing for 5 seconds...\n");
62 usleep(5000000);
63 region2 = _kern_vm_create_anonymous_region("large2", &ptr2, REGION_ADDR_ANY_ADDRESS,
64 64*1024*1024, REGION_WIRING_LAZY, LOCK_RW);
65 if(region2 < 0) {
66 printf("error %d creating large region\n", region2);
67 if(region2 == ERR_VM_WOULD_OVERCOMMIT)
68 printf("good, it failed because of overcommitting\n");
69 } else {
70 printf("region2 = 0x%x @ 0x%x\n", region2, (unsigned int)ptr2);
73 printf("pausing for 5 seconds...\n");
74 usleep(5000000);
75 printf("deleting both regions\n");
76 _kern_vm_delete_region(region);
77 _kern_vm_delete_region(region2);
79 #endif
80 #if 1
82 // create a couple of big regions and time it
83 region_id region;
84 void *ptr;
85 bigtime_t t;
87 printf("running some timing tests on region creation/deletion.\n");
88 printf("you'll want to make sure serial debugging is off or the test will take forever,\n");
89 printf(" use the scroll lock key to toggle it on or off.\n");
90 printf("pausing for 2 seconds...\n");
91 usleep(2000000);
93 t = _kern_system_time();
94 region = _kern_vm_create_anonymous_region("large", &ptr, REGION_ADDR_ANY_ADDRESS,
95 64*1024*1024, REGION_WIRING_LAZY, LOCK_RW);
96 t = _kern_system_time() - t;
98 printf("took %d microseconds to create large region (lazy wiring)\n", (int)t);
100 t = _kern_system_time();
101 _kern_vm_delete_region(region);
102 t = _kern_system_time() - t;
104 printf("took %d microseconds to delete it (with no pages allocated)\n", (int)t);
106 t = _kern_system_time();
107 region = _kern_vm_create_anonymous_region("large", &ptr, REGION_ADDR_ANY_ADDRESS,
108 64*1024*1024, REGION_WIRING_WIRED, LOCK_RW);
109 t = _kern_system_time() - t;
111 printf("took %d microseconds to create large region (wired)\n", (int)t);
113 t = _kern_system_time();
114 _kern_vm_delete_region(region);
115 t = _kern_system_time() - t;
117 printf("took %d microseconds to delete it (with all allocated)\n", (int)t);
119 #endif
121 printf("vmtest: exiting w/return code %d\n", rc);
122 return rc;