Added a test for the BufferPool class.

Began to move the tests directory to bfs/ instead of befs/.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1886 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-11-09 02:08:54 +00:00
parent dab62fa391
commit 9616fa5dfd
4 changed files with 86 additions and 0 deletions

View File

@ -1,3 +1,4 @@
SubDir OBOS_TOP src tests add-ons kernel file_systems ;
SubInclude OBOS_TOP src tests add-ons kernel file_systems befs ;
SubInclude OBOS_TOP src tests add-ons kernel file_systems bfs ;

View File

@ -0,0 +1,4 @@
SubDir OBOS_TOP src tests add-ons kernel file_systems bfs ;
#SubInclude OBOS_TOP src tests add-ons kernel file_systems bfs blockAllocator ;
SubInclude OBOS_TOP src tests add-ons kernel file_systems bfs bufferPool ;

View File

@ -0,0 +1,19 @@
SubDir OBOS_TOP src tests add-ons kernel file_systems bfs bufferPool ;
SubDirHdrs $(OBOS_TOP) src add-ons kernel file_systems bfs ;
{
local defines = [ FDefines USER DEBUG ] ; # _NO_INLINE_ASM
SubDirCcFlags $(defines) -fno-exceptions -fno-rtti ; #-fcheck-memory-usage
SubDirC++Flags $(defines) -fno-exceptions -fno-rtti ; #-fcheck-memory-usage
}
SimpleTest bufferTest
: main.cpp
BufferPool.cpp
: ;
# Tell Jam where to find these sources
SEARCH on [ FGristFiles BufferPool.cpp ]
= [ FDirName $(OBOS_TOP) src add-ons kernel file_systems bfs ] ;

View File

@ -0,0 +1,62 @@
#include "BufferPool.h"
#include <stdio.h>
#include <string.h>
#define BLOCK_SIZE 2048
#define NUM_THREADS 10
#define NUM_LOOPS 50
int32 gID;
int32
allocator(void *_pool)
{
BufferPool &pool = *(BufferPool *)_pool;
int32 id = atomic_add(&gID, 1);
for (int32 i = 0; i < NUM_LOOPS; i++) {
snooze(50000);
printf("%ld. Get buffer...\n", id);
status_t status;
void *buffer;
if ((status = pool.GetBuffer(&buffer)) != B_OK) {
printf("\t%ld. Couldn't get buffer: %s\n", id, strerror(status));
continue;
}
printf("\t%ld. got buffer\n", id);
snooze(50000);
pool.PutBuffer(buffer);
printf("\t%ld. released buffer\n", id);
}
}
int
main(int argc, char **argv)
{
BufferPool pool;
thread_id thread[NUM_THREADS];
if (pool.RequestBuffers(BLOCK_SIZE) == B_OK) {
for (int i = 0; i < NUM_THREADS; i++) {
thread[i] = spawn_thread(allocator, "", B_NORMAL_PRIORITY, (void *)&pool);
if (thread[i] < B_OK)
fprintf(stderr, "Couldn't spawn thread %ld\n", i);
resume_thread(thread[i]);
}
for (int32 i = 0; i < NUM_THREADS; i++) {
status_t status;
wait_for_thread(thread[i], &status);
}
pool.ReleaseBuffers();
}
return 0;
}