Skip to content

Commit

Permalink
Added new tests
Browse files Browse the repository at this point in the history
Fixed kernel unblocking a process on execution when its children died.
This made all grandchildren to be removed from the ready bcp list.
This commit should fix issue #6.
  • Loading branch information
Mithrandir0x committed May 6, 2014
1 parent 644ffbe commit 0150893
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions P3-S2/minikernel/include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ servicio tabla_servicios[NSERVICIOS] = {
*/
//#define __KRN_DBG_UPDATE_SLEPT_PROCESS__
//#define __KRN_DBG_UPDATE_PRIORITIES__
//#define __KRN_DBG_UPDATE_PRIORITIES_LIST_BCPS__

#endif /* _KERNEL_H */
27 changes: 22 additions & 5 deletions P3-S2/minikernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static void tratar_padre()
parent_bcp = p_proc_actual->parent;
parent_bcp->n_children--;

if ( parent_bcp->n_children == 0 )
if ( parent_bcp->n_children == 0 && parent_bcp->estado == BLOQUEADO )
{
printk("\x1B[31m[KRN][%2d][%16.16s] ALL CHILDREN OF PARENT PROCESS [%2d] HAVE ENDED. UNBLOCKING PARENT PROCESS.\x1B[0m\n", p_proc_actual->id, "tratar_padre", parent_bcp->id);
parent_bcp->effective_priority += ( parent_bcp->effective_priority * 10 ) / 100;
Expand Down Expand Up @@ -566,7 +566,7 @@ static void exc_mem(){
*/
static void int_terminal(){

printk("\033[1m\033[31m[KRN][%2d][%16.16s] >> INTERRUPTION [Terminal, key: [%c]]<<\x1B[0m\n", p_proc_actual->id, "int_terminal", leer_puerto(DIR_TERMINAL));
printk("\033[1m\033[31m[KRN][%2d][%16.16s] >> INTERRUPTION [Terminal, key: [%c]] <<\x1B[0m\n", p_proc_actual->id, "int_terminal", leer_puerto(DIR_TERMINAL));

return;
}
Expand Down Expand Up @@ -623,6 +623,15 @@ static void int_sw()
{
printk("\x1B[31m[KRN][%2d][%16.16s] PRIORITIZED PROCESS. CHANGING CONTEXT: [%2d] => [%2d]\x1B[0m\n", p_proc_actual->id, "int_sw", p_proc_anterior->id, p_proc_actual->id);

#ifdef __KRN_DBG_UPDATE_PRIORITIES_LIST_BCPS__
printk("\x1B[31m[KRN][%2d][%16.16s] READY BCP LIST: \x1B[0m\n", p_proc_actual->id, "int_sw");
print_bcp_list(&lista_listos);
printk("\x1B[31m[KRN][%2d][%16.16s] SLEPT BCP LIST: \x1B[0m\n", p_proc_actual->id, "int_sw");
print_bcp_list(&l_slept_procs);
printk("\x1B[31m[KRN][%2d][%16.16s] WAITING BCP LIST: \x1B[0m\n", p_proc_actual->id, "int_sw");
print_bcp_list(&l_wait_procs);
#endif

p_proc_anterior->estado = LISTO;
p_proc_actual->estado = EJECUCION;
cambio_contexto(&(p_proc_anterior->contexto_regs), &(p_proc_actual->contexto_regs));
Expand Down Expand Up @@ -697,6 +706,8 @@ static int crear_tarea(char *prog){
printk("\x1B[31m[KRN][%2d][%16.16s] LOADED IMAGE [%s] WITH PID [%2d]\x1B[0m\n", p_proc_actual->id, "crear_tarea", prog, proc);
else
printk("\x1B[31m[KRN][-1][%16.16s] LOADED IMAGE [%s] WITH PID [%2d]\x1B[0m\n", "crear_tarea", prog, proc);

//print_bcp(p_proc);
}
else
{
Expand Down Expand Up @@ -841,10 +852,16 @@ int sys_get_parent_pid()

int sys_wait()
{
printk("\x1B[31m[KRN][%2d][%16.16s] PROCESS IS WAITING FOR CHILDREN TO END...\x1B[0m\n", p_proc_actual->id, "sys_wait");

/* Block the current process */
block_process(&l_wait_procs);
if ( p_proc_actual->n_children > 0 )
{
printk("\x1B[31m[KRN][%2d][%16.16s] PROCESS WILL WAIT FOR CHILDREN TO END...\x1B[0m\n", p_proc_actual->id, "sys_wait");
block_process(&l_wait_procs);
}
else
{
printk("\x1B[31m[KRN][%2d][%16.16s] PROCESS HAS NO CHILDREN AND WILL NOT WAIT\x1B[0m\n", p_proc_actual->id, "sys_wait");
}

return 0;
}
Expand Down
30 changes: 27 additions & 3 deletions P3-S2/usuario/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,50 @@ static void test_1()

static void test_2()
{
printf("init: ejecutando test_2\n");

crear_proceso("replicate");

srv_wait();
}

static void test_3()
{
printf("init: ejecutando test_3\n");

crear_proceso("replicate");
crear_proceso("getc");

srv_wait();
}

static void test_4()
{
printf("init: ejecutando test_4\n");

crear_proceso("replicate");
crear_proceso("getc");

srv_wait();

crear_proceso("getc");

srv_wait();

crear_proceso("get_c");

srv_wait();
}

typedef void (*TEST_F)(void);

#define N_TESTS 4
#define N_TESTS 5

int main()
{
TEST_F tests[N_TESTS] = { &test_0, &test_1, &test_2, &test_3 };
TEST_F tests[N_TESTS] = { &test_0, &test_1, &test_2, &test_3, &test_4 };

TEST_F test = tests[3];
TEST_F test = tests[4];

printf("PID: %d\n", srv_get_current_process_id());
printf("init: comienza\n");
Expand Down

0 comments on commit 0150893

Please sign in to comment.