Skip to content
Snippets Groups Projects
Commit 10040f18 authored by Matteo's avatar Matteo
Browse files

Added memory allocation test in the MPU testsuite.

parent 29697d23
Branches
Tags
No related merge requests found
...@@ -14,8 +14,7 @@ SUBDIRS := miosix ...@@ -14,8 +14,7 @@ SUBDIRS := miosix
## List here your source files (both .s, .c and .cpp) ## List here your source files (both .s, .c and .cpp)
## ##
SRC := \ SRC := \
./miosix/testsuite/testsuite.cpp main.cpp
#main.cpp
## ##
## List here additional static libraries with relative path ## List here additional static libraries with relative path
......
...@@ -7,19 +7,7 @@ ...@@ -7,19 +7,7 @@
#include <stdio.h> #include <stdio.h>
int main(){ int main(){
//int x[64 * 1024]; volatile unsigned int *pointer = 0x64100400;
//
//int i = 123;
//unsigned int *p = &i;
//
//p = p - 1;
//*p = 567;
volatile unsigned int *pointer = 0x63F00000;// + 0xFFFF;
*pointer = 456; *pointer = 456;
//if(*pointer == 456) write(1, "Ok\n", 3);
//write(1, okMsg2, mystrlen(okMsg2));
return 123; return 123;
} }
##
## Makefile for writing PROGRAMS for the Miosix embedded OS
## TFT:Terraneo Federico Technlogies
##
SRC := \
main.c
## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
OBJ := $(addsuffix .o, $(basename $(SRC)))
AS := arm-miosix-eabi-as
CC := arm-miosix-eabi-gcc
CXX := arm-miosix-eabi-g++
SZ := arm-miosix-eabi-size
AFLAGS := -mcpu=cortex-m3 -mthumb
CFLAGS := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
-ffunction-sections -O2 -Wall -c
CXXFLAGS := $(CFLAGS)
LFLAGS := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
-Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \
-O2 -nostdlib
DFLAGS := -MM
LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group
all: $(OBJ) crt0.o
$(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS)
$(SZ) test.elf
@arm-miosix-eabi-objdump -Dslx test.elf > test.txt
@mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader
@xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h
clean:
-rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h *.d
#pull in dependecy info for existing .o files
-include $(OBJ:.o=.d)
%.o: %.s
$(AS) $(AFLAGS) $< -o $@
%.o : %.c
$(CC) $(CFLAGS) $< -o $@
$(CC) $(DFLAGS) $(CFLAGS) $*.c > $*.d
%.o : %.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(CXX) $(DFLAGS) $(CXXFLAGS) $*.cpp > $*.d
/*
* Startup script for writing PROGRAMS for the Miosix embedded OS
* TFT:Terraneo Federico Technlogies
*/
.syntax unified
.cpu cortex-m3
.thumb
.section .text
/**
* _start, program entry point
*/
.global _start
.type _start, %function
_start:
/* TODO: .ctor */
bl main
/* TODO: .dtor */
bl _exit
/**
* _exit, terminate process
* \param v exit value
*/
.section .text._exit
.global _exit
.type _exit, %function
_exit:
movs r3, #2
svc 0
/**
* open, open a file
* \param fd file descriptor
* \param file access mode
* \param xxx access permisions
* \return file descriptor or -1 if errors
*/
.section .text.open
.global open
.type open, %function
open:
movs r3, #6
svc 0
bx lr
/**
* close, close a file
* \param fd file descriptor
*/
.section .text.close
.global close
.type close, %function
close:
movs r3, #7
svc 0
bx lr
/**
* lseek
* \param fd file descriptor
* \param pos moving offset
* \param start position, SEEK_SET, SEEK_CUR or SEEK_END
.section .text.lseek
.global lseek
.type lseek, %function
movs r3, #8
svc 0
bx lr
*/
/**
* system, fork and execture a program, blocking
* \param program to execute
*/
.section .text.system
.global system
.type system, %function
system:
movs r3, #9
svc 0
bx lr
/**
* write, write to file
* \param fd file descriptor
* \param buf data to be written
* \param len buffer length
* \return number of written bytes or -1 if errors
*/
.section .text.write
.global write
.type write, %function
write:
movs r3, #3
svc 0
bx lr
/**
* read, read from file
* \param fd file descriptor
* \param buf data to be read
* \param len buffer length
* \return number of read bytes or -1 if errors
*/
.section .text.read
.global read
.type read, %function
read:
movs r3, #4
svc 0
bx lr
/**
* usleep, sleep a specified number of microseconds
* \param us number of microseconds to sleep
* \return 0 on success or -1 if errors
*/
.section .text.usleep
.global usleep
.type usleep, %function
usleep:
movs r3, #5
svc 0
bx lr
.end
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
int main(){
//int x[64 * 1024];
//
//int i = 123;
//unsigned int *p = &i;
//
//p = p - 1;
//*p = 567;
volatile unsigned int *pointer = 0x63F00000;// + 0xFFFF;
*pointer = 456;
//if(*pointer == 456) write(1, "Ok\n", 3);
//write(1, okMsg2, mystrlen(okMsg2));
return 123;
}
/*
* Linker script for writing PROGRAMS for the Miosix embedded OS
* TFT:Terraneo Federico Technlogies
*/
OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
/* Here starts the first elf segment, that stays in flash */
. = 0 + SIZEOF_HEADERS;
.text : ALIGN(8)
{
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
}
.rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
.rel.got : { *(.rel.got) }
/* Here starts the second segment, that is copied in RAM and relocated */
. = 0x10000000;
.got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
/* FIXME: If this is put in the other segment, it makes it writable */
.dynamic : { *(.dynamic) }
/* FIXME: The compiler insists in addressing rodata relative to r9 */
.rodata : ALIGN(8)
{
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r.*)
}
.data : ALIGN(8)
{
*(.data)
*(.data.*)
*(.gnu.linkonce.d.*)
}
.bss : ALIGN(8)
{
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
}
/* These are removed since are unused and increase binary size */
/DISCARD/ :
{
*(.interp)
*(.dynsym)
*(.dynstr)
*(.hash)
*(.comment)
*(.ARM.attributes)
}
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <stdexcept> #include <stdexcept>
#include "miosix.h" #include "miosix.h"
#include "kernel/process.h" #include "kernel/process.h"
#include "kernel/process_pool.h"
//Include the test programs //Include the test programs
#include "mpu_testsuite/altered_elfs/includes.h" #include "mpu_testsuite/altered_elfs/includes.h"
...@@ -14,9 +15,12 @@ using namespace miosix; ...@@ -14,9 +15,12 @@ using namespace miosix;
void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length); void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length);
void runMpuTest(const char *name, const unsigned char *filename, unsigned int file_length); void runMpuTest(const char *name, const unsigned char *filename, unsigned int file_length);
void allocationTest();
int main() int main()
{ {
allocationTest();
// Altered elfs tests // Altered elfs tests
iprintf("\nExecuting ELF tests.\n"); iprintf("\nExecuting ELF tests.\n");
iprintf("--------------------\n"); iprintf("--------------------\n");
...@@ -80,8 +84,8 @@ int main() ...@@ -80,8 +84,8 @@ int main()
// Direct mpu tests // Direct mpu tests
iprintf("\n\nExecuting MPU tests.\n"); iprintf("\n\nExecuting MPU tests.\n");
iprintf("---------------------\n"); iprintf("---------------------\n");
runMpuTest("Test7", test1_elf, test1_elf_len); runMpuTest("Test7", test2_elf, test2_elf_len);
runMpuTest("Test8", test2_elf, test2_elf_len); runMpuTest("Test8", test3_elf, test3_elf_len);
} }
void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length) void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length)
...@@ -108,3 +112,23 @@ void runMpuTest(const char *name, const unsigned char *filename, unsigned int fi ...@@ -108,3 +112,23 @@ void runMpuTest(const char *name, const unsigned char *filename, unsigned int fi
if(WTERMSIG(ec)==SIGSEGV) iprintf("passed!\n"); if(WTERMSIG(ec)==SIGSEGV) iprintf("passed!\n");
} }
} }
void allocationTest()
{
iprintf("Executing Allocation test...\n");
unsigned int *size = ProcessPool::instance().allocate(2048);
iprintf("Allocated mem pointer: %p\n", size);
ElfProgram prog(reinterpret_cast<const unsigned int*>(test1_elf),test1_elf_len);
pid_t child=Process::create(prog);
int ec;
pid_t pid;
pid=Process::waitpid(child,&ec,0);
if(WIFEXITED(ec))
{
iprintf("not passed! (Exit status %d)\n", WEXITSTATUS(ec));
}
else if(WIFSIGNALED(ec))
{
if(WTERMSIG(ec)==SIGSEGV) iprintf("passed!\n");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment