Advertisement
Guest User

soft error search

a guest
Nov 21st, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <unistd.h>
  5.  
  6. // USAGE: soft-error size
  7. //  size is in mebibytes
  8. //  default 128 MB if not specified
  9.  
  10. int main( int argc, char *argv[] )
  11. {
  12.     int size = 128;
  13.     if ( argc == 2 )
  14.         size = atoi( argv[1] );
  15.     else if ( argc != 1 )
  16.     {
  17.         fprintf( stderr, "Usage: %s [size_in_MB]\n", argv[0] );
  18.         return 1;
  19.     }
  20.  
  21.     int bsize = size * 1024 * 1024;
  22.  
  23.     unsigned char * mp = new unsigned char[bsize];
  24.     if ( mp == 0 )
  25.     {
  26.         fprintf( stderr, "Error: cannot allocate %d bytes.\n", bsize );
  27.         return 2;
  28.     }
  29.  
  30.     for ( int i = 0; i < bsize; ++i )
  31.         mp[i] = 0x55;
  32.    
  33.     long start_time = time(0);
  34.     long error_count = 0;
  35.     while ( 1 )
  36.     {
  37.         long current_time = time(0);
  38.         for ( int i = 0; i < bsize; ++i )
  39.             if ( mp[i] != 0x55 )
  40.             {
  41.                 printf( "%d seconds, byte %i, got 0x%x, expected 0x55\n", current_time - start_time, i, mp[i] );
  42.                 FILE * fp = fopen( "error.log", "a" );
  43.                 if ( fp )
  44.                 {
  45.                     fprintf( fp, "%d seconds, byte %i, got 0x%x, expected 0x55\n", current_time - start_time, i, mp[i] );
  46.                     fclose( fp );
  47.                 }
  48.                 ++error_count;
  49.                 mp[i] = 0x55;
  50.             }
  51.         sleep(60);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement