void perform_op(op_t op) { int n, size; printf("\n\nRANDOM OP: "); switch (op) { case MALLOC: n = ALLOC_ORDER_MIN + (rand() * 1.0 / RAND_MAX) * ALLOC_ORDER_RANGE; size = 1 << n; printf("Allocating memory of size = %d (count = %d)...\n\n", size, count); ptrs[count++] = mem_malloc(size); break; case FREE: n = (rand() * 1.0 / RAND_MAX) * count; if (n == count) n--; printf("Freeing pointer at index %d (count = %d)...\n\n", n, count); mem_free(ptrs[n]); ptrs[n] = ptrs[--count]; ptrs[count] = NULL; break; } printf("MEMORY AFTER OP:\n"); mem_stat(); }
void dbg_console_thread(void* param) { for (;;) { switch(console_getc(_dbg_console)) { case 'h': printf("dbg console help\n\r"); printf("h - this text\n\r"); #if (KERNEL_PROFILING) printf("m - memory usage statistics\n\r"); printf("p - process list\n\r"); printf("s - system stack usage\n\r"); #endif //KERNEL_PROFILING break; #if (KERNEL_PROFILING) case 'm': mem_stat(); break; case 'p': thread_stat(); break; case 's': stack_stat(); break; #endif //KERNEL_PROFILING } } }
int main(void) { int i, * ptr; op_t op; void * addr; init_mem(); srand(time(NULL)); for (i = 0; i < NPTRS; i++) { ptrs[i] = NULL; } printf("STAGE #1: RANDOM OPERATIONS:\n" "============================\n"); for (i = 0; i < NLOOPS; i++) { op = random_op(); perform_op(op); } printf("\n\n\n"); printf("STAGE #2: BOUNDARY CASES:\n" "=========================\n\n"); printf("BOUNDARY CASE #1: ALLOCATING MEMORY WHEN FULL:\n\n"); printf("Trying to allocate POOL_SIZE = %d bytes of memory...\n", POOL_SIZE); ptr = mem_malloc(POOL_SIZE); if (! ptr) { fprintf(stderr, "\nBoundary case verified: memory full\n"); } else { printf("%d bytes of memory allocated successfully.\n", POOL_SIZE); mem_stat(); printf("\nTrying again to allocate POOL_SIZE = %d bytes of memory...\n", POOL_SIZE); ptr = mem_malloc(POOL_SIZE); if (! ptr) { fprintf(stderr, "\nBoundary case verified: memory full\n"); } } printf("\n\n"); printf("BOUNDARY CASE #2: FREEING ALREADY FREED MEMORY:\n\n"); if (count > 0) { printf("First trying to free existing memory at ptrs[0]...\n"); mem_free(ptrs[0]); printf("mem_free() successful.\n"); mem_stat(); printf("Now trying to free already freed memory at ptrs[0]...\n"); mem_free(ptrs[0]); } else { printf("Trying to free already freed memory at ptrs[0]...\n"); mem_free(ptrs[0]); } printf("\nBoundary case verified: freeing already freed memory\n\n\n"); printf("BOUNDARY CASE #3: FREEING AN INVALID POINTER:\n\n"); addr = (void *) 0x30; /* random memory address */ printf("Trying to free invalid pointer %p...\n", addr); mem_free(addr); printf("\nBoundary case verified: freeing an invalid pointer\n"); return 0; }
int Menu_Global_Options() { int rows, cols, win_size = 11; CON_GetMetrics(&cols, &rows); if (strcmp(LAST_CFG_PATH, USBLOADER_PATH)) win_size += 2; if ((win_size = rows-win_size) < 3) win_size = 3; if (CFG.disable_options) return 0; struct discHdr *header = NULL; int redraw_cover = 0; struct Menu menu; menu_init(&menu, 9); for (;;) { menu.line_count = 0; if (gameCnt) { header = &gameList[gameSelected]; } else { header = NULL; } Con_Clear(); FgColor(CFG.color_header); printf_x(gt("Global Options")); printf(":\n\n"); DefaultColor(); menu_window_begin(&menu, win_size, 9); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Main Menu")); if (menu_window_mark(&menu)) printf("%s%2d/%-2d< %s > (%d)\n", con_align(gt("Profile:"),8), CFG.current_profile + 1, CFG.num_profiles, CFG.profile_names[CFG.current_profile], CFG.num_favorite_game); if (menu_window_mark(&menu)) printf("%s%2d/%2d < %s >\n", con_align(gt("Theme:"),7), cur_theme + 1, num_theme, *CFG.theme ? CFG.theme : gt("none")); if (menu_window_mark(&menu)) printf("%s< %s >\n", con_align(gt("Partition:"),13), CFG.partition); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Download All Missing Covers")); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Update WiiTDB Game Database")); // download database - lustar if (menu_window_mark(&menu)) printf("<%s>\n", gt("Update titles.txt")); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Check For Updates")); DefaultColor(); menu_window_end(&menu, cols); printf_h(gt("Press %s for game options"), (button_names[CFG.button_other.num])); printf("\n"); printf_h(gt("Press %s to save global settings"), (button_names[CFG.button_save.num])); printf("\n\n"); Print_SYS_Info(); DefaultColor(); __console_flush(0); if (redraw_cover) { if (header) Gui_DrawCover(header->id); redraw_cover = 0; } u32 buttons = Wpad_WaitButtonsRpt(); menu_move(&menu, buttons); int change = 0; if (buttons & WPAD_BUTTON_LEFT) change = -1; if (buttons & WPAD_BUTTON_RIGHT) change = +1; if (buttons & CFG.button_confirm.mask) change = +1; if (change) { switch (menu.current) { case 0: Menu_Views(); return 0; case 1: CHANGE(CFG.current_profile, CFG.num_profiles-1); // refresh favorites list Switch_Favorites(enable_favorite); redraw_cover = 1; break; case 2: CFG_switch_theme(cur_theme + change); redraw_cover = 1; Cache_Invalidate(); break; case 3: Menu_Partition(true); return 0; case 4: Download_All_Covers(change > 0); Cache_Invalidate(); if (header) Gui_DrawCover(header->id); Menu_PrintWait(); break; case 5: Download_XML(); break; case 6: Download_Titles(); break; case 7: Online_Update(); break; } } // HOME button if (buttons & CFG.button_exit.mask) { Handle_Home(0); } if (buttons & CFG.button_save.mask) { int ret; printf("\n"); printf_x(gt("Saving Settings... ")); printf("\n"); __console_flush(0); FgColor(CFG.color_inactive); ret = CFG_Save_Global_Settings(); DefaultColor(); if (ret) { printf_(gt("OK")); printf("\n"); Save_Game_List(); } else { printf_(gt("ERROR")); } printf("\n"); //sleep(2); Menu_PrintWait(); } if (buttons & WPAD_BUTTON_PLUS) { printf("\n"); mem_stat(); Menu_PrintWait(); } if (buttons & CFG.button_other.mask) return 1; if (buttons & CFG.button_cancel.mask) break; } return 0; }