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

📄 davevent.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
字号:
/* Copyright (c) 1995-2002 Intel Corporation */
/* Intel Confidential                        */

/* ###########################################################################
###  DAV - Direct Access Volume Enhancement to FDI
###
###  Object: EVENT
###
###  Module: event.c - DAV Test Event Module
###
###  $Workfile: davevent.c $
###  $Revision: 56 $
###  $NoKeywords: $
########################################################################### */

/*                                                               
 *****************************************************************
 * NOTICE OF LICENSE AGREEMENT                                    
 *                                                                
 * This code is provided by Intel Corp., and the use is governed  
 * under the terms of a license agreement. See license agreement  
 * for complete terms of license.                                 
 *                                                                
 * YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS.  YOUR 
 * USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY 
 * PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN  
 * INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE   
 * FROM INTEL LICENSING ANY SUCH USE.                             
 *****************************************************************
 */
 

/*### Include Files
//#########################*/
#include "DavLib.h"

#if (DIRECT_ACCESS_VOLUME == TRUE)

#ifdef ENABLE_EVENT_TESTS

#include <stdio.h>
#include <stdlib.h>

/*
#define EVENT_PRINT_ON
*/

/*### Local Declarations
//#########################*/
#define EVT_MAX_RANDOM_NUMBER 1000

/* This is the percentage that a random event will return true */
int EVT_PercentageTRUE = 50;  

char * event_str[6] = { "UNKNOWN ", "Reclaim ", "RecRcvr ",
                        "Realloc ", "Cfg Hdr ", "Recover " };


/* This should match up to the Event Id's */
char * event_name[] = 
{
   /* RECLAIM                             */
   "BEGIN",
#ifdef ENABLE_RECLAIM_TESTS
   "StateA",   
   "StateB",   
   "StateC",   
   "StateD",   
   "StateE",    "StateE_SP1", "StateE_SP2",
   "StateF",    "StateF_1",  
   "StateF_2",  "StateF_2a",  "StateF_2b", 
   "StateF_2c",
   "StateF_3",  "StateF_3a",  "StateF_3b", 
   "StateF_3c", "StateF_3d",  "StateF_3e", 
   "StateF_3f", "StateF_4",   "StateF_4a", 
   "StateF_4b",
   "StateF_5",  "StateF_5a",  "StateF_5b", 
   "StateF_5c", "StateF_5d",  "StateF_5e", 
   "StateF_6",  "StateF_6a",  "StateF_6b", 
   "StateF_6c",
   "StateG",   
   "StateH",   
   "StateI",    "StateI_SP1",
   "StateJ",   
   "StateK",   
   "StateL",    "StateL_SP1",
   "Random",
#endif
   "END",

   /* RECLAIM RECOVERY                    */
   "BEGIN",
#ifdef ENABLE_RECRCVR_TESTS
   "State1", "State1_a", "State1_b",
   "State2", "State2_a", "State2_b",
   "State3",
   "State4",
   "State5",
   "StateA",
   "StateB",
   "StateC",
   "StateD",
   "StateE",
#endif
   "END",   
   
   /* REALLOCATE                          */
   "BEGIN",
#ifdef ENABLE_REALLOCATE_TESTS
   "RInPlc_Start",
   "NoRestart",
   "ProcBlocks",
   "DeallocRAT",
   "MarkCFGDone",
   "ProcBlkState1",
   "ProcBlkState2",
   "ProcBlkState3",
   "ProcBlkState4",
   "RInPlc_End",
   "Random",
#endif
   "END",
   
   /* CONFIG HEADER                       */
   "BEGIN",
#ifdef ENABLE_CONFIG_HDR_TESTS
   "Rec_Start",
   "RecRestart",
   "ClearUniqueIds",
   "MvToRecBlock",
   "MvFromRecBlock",
   "SetUniqueIds",
   "MvHdrState1",
   "MvHdrState2",
   "MvHdrState3",
#endif
   "END",
   
   /* RECOVER                             */
   "BEGIN",
#ifdef ENABLE_RECOVER_TESTS
   "ValSys_Start",
   "ValSys_End",
   "RstParaRec_Start",
   "RstParaRec_End",
   "RstPageRec_Start",
   "RstPageRec_End",
   "RstReAlloc_Start",
   "RstReAlloc_End",
   "ChkSysStat_Start",
   "ChkSysStat_End",
   "ChkCfHdr_Start",
   "RstrWIPObj_Start",
   "RstrWIPObj_End",
#endif
   "END",

    "RandomFail",

#ifdef ENABLE_HDR_TESTS
    "RepairHdr_Start",
    "RepairHdr_AVAIL",
    "RepairHdr_BAD_WIP",
    "RepairHdr_Unknown",
    "RepairHdr_End",
#endif


   "EVT_TotalEvents"

};

/*## Global Declarations
//#########################*/

BOOLEAN          EVT_CheckPageReclaim = FALSE;
EVT_EventElement EVT_EventList[EVT_TotalEvents];

/*## Local Functions
//#########################*/

/*#######################################################################
//### PrintEventMark
//###
*/
void PrintEventMark(BOOLEAN is_set, FILE *fptr)
{
   if (is_set)
   {
      fprintf(fptr, "x ");
   }
   else
   {
      fprintf(fptr, "  ");
   }
}

/*########################################################################
//### SpecialReclaimTest
//###
*/
BOOLEAN SpecialReclaimTest(int test_point_id)
{
   if (((ReclaimState.ReclaimType == ReclaimParagraphObjects) && 
                                            EVT_CheckPageReclaim) ||
          ((ReclaimState.ReclaimType == ReclaimPageObjects) && 
                                                 !EVT_CheckPageReclaim))
   {
      return FALSE;
   }
   
   return TRUE;
}

/*### Global Functions
//#########################*/

/*########################################################################
//### EVT_DisplayEvents
//### 
*/
void EVT_DisplayEvents(FILE *fptr)
{
int ii;
int test_range;

   if (fptr == NULL)
   {
      fptr = stdout;
   }
   
   fprintf(fptr, "Event List:\n");
   fprintf(fptr, "                             D D D   T       \n");
   fprintf(fptr, "             Item    Event   I S S B I R E K \n");
   fprintf(fptr, " # Module    Count   Count   D U T P M E X E   Id\n");
   fprintf(fptr, "======================================================================\n"); 
   for (ii = 0; ii < EVT_TotalEvents; ii++)
   {
      fprintf(fptr, "%3d ", ii);
      if (ii >= EVT_RECLAIM_BEGIN)
      {
         test_range = 1;
      }
      
      if (ii >= EVT_RECRCVR_BEGIN)
      {
         test_range = 2;
      }
      
      if (ii >= EVT_REALLOCATE_BEGIN)
      {
         test_range = 3;
      }
      
      if (ii >= EVT_CONFIG_HDR_BEGIN)
      {
         test_range = 4;
      }

      if (ii >= EVT_RECOVER_BEGIN)
      {
         test_range = 5;
      }
      
      if (ii >= EVT_TotalEvents)
      {
         test_range = 0;
      }
      
#ifdef ENABLE_EVENT_STATISTICS   
      fprintf(fptr, "%s %07ld %07ld ", event_str[test_range],
              EVT_EventList[ii].TestCount, EVT_EventList[ii].EventCount);
#endif
      
      PrintEventMark(EVT_IsDisplayIdEvent(ii), fptr);
      PrintEventMark(EVT_IsDisplaySummaryEvent(ii), fptr);
      PrintEventMark(EVT_IsDumpStateEvent(ii), fptr);
      PrintEventMark(EVT_IsBreakPointEvent(ii), fptr);
      PrintEventMark(EVT_IsTimerEvent(ii), fptr);
      PrintEventMark(EVT_IsRandomErrorEvent(ii), fptr);
      PrintEventMark(EVT_IsExitEvent(ii), fptr);
      PrintEventMark(EVT_IsKeepEnabledEvent(ii), fptr);

#ifdef ENABLE_EVENT_STATISTICS   
      if ((EVT_EventList[ii].EventCount == 0) && EVT_IsEnabled(ii))
      {
         /* Make a special not of events that are enabled, and */
         /* never tested.                                      */
         fprintf(fptr, " [%s]\n", event_name[ii]);
      }
      else
      {
         fprintf(fptr, "  %s\n", event_name[ii]);
      }
#endif
   }
}

/*########################################################################
//### EVT_SetEvent
//### 
*/
void EVT_SetEvent(EVT_TestPointIds test_point_id,
                  EVT_EventElementPtr event_ptr)
{
   *(UINT16_PTR)&(EVT_EventList[test_point_id].Event) =
                                      *(UINT16_PTR)&(event_ptr->Event);
}

/*########################################################################
//### EVT_ClearEvent
//### 
*/
void EVT_ClearEvent(EVT_EventElementPtr event_ptr)
{
   *(UINT16_PTR)&(event_ptr->Event) = 0;
}

/*########################################################################
//### EVT_InitEvents
//### 
*/
void EVT_InitEvents(void)
{
int ii;

   for (ii = 0; ii < EVT_TotalEvents; ii++)
   {
      EVT_ClearEvent(&EVT_EventList[ii]);
   }
}

/*########################################################################
//### EVT_SetAllEvents
//### 
*/
void EVT_SetAllEvents(EVT_TestPointIds start_id, EVT_TestPointIds end_id, 
                                             EVT_EventElementPtr event_ptr)
{
int ii;

   for (ii = start_id; ii <= end_id; ii++)
   {
      EVT_SetEvent(ii, event_ptr);
   }
}

