view TaskManager/test/SemMailManagerTest/MailManagerTest.cc @ 1553:21ddbc06dcde draft

fix GpuScheduler
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Sun, 17 Feb 2013 19:42:36 +0900
parents 898fdcf53c31
children
line wrap: on
line source

#include <stdio.h>
#include "TaskManager/MailManager.h"
#include "TaskManager/SemMailManager.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 SemMailManager(2);
    tester(m,16);
    tester(m,32);
    tester(m,48);
    delete m; 
    MailManagerPtr m1 = new SemMailManager(32);
    tester(m1,16);
    tester(m1,48);
    delete m1;
}

int
main(int ac, const char *av[])
{
    test1();
    printf("MailManagerTest succeed\n");
}

/* end */