Exemple #1
0
/* Remove the head of the PCB queue of the given semaphore*/
pcb_t *removeBlocked (int *semAdd){
  semd_t *prec;
  prec = semd_h;
  
  /* Find the correct element */
  while(prec->s_next != NULL && (prec->s_next)->s_semAdd != semAdd){
    prec=prec->s_next;
  }

  if(prec->s_next == NULL){
    return NULL;
  }
  
  /* Coltrol if we find the element and remove it if we did */
  if((prec->s_next)->s_semAdd==semAdd){
    pcb_t *ris , *tp;
    semd_t *tmp;
    tp=(prec->s_next)->s_procQ;
    ris=removeProcQ(&tp);
    if(!emptyProcQ(tp)){
      return ris;
    }
    else{
      tmp=prec->s_next;
      prec->s_next=tmp->s_next;
      tmp->s_next=semdFree_h;
      semdFree_h=tmp;
      return ris;
    }
  }
  return NULL;
}	
Exemple #2
0
int test_outProcQ(void) {
    int success = 1;
    pcb_t *p1, *p2, *p3;
    pcbq_t *q;

    initProc();
    q = mkEmptyProcQ();
    p1 = allocPcb();
    p2 = allocPcb();
    p3 = allocPcb();

    success &= outProcQ(NULL, p1) == NULL;
    success &= outProcQ(&q, NULL) == NULL;
    success &= outProcQ(&q, p1) == NULL;
    success &= outProcQ(&q, p2) == NULL;
    success &= outProcQ(&q, p3) == NULL;

    insertProcQ(&q, p1);
    insertProcQ(&q, p2);
    success &= outProcQ(&q, p3) == NULL;
    insertProcQ(&q, p3);
    success &= outProcQ(&q, p3) == p3;
    success &= outProcQ(&q, p1) == p1;
    success &= removeProcQ(&q) == p2;

    return success;
}
Exemple #3
0
void scheduler()
{
	
	//Due possibili casi:
	//	-Esiste un processo in esecuzione -> context switch
	//	-Non c'è un processo -> ne carico uno
	
	if(currentProcess!=NULL){ //current process è quello che deve essere eseguito
		
		timer+=getTODLO()-last_access;
		last_access=getTODLO();
		
		//#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -> sta su uARMconst
		//#define SCHED_TIME_SLICE 5000
		//#define SCHED_PSEUDO_CLOCK 100000

		setTIMER(MIN(SCHED_TIME_SLICE, SCHED_PSEUDO_CLOCK-timer));
		
		LDST(&(currentProcess->s_t));
		
		
	}
	else{
		
		//Anche qui due casi possibili, controlliamo se la readyQueue è vuota
		if(clist_empty(readyQueue)){
			
			//processCount = 0 -> HALT -> non ci sono processi
			if(processCount == 0) HALT();
			
			//processCount>0 e SBC==0-> qualcosa è andato storto -> deadlock
			if(processCount>0 && softBlockCount == 0) PANIC();
			
			//caso "normale" -> aspettiamo che un processo necessiti di essere allocato
			if(processCount>0 && softBlockCount > 0) WAIT();
			
			//qualsiasi altro stato
			PANIC();
			
		}
		
		else{
			//semplicemente carico il primo processo in memoria
			//scherzavo, non è semplice
			
			currentProcess = removeProcQ(readyQueue);
			
			if(currentProcess == NULL) PANIC(); //qualcosa è andato storto
			
			//imposta i timer e altre cose brutte
		
			scheduler();
		}
	}

}
Exemple #4
0
Fichier : pcb.c Projet : emulk/SOS
/*[3]
 * Restituisce NULL se la pcbFree e’ vuota. Altrimenti rimuove un 
 * elemento dalla pcbFree, inizializza tutti i 
 * campi (NULL/0) e restituisce l’elemento rimosso.
*/
pcb_t *allocPcb(void){
	pcb_t *tmp;
	tmp=removeProcQ(&pcbfree_h);
	/*se la pcbFree e vuota restituisco NULL*/
	if (tmp==NULL)
		return NULL;
	/*dopo aver rimosso un elemento dalla pcbFree reseto tutti i campi a NULL/0*/
	reset(tmp);
	return tmp;
}
Exemple #5
0
Fichier : pcb.c Projet : emulk/SOS
/*[10]
 * Rimuove il primo figlio del PCB puntato da p. Se p non ha figli, restituisce NULL
*/
pcb_t *removeChild(pcb_t *p){
	pcb_t *tmp;
	if (p!=NULL){
		tmp=removeProcQ(&p->p_first_child);
		if(tmp!=NULL)
			tmp->p_parent=NULL;
		return tmp;
	}
	/*se p non ha figli*/
	return NULL;
}
Exemple #6
0
/*Ritorna il primo PCB dalla coda dei processi bloccati(s_ProcQ) associata al SEMD della ASL con chiave key. 
Se tale descrittore non esiste nella ASL, restituisce NULL. 
Altrimenti,restituisce l’elemento rimosso. 
Se la coda dei processi bloccati per il semaforo diventa vuota, rimuove il descrittore del semaforo corrispondente dalla ASL e lo inserisce nella coda dei semafori liberi (semdFree).*/
pcb_t* removeBlocked(int *key){
	semd_t *semd_target = getSemd(key);
	if(semd_target){
		/*Il semaforo è nella ASL*/
		pcb_t *removed = removeProcQ(&(semd_target->s_procQ)); /*Rimuovo il primo PCB della sua coda di processi*/
		if (semd_target->s_procQ == NULL)
			deAllocSem(&semd_h, semd_target);
		return removed;	
	}
	else
		return NULL;
}
Exemple #7
0
/** Rimuove il primo pcb dalla coda associata al semaforo di indirizzo semAdd
*	Restituisce NULL se non esiste un semaforo di indirizzo semAdd */
pcb_t *removeBlocked(int *semAdd){
    pcb_t *result = NULL;
   	semd_t *i = findSemd(semAdd);
	if(i != NULL){
		result = removeProcQ(&(i -> s_procQ));
		/* Se la sua coda diventa vuota */
		if(emptyProcQ(i ->s_procQ)){
			freeSemd(i);
		}
	}
	return result;
}
Exemple #8
0
int test_insertProcQ(void) {
    int success = 1;
    int i;
    pcbq_t *q = mkEmptyProcQ();

    initProc();

    success &= emptyProcQ(q);
    insertProcQ(&q, NULL);
    success &= emptyProcQ(q);

    for (i = 0; i < MAXPROCESS; ++i) {
        insertProcQ(&q, allocPcb());
    }

    for (i = 0; i < MAXPROCESS; ++i) {
        success &= removeProcQ(&q) != NULL;
    }
    success &= !removeProcQ(&q);


    return success;
}
Exemple #9
0
int test_removeProcQ(void) {
    int success = 1;
    pcb_t *p1, *p2;
    pcbq_t *q;

    initProc();
    p1 = allocPcb();
    p2 = allocPcb();
    q = mkEmptyProcQ();

    success &= removeProcQ(NULL) == NULL;

    insertProcQ(&q, p1);
    success &= !emptyProcQ(q);
    success &= removeProcQ(&q) == p1;
    success &= emptyProcQ(q);

    insertProcQ(&q, p1);
    insertProcQ(&q, p2);
    success &= removeProcQ(&q) == p1;
    success &= removeProcQ(&q) == p2;

    return success;
}
Exemple #10
0
Fichier : asl.c Projet : emulk/SOS
/**[5]
 * Ritorna il primo PCB dalla coda dei processi bloccati (s_ProcQ) associata al SEMD
 * della ASL con chiave key. Se tale descrittore non esiste nella ASL, restituisce NULL.
 * Altrimenti, restituisce l’elemento rimosso. Se la coda dei processi bloccati per il
 * semaforo diventa vuota, rimuove il descrittore corrispondente dalla ASL e lo
 * inserisce nella coda dei descrittori liberi (semdFree).
 */