/*########################################################################
//### EVT_DisableEvent
//### 
*/
BOOLEAN EVT_DisableEvent(EVT_TestPointIds test_point_id)
{
   EVT_EventList[test_point_id].Event &= ~EVT_ENABLE;
   
   return TRUE;
}

/*########################################################################
//### EVT_EnableEvent
//### 
*/
BOOLEAN EVT_EnableEvent(EVT_TestPointIds test_point_id)
{
   EVT_SetEnabled(test_point_id);
   
   return TRUE;
}

void DisplayEventId(EVT_TestPointIds test_point_id)
{
int test_range;

   if (test_point_id >= EVT_RECLAIM_BEGIN)
   {
      test_range = 1;
   }
   
   if (test_point_id >= EVT_REALLOCATE_BEGIN)
   {
      test_range = 2;
   }
   
   if (test_point_id >= EVT_CONFIG_HDR_BEGIN)
   {
      test_range = 3;
   }

   if (test_point_id >= EVT_RECOVER_BEGIN)
   {
      test_range = 4;
   }
   
   if (test_point_id >= EVT_RECRCVR_BEGIN)
   {
      test_range = 5;
   }
      
   if (test_point_id >= EVT_TotalEvents)
   {
      test_range = 0;
   }

   printf("TEST POINT: (0x%02x) %s", test_point_id, 
                                     event_str[test_range]);
   printf("  %s\n",event_name[test_point_id]);
}


/*########################################################################
//### EVT_TestEvent
//### 
*/
BOOLEAN EVT_TestEvent(EVT_TestPointIds test_point_id)
{
BOOLEAN event_actuated;

static  BOOLEAN          all_events_disabled = FALSE;
static  EVT_TestPointIds disabler_event;

   #ifdef ENABLE_EVENT_STATISTICS
      EVT_EventList[test_point_id].TestCount++;
   #endif
   
   if (EVT_IsDisplayIdEvent(test_point_id))
   {
      DisplayEventId(test_point_id);
   }

   /* Allow the DisableAll event to turn off all events until  */
   /*  it clears its DisableAll event and calls this function. */
   /*  This will only allow the caller of the DisableAll to    */
   /*  turn the events back on!!!                              */
   if (all_events_disabled)
   {
      if (disabler_event == test_point_id)
      {
         if (!EVT_IsDisableAllEvent(test_point_id))
         {
            all_events_disabled = FALSE;
         }
      }
      
      return FALSE;
   }
   
   if (!EVT_IsEnabled(test_point_id))
   {
      return FALSE;
   }

#ifdef ENABLE_SPECIAL_RECLAIM_TEST
   if ((test_point_id >= EVT_RECLAIM_BEGIN) && 
                       (test_point_id <= EVT_RECLAIM_END))
   {
      if (!SpecialReclaimTest(test_point_id))
      {
         return FALSE;
      }
   }
#endif

   event_actuated = FALSE;
   
   if (EVT_IsDisableAllEvent(test_point_id))
   {
      all_events_disabled = TRUE;
      disabler_event = test_point_id;
      event_actuated = TRUE;
   }
   
   if (EVT_IsDisplaySummaryEvent(test_point_id))
   {
      DisplayMem();
   }
   
   if (EVT_IsDumpStateEvent(test_point_id))
   {
      /* Dump an ascii readable version of the flash array */
      DumpFlashState("fstate.txt");
      
      /* Dump a reloadable version of the flash array */
      SaveFlashState("fstate.bin");
      event_actuated = TRUE;
   }

   if (EVT_IsBreakPointEvent(test_point_id))
   {
      /* Enable for DOS debug (int 3 is the breakpoint instruction)
      asm { int 3 };
      */
      event_actuated = TRUE;
   }

   if (EVT_IsTimerEvent(test_point_id))
   {
      /* ADD CODE HERE TO START AND STOP TIMER  */
   }

   if (EVT_IsRandomErrorEvent(test_point_id))
   {

      /* GENERATE A TRUE OR FALSE RANDOMLY */
      if (GetRandom(0, EVT_PercentageTRUE) == (EVT_PercentageTRUE / 2))

      {
#ifdef EVENT_PRINT_ON      
         printf("\nRandom Event Triggered: \n");
         DisplayEventId(test_point_id);
#endif         
         event_actuated = TRUE;
      }
   }
   else
   {
      event_actuated = TRUE;
   }

   
   if (EVT_IsExitEvent(test_point_id))
   {
      printf("\nExit Event...Exiting: \n");
      DisplayEventId(test_point_id);
      exit(1);
   }
   
   #ifdef ENABLE_EVENT_STATISTICS
      if (event_actuated)
      {
         EVT_EventList[test_point_id].EventCount++;
      }
   #endif
      
   if (!EVT_IsKeepEnabledEvent(test_point_id))
   {
      EVT_EventList[test_point_id].Event &= ~EVT_ENABLE;
   }

   return event_actuated;
}

#endif  /* end event.c */

#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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