[haiku-commits] r33593 - haiku/trunk/src/tests/system/kernel

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 15 Oct 2009 11:30:48 +0200 (CEST)

Author: axeld
Date: 2009-10-15 11:30:48 +0200 (Thu, 15 Oct 2009)
New Revision: 33593
Changeset: http://dev.haiku-os.org/changeset/33593/haiku

Added:
   haiku/trunk/src/tests/system/kernel/reserved_areas_test.cpp
Modified:
   haiku/trunk/src/tests/system/kernel/Jamfile
Log:
* Added test application that easily reproduces bug #4778.


Modified: haiku/trunk/src/tests/system/kernel/Jamfile
===================================================================
--- haiku/trunk/src/tests/system/kernel/Jamfile 2009-10-15 07:48:31 UTC (rev 
33592)
+++ haiku/trunk/src/tests/system/kernel/Jamfile 2009-10-15 09:30:48 UTC (rev 
33593)
@@ -35,6 +35,8 @@
 SimpleTest port_wakeup_test_8 : port_wakeup_test_8.cpp ;
 SimpleTest port_wakeup_test_9 : port_wakeup_test_9.cpp ;
 
+SimpleTest reserved_areas_test : reserved_areas_test.cpp ;
+
 SimpleTest select_check : select_check.cpp ;
 SimpleTest select_close_test : select_close_test.cpp ;
 
@@ -42,7 +44,7 @@
 
 SimpleTest spinlock_contention : spinlock_contention.cpp ;
 
-SimpleTest syscall_restart_test : syscall_restart_test.cpp 
+SimpleTest syscall_restart_test : syscall_restart_test.cpp
        : network $(TARGET_LIBSUPC++) ;
 
 SetSupportedPlatformsForTarget syscall_time

Added: haiku/trunk/src/tests/system/kernel/reserved_areas_test.cpp
===================================================================
--- haiku/trunk/src/tests/system/kernel/reserved_areas_test.cpp                 
        (rev 0)
+++ haiku/trunk/src/tests/system/kernel/reserved_areas_test.cpp 2009-10-15 
09:30:48 UTC (rev 33593)
@@ -0,0 +1,88 @@
+//!    Test application that reproduces bug #4778.
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <OS.h>
+
+#include <syscalls.h>
+
+
+status_t
+memory_eater(void*)
+{
+       size_t total = 0;
+
+       while (true) {
+               size_t size = rand() % 16384 + 8;
+               if (malloc(size) == NULL) {
+                       printf("out of memory after having allocated %ld 
bytes\n", total);
+                       break;
+               } else
+                       total += size;
+
+               putchar('.');
+       }
+
+       return B_OK;
+}
+
+
+status_t
+area_creator(void*)
+{
+       while (true) {
+               status_t status = B_ERROR;
+               uint32 addressSpec = B_ANY_ADDRESS;
+               void* base;
+               bool readOnly = false;//(rand() % 256) > 127;
+               if (!readOnly) {
+                       // reserve 128 MB of space for the area
+                       base = (void*)0x60000000;
+                       status = _kern_reserve_address_range((addr_t*)&base, 
B_BASE_ADDRESS,
+                               128 * 1024 * 1024);
+                       if (status != B_OK)
+                               snooze(10000000LL);
+                       addressSpec = status == B_OK ? B_EXACT_ADDRESS : 
B_BASE_ADDRESS;
+printf("\naddress spec = %lx, base %p (status %s)\n", addressSpec, base, 
strerror(status));
+               }
+
+               area_id area = create_area(readOnly ? "read-only memory" : "r/w 
memory",
+                       &base, addressSpec, B_PAGE_SIZE * 4, B_NO_LOCK,
+                       B_READ_AREA | (readOnly ? 0 : B_WRITE_AREA));
+               if (area >= 0) {
+printf("new %s area %ld at %p\n", readOnly ? "read-only" : "r/w", area, base);
+//                     putchar('#');
+               } else
+                       break;
+
+               snooze(10000);
+       }
+
+       return B_OK;
+}
+
+
+int
+main(int argc, char** argv)
+{
+       thread_id eater = spawn_thread(&memory_eater, "memory eater",
+               B_NORMAL_PRIORITY, NULL);
+       resume_thread(eater);
+
+       thread_id creator = spawn_thread(&area_creator, "area creator",
+               B_NORMAL_PRIORITY, NULL);
+       resume_thread(creator);
+
+       object_wait_info waitInfos[2] = {
+               { eater, B_OBJECT_TYPE_THREAD, 0 },
+               { creator, B_OBJECT_TYPE_THREAD, 0 }
+       };
+       ssize_t which = wait_for_objects(waitInfos, 2);
+       printf("wait for objects: %ld\n", which);
+
+       debugger("Welcome to the land of tomorrow");
+       return 0;
+}


Other related posts:

  • » [haiku-commits] r33593 - haiku/trunk/src/tests/system/kernel - axeld