1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #13554 from OTAkeys/fix/memarray_init

memarray: fix memarray init
This commit is contained in:
Alexandre Abadie 2020-03-09 19:21:33 +01:00 committed by GitHub
commit 803698037a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 8 deletions

View File

@ -28,6 +28,7 @@ void memarray_init(memarray_t *mem, void *data, size_t size, size_t num)
void *next = ((char *)mem->free_data) + ((i + 1) * mem->size); void *next = ((char *)mem->free_data) + ((i + 1) * mem->size);
memcpy(((char *)mem->free_data) + (i * mem->size), &next, sizeof(void *)); memcpy(((char *)mem->free_data) + (i * mem->size), &next, sizeof(void *));
} }
memset(((char *)mem->free_data) + ((mem->num - 1) * (mem->size)), 0, sizeof(void *));
} }
void *memarray_alloc(memarray_t *mem) void *memarray_alloc(memarray_t *mem)

View File

@ -35,6 +35,11 @@
#define NUMBER_OF_TESTS (12) #define NUMBER_OF_TESTS (12)
#endif #endif
#ifndef NUMBER_OF_LOOPS
#define NUMBER_OF_LOOPS (2)
#endif
extern int _ps_handler(int argc, char **argv); extern int _ps_handler(int argc, char **argv);
struct block_t { struct block_t {
@ -101,14 +106,17 @@ void free_memory(struct block_t *head)
int main(void) int main(void)
{ {
printf("MAX_NUMBER_BLOCKS: %d\n", MAX_NUMBER_BLOCKS); printf("MAX_NUMBER_BLOCKS: %d\n", MAX_NUMBER_BLOCKS);
printf("NUMBER_OF_LOOPS: %d\n", NUMBER_OF_LOOPS);
printf("NUMBER_OF_TESTS: %d\n", NUMBER_OF_TESTS); printf("NUMBER_OF_TESTS: %d\n", NUMBER_OF_TESTS);
memory_block_init(); memory_block_init();
int count = 0; int count = 0;
int loop = 0;
printf("Starting (%d, %u)\n", MAX_NUMBER_BLOCKS, MESSAGE_SIZE); printf("Starting (%d, %u)\n", MAX_NUMBER_BLOCKS, MESSAGE_SIZE);
_ps_handler(0, NULL); _ps_handler(0, NULL);
printf("LOOP #%i:\n", loop + 1);
while (count < NUMBER_OF_TESTS) { while (count < NUMBER_OF_TESTS) {
struct block_t *head = (struct block_t *) memarray_alloc(&block_storage); struct block_t *head = (struct block_t *) memarray_alloc(&block_storage);
@ -119,6 +127,20 @@ int main(void)
count++; count++;
} }
count = 0;
loop++;
printf("LOOP #%i:\n", loop + 1);
while (count < NUMBER_OF_TESTS) {
memory_block_init();
struct block_t *head = (struct block_t *) memarray_alloc(&block_storage);
printf("TEST #%i:\n", count + 1 );
fill_memory(head);
free_memory(head);
count++;
}
printf("Finishing\n"); printf("Finishing\n");
_ps_handler(0, NULL); _ps_handler(0, NULL);

View File

@ -13,8 +13,12 @@ from testrunner import run
def testfunc(child): def testfunc(child):
child.expect(r'MAX_NUMBER_BLOCKS: (\d+)\r\n') child.expect(r'MAX_NUMBER_BLOCKS: (\d+)\r\n')
max_number_blocks = int(child.match.group(1)) max_number_blocks = int(child.match.group(1))
child.expect(r'NUMBER_OF_LOOPS: (\d+)\r\n')
number_of_loops = int(child.match.group(1))
child.expect(r'NUMBER_OF_TESTS: (\d+)\r\n') child.expect(r'NUMBER_OF_TESTS: (\d+)\r\n')
number_of_tests = int(child.match.group(1)) number_of_tests = int(child.match.group(1))
for loop in range(number_of_loops):
child.expect_exact("LOOP #{}:".format(loop + 1))
for test in range(number_of_tests): for test in range(number_of_tests):
child.expect_exact("TEST #{}:".format(test + 1)) child.expect_exact("TEST #{}:".format(test + 1))
for i in range(max_number_blocks): for i in range(max_number_blocks):