int main () { if ( (sem_init (&binsem, 0, 1)) != 0) { printf("\n Error creating semaphore\n"); exit(1); } srand(time(NULL)); clock_t start, end; double cpu_time_used; start = clock(); init(); memoryMaxer(); end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("\n\n TOTAL TIME TAKEN IS: %g \n\n", cpu_time_used); sem_destroy(&binsem); return 0; }
/** * Run the stress tests. */ int main(int argc, char *argv[]){ if (argc != 3){ printf("Correct usage is ./test <test-number> <eviction-algorithm-number>\n"); exit(0); } else { int choice = atoi(argv[1]); EVICT_ALGO_NUMBER = atoi(argv[2]); clock_t begin, end; if (choice == 1) { begin = clock(); memoryMaxer(); end = clock(); printf("FOR EVICTION ALGORITHM %d\n", EVICT_ALGO_NUMBER); printf("--------Time spent on memoryMaxer() = %f s\n", (double) (end - begin)/CLOCKS_PER_SEC ); } else if (choice == 2) { begin = clock(); testRAM(); end = clock(); printf("FOR EVICTION ALGORITHM %d\n", EVICT_ALGO_NUMBER); printf("--------Time spent on testRAM() = %f s\n", (double) (end - begin)/CLOCKS_PER_SEC); } else if (choice == 3) { begin = clock(); testFullMemory(); end = clock(); printf("FOR EVICTION ALGORITHM %d\n", EVICT_ALGO_NUMBER); printf("--------Time spent on testFullMemory() = %f s\n", (double) (end - begin)/CLOCKS_PER_SEC); } else if (choice == 4){ // This test checks multithreading. We will uncomment this in our demo, to demonstrate that it works begin = clock(); testMultithreaded(); end = clock(); printf("FOR EVICTION ALGORITHM %d\n", EVICT_ALGO_NUMBER); printf("--------Time spent on testMultithreaded() = %f s\n", (double) (end - begin)/CLOCKS_PER_SEC); } return 0; } }
// Main to test this algorithm int main() { // Setup timevals struct timeval startTime, endTime; // Run a variety of functions __initialize(); // Initialize the page fault simulator printf("=-=-=-=-= MEMORY MAXER\n\n"); gettimeofday(&startTime, NULL); // Measure time performance memoryMaxer(); gettimeofday(&endTime, NULL); // Measure time performace printf("=-=-=-=-= Memory Maxer Statistics:\n"); printf(" Time taken for execution with random algorithm for picking pages = %ld msec\n\n", timedifference(endTime, startTime)); printf("=-=-=-=-= PERSONAL FUNCTION 1\n\n"); gettimeofday(&startTime, NULL); // Measure time performance memoryTester(); gettimeofday(&endTime, NULL); // Measure time performace printf("=-=-=-=-= Personal Function 1 Statistics:\n"); printf(" Time taken for execution with random algorithm for picking pages = %ld msec\n\n", timedifference(endTime, startTime)); return 0; }
int main(int argc, char** argv) { int i, eviction_algorithm, seed; //Parse input if(argc == 2){ eviction_algorithm = atoi(argv[1]); seed = time(NULL); }else if(argc == 3) { eviction_algorithm = atoi(argv[1]); seed = atoi(argv[2]); }else{ printf("1st argument: eviction algorithm (0-Random; 1-Clock; 2-Clock2ndChance)\n2nd argument: seed for random algorithm\n"); return -1; } init_memory(eviction_algorithm, seed); printf("STORE VALUES IN ORDER value = vAddr+1 (press enter to continue):\n"); memoryMaxer(PAGE_TABLE_SIZE+2);//beyond the limit (the last 2 page creations are ignored) print_memory_state(); getchar(); printf("GET_VALUE FROM ALL ADDRESSES (press enter to continue):\n"); for(i = 0; i < PAGE_TABLE_SIZE; i++){ if(get_value(i, NULL) != i+1){ printf("wrong answer for page %d\n", i); return -1;//not supposed to happen } } print_memory_state(); getchar(); printf("FREE RANDOM pages AND TRY TO GET_VALUE. AND CREATE SOME PAGES (press enter to continue):\n"); for (i = 0; i < 20; i++){ int addr = uniform_rand(0, PAGE_TABLE_SIZE); printf("free %d\n", addr); free_page(addr); int valid; get_value(addr, &valid); if(valid == 0) printf("Couldn't read from addr %d\n", addr); } for (i = 0; i < 10; i++) { vAddr addr = create_page(); uint32_t v = uniform_rand(0, PAGE_TABLE_SIZE); store_value(addr, &v); printf("created page %d with value %d\n", addr, v); } print_memory_state(); getchar(); printf("ALTERNATE STORE AND GET (press enter to continue)\n"); for (i = 0; i < 20; i++){ int addr = uniform_rand(0, PAGE_TABLE_SIZE); uint32_t v = uniform_rand(0, 100); store_value(addr, &v); printf("store %d in vAddr %d\n", v, addr); int valid; addr = uniform_rand(0, PAGE_TABLE_SIZE); v = get_value(addr, &valid); if(valid) printf("got %d from addr %d\n", v, addr); else printf("Couldn't read from addr %d\n", addr); } print_memory_state(); getchar(); destroy_memory(); return 0; }