Exemplo n.º 1
0
int
cvtest(int nargs, char **args)
{

	int i, result;

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting CV test...\n");
	kprintf("Threads should print out in reverse order.\n");

	testval1 = NTHREADS-1;

	for (i=0; i<NTHREADS; i++) {
		result = thread_fork("synchtest", NULL, cvtestthread, NULL, i);
		if (result) {
			panic("cvtest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}
	for (i=0; i<NTHREADS; i++) {
		P(donesem);
	}

	kprintf("CV test done\n");

	return 0;
}
Exemplo n.º 2
0
int
semtest(int nargs, char **args)
{
	int i, result;

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting semaphore test...\n");
	kprintf("If this hangs, it's broken: ");
	P(testsem);
	P(testsem);
	kprintf("ok\n");

	for (i=0; i<NTHREADS; i++) {
		result = thread_fork("semtest", NULL, semtestthread, NULL, i);
		if (result) {
			panic("semtest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}

	for (i=0; i<NTHREADS; i++) {
		V(testsem);
		P(donesem);
	}

	/* so we can run it again */
	V(testsem);
	V(testsem);

	kprintf("Semaphore test done.\n");
	return 0;
}
Exemplo n.º 3
0
int
locktest(int nargs, char **args)
{
	int i, result;

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting lock test...\n");

	for (i=0; i<NTHREADS; i++) {
		result = thread_fork("synchtest", NULL, locktestthread,
				     NULL, i);
		if (result) {
			panic("locktest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}
	for (i=0; i<NTHREADS; i++) {
		P(donesem);
	}

	kprintf("Lock test done.\n");

	return 0;
}
Exemplo n.º 4
0
int
cvtest(int nargs, char **args)
{

	int i, result;

	(void)nargs;
	(void)args;
	
	const char *tname[32] = {"t00", "t01", "t02", "t03", "t04", "t05", "t06", "t07", "t08", "t09", "t10", "t11", "t12", "t13", "t14", "t15", "t16", "t17", "t18", "t19", "t20", "t21", "t22", "t23", "t24", "t25", "t26", "t27", "t28", "t29", "t30", "t31"};
	
	inititems();
	kprintf("Starting CV test...\n");
	kprintf("Threads should print out in reverse order.\n");

	testval1 = NTHREADS-1;

	for (i=0; i<NTHREADS; i++) {
		result = thread_fork(tname[i], NULL, i, cvtestthread,
				      NULL);
		if (result) {
			panic("cvtest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}
	for (i=0; i<NTHREADS; i++) {
		P(donesem);
	}

	kprintf("CV test done\n");

	return 0;
}
Exemplo n.º 5
0
// This test should demonstrate fairness of mutex locks.
// Threads should acquire the lock approximately equally often.
int
fairlocktest(int nargs, char **args)
{

	int i, result;

	(void)nargs;
	(void)args;
    
    inititems(); 
	kprintf("Starting fair lock test...\n");
	kprintf("Threads should print the number of times they acquire the lock.\n");

	for (i=0; i<NTHREADS; i++) {
		result = thread_fork("fairlocktest", fairlocktestthread, NULL, i,
							NULL);
		if (result) {
			panic("fairlocktest: thread_fork failed: %s\n",
						strerror(result));
		}
	}
	for (i=0; i<NTHREADS; i++) {
		P(donesem);
	}

	kprintf("Fair lock test done\n");

	return 0;
}
Exemplo n.º 6
0
int
uwvmstatstest(int nargs, char **args)
{
	int i, result;
  char name[NAME_LEN];

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting uwvmstatstest...\n");

  kprintf("Initializing vmstats\n");
  vmstats_init();

	for (i=0; i<NTESTTHREADS; i++) {
    snprintf(name, NAME_LEN, "vmstatsthread %d", i);
		result = thread_fork(name, NULL, vmstats_thread, NULL, i);
		if (result) {
			panic("uwvmstatstest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}

	for (i=0; i<NTESTTHREADS; i++) {
		P(donesem);
	}

  vmstats_print();

	cleanitems();
	kprintf("uwvmstatstest done.\n");

	return 0;
}
Exemplo n.º 7
0
int
uwlocktest1(int nargs, char **args)
{
	int i, result;
  char name[NAME_LEN];

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting uwlocktest1...\n");

	for (i=0; i<NTESTTHREADS; i++) {
    snprintf(name, NAME_LEN, "add_thread %d", i);
		result = thread_fork(name, NULL, add_thread, NULL, i);
		if (result) {
			panic("uwlocktest1: thread_fork failed: %s\n",
			      strerror(result));
		}
	}

	for (i=0; i<NTESTTHREADS; i++) {
    snprintf(name, NAME_LEN, "sub_thread %d", i);
		result = thread_fork(name, NULL, sub_thread, NULL, i);
		if (result) {
			panic("uwlocktest1: thread_fork failed: %s\n",
			      strerror(result));
		}
	}

	for (i=0; i<NTESTTHREADS*2; i++) {
		P(donesem);
	}

	kprintf("value of test_value = %d should be %d\n", test_value, START_VALUE);
	if (test_value == START_VALUE) {
  	kprintf("TEST SUCCEEDED\n");
  } else {
  	kprintf("TEST FAILED\n");
  }
	KASSERT(test_value == START_VALUE);

	cleanitems();
	kprintf("uwlocktest1 done.\n");

	return 0;
}
Exemplo n.º 8
0
int
rwtest(int nargs, char **args)
{
	int i, result;

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting RW lock test...\n");

	for (i=0; i<NRWTHREADS; i++) {
		if(i%2 == 0){
			kprintf("Reader %d created.\n",i);
			result = thread_fork("synchtest", readtestthread, NULL, i,
						 NULL);
			if (result) {
				panic("rwlocktest: thread_fork failed: %s\n",
					  strerror(result));
			}
		}
		else
		{
			kprintf("Writer %d created.\n",i);
			result = thread_fork("synchtest", writetestthread, NULL, i,
						 NULL);
			if (result) {
				panic("rwlocktest: thread_fork failed: %s\n",
					  strerror(result));
			}
		}
	}

	for (i=0; i<NRWTHREADS; i++) {
		P(donesem);
	}
	kprintf("RW Lock test done.\n");


	return 0;
}
Exemplo n.º 9
0
int
rwlocktest(int nargs, char **args)
{
	int i, result;

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting rwlock test...\n");

	for (i=0; i<NTHREADS; i++) {
		if(i < 3){
			result = thread_fork("synchtest", rwlocktestthread_writer, NULL, i,
							     NULL);
		}
//		else if(i < 5){
//			result = thread_fork("synchtest", rwlocktestthread_writer, NULL, i,
//							     NULL);
//		}
		else{
			result = thread_fork("synchtest", rwlocktestthread_reader, NULL, i,
							     NULL);
		}

		if (result) {
			panic("rwlocktest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}
	for (i=0; i<NTHREADS; i++) {
		P(donesem);
	}

	kprintf("Rwlock test done.\n");

	return 0;
}
Exemplo n.º 10
0
// Change this function as necessary
int
bathroom(int nargs, char **args)
{

	int i, err=0;

	(void)nargs;
	(void)args;

	inititems();
	for (i = 0; i < NPEOPLE; i++) {
		/*
		err = thread_fork("Boy Thread", NULL,
		  boy, NULL, i);
		  */
		
		switch(i % 2) {
			case 0:
			err = thread_fork("Boy Thread", NULL,
					  boy, NULL, i);
			break;
			case 1:
			err = thread_fork("Girl Thread", NULL,
					  girl, NULL, i);
			break;
			}
			
		if (err) {
			panic("bathroom: thread_fork failed: %s)\n",
				strerror(err));
		}
	}

	for(i=0;i<NPEOPLE;i++)
		P(doneSem);

	return 0;
}
Exemplo n.º 11
0
int
locktest(int nargs, char **args)
{
	// ===============================
	// DEBUG: Timeout
	// ===============================
	//char *tname[32] = {"t00", "t01", "t02", "t03", "t04", "t05", "t06", "t07", "t08", "t09", "t10", "t11", "t12", "t13", "t14", "t15", "t16", "t17", "t18", "t19", "t20", "t21", "t22", "t23", "t24", "t25", "t26", "t27", "t28", "t29", "t30", "t31"};
	// ===============================
	int i, result;

	(void)nargs;
	(void)args;

	inititems();
	kprintf("Starting lock test...\n");

	for (i=0; i<NTHREADS; i++) {
		// ========================================
		// DEBUG: Timeout
		// ========================================
		result = thread_fork("synchtest", NULL, i, locktestthread,
				     NULL);
		//result = thread_fork(tname[i], NULL, i, locktestthread, NULL);
		// ========================================
		if (result) {
			panic("locktest: thread_fork failed: %s\n",
			      strerror(result));
		}
	}
	for (i=0; i<NTHREADS; i++) {
		P(donesem);
	}

	kprintf("Lock test done.\n");

	return 0;
}
Exemplo n.º 12
0
/*main loop, message sender, etc.pp.*/
int main(int argc,char**argv)
{
	int c,optindex=1;
	struct dhcp_msg *msg;
	/*parse options*/
	argv0=*argv;
        while(1){
                c=getopt_long(argc,argv,shortopt,longopt,&optindex);
                if(c==-1)break;
                switch(c){
                        case 'p':getprefix=1;break;
                        case 'P':getprefix=0;break;
                        case 'a':getaddress=1;break;
                        case 'A':getaddress=0;break;
                        case 'd':getdns=1;break;
                        case 'D':getdns=0;break;
                        case 'r':retries=atoi(optarg);break;
                        case 'l':localid=optarg;break;
                        case 'u':setduid(optarg);break;
                        case 'c':userapid=1;break;
                        case 'C':userapid=0;break;
                        case 'L':setloglevel(optarg);break;
                        default:
                                fprintf(stderr,"Syntax error in arguments.\n");
                                printhelp();
                                return 1;
                                break;
                        case 'h':
                                printhelp();
                                return 0;
                                break;
                }
        }
        if((optind+2)!=argc){
        	fprintf(stderr,"Syntax error.\n");
        	printhelp();
        	return 1;
	}
	device=argv[optind];
	script=argv[optind+1];

	if(DUIDLEN==0){
		if(localid)
			setlocalid(localid);
		else
			initlocalid();
	}
	/*init socket*/
	initsocket(DHCP_CLIENTPORT,device);
	if(sockfd<0){
		td_log(LOGERROR,"unable to allocate socket, exiting.");
		exit(1);
	}
	/*init my own stuff*/
	inititems();
	/*init SOLICIT/IREQ msg*/
	if(!getaddress && !getprefix){
		msg=newmessage(MSG_IREQUEST);
		addrecvfilter(MSG_REPLY);
	}else{
		msg=newmessage(MSG_SOLICIT);
		addrecvfilter(MSG_ADVERTISE);
	}
	COMPAREMSGID=1;
	settargetserver(&msg->msg_peer);
	messageaddopt(msg,OPT_CLIENTID);
	if(getdns){
		messageaddoptrequest(msg,OPT_DNS_SERVER);
		messageaddoptrequest(msg,OPT_DNS_NAME);
	}
	if(getaddress)messageaddopt(msg,OPT_IANA);
	if(getprefix)messageaddopt(msg,OPT_IAPD);
	if(userapid&&(getaddress||getprefix))messageaddopt(msg,OPT_RAPIDCOMMIT);
	/*start main loop*/
	for(c=0;c<retries;c++){
		sendmessage(msg);
		fd_set rfd,xfd;
		struct timeval tv;
		int sret;
		//wait for event
		FD_ZERO(&rfd);
		FD_ZERO(&xfd);
		FD_SET(sockfd,&rfd);
		FD_SET(sockfd,&xfd);
		tv.tv_sec=1;
		tv.tv_usec=0;
		sret=select(sockfd+1,&rfd,0,&xfd,&tv);
		//check for errors
		if(sret<0){
			int e=errno;
			if(e==EAGAIN)continue;
			td_log(LOGERROR,"Error caught: %s\n",strerror(e));
			return 1;
		}
		//check for event
		if(sret>0){
			if(FD_ISSET(sockfd,&rfd)){
				struct dhcp_msg*msg2;
				msg2=readmessage();
				if(msg2)
					if(handlemessage(msg2,msg)==0)break;
			}
			if(FD_ISSET(sockfd,&xfd)){
				td_log(LOGERROR,"Exception on socket caught.\n");
				return 1;
			}
		}else
			td_log(LOGDEBUG,"timeout, iteration %i",c);
	}
	/*execute script*/
	return execscript();
}