2019-09-07 17:39:09 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#define BUFFER_SIZE (512)
|
|
|
|
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
uint16_t *buffA, *buffB;
|
|
|
|
bool test_ok = true;
|
2019-09-07 17:40:00 +08:00
|
|
|
uint8_t *buffC;
|
2019-09-07 17:39:09 +08:00
|
|
|
|
|
|
|
printf("Malloc Test\n");
|
|
|
|
|
2019-09-07 17:40:00 +08:00
|
|
|
printf("buffA: %p\n", (void *) buffA);
|
|
|
|
printf("buffB: %p\n", (void *) buffB);
|
|
|
|
printf("buffC: %p\n", (void *) buffC);
|
|
|
|
|
2019-09-07 17:39:09 +08:00
|
|
|
buffA = malloc(BUFFER_SIZE * sizeof(uint16_t));
|
|
|
|
buffB = malloc(BUFFER_SIZE * sizeof(uint16_t));
|
|
|
|
|
2019-09-07 17:40:00 +08:00
|
|
|
printf("buffA: %p\n", (void *) buffA);
|
|
|
|
printf("buffB: %p\n", (void *) buffB);
|
|
|
|
printf("buffC: %p\n", (void *) buffC);
|
|
|
|
|
2019-09-07 17:39:09 +08:00
|
|
|
if ( (buffA == NULL ) || (buffB == NULL) ) {
|
|
|
|
printf("Error malloc\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0;i<BUFFER_SIZE;i++) {
|
|
|
|
buffA[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffB, buffA, BUFFER_SIZE * sizeof(uint16_t));
|
|
|
|
|
|
|
|
for(int i=0;i<BUFFER_SIZE;i++) {
|
|
|
|
if (buffA[i] != buffB[i]) {
|
|
|
|
printf("Error at postion %d\n", i);
|
|
|
|
test_ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 17:40:00 +08:00
|
|
|
free(buffA);
|
|
|
|
free(buffB);
|
|
|
|
|
|
|
|
printf("buffA: %p\n", (void *) buffA);
|
|
|
|
printf("buffB: %p\n", (void *) buffB);
|
|
|
|
printf("buffC: %p\n", (void *) buffC);
|
|
|
|
|
|
|
|
/* buffC should reuse address previously used by buffA (?) */
|
|
|
|
buffC = malloc(512);
|
|
|
|
printf("buffC: %p\n", (void *) buffC);
|
|
|
|
|
2019-09-07 17:39:09 +08:00
|
|
|
if (test_ok == true) {
|
|
|
|
printf("Test were OK\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
asm volatile ("ecall");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|