Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Stress File utility

Stress File is a stress testing utility application. Stress File hogs the available EFS space from a minimum to a maximum amount according to the setting in the .ini file. Stress File continues to run if other applications are launched on top of it.

The .ini file has these parameters:

Parameter Description

SpaceFree=500;

Remaining EFS space free in KB

Cleanup=1;

1 = clean up on subsequent runs

0 = no cleanup

SIMDiskSpace=20000000;

Maximum disk space in bytes to fill on the SIM

Output

The Simulator screen displays a thermometer indicating how full the file system is in red. The .ini file requested user setting is displayed in yellow. After cleaning up any temporary files from previous runs, Stress File fills the file system with temporary files until the requested percentage to fill is reached.

Command-line parameters

Stress File can be run with these command-line parameters.

  • Remaining space free requested in KB
  • Flag to indicate if the application should start by cleaning up files created on a previous run: 0 for no and 1 for yes.
  • Optional and for Simulator only: Available simulated disk space in bytes, range 5000000 to 20000000.

Requirements

To run the c_basicapp sample code, you need the following:

  • Brew MP 1.0 SDK rev 7.11.1 or higher
  • Brew MP-enabled device or a Simulator target
  • Installed copy of Sample Code from the SDK Manager

Sample code location

Filename

Location

Run application

stressfile

Sample code installation folder

  • Open stressfile.sln in Visual Studio.
  • Compile the applet.

  • Click the Click2Run icon.

Event handling

Stress File is designed to run as a background application and has minimal event handling.

Example

Stress File uses the new file interfaces – IFileSystem2 and IFilePort1 – to create temporary files until the desired EFS space is used.
void MakeFillFile(StressFile *pMe)
{
   char tempnam[256];
   int iDropDead = 0;
   IFilePort1 *filePort = NULL;
   AEEResult nRes = AEE_SUCCESS;
   GetTempFileName(pMe, tempnam);

   while (++iDropDead < 10) //set for n retries on tempname
   {
      nRes = IFileSystem2_Open(pMe->m_pFileSystem, tempnam, 
         FS_CAP_RDWR FS_CAP_CREATE, &filePort);

      //if file exists then bump the temp name and try again
      if (nRes == AEEFS_EFILEEXISTS)
      {
         continue;
      }
      else if (nRes == AEEFS_EFSFULL) //Full!!
      {
         DBGPRINTF("File System Full");
      }
      else if (nRes != AEE_SUCCESS)
      {
         DBGPRINTF("Error Creating Temp File :%s Error :%d", tempnam, nRes);
      }
      break;
   }

   //if we got out fileport then fill it up
   if (nRes == AEE_SUCCESS)
   {
      int iLen = 0;
      int iToWrite = FILE_BUF_SIZE;
      int iWritten = 0;
      if (!pMe->m_pFileBuffer)
      {
         pMe->m_pFileBuffer = (unsigned char *)MALLOC(iToWrite);
         if (!pMe->m_pFileBuffer)
         {
            DBGPRINTF("Error Allocating buffer for temp file!");
            RELEASEIF(filePort);
            return;
         }
      }
      while (iWritten < iToWrite)
      {
         if (AEE_SUCCESS == IFilePort1_Write(filePort, pMe->m_pFileBuffer, 
                            iToWrite - iWritten, &iLen))
         {
            iWritten += iToWrite;
         }
         else
         {
            DBGPRINTF("Error writing to temp file!");
            break;
         }
      }
      RELEASEIF(filePort);
   }
}


The application searches for and remove its own temporary files if the cleanup .ini file option is selected.

//look for a .tmp file and remove it
//as a process of cleaning up
boolean RemoveFillFile(StressFile *pMe)
{
   IFilePort1* pFilePort = NULL;
   boolean bFoundOne = FALSE;
   AEEResult nErr = AEE_SUCCESS;
   char pToken[1024];
   char pTokenMode[1024];
   if (!pMe->m_pFileSystemBuffer)
   {
      nErr = IFileSystem2_Open(pMe->m_pFileSystem, "fs:/~0x010bfe85/", 
        "Dmn" /*FS_CAP_DIR FS_CAP_DIR_NAME*/, &pFilePort);
      if (AEE_SUCCESS == nErr)
      {
         int iRead = 0;
         int iBufferSize = 32768;
         int iTotal = 0;
         pMe->m_pFileSystemBuffer = (char *)MALLOC(iBufferSize);
         
         while (TRUE)
         {
            nErr = IFilePort1_Read(pFilePort, (byte *)pMe->m_pFileSystemBuffer 
                   + iTotal, 
               iBufferSize - iTotal, &iRead);
            if (nErr != AEE_SUCCESS)
            {
               DBGPRINTF("Error Reading from Directory:%d", nErr);
               break;  //try to process what we got if any
            }
            if (iRead == iBufferSize)
            {
               iBufferSize += 32768;
               if (iBufferSize < 0)
               {
                  DBGPRINTF("Buffer Size Overflow, processing MAX_INT buffer");
                  break;  //out limit is hit .. just process what we have
               }
               pMe->m_pFileSystemBuffer = (char *)REALLOC(pMe->
                    m_pFileSystemBuffer, iBufferSize);
               if (!pMe->m_pFileSystemBuffer)
               {
                  DBGPRINTF("Error Realloc buffer space size:%d", iBufferSize);
                  return FALSE;
               }
            }
            else
            {
               break;
            }
            iTotal += iRead;
         }
      }
      if (pFilePort)
      {
         RELEASEIF(pFilePort);
      }
      pMe->m_pMyRunningBuffer = pMe->m_pFileSystemBuffer;
   }
      
   //now tokenize/process the contents
   while (*pMe->m_pMyRunningBuffer)
   {
      int iMode = 0;
      STRCPY(pTokenMode, pMe->m_pMyRunningBuffer);
      iMode = ATOI(pTokenMode);
      pMe->m_pMyRunningBuffer += STRLEN(pMe->m_pMyRunningBuffer) + 1;
      STRCPY(pToken, pMe->m_pMyRunningBuffer);
      pMe->m_pMyRunningBuffer += STRLEN(pMe->m_pMyRunningBuffer) + 1;

      //is this a file?
      if (/*FS_S_IFDIR*/ 4000 != iMode)
      {
         if (STRSTR(pToken, ".tmp") != 0)
         {
            char szFileName[1024];
            SPRINTF(szFileName, "fs:/~0x010bfe85/%s", pToken);
            //remove the file
            if (AEE_SUCCESS != IFileSystem2_Unlink(pMe->m_pFileSystem, 
                               szFileName))
            {
               DBGPRINTF("Error removing %s", pToken);
            }
            else
            {
               bFoundOne = TRUE;
            }
            break;  //WE ONLY DO ONE tmp file SO EXIT
         }
      }
   }
   return bFoundOne;
}

Error handling

The application uses the following macros for error handling.

#define ERR_CATCH        __errcatch
#define ERR_TRY(x)  do{nErr = (x); if(AEE_SUCCESS != nErr) goto ERR_CATCH;} 
                                      while(0)
#define ERR_THROW(e) do { nErr = (e); goto ERR_CATCH; } while(0)
#define ERR_CHECK_PTR(p)      if (NULL == p) ERR_THROW(AEE_EFAILED);