new malloc test
This commit is contained in:
		
							parent
							
								
									dd847804c0
								
							
						
					
					
						commit
						a703c5f4ba
					
				|  | @ -0,0 +1,50 @@ | |||
| TARGET   = test_malloc | ||||
| 
 | ||||
| TARGET_ARCH=riscv32 | ||||
| 
 | ||||
| CC       = riscv32-unknown-elf-gcc | ||||
| 
 | ||||
| # compiling flags here
 | ||||
| CFLAGS = -Wall -I. -O0 -static --specs=nosys.specs | ||||
| 
 | ||||
| LINKER   = riscv32-unknown-linux-gnu-gcc | ||||
| # linking flags here
 | ||||
| LDFLAGS   = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld | ||||
| LIBS   = $(EXTRA_LIBS) | ||||
| 
 | ||||
| 
 | ||||
| # change these to proper directories where each file should be
 | ||||
| SRCDIR   = ./ | ||||
| OBJDIR   = . | ||||
| BINDIR   = ./ | ||||
| INCDIR = -I. | ||||
| LIBDIR = -L. | ||||
| 
 | ||||
| 
 | ||||
| SOURCES  := $(wildcard $(SRCDIR)/*.c) | ||||
| INCLUDES := $(wildcard $(INCDIR)/*.h) | ||||
| OBJECTS  := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) | ||||
| rm       = rm -f | ||||
| 
 | ||||
| 
 | ||||
| $(BINDIR)/$(TARGET): $(OBJECTS) | ||||
| #	$(LINKER) $(OBJECTS) $(LDFLAGS) $(LIBS) $(LIBDIR) -o $@
 | ||||
| 	riscv32-unknown-elf-objdump -d $< > dump | ||||
| 	objcopy -Oihex $< $(TARGET).hex | ||||
| #	@echo "Linking complete!"
 | ||||
| 
 | ||||
| $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c | ||||
| 	@echo "Compiling "$<" ..." | ||||
| #	$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
 | ||||
| 	$(CC) $(CFLAGS) $(INCDIR) $< -o $@ | ||||
| 	@echo "Done!" | ||||
| 
 | ||||
| .PHONY: clean | ||||
| clean: | ||||
| 	@$(rm) $(OBJECTS) *.hex dump | ||||
| 	@echo "Cleanup complete!" | ||||
| 
 | ||||
| .PHONY: remove | ||||
| remove: clean | ||||
| 	@$(rm) $(BINDIR)/$(TARGET) | ||||
| 	@echo "Executable removed!" | ||||
|  | @ -0,0 +1,55 @@ | |||
| #include <string.h> | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <stdbool.h> | ||||
| 
 | ||||
| #define BUFFER_SIZE (512) | ||||
| #define TRACE (*(unsigned char *)0x40000000) | ||||
| 
 | ||||
| int _write(int file, const char *ptr, int len) { | ||||
|   int x; | ||||
| 
 | ||||
|   for (x = 0; x < len; x++) { | ||||
|     TRACE =  *ptr++; | ||||
|   } | ||||
| 
 | ||||
|   return (len); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| int main(void) { | ||||
|   uint16_t *buffA, *buffB;   | ||||
|   bool test_ok = true; | ||||
|    | ||||
|   printf("Malloc Test\n"); | ||||
| 
 | ||||
|   buffA = malloc(BUFFER_SIZE * sizeof(uint16_t)); | ||||
|   buffB = malloc(BUFFER_SIZE * sizeof(uint16_t)); | ||||
| 
 | ||||
|   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; | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   if (test_ok == true) { | ||||
|     printf("Test were OK\n"); | ||||
|   } | ||||
|    | ||||
|   asm volatile ("ecall"); | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue