From 02e1cbfbe9f8c38fe5e9f2ecb656e81b642d0ae1 Mon Sep 17 00:00:00 2001 From: Andrea Pontecorvo <andrea.ponte1987@gmail.com> Date: Tue, 8 Jan 2013 16:09:24 +0100 Subject: [PATCH] Testsuite for syscalls is working, making the one for processes --- .directory | 5 +- Makefile | 3 +- miosix/testsuite/testsuite.cpp | 73 ++++++++++++++++++- .../{testsuit_simple.h => testsuite_simple.h} | 4 +- .../{testsuit_simple => testsuite_simple}/.h | 0 .../Makefile | 0 .../crt0.s | 0 .../log.txt | 0 .../main.c | 0 .../miosix.ld | 0 .../prog3.h | 0 .../test.txt | 0 ...testsuit_syscall.h => testsuite_syscall.h} | 4 +- .../.h | 0 .../Makefile | 0 .../crt0.s | 0 .../log.txt | 0 .../main.c | 30 ++++---- .../miosix.ld | 0 .../prog3.h | 0 .../test.txt | 0 21 files changed, 95 insertions(+), 24 deletions(-) rename miosix/testsuite/{testsuit_simple.h => testsuite_simple.h} (92%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/.h (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/Makefile (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/crt0.s (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/log.txt (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/main.c (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/miosix.ld (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/prog3.h (100%) rename miosix/testsuite/{testsuit_simple => testsuite_simple}/test.txt (100%) rename miosix/testsuite/{testsuit_syscall.h => testsuite_syscall.h} (96%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/.h (100%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/Makefile (100%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/crt0.s (100%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/log.txt (100%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/main.c (76%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/miosix.ld (100%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/prog3.h (100%) rename miosix/testsuite/{testsuit_syscall => testsuite_syscall}/test.txt (100%) diff --git a/.directory b/.directory index 12b13629..caec0434 100644 --- a/.directory +++ b/.directory @@ -1,6 +1,3 @@ [Dolphin] -Timestamp=2013,1,7,14,37,46 +Timestamp=2013,1,8,14,55,19 Version=3 - -[Settings] -HiddenFilesShown=true diff --git a/Makefile b/Makefile index 3e615d0e..c665a793 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,8 @@ SUBDIRS := miosix ## List here your source files (both .s, .c and .cpp) ## SRC := \ -main.cpp +./miosix/testsuite/testsuite.cpp +#main.cpp ## ## List here additional static libraries with relative path diff --git a/miosix/testsuite/testsuite.cpp b/miosix/testsuite/testsuite.cpp index 66f82e39..e24ff01e 100644 --- a/miosix/testsuite/testsuite.cpp +++ b/miosix/testsuite/testsuite.cpp @@ -47,6 +47,12 @@ #include "board_settings.h" #include "interfaces/endianness.h" +#include "miosix/kernel/elf_program.h" +#include "miosix/kernel/process.h" + +#include "testsuite_syscall.h" +#include "testsuite_simple.h" + using namespace miosix; // A reasonably small stack value for spawning threads during the test. @@ -97,6 +103,9 @@ static void benchmark_4(); static void exception_test(); #endif //__NO_EXCEPTIONS +#ifdef WITH_PROCESSES +void syscall_test_1(); +#endif //main(), calls all tests int main() { @@ -106,7 +115,7 @@ int main() for(;;) { iprintf("Type 't' for kernel test, 'f' for filesystem test, 'x' for " - "exception test, 'b' for benchmarks or 's' for shutdown\n"); + "exception test, 'b' for benchmarks, 'p' for process test, 'y' for syscall test or 's' for shutdown\n"); char c; for(;;) { @@ -179,6 +188,15 @@ int main() iprintf("Shutting down\n"); while(!Console::txComplete()) ; shutdown(); + case 'y': + #ifdef WITH_PROCESSES + ledOn(); + syscall_test_1(); + ledOff(); + #else + fail("Process not supported"); + #endif + break; default: iprintf("Unrecognized option\n"); } @@ -217,6 +235,59 @@ static void fail(const char *cause) reboot(); } +void syscall_test_1(){ + test_name("System Call: open, read, write, seek, close, sytem"); + + char msg[256] = {0}; + + ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_syscall_elf),testsuite_syscall_len); + int ret = 0; + + remove("/testsuite.bin"); + + pid_t child = Process::create(prog); + Process::waitpid(child, &ret, 0); + + switch(ret){ + case 0: + pass(); + break; + case 1: + fail("open with O_RDWR should have failed, the file doesn't exist"); + break; + case 2: + fail("cannot craete new file"); + break; + case 3: + fail("file descriptor not valid"); + break; + case 4: + fail("write has written the wrong amount of data"); + break; + case 5: + fail("read has read the wrong amount of data"); + break; + case 6: + fail("readed data doesn't match the written one"); + break; + case 7: + fail("close hasn't returned 0"); + break; + case 8: + fail("open with O_RDWR failed, but the file exists"); + break; + case 9: + fail("read has return the wrogn amount of data"); + break; + case 10: + fail("readed data doesn't match the written one"); + break; + case 11: + fail("close hasn't returned 0"); + break; + } +} + // // Test 1 // diff --git a/miosix/testsuite/testsuit_simple.h b/miosix/testsuite/testsuite_simple.h similarity index 92% rename from miosix/testsuite/testsuit_simple.h rename to miosix/testsuite/testsuite_simple.h index df98510d..66e912f2 100644 --- a/miosix/testsuite/testsuit_simple.h +++ b/miosix/testsuite/testsuite_simple.h @@ -1,4 +1,4 @@ -const unsigned char __attribute__((aligned(8))) test_elf[] = { +const unsigned char __attribute__((aligned(8))) testsuit_simple[] = { 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -19,4 +19,4 @@ const unsigned char __attribute__((aligned(8))) test_elf[] = { 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -unsigned int test_elf_len = 220; +unsigned int testsuit_simple_len = 220; diff --git a/miosix/testsuite/testsuit_simple/.h b/miosix/testsuite/testsuite_simple/.h similarity index 100% rename from miosix/testsuite/testsuit_simple/.h rename to miosix/testsuite/testsuite_simple/.h diff --git a/miosix/testsuite/testsuit_simple/Makefile b/miosix/testsuite/testsuite_simple/Makefile similarity index 100% rename from miosix/testsuite/testsuit_simple/Makefile rename to miosix/testsuite/testsuite_simple/Makefile diff --git a/miosix/testsuite/testsuit_simple/crt0.s b/miosix/testsuite/testsuite_simple/crt0.s similarity index 100% rename from miosix/testsuite/testsuit_simple/crt0.s rename to miosix/testsuite/testsuite_simple/crt0.s diff --git a/miosix/testsuite/testsuit_simple/log.txt b/miosix/testsuite/testsuite_simple/log.txt similarity index 100% rename from miosix/testsuite/testsuit_simple/log.txt rename to miosix/testsuite/testsuite_simple/log.txt diff --git a/miosix/testsuite/testsuit_simple/main.c b/miosix/testsuite/testsuite_simple/main.c similarity index 100% rename from miosix/testsuite/testsuit_simple/main.c rename to miosix/testsuite/testsuite_simple/main.c diff --git a/miosix/testsuite/testsuit_simple/miosix.ld b/miosix/testsuite/testsuite_simple/miosix.ld similarity index 100% rename from miosix/testsuite/testsuit_simple/miosix.ld rename to miosix/testsuite/testsuite_simple/miosix.ld diff --git a/miosix/testsuite/testsuit_simple/prog3.h b/miosix/testsuite/testsuite_simple/prog3.h similarity index 100% rename from miosix/testsuite/testsuit_simple/prog3.h rename to miosix/testsuite/testsuite_simple/prog3.h diff --git a/miosix/testsuite/testsuit_simple/test.txt b/miosix/testsuite/testsuite_simple/test.txt similarity index 100% rename from miosix/testsuite/testsuit_simple/test.txt rename to miosix/testsuite/testsuite_simple/test.txt diff --git a/miosix/testsuite/testsuit_syscall.h b/miosix/testsuite/testsuite_syscall.h similarity index 96% rename from miosix/testsuite/testsuit_syscall.h rename to miosix/testsuite/testsuite_syscall.h index dfc8d01c..94e1ef64 100644 --- a/miosix/testsuite/testsuit_syscall.h +++ b/miosix/testsuite/testsuite_syscall.h @@ -1,4 +1,4 @@ -const unsigned char __attribute__((aligned(8))) test_elf[] = { +const unsigned char __attribute__((aligned(8))) testsuite_syscall_elf[] = { 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -45,4 +45,4 @@ const unsigned char __attribute__((aligned(8))) test_elf[] = { 0x00, 0x00, 0x00, 0x00, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x75, 0x69, 0x74, 0x2e, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00 }; -unsigned int test_elf_len = 536; +unsigned int testsuite_syscall_len = 536; diff --git a/miosix/testsuite/testsuit_syscall/.h b/miosix/testsuite/testsuite_syscall/.h similarity index 100% rename from miosix/testsuite/testsuit_syscall/.h rename to miosix/testsuite/testsuite_syscall/.h diff --git a/miosix/testsuite/testsuit_syscall/Makefile b/miosix/testsuite/testsuite_syscall/Makefile similarity index 100% rename from miosix/testsuite/testsuit_syscall/Makefile rename to miosix/testsuite/testsuite_syscall/Makefile diff --git a/miosix/testsuite/testsuit_syscall/crt0.s b/miosix/testsuite/testsuite_syscall/crt0.s similarity index 100% rename from miosix/testsuite/testsuit_syscall/crt0.s rename to miosix/testsuite/testsuite_syscall/crt0.s diff --git a/miosix/testsuite/testsuit_syscall/log.txt b/miosix/testsuite/testsuite_syscall/log.txt similarity index 100% rename from miosix/testsuite/testsuit_syscall/log.txt rename to miosix/testsuite/testsuite_syscall/log.txt diff --git a/miosix/testsuite/testsuit_syscall/main.c b/miosix/testsuite/testsuite_syscall/main.c similarity index 76% rename from miosix/testsuite/testsuit_syscall/main.c rename to miosix/testsuite/testsuite_syscall/main.c index 8068820d..eaebafa3 100644 --- a/miosix/testsuite/testsuit_syscall/main.c +++ b/miosix/testsuite/testsuite_syscall/main.c @@ -18,50 +18,52 @@ int main(){ for(i = 0; i < SIZE; i++) buffer[i] = i; - int fd = open("/testsuit.bin", O_RDWR, 0); + int fd = open("/testsuite.bin", O_RDWR, 0); if(fd != -1) - return error(0); + return error(1); + + close(fd); - fd = open("/testsuit.bin", O_RDWR|O_TRUNC, 0); + fd = open("/testsuite.bin", O_RDWR|O_TRUNC, 0); if(fd == -1) - return error(1); + return error(2); if(fd >= 0 && fd <= 2) - return error(2); + return error(3); if(write(fd, buffer, SIZE) != SIZE) - return error(3); + return error(4); seek(fd, SEEK_SET, 0); if(read(fd, buffer2, SIZE) != SIZE) - return error(4); + return error(5); for(i = 0; i < SIZE; i++){ if(buffer[i] != buffer2[i]) - return error(5); + return error(6); } if(close(fd) != 0) - return error(6); + return error(7); - fd = open("/testsuit.bin", O_RDWR); + fd = open("/testsuite.bin", O_RDWR); if(fd < 2) - return error(7); + return error(8); if(read(fd, buffer2, SIZE) != SIZE) - return error(8); + return error(9); for(i = 0; i < SIZE; i++){ if(buffer[i] != buffer2[i]) - return error(9); + return error(10); } if(close(fd)) - return error(10); + return error(11); return 0; } diff --git a/miosix/testsuite/testsuit_syscall/miosix.ld b/miosix/testsuite/testsuite_syscall/miosix.ld similarity index 100% rename from miosix/testsuite/testsuit_syscall/miosix.ld rename to miosix/testsuite/testsuite_syscall/miosix.ld diff --git a/miosix/testsuite/testsuit_syscall/prog3.h b/miosix/testsuite/testsuite_syscall/prog3.h similarity index 100% rename from miosix/testsuite/testsuit_syscall/prog3.h rename to miosix/testsuite/testsuite_syscall/prog3.h diff --git a/miosix/testsuite/testsuit_syscall/test.txt b/miosix/testsuite/testsuite_syscall/test.txt similarity index 100% rename from miosix/testsuite/testsuit_syscall/test.txt rename to miosix/testsuite/testsuite_syscall/test.txt -- GitLab