From a703c5f4baaec393a1635c083abc24b92209e5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A0rius=20Mont=C3=B3n?= Date: Sat, 7 Sep 2019 11:39:09 +0200 Subject: [PATCH] new malloc test --- tests/C/test_malloc/Makefile | 50 ++++++++++++++++++++++++++++ tests/C/test_malloc/test_malloc.c | 55 +++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 tests/C/test_malloc/Makefile create mode 100644 tests/C/test_malloc/test_malloc.c diff --git a/tests/C/test_malloc/Makefile b/tests/C/test_malloc/Makefile new file mode 100644 index 0000000..656ba6c --- /dev/null +++ b/tests/C/test_malloc/Makefile @@ -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!" diff --git a/tests/C/test_malloc/test_malloc.c b/tests/C/test_malloc/test_malloc.c new file mode 100644 index 0000000..f9b76a6 --- /dev/null +++ b/tests/C/test_malloc/test_malloc.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#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