Applied memory tests
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
#include "mem-allocator.h"
|
||||
|
||||
extern void srand (unsigned int __seed);
|
||||
extern int rand (void);
|
||||
extern long int time (long int *__timer);
|
||||
extern int printf (__const char *__restrict __format, ...);
|
||||
extern void *memset (void *__s, int __c, size_t __n);
|
||||
|
||||
// Heap size is 8K
|
||||
const size_t test_heap_size = 8 * 1024;
|
||||
|
||||
// Iterations count
|
||||
const uint32_t test_iters = 1024 * 1024;
|
||||
|
||||
// Subiterations count
|
||||
const uint32_t test_sub_iters = 3;
|
||||
|
||||
// Threshold size of block to allocate
|
||||
const uint32_t test_threshold_block_size = 2048;
|
||||
|
||||
int
|
||||
main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
uint8_t test_native_heap[test_heap_size];
|
||||
|
||||
mem_HeapInit( test_native_heap, sizeof (test_native_heap));
|
||||
|
||||
srand((unsigned int) time(NULL));
|
||||
int k = rand();
|
||||
printf("seed=%d\n", k);
|
||||
srand((unsigned int) k);
|
||||
|
||||
mem_HeapPrint( false);
|
||||
|
||||
for ( int i = 0; i < test_iters; i++ )
|
||||
{
|
||||
const int subiters = test_sub_iters;
|
||||
uint8_t * ptrs[subiters];
|
||||
size_t sizes[subiters];
|
||||
|
||||
for ( int j = 0; j < subiters; j++ )
|
||||
{
|
||||
size_t size = (unsigned int) rand() % ( test_threshold_block_size );
|
||||
ptrs[j] = mem_HeapAllocBlock( size, ( rand() % 2 ) ? MEM_HEAP_ALLOC_SHORT_TERM : MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
sizes[j] = size;
|
||||
if ( ptrs[j] != NULL )
|
||||
{
|
||||
memset(ptrs[j], 0, sizes[j]);
|
||||
}
|
||||
// JERRY_ASSERT(ptrs[j] != NULL);
|
||||
}
|
||||
|
||||
// mem_HeapPrint( true);
|
||||
|
||||
for ( int j = 0; j < subiters; j++ )
|
||||
{
|
||||
if ( ptrs[j] != NULL )
|
||||
{
|
||||
for( size_t k = 0; k < sizes[j]; k++ )
|
||||
{
|
||||
JERRY_ASSERT( ptrs[j][k] == 0 );
|
||||
}
|
||||
mem_HeapFreeBlock( ptrs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
@@ -0,0 +1,91 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define JERRY_MEM_POOL_INTERNAL
|
||||
|
||||
#include "globals.h"
|
||||
#include "mem-allocator.h"
|
||||
#include "mem-pool.h"
|
||||
|
||||
extern void srand (unsigned int __seed);
|
||||
extern int rand (void);
|
||||
extern long int time (long int *__timer);
|
||||
extern int printf (__const char *__restrict __format, ...);
|
||||
extern void *memset (void *__s, int __c, size_t __n);
|
||||
|
||||
// Pool area size is 8K
|
||||
const size_t test_pool_area_size = 8 * 1024;
|
||||
|
||||
// Iterations count
|
||||
const uint32_t test_iters = 64;
|
||||
|
||||
// Subiterations count
|
||||
const uint32_t test_max_sub_iters = 1024;
|
||||
|
||||
// Maximum size of chunk divided by MEM_ALIGNMENT
|
||||
const uint32_t test_max_chunk_size_divided_by_alignment = 32;
|
||||
|
||||
int
|
||||
main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
srand((unsigned int) time(NULL));
|
||||
int k = rand();
|
||||
printf("seed=%d\n", k);
|
||||
srand((unsigned int) k);
|
||||
|
||||
for ( int i = 0; i < test_iters; i++ )
|
||||
{
|
||||
mem_PoolState_t pool;
|
||||
uint8_t test_pool[test_pool_area_size] __attribute__((aligned(MEM_ALIGNMENT)));
|
||||
|
||||
const size_t chunkSize = MEM_ALIGNMENT * ( ( rand() % test_max_chunk_size_divided_by_alignment ) + 1 );
|
||||
|
||||
mem_PoolInit( &pool, chunkSize, test_pool, sizeof (test_pool));
|
||||
|
||||
const size_t subiters = ( (size_t) rand() % test_max_sub_iters ) + 1;
|
||||
uint8_t* ptrs[subiters];
|
||||
|
||||
for ( size_t j = 0; j < subiters; j++ )
|
||||
{
|
||||
ptrs[j] = mem_PoolAllocChunk( &pool);
|
||||
|
||||
// TODO: Enable check with condition that j <= minimum count of chunks that fit in the pool
|
||||
// JERRY_ASSERT(ptrs[j] != NULL);
|
||||
|
||||
if ( ptrs[j] != NULL )
|
||||
{
|
||||
memset(ptrs[j], 0, chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
// mem_HeapPrint( true);
|
||||
|
||||
for ( size_t j = 0; j < subiters; j++ )
|
||||
{
|
||||
if ( ptrs[j] != NULL )
|
||||
{
|
||||
for ( size_t k = 0; k < chunkSize; k++ )
|
||||
{
|
||||
JERRY_ASSERT( ((uint8_t*)ptrs[j])[k] == 0 );
|
||||
}
|
||||
|
||||
mem_PoolFreeChunk( &pool, ptrs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
@@ -0,0 +1,97 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit test for pool manager.
|
||||
*/
|
||||
|
||||
#define JERRY_MEM_POOL_INTERNAL
|
||||
|
||||
#include "globals.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "mem-allocator.h"
|
||||
#include "mem-pool.h"
|
||||
#include "mem-poolman.h"
|
||||
|
||||
extern void srand (unsigned int __seed);
|
||||
extern int rand (void);
|
||||
extern long int time (long int *__timer);
|
||||
|
||||
// Heap size is 8K
|
||||
const size_t test_heap_size = 8 * 1024;
|
||||
|
||||
// Iterations count
|
||||
const uint32_t test_iters = 16384;
|
||||
|
||||
// Subiterations count
|
||||
const uint32_t test_max_sub_iters = 64;
|
||||
|
||||
int
|
||||
main( int __unused argc,
|
||||
char __unused **argv)
|
||||
{
|
||||
uint8_t heap[test_heap_size] __attribute__((aligned(MEM_ALIGNMENT)));
|
||||
|
||||
mem_HeapInit( heap, sizeof (heap));
|
||||
mem_PoolsInit();
|
||||
|
||||
srand((unsigned int) time(NULL));
|
||||
unsigned int seed = (unsigned int)rand();
|
||||
libc_printf("seed=%u\n", seed);
|
||||
srand(seed);
|
||||
|
||||
for ( int i = 0; i < test_iters; i++ )
|
||||
{
|
||||
const size_t subiters = ( (size_t) rand() % test_max_sub_iters ) + 1;
|
||||
|
||||
uint8_t * ptrs[subiters];
|
||||
mem_PoolChunkType_t types[subiters];
|
||||
|
||||
for ( size_t j = 0; j < subiters; j++ )
|
||||
{
|
||||
mem_PoolChunkType_t type = (mem_PoolChunkType_t) (rand() % MEM_POOL_CHUNK_TYPE__COUNT);
|
||||
const uint32_t chunkSize = mem_GetChunkSize( type);
|
||||
|
||||
types[j] = type;
|
||||
ptrs[j] = mem_PoolsAlloc( type);
|
||||
JERRY_ASSERT(ptrs[j] != NULL);
|
||||
|
||||
if ( ptrs[j] != NULL )
|
||||
{
|
||||
libc_memset(ptrs[j], 0, chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
// mem_HeapPrint( false);
|
||||
|
||||
for ( size_t j = 0; j < subiters; j++ )
|
||||
{
|
||||
if ( ptrs[j] != NULL )
|
||||
{
|
||||
mem_PoolChunkType_t type = types[j];
|
||||
const uint32_t chunkSize = mem_GetChunkSize( type);
|
||||
|
||||
for ( size_t k = 0; k < chunkSize; k++ )
|
||||
{
|
||||
JERRY_ASSERT( ((uint8_t*) ptrs[j])[k] == 0 );
|
||||
}
|
||||
|
||||
mem_PoolsFree( type, ptrs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
Reference in New Issue
Block a user