📄 spacebank_test.c
字号:
count = 0; /* initialize count */ STPRINTF(KR_CONSOLEKEY,"%s: Beginning Test\n",test_name);#ifdef VERBOSE /* NO TRAILING NEWLINE -- we print dots as we allocate */ kprintf(KR_CONSOLEKEY,"%s: Allocating",test_name); #endif for (count = 0; ; count++) { /* infernal loop */ /* note: count is incremented only on completion of loop */ if ((*alloc_func)(KR_TMP0,KR_PARBANK) != RC_OK) {#ifdef VERBOSE kprintf(KR_CONSOLEKEY, "\n%s: alloc_func failed (this is okay)\n", test_name);#endif break; /* done */ } if (insert_key(&info,test_name,KR_PARBANK,KR_TMP0) != RC_OK) {#ifdef VERBOSE if (dealloc_func) { kprintf(KR_CONSOLEKEY, "\n%s: insert_key failed -- deallocating last object\n", test_name); } else { kprintf(KR_CONSOLEKEY, "\n%s: insert_key failed -- last object will be destroyed" "with the bank\n", test_name); }#endif if (dealloc_func && (*dealloc_func)(KR_TMP0,KR_PARBANK) != RC_OK) { kdprintf(KR_CONSOLEKEY, "%s: Insert_key failed, and I can't deallocate " "the last object!!\n", test_name); return 1; } break; }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,".");#endif } /* for (count = 0;;count++) */ STPRINTF(KR_CONSOLEKEY, "\n%s: Finished allocating. A total of %d objects allocated.\n", test_name, count); if (dealloc_func) { kprintf(KR_CONSOLEKEY, "%s: Beginning Deallocation pass...\n", test_name); if (dealloc_array(&info,test_name,dealloc_func, KR_PARBANK,KR_TMP0) != RC_OK) { kdprintf(KR_CONSOLEKEY,"%s: Error deallocating objects.\n",test_name); return 1; } kprintf(KR_CONSOLEKEY, "%s: Destroying bank...\n", test_name); } else { kprintf(KR_CONSOLEKEY, "%s: Destroying bank and space...\n", test_name); } if (spcbank_destroy_bank(KR_PARBANK,(dealloc_func == NULL)) != RC_OK) { kdprintf(KR_CONSOLEKEY, "%s: Failed to destroy bank%s.\n", test_name, (dealloc_func == NULL)?" and space":""); } STPRINTF(KR_CONSOLEKEY, "%s: Finished deallocation.\n",test_name); return 0;}uint32_tpage_allocate(uint32_t toKey, uint32_t krBank){ return spcbank_buy_data_pages(krBank,1,toKey,KR_VOID,KR_VOID);}uint32_tpage_dealloc(uint32_t fromKey, uint32_t krBank){ return spcbank_return_data_page(krBank,fromKey);}uint16_tPageAllocTest(uint32_t deallocManually){ return RunAllocTest("PageAllocTest", page_allocate, (deallocManually)? page_dealloc : NULL);}uint32_tnode_allocate(uint32_t toKey, uint32_t krBank){ return spcbank_buy_nodes(krBank,1,toKey,KR_VOID,KR_VOID);}uint32_tnode_dealloc(uint32_t fromKey, uint32_t krBank){ return spcbank_return_node(krBank,fromKey);}uint16_tNodeAllocTest(uint32_t deallocManually){ return RunAllocTest("NodeAllocTest", node_allocate, (deallocManually)? node_dealloc : NULL);}uint16_t SpaceBankInit(){ uint32_t isGood; uint32_t result; uint32_t keyType; kprintf(KR_CONSOLEKEY, "Spacebank test domain: identifying spacebank.\n"); result = key_kt(KR_SPACEBANK, &keyType, 0); /* this step will also initialize the spacebank */ if (result == RC_OK && keyType == AKT_SpaceBank) { STPRINTF(KR_CONSOLEKEY, "Spacebank verified. \n"); } else { kprintf(KR_CONSOLEKEY, "Spacebank NOT verified.\n" "Result from spacebank was 0x%08x\n", result); return 0; } result = spcbank_verify_bank(KR_SPACEBANK, KR_SPACEBANK, &isGood); if (result != RC_OK || isGood == 0) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Verification of prime bank failed! (0x%08x, %d)\n", result, isGood); return 0; } return 1;}uint16_tSubBankTest(){ uint32_t result; uint32_t isGood; uint32_t keyType; kprintf(KR_CONSOLEKEY, "SpaceBankTest: Starting SubBankTest\n");#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating parent\n");#endif result = spcbank_create_subbank(KR_SPACEBANK, KR_PARBANK); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error creating Parent! (0x%08x)\n", result); return 0; } result = spcbank_verify_bank(KR_SPACEBANK, KR_PARBANK, &isGood); if (result != RC_OK || isGood == 0) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Verification of new bank failed! (0x%08x)\n", result); }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating first child\n");#endif result = spcbank_create_subbank(KR_PARBANK, KR_SUBBANK); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error creating first sub-bank! (0x%08x)\n", result); return 0; } result = spcbank_verify_bank(KR_PARBANK, KR_SUBBANK, &isGood); if (result != RC_OK || isGood == 0) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Verification of new bank failed! (0x%08x)\n", result); }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating first two pages\n");#endif result = spcbank_buy_data_pages(KR_SUBBANK, 2, KR_TMP0, KR_TMP1, 0); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error buying first two pages! (0x%08x)\n", result); return 0; }#ifdef VERBOSE ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP0); ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP1);#endif #ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating first two nodes\n");#endif result = spcbank_buy_nodes(KR_SUBBANK, 2, KR_TMP2, KR_TMP3, 0); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error buying first two nodes! (0x%08x)\n", result); return 0; }#ifdef VERBOSE ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP2); ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP3);#endif #ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: destroying 1st subbank + space\n");#endif /* destroy bank and space */ result = spcbank_destroy_bank(KR_SUBBANK, 1); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error destroying first subbank and space! (0x%08x)\n", result); return 0; } key_kt(KR_TMP3, &keyType, 0); if (keyType != RC_Void) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Keys not voided on destroy first bank and space\n", result); return 0; } result = spcbank_verify_bank(KR_SPACEBANK, KR_SUBBANK, &isGood); if (result == RC_OK || isGood == 0) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Verification of destroyed bank key succedded!\n", result); }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating 2nd subbank\n");#endif result = spcbank_create_subbank(KR_PARBANK, KR_SUBBANK); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error creating second sub-bank! (0x%08x)\n", result); return 0; } result = spcbank_verify_bank(KR_SPACEBANK, KR_SUBBANK, &isGood); if (result != RC_OK || isGood == 0) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Verification of new bank failed! (0x%08x)\n", result); }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating second two pages\n");#endif result = spcbank_buy_data_pages(KR_SUBBANK, 2, KR_TMP0, KR_TMP1, 0); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error buying second two pages! (0x%08x)\n", result); return 0; }#ifdef VERBOSE ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP0); ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP1);#endif #ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: creating second two nodes\n");#endif result = spcbank_buy_nodes(KR_SUBBANK, 2, KR_TMP2, KR_TMP3, 0); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error buying second two nodes! (0x%08x)\n", result); return 0; }#ifdef VERBOSE ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP2); ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP3);#endif #ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: destroying 2nd subbank\n");#endif /* destroy bank, returning space to parent*/ result = spcbank_destroy_bank(KR_SUBBANK, 0); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error destroying second subbank! (0x%08x)\n", result); return 0; } key_kt(KR_TMP3, &keyType, 0); if (keyType != AKT_Node) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Keys zeroed on destroy 2nd bank return to parent!\n", result); return 0; }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: returning a page and a node\n");#endif /* return one node and one page to the parent bank */ result = (spcbank_return_data_page(KR_PARBANK, KR_TMP0) || spcbank_return_node(KR_PARBANK, KR_TMP2)); if (result) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error returning items to parent bank\n"); return 0; }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: destroying parent bank and space\n");#endif result = spcbank_destroy_bank(KR_PARBANK, 1); if (result != RC_OK) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Error destroying parent bank and space! (0x%08x)\n", result); return 0; }#ifdef VERBOSE kprintf(KR_CONSOLEKEY,"SpaceBankTest: verifying destruction\n");#endif { uint32_t tmp3Type; uint32_t tmp1Type; key_kt (KR_TMP3, &tmp3Type, 0); key_kt (KR_TMP1, &tmp1Type, 0); if (tmp3Type != RC_Void || tmp1Type != RC_Void) { kdprintf(KR_CONSOLEKEY, "SpaceBankTest: Keys not voided on parent destroy bank and space\n", result); return 0; } } return 1;}intmain(){ int idx; /* * simple spacebank test domain. the test * is divided into three stages: init, nodes, pages. */ sl_sleep(KR_SLEEPKEY, SLEEP_TME); if (SpaceBankInit() && NodeAllocTest(1) && PageAllocTest(1) && SubBankTest()) kprintf(KR_CONSOLEKEY, "\nSpacebank test domain: Success.\n"); else kprintf(KR_CONSOLEKEY, "\nSpacebank test domain. Failure.\n"); kdprintf(KR_CONSOLEKEY, "Stress test?\n"); for(idx = 0; ; idx++) { kprintf(KR_CONSOLEKEY,"Loop %x: NodeTest\n",idx); NodeAllocTest(1); kprintf(KR_CONSOLEKEY,"Loop %x: PageTest\n",idx); PageAllocTest(1); kprintf(KR_CONSOLEKEY,"Loop %x: SubBankTest\n",idx); SubBankTest(); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -