void testScheduleRealTimeOverLShort2() { int id = fork(); int status; if (id > 0) { struct sched_param param1; int expected_requested_time = 30000; int expected_level = 8; param1.lshort_params.requested_time = expected_requested_time; param1.lshort_params.level = expected_level; int id2 = fork(); if (id2 == 0) { doMediumTask(); printf("\t\tLSHORT son finished\n"); _exit(0); } else { struct sched_param param2; param2.sched_priority = 1; sched_setscheduler(id, 1, ¶m2); //FIFO RealTime process sched_setscheduler(id2, SCHED_LSHORT, ¶m1); // LSHORT process } wait(&status); wait(&status); printf("OK\n"); } else if (id == 0) { doMediumTask(); printf("\tRT son finished\n"); _exit(0); } }
void testScheduleOtherOverOverdue2() { int id = fork(); int status; if (id > 0) { struct sched_param param1; int expected_requested_time = 1; int expected_level = 8; param1.lshort_params.requested_time = expected_requested_time; param1.lshort_params.level = expected_level; int id2 = fork(); if (id2 == 0) { doMediumTask(); printf("\tSCHED_OTHER son finished\n"); _exit(0); } else { struct sched_param param2; param2.sched_priority = 1; sched_setscheduler(id2, 0, ¶m2); // regular SCHED_OTHER sched_setscheduler(id, SCHED_LSHORT, ¶m1); // LSHORT process } wait(&status); wait(&status); printf("OK\n"); } else if (id == 0) { doMediumTask(); printf("\t\tOVERDUE son finished\n"); _exit(0); } }
void printingProgressBar() { printf("\n"); char* line1 = "||||| 20%% *___*"; char* line2 = "|||||||||| 40%% *___*"; char* line3 = "||||||||||||||| 60%% *___*"; char* line4 = "|||||||||||||||||||| 80%% *___*"; char* line5 = "||||||||||||||||||||||||| 100%% *___*"; char* text[5] = {line1,line2,line3,line4,line5}; //print text int i; for (i = 0; i < 5; ++i) { doMediumTask(); doMediumTask(); doMediumTask(); doMediumTask(); printf("\033[1A"); printf("\r"); printf("%s\n",text[i]); } doMediumTask(); doMediumTask(); doMediumTask(); doMediumTask(); }
void printWelcome() { char* gameboy1 = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| | | |\n| | | |\n| | | |\n| | | |\n| | | |\n| | | |\n| | | |\n| | | |\n| | | |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\"\n"; char* gameboy2 = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\"\n"; char* gameboy3 = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |******[WELCOME]*****| |\n| |********[TO]********| |\n| |********************| |\n| |********************| |\n| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\"\n"; char* gameboy4 = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |* [GAME OF SNAKES] *| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\"\n"; char* gameboy5 = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| |********************| |\n| |********************| |\n| |********************| |\n| |* [GAME OF SNAKES] *| |\n| |********************| |\n| |********************| |\n| |********************| |\n| |*[PLAY]**[RUN TEST]*| |\n| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\"\n"; char* gameboy[5] = {gameboy1,gameboy2,gameboy3,gameboy4,gameboy5}; int i; for (i = 0; i < 5; i++) { cleanScreen(); printf("%s\n", gameboy[i]); if (i==4) { printf("Press A to [PLAY], Press B to [RUN TEST]\n"); } int j; for (j = 0; j < 6; j++){ doMediumTask(); } } }
bool PrintBoardTest() { char* moduleName = getModule(); char board[BUFFER_SIZE+1]; board[BUFFER_SIZE]='\0'; // <---- might be redundant but i cant leave it like that! it's a disturbia int a; int b; int status; int pid1 = fork(); if(pid1 == 0) { //player 1 (white) a=open(moduleName, O_RDWR); ASSERT(a>=0); int readRes = read(a, NULL, BUFFER_SIZE); printf("\n\n[readRes=%d, should be=-1]\n\n", readRes); ASSERT(readRes == -1); // <---- should bring 0 according to the metargelim (piazza return -EFAULT;) readRes = read(a, board, 0); printf("\n\n[readRes=%d, should be=0]\n\n", readRes); ASSERT(readRes == 0); // <---- should bring 0 according to the metargelim (piazza return 0;) readRes = read(a, NULL, 0); printf("\n\n[readRes=%d, should be=0]\n\n", readRes); ASSERT(readRes == 0); // <---- should bring 0 according to the metargelim (piazza return 0;) //LET PLAYER 2 THE CHANCE TO PRINT BEFORE I GO int j; for (j = 0; j < 6; j++){ doMediumTask(); } close(a); _exit(0); } else { int pid2 = fork(); if(pid2 == 0) { doLongTask(); //player 2 (black) b=open(moduleName, O_RDWR); ASSERT(b>=0); int readRes = read(b, board, BUFFER_SIZE); printBoard(board); printf("\n\n[readRes=%d, should be=%d]\n\n", readRes,BUFFER_SIZE); ASSERT(readRes == BUFFER_SIZE); close(b); _exit(0); } else { wait(&status); } wait(&status); } return true; }
void testOverdueRoundRobin() { int id = fork(); int status; if (id > 0) { struct sched_param param1; int expected_requested_time = 1; int expected_level = 8; param1.lshort_params.requested_time = expected_requested_time; param1.lshort_params.level = expected_level; int id2 = fork(); if (id2 == 0) { int i, j; for (i=0; i < 4; i++) { doMediumTask(); printf("\t\tSon2\n"); } _exit(0); } else { struct sched_param param2; param2.lshort_params.requested_time = expected_requested_time; param2.lshort_params.level = expected_level; sched_setscheduler(id2, SCHED_LSHORT, ¶m1); sched_setscheduler(id, SCHED_LSHORT, ¶m2); } wait(&status); wait(&status); printf("OK\n"); } else if (id == 0) { int i, j; for (i=0; i < 4; i++) { doMediumTask(); printf("\tSon1\n"); } _exit(0); } }
void fibonaci(void* n) { int num = *((int*)(n)); printf("Calculating Fibonaci of %d\n",num); int res = fibonaciAux(num); int i; for (i = 0; i < 20; i++) doMediumTask(); printf("Fibonaci of %d is %d ... apparently\n\n",num,res); }
void doMediumTaskWithPrint(void* a) { printf("Doing a medium task\n"); doMediumTask(); if (a==NULL) { return; } AwesomeContainer* con = (AwesomeContainer*)(a); con->awesomeNum = 1; // for success }
void printingCannabisText(void* a) { int i; char* line0 = "A bit of reading while your at it..."; char* cannabisDraw[17] = {" 0"," 00"," 0000"," 0 000000 0"," 00 000000 0"," 0000 000000 00"," 000000 0000000 00000"," 0 0000000 000000 00000000 0","00 000000 00000 0000000 00","0000 000000 000 000000 0000"," 000000000 0000 0 000 0 000000000"," 000000000 0 0 0 00000000000"," 000000000000000000000"," 000 0 0000"," 00000 0 00000"," 00 0 00"," 0"}; //char* cannabisDraw = " 0\n 00\n 0000\n 0 000000 0\n 00 000000 0\n 0000 000000 00\n 000000 0000000 00000\n 0 0000000 000000 00000000 0\n00 000000 00000 0000000 00\n0000 000000 000 000000 0000\n 000000000 0000 0 000 0 000000000\n 000000000 0 0 0 00000000000\n 000000000000000000000\n 000 0 0000\n 00000 0 00000\n 00 0 00\n 0\n"; char* line1 = "Cannabis is an annual, dioecious, flowering herb."; char* line2 = "The leaves are palmately compound or digitate, with serrate leaflets."; char* line3 = "The first pair of leaves usually have a single leaflet, the number gradually increasing up to a"; char* line4 = "maximum of about thirteen leaflets per leaf (usually seven or nine), depending on variety and growing conditions."; char* text[5] = {line1,line2,line3,line4}; printf("\n\n%s\n\n\n",line0); for (i = 0; i < 20; i++) doMediumTask(); //print leaf for (i = 0; i < 17; i++){ printf("%s\n", cannabisDraw[i]); doMediumTask(); } //print text for (i = 0; i < 4; ++i) { doMediumTask(); doMediumTask(); doMediumTask(); doMediumTask(); printf("%s\n",text[i]); } printf("\n"); printf("\n"); }
void awesomePrint(void* a) { printf("\n"); printf("\n"); AwesomeContainer* con = (AwesomeContainer*)(a); int i; char* stars = "****************************"; for(i=0 ; i<con->awesomeNum ; ++i) { printf("%s\n",stars); doMediumTask(); } printf("\n"); printf("%s\n",con->awesomeString); printf("\n"); for(i=0 ; i<con->awesomeNum ; ++i) { printf("%s\n",stars); doMediumTask(); } printf("\n"); printf("\n"); }
bool PrintBoardSmallCountTest() { char* moduleName = getModule(); char board[BUFFER_SIZE+1]; board[BUFFER_SIZE]='\0'; // <---- might be redundant but i cant leave it like that! it's a disturbia int a; int b; int status; int pid1 = fork(); if(pid1 == 0) { //player 1 (white) a=open(moduleName, O_RDWR); ASSERT(a>=0); //LET PLAYER 2 THE CHANCE TO PRINT BEFORE I GO int j; for (j = 0; j < 6; j++){ doMediumTask(); } close(a); _exit(0); } else { int pid2 = fork(); if(pid2 == 0) { doLongTask(); //player 2 (black) b=open(moduleName, O_RDWR); ASSERT(b>=0); int readRes = read(b, board, 40); printBoard(board); ASSERT(readRes == 40); close(b); _exit(0); } else { wait(&status); } wait(&status); } return true; }
void testMakeLshort() { int thisId = getpid(); struct sched_param param; int expected_requested_time = 30000; int expected_level = 8; param.lshort_params.requested_time = expected_requested_time; param.lshort_params.level = expected_level; sched_setscheduler(thisId, SCHED_LSHORT, ¶m); assert(sched_getscheduler(thisId) == SCHED_LSHORT); assert(sched_getparam(thisId, ¶m) == 0); assert(param.lshort_params.requested_time == expected_requested_time); assert(param.lshort_params.level == expected_level); int i; doMediumTask(); assert(sched_getparam(thisId, ¶m) == 0); int afterTime = lshort_query_remaining_time(thisId); assert(afterTime > 0); assert(afterTime < expected_requested_time); assert(lshort_query_overdue_time(thisId) == 0); printf("OK\n"); }
void printingProgressBar() { char* loading1 = "\n**********************\n**********************\n**********************\n**------------------**\n**-[GAME OF SNAKES]-**\n**------------------**\n*******[LOADING]******\n**********************\n[ ]\n"; char* loading2 = "\n**********************\n**********************\n**********************\n**------------------**\n**-[GAME OF SNAKES]-**\n**------------------**\n*******[LOADING]******\n**********************\n[+++++ ]\n"; char* loading3 = "\n**********************\n**********************\n**********************\n**------------------**\n**-[GAME OF SNAKES]-**\n**------------------**\n*******[LOADING]******\n**********************\n[++++++++++ ]\n"; char* loading4 = "\n**********************\n**********************\n**********************\n**------------------**\n**-[GAME OF SNAKES]-**\n**------------------**\n*******[LOADING]******\n**********************\n[+++++++++++++++ ]\n"; char* loading5 = "\n**********************\n**********************\n**********************\n**------------------**\n**-[GAME OF SNAKES]-**\n**------------------**\n*******[LOADING]******\n**********************\n[++++++++++++++++++++]\n"; char* loading[5] = {loading1,loading2,loading3,loading4,loading5}; //print text int i; for (i = 0; i < 5; ++i) { int j; for (j = 0; j < 6; ++j) { doMediumTask(); } printf("\033[11A"); printf("\r"); printf("%s\n",loading[i]); } }
void testFork() { int expected_requested_time = 30000; int id = fork(); int status; if (id > 0) { struct sched_param param; int expected_level = 8; param.lshort_params.requested_time = expected_requested_time; param.lshort_params.level = expected_level; sched_setscheduler(id, SCHED_LSHORT, ¶m); assert(sched_getscheduler(id) == SCHED_LSHORT); assert(sched_getparam(id, ¶m) == 0); assert(param.lshort_params.requested_time == expected_requested_time); assert(param.lshort_params.level == expected_level); wait(&status); printf("OK\n"); } else if (id == 0) { assert(lshort_query_remaining_time(getpid()) == expected_requested_time); int son = fork(); if (son == 0) { int grandson_initial_time = lshort_query_remaining_time(getpid()); assert(grandson_initial_time < (expected_requested_time*2)/3); assert(grandson_initial_time > 0); doMediumTask(); assert(lshort_query_remaining_time(getpid()) < grandson_initial_time); _exit(0); } else { assert(lshort_query_remaining_time(getpid()) < expected_requested_time/2); wait(&status); } _exit(0); } }
void printButtonPress(char* board , char* dir) { char direction = dir[0]; cleanScreen(); char* upperWhite = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| |********WHITE*******| |\n| |********************| |"; char* upperBlack = "_n________________________\n|_|______________________|_|\n| ,--------------------. |\n| |********BLACK*******| |\n| |********************| |"; if (*Currentplayer == 1) { printf("%s\n",upperBlack); } else if (*Currentplayer == -1) { printf("%s\n",upperWhite); } char middle[BUFFER_SIZE]; int i; for (i = 0; i < BUFFER_SIZE; ++i) { middle[i] = '\0'; } //row1 strcat(middle,"| |**"); strcat(middle,board); middle[21] = '\0'; strcat(middle,"***| |\n"); //row2 strcat(middle,"| |**"); strcat(middle,board+16); middle[50] = '\0'; strcat(middle,"***| |\n"); //row3 strcat(middle,"| |**"); strcat(middle,board+32); middle[79] = '\0'; strcat(middle,"***| |\n"); //row4 strcat(middle,"| |**"); strcat(middle,board+48); middle[108] = '\0'; strcat(middle,"***| |\n"); //row5 strcat(middle,"| |**"); strcat(middle,board+64); middle[137] = '\0'; strcat(middle,"***| |\n"); //row6 strcat(middle,"| |**"); strcat(middle,board); middle[166] = '\0'; strcat(middle,"***| |\0"); printf("%s\n",middle ); char* downerUp = "| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _|X|_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\""; char* downerDown = "| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O _| ,-. \"._,\" |\n| |X| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\""; char* downerRight = "| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |_ O X| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\""; char* downerLeft = "| |********************| |\n| `--------------------' |\n| _ GAME BOY |\n| _| |_ ,-. |\n| |X O _| ,-. \"._,\" |\n| |_| \"._,\" A |\n| _ _ B |\n| // // |\n| // // \\\\\\\\\\\\ |\n| ` ` \\\\\\\\\\\\ ,\n|___________...__________,\""; if (direction == UP) { printf("%s\n",downerUp); } else if (direction == RIGHT) { printf("%s\n",downerRight); } else if (direction == LEFT) { printf("%s\n",downerLeft); } else if (direction == DOWN) { printf("%s\n",downerDown); } doMediumTask(); doMediumTask(); doMediumTask(); }
void halt() { int i; for (i = 0; i < 10; i++) doMediumTask(); }