⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spacebank_test.c

📁 C++ 编写的EROS RTOS
💻 C
📖 第 1 页 / 共 2 页
字号:
      if (result != RC_OK) {	kdprintf(KR_CONSOLEKEY,		 "Error buying node ndx=%d subndx=%d (0x%08x)\n",		 nodeIndex, subnodeIndex, result);	return 0;      }      #ifdef VERBOSE      /* show off the key */      ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP2);#endif            result = node_swap(KR_TMP1, subnodeIndex, KR_TMP2, KR_VOID);      if (result != RC_OK) {	kdprintf(KR_CONSOLEKEY,		 "sb test line %d: Error 0x%08x (%d) inserting node\n",		 __LINE__, result, result,		 nodeIndex,		 result);	return 0;      }    #ifdef VERBOSE      sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif      for (theNodeIndex = 0; theNodeIndex < EROS_NODE_SIZE; theNodeIndex++) {#ifdef VERBOSE	kprintf(KR_CONSOLEKEY,		"SpaceBankTest: NodeAllocTest allocating node %d:%d:%d\n",		nodeIndex,		subnodeIndex,		theNodeIndex);#endif	result = spcbank_buy_nodes(sbKey, 1, KR_TMP3, 0, 0);	if (result != RC_OK) {	  if (result == RC_SB_LimitReached) {#ifdef VERBOSE	    kprintf(KR_CONSOLEKEY,		     "SpaceBankTest: NodeAllocTest limit reached\n");#endif	    goto doneAllocating;	  } else {	    kdprintf(KR_CONSOLEKEY,		     "Error buying node %d:%d (0x%08x)\n",		     nodeIndex,		     theNodeIndex,		     result);	    return 0;	  }	}#ifdef VERBOSE	ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP3);#endif	/* modify the thing */	node_swap(KR_TMP3, 0, KR_SLEEPKEY, KR_VOID);		result = node_swap(KR_TMP2, theNodeIndex, KR_TMP3, KR_VOID);	if (result != RC_OK) {	  kdprintf(KR_CONSOLEKEY,		   "sb test line %d: Error 0x%08x (%d) inserting node (0x%08x)\n",		   __LINE__, result, result,		   nodeIndex,		   theNodeIndex,		   result);	  return 0;	}	nodesAllocated++;#ifdef VERBOSE	sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif      }    }  }  doneAllocating:  STPRINTF(KR_CONSOLEKEY,	   "SpaceBankTest: Finished allocating.  Allocated %u nodes\n",	   nodesAllocated);#ifdef VERBOSE  sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif  if (!deallocManually) {    /* destroy the bank and it's space */    result = spcbank_destroy_bank(sbKey, 1);    return (result == RC_OK);  }  kprintf(KR_CONSOLEKEY,	  "SpaceBankTest: NodeAllocTest now deallocating storage.\n");  for (nodeIndex = 0; nodeIndex < EROS_NODE_SIZE; nodeIndex++) {    uint32_t kt;        /* grab the node key */#ifdef VERBOSE    kprintf(KR_CONSOLEKEY,	    "SpaceBankTest: NodeAllocTest: Grabbing Node %d\n",	    nodeIndex);#endif        result = node_copy(KR_TMP0, nodeIndex, KR_TMP1);    if (result != RC_OK) {      kdprintf(KR_CONSOLEKEY,	       "Error grabbing node %d (0x%08x)\n",	       nodeIndex,	       result);      return 0;    }#ifdef VERBOSE     ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP1);#endif    kt = key_kt(KR_TMP1);    if (kt != AKT_Node) {      if (kt == AKT_Number) {	kprintf(KR_CONSOLEKEY,		"Finished deallocating nodes\n");	break; /* BREAK */      } else {	kdprintf(KR_CONSOLEKEY,		 "Error: invalid kt (0x%08x) for node %d\n",		 kt,		 nodeIndex);	return 0;      }    }#ifdef VERBOSE     sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif        for (subnodeIndex = 0; subnodeIndex < EROS_NODE_SIZE; subnodeIndex++) {      uint32_t kt;          /* grab the node key */#ifdef VERBOSE       kprintf(KR_CONSOLEKEY,	      "SpaceBankTest: NodeAllocTest: Grabbing Node %d:%d\n",	      nodeIndex,subnodeIndex);#endif          result = node_copy(KR_TMP1, subnodeIndex, KR_TMP2);      if (result != RC_OK) {	kdprintf(KR_CONSOLEKEY,		 "Error grabbing node (0x%08x)\n",		 result);	return 0;      }      #ifdef VERBOSE       ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP2);#endif      kt = key_kt(KR_TMP2);      if (kt != AKT_Node) {	if (kt == AKT_Number) {	  break; /* BREAK */	} else {	  kdprintf(KR_CONSOLEKEY,		   "Error: invalid kt (0x%08x) for node\n",		   kt,		   nodeIndex);	  return 0;	}      }#ifdef VERBOSE       sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif            for (theNodeIndex = 0; theNodeIndex < EROS_NODE_SIZE; theNodeIndex++) {	/* grab the node key */#ifdef VERBOSE  	kprintf(KR_CONSOLEKEY,		"SpaceBankTest: NodeAllocTest: Grabbing node %d:%d:%d\n",		nodeIndex,		subnodeIndex,		theNodeIndex);#endif		result = node_copy(KR_TMP2, theNodeIndex, KR_TMP3);	if (result != RC_OK) {	  kdprintf(KR_CONSOLEKEY,		   "Error grabbing node (0x%08x)\n",		   result);	  return 0;	}	#ifdef VERBOSE	ShowKey(KR_CONSOLEKEY, KR_KEYBITS, KR_TMP3);#endif      	kt = key_kt(KR_TMP3);	if (kt != AKT_Node) {	  if (kt == AKT_Number) {	    /* done */	    break; /* BREAK */	  } else {	    kdprintf(KR_CONSOLEKEY,		     "Error: invalid kt (0x%08x) for node %d:%d:%d\n",		     kt,		     nodeIndex,		     subnodeIndex,		     theNodeIndex);	    return 0;	  }	}		/* free the node */	result = spcbank_return_node(sbKey, KR_TMP3);	if (result != RC_OK) {	  kdprintf(KR_CONSOLEKEY,		   "Error returning node (0x%08x)\n",		   result);	  return 0;	}#ifdef VERBOSE		kprintf(KR_CONSOLEKEY,		"SpaceBankTest: Node %d:%d:%d successfully returned.\n",		nodeIndex,		subnodeIndex,		theNodeIndex);		sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif      }      /* all the nodes are dealloced, now free the node. */      result = spcbank_return_node(sbKey, KR_TMP2);      if (result != RC_OK) {	kdprintf(KR_CONSOLEKEY,		 "Error returning node %d:%d (0x%08x)\n",		 nodeIndex,		 subnodeIndex,		 result);	return 0;      }#ifdef VERBOSE       kprintf(KR_CONSOLEKEY,	      "SpaceBankTest: Node %d successfully returned.\n",	      subnodeIndex);            sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif    }        /* all the nodes are dealloced, now free the node. */    result = spcbank_return_node(sbKey, KR_TMP1);    if (result != RC_OK) {      kdprintf(KR_CONSOLEKEY,	       "Error returning node %d (0x%08x)\n",	       nodeIndex,	       result);      return 0;    }#ifdef VERBOSE     kprintf(KR_CONSOLEKEY,	    "SpaceBankTest: Node %d successfully returned.\n",	    nodeIndex);          sl_sleep(KR_SLEEPKEY, SLEEP_TME);#endif  }#ifdef VERBOSE   kprintf(KR_CONSOLEKEY,	  "SpaceBankTest: Finished deallocating.  Rescinding top node.\n");#endif  result = spcbank_return_node(sbKey, KR_TMP0);  if (result != RC_OK) {    kdprintf(KR_CONSOLEKEY,	     "Error returning top node (0x%08x)\n",	     result);    return 0;  }#ifdef VERBOSE   kprintf(KR_CONSOLEKEY,	  "SpaceBankTest: Top node returned.\n");#endif    kprintf(KR_CONSOLEKEY,	  "SpaceBankTest:  NodeAllocTest complete.\n");    sl_sleep(KR_SLEEPKEY, SLEEP_TME);  return 1;}uint16_t SpaceBankInit(){  uint32_t Result;  kprintf(KR_CONSOLEKEY, "Spacebank test domain: identifying spacebank.\n");    Result = key_kt(KR_SPACEBANK);             /* this step will also initialize the spacebank */    if (Result == 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;  }        return 1;}uint16_tSubBankTest(){  uint32_t result;  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);  if (result != RC_OK) {    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);  if (result != RC_OK) {    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;  }  if (key_kt(KR_TMP3) != AKT_Number) {    kdprintf(KR_CONSOLEKEY,	     "SpaceBankTest: Keys not zeroed on destroy first bank and space\n",	     result);    return 0;      }  result = spcbank_verify_bank(KR_SPACEBANK, KR_SUBBANK);  if (result == RC_OK) {    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);  if (result != RC_OK) {    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;  }  if (key_kt(KR_TMP3) != 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  if (key_kt(KR_TMP3) != AKT_Number || key_kt(KR_TMP1) != AKT_Number) {    kdprintf(KR_CONSOLEKEY,	     "SpaceBankTest: Keys not zeroed on parent destroy bank and space\n",	     result);    return 0;      }    return 1;}voidmain(){  uint32_t pass = 0;  /*   * simple spacebank test domain.  the test   * is divided into three stages: init, nodes, pages.   */  sl_sleep(KR_SLEEPKEY, SLEEP_TME);  if (!SpaceBankInit())    kdprintf(KR_CONSOLEKEY, "\nSpacebank test domain.  Init Failure.\n");      if (NodeAllocTest(KR_SPACEBANK, 1)      && PageAllocTest(KR_SPACEBANK, 1)      && SubBankTest())    kprintf(KR_CONSOLEKEY, "\nSpacebank test domain:  Success.\n");  else    kprintf(KR_CONSOLEKEY, "\nSpacebank test domain.  Failure.\n");  kprintf(KR_CONSOLEKEY, "Starting stress test?\n");  for(;;) {    ++pass;    kprintf(KR_CONSOLEKEY, "Stress test pass %d\n", pass);    NodeAllocTest(KR_SPACEBANK, 1);    PageAllocTest(KR_SPACEBANK, 1);    SubBankTest();  }  return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -