Mercurial > hg > Game > Cerium
changeset 1187:d4311f83377a draft
Put in order Test directory
author | Daichi TOMA |
---|---|
date | Thu, 07 Jul 2011 13:31:02 +0900 |
parents | 4c209dd223cd |
children | ad64e2b20a9f |
files | TaskManager/CpuThreadsTest/CpuThreadsTest.cc TaskManager/CpuThreadsTest/Makefile TaskManager/kernel/ppe/MailManager.cc TaskManager/kernel/ppe/Sem.cc TaskManager/test/CpuThreadsTest/CpuThreadsTest.cc TaskManager/test/CpuThreadsTest/Makefile TaskManager/test/MailManagerTest.cc TaskManager/test/MailManagerTest/MailManagerTest.cc TaskManager/test/MailManagerTest/Makefile TaskManager/test/Makefile TaskManager/test/SemMailManagerTest/MailManagerTest.cc TaskManager/test/SemMailManagerTest/Makefile |
diffstat | 12 files changed, 229 insertions(+), 166 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/CpuThreadsTest/CpuThreadsTest.cc Mon Jul 04 14:11:26 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -#include <stdio.h> -#include "TaskManager/CpuThreads.h" -#include "TaskManager/CellTaskManagerImpl.h" - -static void -fail(const char *reason) -{ - printf("CpuThreadTest failed %s", reason); -} - -static void -tester(CpuThreadsPtr c, int num, int size) -{ - for(int id = 0; id < num; id++){ - for(int i = 0; i < size; i++) { - c->send_mail(id, 1, (memaddr *) i); //mailqueue1に書き込む - } - } - - for(int id = 0; id < num; id++){ - for(int i = 0; i < size; i++) { - memaddr data; - if (c->has_mail(id, 1, &data) == 0) { - fail("early read fail\n"); - break; - } - if (data != (memaddr)i) { - fail("read data fail\n"); - break; - } - } - } -} - -static void -test1() { - int num = 1; - CpuThreadsPtr c = new CpuThreads(num); - c->init(); - tester(c,num,16); - delete c; -} - -int -main(int ac, const char *av[]) -{ - test1(); - printf("CpuThreads succeed\n"); -} - -/* end */
--- a/TaskManager/CpuThreadsTest/Makefile Mon Jul 04 14:11:26 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -include ../Makefile.def - -CPPFLAGS += -g -Wall -I../../include -m$(ABIBIT) - -TARGET=CpuThreadsTest - -$(TARGET) : - -LIBS += ../libParallelManager.a - -CpuThreadsTest : CpuThreadsTest.o - $(CC) $(CFLAGS) -o $@ $? $(LIBS) - -clean: - rm -rf *.o $(TARGET)
--- a/TaskManager/kernel/ppe/MailManager.cc Mon Jul 04 14:11:26 2011 +0900 +++ b/TaskManager/kernel/ppe/MailManager.cc Thu Jul 07 13:31:02 2011 +0900 @@ -17,7 +17,7 @@ calc_mask(qsize); queue = Newq(memaddr,size); - queue_remain = new Sem(size-1); //queue内にあと入る数 + queue_remain = new Sem(size-1); //queue内に入る残りの数 queue_count = new Sem(0); //queue内に現在入っている数 }
--- a/TaskManager/kernel/ppe/Sem.cc Mon Jul 04 14:11:26 2011 +0900 +++ b/TaskManager/kernel/ppe/Sem.cc Thu Jul 07 13:31:02 2011 +0900 @@ -30,6 +30,7 @@ } //atomic //sem->value--; //資源の確保 + //count()のvalueを取得する際にアトミック操作が必要 __sync_fetch_and_sub(&sem->value,1); pthread_mutex_unlock(&sem->mutex); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/CpuThreadsTest/CpuThreadsTest.cc Thu Jul 07 13:31:02 2011 +0900 @@ -0,0 +1,51 @@ +#include <stdio.h> +#include "TaskManager/CpuThreads.h" +#include "TaskManager/CellTaskManagerImpl.h" + +static void +fail(const char *reason) +{ + printf("CpuThreadTest failed %s", reason); +} + +static void +tester(CpuThreadsPtr c, int num, int size) +{ + for(int id = 0; id < num; id++){ + for(int i = 0; i < size; i++) { + c->send_mail(id, 1, (memaddr *) i); //mailqueue1に書き込む + } + } + + for(int id = 0; id < num; id++){ + for(int i = 0; i < size; i++) { + memaddr data; + if (c->has_mail(id, 1, &data) == 0) { + fail("early read fail\n"); + break; + } + if (data != (memaddr)i) { + fail("read data fail\n"); + break; + } + } + } +} + +static void +test1() { + int num = 1; + CpuThreadsPtr c = new CpuThreads(num); + c->init(); + tester(c,num,16); + delete c; +} + +int +main(int ac, const char *av[]) +{ + test1(); + printf("CpuThreads succeed\n"); +} + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/CpuThreadsTest/Makefile Thu Jul 07 13:31:02 2011 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include -m$(ABIBIT) + +TARGET=CpuThreadsTest + +$(TARGET) : + +LIBS += ../../libFifoManager.a + +CpuThreadsTest : CpuThreadsTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)
--- a/TaskManager/test/MailManagerTest.cc Mon Jul 04 14:11:26 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -#include <stdio.h> -#include "TaskManager/MailManager.h" - -typedef struct _thread_arg { - MailManagerPtr m; - int size; -} thread_arg_t; - -static void -fail(const char *reason) -{ - printf("MailManagerTest failed %s", reason); -} - -static void -send_func(void *arg) -{ - thread_arg_t* targ = (thread_arg_t *)arg; - for(int i = 0; i < targ->size; i++) { - printf("send %d\n",i); - targ->m->send((memaddr)i); - } - return; -} - -static void -recv_func(void *arg) -{ - thread_arg_t* targ = (thread_arg_t *)arg; - for(int i = 0; i < targ->size; i++) { - if (targ->m->recv() != (memaddr)i) { - fail("read data fail\n"); - break; - } - printf("\t receive %d\n",i); - } - return; -} - -static void -tester(MailManagerPtr m, int size) -{ - //送信者スレッド作成 - thread_arg_t starg; - starg.m = m; - starg.size = size; - - pthread_t send; - pthread_create(&send, NULL, (void* (*)(void*))&send_func, (void*)&starg); - - //受信者スレッド作成 - thread_arg_t rtarg; - rtarg.m = m; - rtarg.size = size; - - pthread_t recv; - pthread_create(&recv, NULL, (void* (*)(void*))&recv_func, (void*)&rtarg); - - //終了待ち - pthread_join(send, NULL); - pthread_join(recv, NULL); -} - -static void -test1() { - MailManagerPtr m = new MailManager(2); - tester(m,16); - tester(m,32); - tester(m,48); - delete m; - MailManagerPtr m1 = new MailManager(32); - tester(m1,16); - tester(m1,48); - delete m1; -} - -int -main(int ac, const char *av[]) -{ - test1(); - printf("MailManagerTest succeed\n"); -} - -/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/MailManagerTest/MailManagerTest.cc Thu Jul 07 13:31:02 2011 +0900 @@ -0,0 +1,47 @@ +#include <stdio.h> +#include "TaskManager/MailManager.h" + +static void +fail(const char *reason) +{ + printf("MailManagerTest failed %s", reason); +} + +static void +tester(MailManagerPtr m, int size) +{ + + for(int i=0;i<size;i++) { + m->send((memaddr)i); + } + for(int i=0;i<size;i++) { + if (m->count()==0) { + fail("early read fail\n"); break; + } + if (m->recv()!=(memaddr)i) { + fail("read data fail\n"); break; + } + } +} + +static void +test1() { + MailManagerPtr m = new MailManager(); + tester(m,16); + tester(m,32); + tester(m,48); + delete m; + MailManagerPtr m1 = new MailManager(40); + tester(m1,16); + tester(m1,48); + delete m1; +} + +int +main(int ac, const char *av[]) +{ + test1(); + printf("MailManagerTest succeed\n"); +} + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/MailManagerTest/Makefile Thu Jul 07 13:31:02 2011 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include -m$(ABIBIT) + +TARGET=MailManagerTest + +$(TARGET) : + +LIBS += ../../libFifoManager.a + +MailManagerTest : MailManagerTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)
--- a/TaskManager/test/Makefile Mon Jul 04 14:11:26 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -include ../Makefile.def - -CPPFLAGS += -g -Wall -I../../include -m$(ABIBIT) - -TARGET=MailManagerTest - -$(TARGET) : - -LIBS += ../libFifoManager.a - -MailManagerTest : MailManagerTest.o - $(CC) $(CFLAGS) -o $@ $? $(LIBS) - -clean: - rm -rf *.o $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/SemMailManagerTest/MailManagerTest.cc Thu Jul 07 13:31:02 2011 +0900 @@ -0,0 +1,84 @@ +#include <stdio.h> +#include "TaskManager/MailManager.h" + +typedef struct _thread_arg { + MailManagerPtr m; + int size; +} thread_arg_t; + +static void +fail(const char *reason) +{ + printf("MailManagerTest failed %s", reason); +} + +static void +send_func(void *arg) +{ + thread_arg_t* targ = (thread_arg_t *)arg; + for(int i = 0; i < targ->size; i++) { + printf("send %d\n",i); + targ->m->send((memaddr)i); + } + return; +} + +static void +recv_func(void *arg) +{ + thread_arg_t* targ = (thread_arg_t *)arg; + for(int i = 0; i < targ->size; i++) { + if (targ->m->recv() != (memaddr)i) { + fail("read data fail\n"); + break; + } + printf("\t receive %d\n",i); + } + return; +} + +static void +tester(MailManagerPtr m, int size) +{ + //送信者スレッド作成 + thread_arg_t starg; + starg.m = m; + starg.size = size; + + pthread_t send; + pthread_create(&send, NULL, (void* (*)(void*))&send_func, (void*)&starg); + + //受信者スレッド作成 + thread_arg_t rtarg; + rtarg.m = m; + rtarg.size = size; + + pthread_t recv; + pthread_create(&recv, NULL, (void* (*)(void*))&recv_func, (void*)&rtarg); + + //終了待ち + pthread_join(send, NULL); + pthread_join(recv, NULL); +} + +static void +test1() { + MailManagerPtr m = new MailManager(2); + tester(m,16); + tester(m,32); + tester(m,48); + delete m; + MailManagerPtr m1 = new MailManager(32); + tester(m1,16); + tester(m1,48); + delete m1; +} + +int +main(int ac, const char *av[]) +{ + test1(); + printf("MailManagerTest succeed\n"); +} + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/SemMailManagerTest/Makefile Thu Jul 07 13:31:02 2011 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include -m$(ABIBIT) + +TARGET=MailManagerTest + +$(TARGET) : + +LIBS += ../../libFifoManager.a + +MailManagerTest : MailManagerTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)