struct pcb_t* removeBlocked(int *key)
{
	semd_t *tmp;
	pcb_t* rem;
	tmp = getSemd(key);

	if(tmp == NULL){
		return NULL;
	}else{
		rem = removeProcQ(&(tmp->s_procQ));
		if (tmp->s_procQ == NULL)
		RemRec(&semd_h, tmp);
		return rem;
	}
	
}
Exemple #11
0
/* Return NULL if the pcbFree list is empty. Otherwise, remove
an element from the pcbFree list, provide initial values for ALL
of the ProcBlk’s fields (i.e. NULL and/or 0) and then return a
pointer to the removed element. ProcBlk’s get reused, so it is
important that no previous value persist in a ProcBlk when it
gets reallocated. */
pcb_t *allocPcb(){
	pcb_t *temp;
	temp = removeProcQ(&freePcb_tp);
	if(temp != NULL){
		temp->p_next = NULL;
		temp->p_prev = NULL;
		temp->p_prnt = NULL;
		temp->p_child = NULL;
		temp->p_sib = NULL;
		temp->p_prev_sib = NULL;
		temp->p_semAdd = NULL;
		temp->p_time = 0;
		temp->p_states[2].newState = NULL;
		temp->p_states[2].oldState = NULL;
		temp->p_states[0].newState = NULL;
		temp->p_states[0].oldState = NULL;
		temp->p_states[1].newState = NULL;
		temp->p_states[1].oldState = NULL;
	}
	return(temp);
}
Exemple #12
0
int test_EmptyProcQ(void) {
    int success = 1;
    pcb_t *p;
    pcbq_t *q;

    initProc();

    success &= emptyProcQ(NULL);

    q = mkEmptyProcQ();
    success &= emptyProcQ(q);

    p = allocPcb();
    insertProcQ(&q, p);
    success &= !emptyProcQ(q);
    success &= getPNext(p) == p;
    removeProcQ(&q);
    success &= emptyProcQ(q);

    return success;
}
Exemple #13
0
/* Remove the ProcBlk pointed to by p from the process queue whose
tail-pointer is pointed to by tp. Update the process queue’s tail
pointer if necessary. If the desired entry is not in the indicated queue
(an error condition), return NULL; otherwise, return p. Note that p
can point to any element of the process queue. */
pcb_t *outProcQ(pcb_t **tp, pcb_t *p){
	/* Case 1: ProcQ is empty.*/
	if(emptyProcQ(*tp)){
		return(NULL);
	} /* Case 2: ProcQ has only 1 ProcBlk*/
	else if((*tp)->p_prev == *tp){
		if(*tp == p){
			pcb_t *outproc = *tp;
			*tp = mkEmptyProcQ();
			return(outproc);
		}else{
			return(NULL);
		}
	}/* Case 3: ProcQ has more than one ProcBlk*/
	else{/*Subcase 1: Removing the ProcBlk pointed to by the tail pointer*/
		if(*tp == p){
			pcb_t *outproc = *tp;
			(*tp)->p_prev->p_next = (*tp)->p_next;
			(*tp)->p_next->p_prev = (*tp)->p_prev;
			*tp = (*tp)->p_prev;
			return(outproc);
		}else{
			pcb_t *index = (*tp)->p_next;
			while(index != *tp){/*Subcase 2: Removing the head*/
				if(p == index && index == (*tp)->p_next){
					return removeProcQ(tp);
				}/*Subcas3: Removing a middle ProcBlk*/
				else if(p == index){
					index->p_prev->p_next = index->p_next;
					index->p_next->p_prev = index->p_prev;
					return(index);
				}else{
					index = index->p_next;
				}
			}
			return(NULL);
		}
	}
	
}
int main() {
	int i;

	initPcbs();
	addokbuf("Initialized process control blocks   \n");

	/* Check allocPcb */
	for (i = 0; i < MAXPROC; i++) {
		if ((procp[i] = allocPcb()) == NULL)
			adderrbuf("allocPcb(): unexpected NULL   ");
	}
	if (allocPcb() != NULL) {
		adderrbuf("allocPcb(): allocated more than MAXPROC entries   ");
	}
	addokbuf("allocPcb ok   \n");

	/* return the last 10 entries back to free list */
	for (i = 10; i < MAXPROC; i++)
		freePcb(procp[i]);
	addokbuf("freed 10 entries   \n");

	/* create a 10-element process queue */
	qa = mkEmptyProcQ();
	if (!emptyProcQ(qa)) adderrbuf("emptyProcQ(qa): unexpected FALSE   ");
	addokbuf("Inserting...   \n");
	for (i = 0; i < 10; i++) {
		if ((q = allocPcb()) == NULL)
			adderrbuf("allocPcb(): unexpected NULL while insert   ");
		switch (i) {
			case 0:
				firstproc = q;
				break;
			case 5:
				midproc = q;
				break;
			case 9:
				lastproc = q;
				break;
			default:
				break;
		}
		insertProcQ(&qa, q);
	}
	addokbuf("inserted 10 elements   \n");

	if (emptyProcQ(qa)) adderrbuf("emptyProcQ(qa): unexpected TRUE"   );

	/* Check outProcQ and headProcQ */
	if (headProcQ(qa) != firstproc)
		adderrbuf("headProcQ(qa) failed   ");

	q = outProcQ(&qa, firstproc);
	if ((q == NULL) || (q != firstproc))
		adderrbuf("outProcQ(&qa, firstproc) failed on first entry   ");		
	freePcb(q);

	q = outProcQ(&qa, midproc);
	if (q == NULL || q != midproc)
		adderrbuf("outProcQ(&qa, midproc) failed on middle entry   ");
	freePcb(q);

	if (outProcQ(&qa, procp[0]) != NULL)
		adderrbuf("outProcQ(&qa, procp[0]) failed on nonexistent entry   ");
	addokbuf("outProcQ() ok   \n");

	/* Check if removeProc and insertProc remove in the correct order */
	addokbuf("Removing...   \n");
	for (i = 0; i < 8; i++) {
		if ((q = removeProcQ(&qa)) == NULL)
			adderrbuf("removeProcQ(&qa): unexpected NULL   ");
		freePcb(q);
	}

	if (q != lastproc)
		adderrbuf("removeProcQ(): failed on last entry   ");

	if (removeProcQ(&qa) != NULL)
		adderrbuf("removeProcQ(&qa): removes too many entries   ");

	if (!emptyProcQ(qa))
		adderrbuf("emptyProcQ(qa): unexpected FALSE   ");

	addokbuf("insertProcQ(), removeProcQ() and emptyProcQ() ok   \n");
	addokbuf("process queues module ok      \n");

	addokbuf("checking process trees...\n");

	if (!emptyChild(procp[2]))
		adderrbuf("emptyChild: unexpected FALSE   ");

	/* make procp[1] through procp[9] children of procp[0] */
	addokbuf("Inserting...   \n");
	for (i = 1; i < 10; i++) {
		insertChild(procp[0], procp[i]);
	}
	addokbuf("Inserted 9 children   \n");

	if (emptyChild(procp[0]))
		adderrbuf("emptyChild(procp[0]): unexpected TRUE   ");

	/* Check outChild */
	q = outChild(procp[1]);
	if (q == NULL || q != procp[1])
		adderrbuf("outChild(procp[1]) failed on first child   ");
	q = outChild(procp[4]);
	if (q == NULL || q != procp[4])
		adderrbuf("outChild(procp[4]) failed on middle child   ");
	if (outChild(procp[0]) != NULL)
		adderrbuf("outChild(procp[0]) failed on nonexistent child   ");
	addokbuf("outChild ok   \n");

	/* Check removeChild */
	addokbuf("Removing...   \n");
	for (i = 0; i < 7; i++) {
		if ((q = removeChild(procp[0])) == NULL)
			adderrbuf("removeChild(procp[0]): unexpected NULL   ");
	}

	if (removeChild(procp[0]) != NULL)
		adderrbuf("removeChild(): removes too many children   ");

	if (!emptyChild(procp[0]))
		adderrbuf("emptyChild(procp[0]): unexpected FALSE   ");

	addokbuf("insertChild(), removeChild() and emptyChild() ok   \n");
	addokbuf("process tree module ok      \n");

	for (i = 0; i < 10; i++) 
		freePcb(procp[i]);


	/* check ASL */
	initASL();
	addokbuf("Initialized active semaphore list   \n");

	/* check removeBlocked and insertBlocked */
	addokbuf("insertBlocked() test #1 started  \n");
	for (i = 10; i < MAXPROC; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(&sem[i], procp[i]))
			adderrbuf("insertBlocked() test#1: unexpected TRUE   ");
	}
	addokbuf("insertBlocked() test #2 started  \n");
	for (i = 0; i < 10; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(&sem[i], procp[i]))
			adderrbuf("insertBlocked() test #2: unexpected TRUE   ");
	}

	/* check if semaphore descriptors are returned to free list */
	p = removeBlocked(&sem[11]);
	if (insertBlocked(&sem[11],p))
		adderrbuf("removeBlocked(): fails to return to free list   ");

	if (insertBlocked(&onesem, procp[9]) == FALSE)
		adderrbuf("insertBlocked(): inserted more than MAXPROC   ");

	addokbuf("removeBlocked() test started   \n");
	for (i = 10; i< MAXPROC; i++) {
		q = removeBlocked(&sem[i]);
		if (q == NULL)
			adderrbuf("removeBlocked(): wouldn't remove   ");
		if (q != procp[i])
			adderrbuf("removeBlocked(): removed wrong element   ");
		if (insertBlocked(&sem[i-10], q))
			adderrbuf("insertBlocked(3): unexpected TRUE   ");
	}
	if (removeBlocked(&sem[11]) != NULL)
		adderrbuf("removeBlocked(): removed nonexistent blocked proc   ");
	addokbuf("insertBlocked() and removeBlocked() ok   \n");

	if (headBlocked(&sem[11]) != NULL)
		adderrbuf("headBlocked(): nonNULL for a nonexistent queue   ");
	if ((q = headBlocked(&sem[9])) == NULL)
		adderrbuf("headBlocked(1): NULL for an existent queue   ");
	if (q != procp[9])
		adderrbuf("headBlocked(1): wrong process returned   ");
	p = outBlocked(q);
	if (p != q)
		adderrbuf("outBlocked(1): couldn't remove from valid queue   ");
	q = headBlocked(&sem[9]);
	if (q == NULL)
		adderrbuf("headBlocked(2): NULL for an existent queue   ");
	if (q != procp[19])
		adderrbuf("headBlocked(2): wrong process returned   ");
	p = outBlocked(q);
	if (p != q)
		adderrbuf("outBlocked(2): couldn't remove from valid queue   ");
	p = outBlocked(q);
	if(c = p)
		addokbuf("saaaaaas \n");
	if (p != NULL)
		adderrbuf("outBlocked(): removed same process twice.");
	if (headBlocked(&sem[9]) != NULL)
		adderrbuf("out/headBlocked: unexpected nonempty queue   ");
	addokbuf("headBlocked() and outBlocked() ok   \n");
	addokbuf("ASL module ok   \n");
	addokbuf("So Long and Thanks for All the Fish\n");

	return 0;

}
int main() {
	int i;

	initPcbs();
	addokbuf("Initialized Process Control Blocks   \n");

	/* Check allocPcb */
	for (i = 0; i < MAXPROC; i++) {
		if ((procp[i] = allocPcb()) == NULL)
			adderrbuf("allocPcb(): unexpected NULL   ");
	}
	
	if (allocPcb() != NULL) {
		adderrbuf(" ERROR: allocPcb(): allocated more than MAXPROC entries   ");
	}
	addokbuf(" allocPcb test OK   \n");

	
	/* Return the last 10 entries back to free list */
	for (i = 10; i < MAXPROC; i++)
          freePcb(procp[i]);
	
	addokbuf(" Added 10 entries to the free PCB list   \n");

	/* Create a 10-element process queue */
	INIT_LIST_HEAD(&qa);
	
	if (!emptyProcQ(&qa)) adderrbuf("ERROR: emptyProcQ(qa): unexpected FALSE   ");
	
	addokbuf("Testing insertProcQ ...   \n");
	
	for (i = 0; i < 10; i++) {
		if ((q = allocPcb()) == NULL)
			adderrbuf("ERROR: allocPcb(): unexpected NULL while insert   ");
		switch (i) {
			case 3:
				q->priority=DEFAULT_PCB_PRIORITY;
				proc = q;
			break;
			case 4:
				q->priority=MAX_PCB_PRIORITY;
				maxproc = q;
				break;	
			case 5:
				q->priority=MIN_PCB_PRIORITY;
				minproc=q;
			break;
			default:
				q->priority=DEFAULT_PCB_PRIORITY;
			break;
		}
		insertProcQ(&qa, q);
	}
	
	addokbuf("Test insertProcQ: OK. Inserted 10 elements \n");
	
	if (emptyProcQ(&qa)) adderrbuf("ERROR: emptyProcQ(qa): unexpected TRUE"   );

	/* Check outProcQ and headProcQ */
	if (headProcQ(&qa) != maxproc)
		adderrbuf("ERROR: headProcQ(qa) failed   ");
	
	/* Removing an element from ProcQ */
	q = outProcQ(&qa, proc);
	if ((q == NULL) || (q != proc))
		adderrbuf("ERROR: outProcQ(&qa, proc) failed to remove the entry   ");		
	freePcb(q);
	
	/* Removing the first element from ProcQ */
	q = removeProcQ(&qa);
	if (q == NULL || q != maxproc)
		adderrbuf("ERROR: removeProcQ(&qa, midproc) failed to remove the elements in the right order   ");
	freePcb(q);

	/* Removing other 7 elements  */
	addokbuf(" Testing removeProcQ ...   \n");
	for (i = 0; i < 7; i++) {
		if ((q = removeProcQ(&qa)) == NULL)
			adderrbuf("removeProcQ(&qa): unexpected NULL   ");
		freePcb(q);
	}
	
	// Removing the last element
	q=removeProcQ(&qa);
	if (q != minproc)
		adderrbuf("ERROR: removeProcQ(): failed on last entry   ");
	freePcb(q);
	
	if (removeProcQ(&qa) != NULL)
		adderrbuf("ERROR: removeProcQ(&qa): removes too many entries   ");

	if (!emptyProcQ(&qa))
		adderrbuf("ERROR: emptyProcQ(qa): unexpected FALSE   ");

	addokbuf(" Test insertProcQ(), removeProcQ() and emptyProcQ(): OK   \n");
	addokbuf(" Test process queues module: OK      \n");

	addokbuf(" Testing process trees...\n");

	if (!emptyChild(procp[2]))
	  adderrbuf("ERROR: emptyChild: unexpected FALSE   ");
	
	/* make procp[1],procp[2],procp[3], procp[7] children of procp[0] */
	addokbuf("Inserting...   \n");
	insertChild(procp[0], procp[1]);
	insertChild(procp[0], procp[2]);
	insertChild(procp[0], procp[3]);
	insertChild(procp[0], procp[7]);
	addokbuf("Inserted 2 children of pcb0  \n");
	
	/* make procp[8],procp[9] children of procp[7] */
	insertChild(procp[7], procp[8]);
	insertChild(procp[7], procp[9]);
	addokbuf("Inserted 2 children of pcb7  \n");
	

	if (emptyChild(procp[0]))
	  adderrbuf("ERROR: emptyChild(procp[0]): unexpected TRUE   ");
	
	if (emptyChild(procp[7]))
		adderrbuf("ERROR: emptyChild(procp[0]): unexpected TRUE   ");

	
	/* Check outChild */
	q = outChild(procp[1]);
	if (q == NULL || q != procp[1])
		adderrbuf("ERROR: outChild(procp[1]) failed ");
	
	q = outChild(procp[8]);
	if (q == NULL || q != procp[8])
		adderrbuf("ERROR: outChild(procp[8]) failed ");
	
	/* Check removeChild */
	q = removeChild(procp[0]);
	if (q == NULL || q != procp[2])
		adderrbuf("ERROR: removeChild(procp[0]) failed ");
	
	q = removeChild(procp[7]);
	if (q == NULL || q != procp[9])
		adderrbuf("ERROR: removeChild(procp[7]) failed ");
	
	q = removeChild(procp[0]);
	if (q == NULL || q != procp[3])
		adderrbuf("ERROR: removeChild(procp[0]) failed ");

	q = removeChild(procp[0]);
	if (q == NULL || q != procp[7])
		adderrbuf("ERROR: removeChild(procp[0]) failed ");
	
	
	if (removeChild(procp[0]) != NULL)
		adderrbuf("ERROR: removeChild(): removes too many children   ");

	if (!emptyChild(procp[0]))
	    adderrbuf("ERROR: emptyChild(procp[0]): unexpected FALSE   ");
	    
	addokbuf("Test: insertChild(), removeChild() and emptyChild() OK   \n");
	addokbuf("Testing process tree module OK      \n");

	 
	freePcb(procp[0]);
	freePcb(procp[1]);
	freePcb(procp[2]);
	freePcb(procp[3]);
	freePcb(procp[4]);
	freePcb(procp[5]);
	freePcb(procp[6]);
	freePcb(procp[7]);
	freePcb(procp[8]);
	freePcb(procp[9]);
	
	
	/* check ASL */
	initASL();
	addokbuf("Initializing active semaphore list   \n");

	/* check removeBlocked and insertBlocked */
	addokbuf(" Test insertBlocked(): test #1 started  \n");
	for (i = 10; i < MAXPROC; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(i, procp[i]))
			adderrbuf("ERROR: insertBlocked() test#1: unexpected TRUE   ");
	}

	addokbuf("Test insertBlocked(): test #2 started  \n");
	for (i = 0; i < 10; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(i, procp[i]))
			adderrbuf("ERROR:insertBlocked() test #2: unexpected TRUE   ");
	}

	/* check if semaphore descriptors are returned to the free list */
	p = removeBlocked(11);
	if (insertBlocked(11,p))
		adderrbuf("ERROR: removeBlocked(): fails to return to free list   ");

	if (insertBlocked(MAXPROC+1, procp[9]) == FALSE)
		adderrbuf("ERROR: insertBlocked(): inserted more than MAXPROC   ");
	
	addokbuf("Test removeBlocked(): test started   \n");
	for (i = 10; i< MAXPROC; i++) {
		q = removeBlocked(i);
		if (q == NULL)
			adderrbuf("ERROR: removeBlocked(): wouldn't remove   ");
		if (q != procp[i])
			adderrbuf("ERROR: removeBlocked(): removed wrong element   ");

	}

	if (removeBlocked(11) != NULL)
		adderrbuf("ERROR: removeBlocked(): removed nonexistent blocked proc   ");
	
	addokbuf("Test: insertBlocked() and removeBlocked() ok   \n");

	if (headBlocked(11) != NULL)
		adderrbuf("ERROR: headBlocked(): nonNULL for a nonexistent queue   ");
	
	if ((q = headBlocked(9)) == NULL)
		adderrbuf("ERROR: headBlocked(1): NULL for an existent queue   ");
	if (q != procp[9])
		adderrbuf("ERROR: headBlocked(1): wrong process returned   ");
	p = outBlocked(q);
	if (p != q)
		adderrbuf("ERROR: outBlocked(1): couldn't remove from valid queue   ");

	/* Creating a 2-layer tree */
	insertChild(procp[0], procp[1]);
	insertChild(procp[0], procp[2]);
	insertChild(procp[0], procp[3]);
	insertChild(procp[3], procp[4]);
	
	/* Testing outChildBlocked */
	outChildBlocked(procp[0]);
	
	if (headBlocked(0) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (0)  ");
	if (headBlocked(1) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (1)  ");
	if (headBlocked(2) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue  (2) ");
	if (headBlocked(3) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (3)  ");
	if (headBlocked(4) != NULL)
			adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (4)  ");	
	if (headBlocked(5) == NULL)
			adderrbuf("ERROR: outChildBlocked(): NULL for an existent queue  (5) ");	
	
	addokbuf("Test headBlocked() and outBlocked(): OK   \n");
	
	addokbuf("ASL module OK   \n");
	addokbuf("So Long and Thanks for All the Fish\n");
  
	return 0;

}