home *** CD-ROM | disk | FTP | other *** search
/ PC to Maximum / PC-na-maximum.bin / DriveSpeed / SRC / DRSP / DIAGS.CPP next >
Encoding:
C/C++ Source or Header  |  2000-06-04  |  9.8 KB  |  466 lines

  1. /*
  2.  *  DRSP - DriveSpeed, version 3.10 (GPL FREEWARE)
  3.  *  Copyleft (l) Stanislav Sokolov, May 1998 and onwards.
  4.  *
  5.  *  This program is subject to GNU General Public License ver. 2 of June 1991
  6.  *  and any later version.
  7.  *
  8.  *  You may use this source with your programs, provided
  9.  *  due credits are given.
  10.  *
  11.  *  Contact the author by e-mail: stanislavs@hotmail.com
  12.  *
  13.  *  Internet:  http://members.tripod.com/~stanislavs/prog/prog.htm
  14.  */
  15.  
  16. #include "D:\TC\MY\DRSP\DRSP.H"
  17.  
  18.  
  19. //DoTest for a RW process
  20. void DoTest(TestData TD, float *ReadSpd, float *WriteSpd){
  21.     int Handle = 0, ax_, i, Length;
  22.     unsigned long j;
  23.     register int k;
  24.     struct time WOn, WOff, ROn, ROff;
  25.     FindLong f;
  26.     char *buffer;
  27.     char FName[] = FILE_NAME;
  28.  
  29.     if((buffer = (char *)malloc(10000)) == NULL)
  30.         Abort(0, NULL, "Out of memory in DoTest().", EX_NO_MEM);
  31.  
  32.     strcpy(buffer, "DRSP (version 3.10) - DriveSpeed test file\x1A\r");
  33.  
  34.     FName[0] = TD.Drive;
  35.  
  36.     f.Whole = (long)buffer;
  37.  
  38.     //Set blinking ". . ."
  39.     printf("\n\n");
  40.     gotoxy(9, wherey());
  41.     textcolor(128 + 7);
  42.     cprintf(". . .");
  43.     textcolor(7);
  44.     gotoxy(1, wherey());
  45.     _setcursortype(_NOCURSOR);
  46.  
  47.     //Main loop
  48.     for(i = 1; i <= TD.Turns; i++){
  49.         printf("Writing");
  50.  
  51.         //Generate random test string
  52.         srand((unsigned) time(NULL));
  53.         for(k = 45; k <= 9999; k++) buffer[k] = char(random(254) + 1);
  54.  
  55.         //Open
  56.         unlink(FName);
  57.  
  58.         if((Handle = open(FName, O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE)) == -1)
  59.             Abort(0, NULL, "Error opening test-file.", EX_OPEN_ERR);
  60.  
  61.         Length = 10000;
  62.         j = 0;
  63.  
  64.         ClearCache();
  65.  
  66.         //Test writing speed
  67.         gettime(&WOn);
  68.         do{
  69.             //Adjust write length
  70.             //(last write operation will generally be shorter than 10000)
  71.             j += 10000;
  72.             if(j > TD.Size) Length = int(TD.Size - (j - 10000));
  73.                         //Perform write operation
  74.             asm{
  75.                 mov AH, 0x40
  76.                 mov BX, Handle
  77.                 push DS
  78.                 mov DS, word ptr [f.Part.High]
  79.                 mov DX, word ptr [f.Part.Low]
  80.                 mov CX, Length
  81.                 int 0x21
  82.                 mov ax_, AX
  83.                 pop DS
  84.             }
  85.  
  86.             //Check for errors
  87.             if(ax_ != Length) Abort(Handle, FName, "Error writing to file.", EX_WRITE_ERR);
  88.  
  89.         }while(j < TD.Size);
  90.  
  91.         //Commit cached data to file (only available from DOS 3.3)
  92.         asm{
  93.             mov AH, 0x68
  94.             mov BX, Handle
  95.             int 0x21
  96.         }
  97.         gettime(&WOff);
  98.  
  99.         *WriteSpd += finddiff(WOn, WOff);
  100.  
  101.         if(kbhit() && getch() == 27)
  102.             Abort(Handle, FName, "\nAborted by user.", EX_ABORT);
  103.  
  104.         lseek(Handle, 0, SEEK_SET);
  105.  
  106.         Length = 10000;
  107.         j = 0;
  108.  
  109.         ClearCache();
  110.  
  111.         //Test reading speed
  112.         gotoxy(1, wherey());
  113.         printf("Reading\n\n");
  114.  
  115.         gettime(&ROn);
  116.         do{
  117.             //Adjust read length
  118.             //(last read operation will generally be shorter than 10000)
  119.             j += 10000;
  120.             if(j > TD.Size) Length = int(TD.Size - (j - 10000));
  121.  
  122.             //Perform read operation
  123.             asm{
  124.                 mov AH, 0x3F
  125.                 mov BX, Handle
  126.                 push DS
  127.                 mov DS, word ptr [f.Part.High]
  128.                 mov DX, word ptr [f.Part.Low]
  129.                 mov CX, Length
  130.                 int 0x21
  131.                 mov ax_, AX
  132.                 pop DS
  133.             }
  134.  
  135.             //Check for errors (this is a do-nothing condition, preserved
  136.             //only to give comparable results with write operation)
  137.             if(ax_ != Length) ax_ = 0;
  138.  
  139.         }while(j < TD.Size);
  140.         gettime(&ROff);
  141.  
  142.         *ReadSpd += finddiff(ROn, ROff);
  143.  
  144.         if(kbhit() && getch() == 27)
  145.             Abort(Handle, FName, "\n\nAborted by user.", EX_ABORT);
  146.  
  147.         close(Handle);
  148.  
  149.         printf("Turn %i out of %i complete.", i, TD.Turns);
  150.         gotoxy(1, wherey() - 2);
  151.  
  152.     }
  153.  
  154.     cprintf("Done.        \n\n\n\n");
  155.     _setcursortype(_NORMALCURSOR);
  156.     unlink(FName);
  157.  
  158.     nfree(buffer);
  159.  
  160.     //Return values
  161.     *WriteSpd /= TD.Turns;
  162.     *ReadSpd /= TD.Turns;
  163. }
  164.  
  165.  
  166.  
  167. //DoTest for a RO multi-pass process
  168. float DoTest(char *RetPath, TestData TD){
  169.     int Handle = 0, ax_, i, Length;
  170.     unsigned long j;
  171.     float ReadSpd = 0.0;
  172.     struct time ROn, ROff;
  173.     FindLong f;
  174.     char *FName = RetPath, *buffer;
  175.  
  176.     if((buffer = (char *)malloc(10000)) == NULL)
  177.         Abort(0, NULL, "Out of memory in DoTest().", EX_NO_MEM);
  178.  
  179.     f.Whole = (long)buffer;
  180.  
  181.     //Set blinking ". . ."
  182.     printf("\n\n");
  183.     gotoxy(9, wherey());
  184.     textcolor(128 + 7);
  185.     cprintf(". . .");
  186.     textcolor(7);
  187.     gotoxy(1, wherey());
  188.     _setcursortype(_NOCURSOR);
  189.  
  190.     //Main loop
  191.     for(i = 1; i <= TD.Turns; i++){
  192.  
  193.         //Open
  194.         if((Handle = open(FName, O_BINARY, S_IREAD)) == -1)
  195.             Abort(0, NULL, "Error opening test-file.", EX_OPEN_ERR);
  196.  
  197.         Length = 10000;
  198.         j = 0;
  199.  
  200.         if(kbhit() && getch() == 27)
  201.             Abort(Handle, NULL, "\nAborted by user.", EX_ABORT);
  202.  
  203.         lseek(Handle, 0, SEEK_SET);
  204.  
  205.         Length = 10000;
  206.         j = 0;
  207.  
  208.         //Test reading speed
  209.         gotoxy(1, wherey());
  210.         printf("Reading\n\n");
  211.  
  212.         ClearCache();
  213.  
  214.         gettime(&ROn);
  215.         do{
  216.             //Adjust read length
  217.             //(last read operation will generally be shorter than 10000)
  218.             j += 10000;
  219.             if(j > TD.Size) Length = int(TD.Size - (j - 10000));
  220.  
  221.             //Perform read operation
  222.             asm{
  223.                 mov AH, 0x3F
  224.                 mov BX, Handle
  225.                 push DS
  226.                 mov DS, word ptr [f.Part.High]
  227.                 mov DX, word ptr [f.Part.Low]
  228.                 mov CX, Length
  229.                 int 0x21
  230.                 mov ax_, AX
  231.                 pop DS
  232.             }
  233.  
  234.             //Check for errors (this is a do-nothing condition, preserved
  235.             //only to give comparable results with write operation)
  236.             if(ax_ != Length) ax_ = 0;
  237.  
  238.         }while(j < TD.Size);
  239.         gettime(&ROff);
  240.  
  241.         ReadSpd += finddiff(ROn, ROff);
  242.  
  243.         if(kbhit() && getch() == 27)
  244.             Abort(Handle, NULL, "\n\nAborted by user.", EX_ABORT);
  245.  
  246.         close(Handle);
  247.  
  248.         printf("Turn %i out of %i complete.", i, TD.Turns);
  249.         gotoxy(1, wherey() - 2);
  250.  
  251.     }
  252.  
  253.     cprintf("Done.        \n\n\n\n");
  254.     _setcursortype(_NORMALCURSOR);
  255.  
  256.     nfree(buffer);
  257.  
  258.     //Return value
  259.     return ReadSpd /= TD.Turns;
  260. }
  261.  
  262.  
  263. //DoTest for a RO single-pass process
  264. float DoTest(TestFile TF[], unsigned long Size){
  265.     int Handle = 0, ax_, i, Length;
  266.     unsigned long j;
  267.     float ReadSpd = 0.0;
  268.     struct time ROn, ROff;
  269.     FindLong f;
  270.     char *FName, *buffer;
  271.  
  272.     if((buffer = (char *)malloc(10000)) == NULL)
  273.         Abort(0, NULL, "Out of memory in DoTest().", EX_NO_MEM);
  274.  
  275.     f.Whole = (long)buffer;
  276.  
  277.     //Set blinking ". . ."
  278.     printf("\n\n");
  279.     gotoxy(9, wherey());
  280.     textcolor(128 + 7);
  281.     cprintf(". . .");
  282.     textcolor(7);
  283.     gotoxy(1, wherey());
  284.     _setcursortype(_NOCURSOR);
  285.  
  286.     printf("Reading\n\n");
  287.  
  288.     //Main loop
  289.     for(i = 0; i < MAX_FBUF; i++){
  290.         if(TF[i].Size == 0) break;
  291.  
  292.         //Open
  293.         FName = TF[i].Path;
  294.         printf("Testing file #%d.\n%s", i + 1, FName);
  295.         for(int k = 1; k < MAX_PATH - strlen(TF[i].Path); k++) printf(" ");
  296.  
  297.         if((Handle = open(FName, O_BINARY, S_IREAD)) == -1)
  298.             Abort(0, NULL, "Error opening test-file.", EX_OPEN_ERR);
  299.  
  300.         if(kbhit() && getch() == 27)
  301.             Abort(Handle, NULL, "\nAborted by user.", EX_ABORT);
  302.  
  303.         lseek(Handle, 0, SEEK_SET);
  304.  
  305.         Length = 10000;
  306.         j = 0;
  307.  
  308.         //Test reading speed
  309.         gettime(&ROn);
  310.         do{
  311.             //Adjust read length
  312.             //(last read operation will generally be shorter than 10000)
  313.             j += 10000;
  314.             if(j > Size) Length = int(Size - (j - 10000));
  315.  
  316.             //Perform read operation
  317.             asm{
  318.                 mov AH, 0x3F
  319.                 mov BX, Handle
  320.                 push DS
  321.                 mov DS, word ptr [f.Part.High]
  322.                 mov DX, word ptr [f.Part.Low]
  323.                 mov CX, Length
  324.                 int 0x21
  325.                 mov ax_, AX
  326.                 pop DS
  327.             }
  328.  
  329.             //Check for errors (this is a do-nothing condition, preserved
  330.             //only to give comparable results with write operation)
  331.             if(ax_ != Length) ax_ = 0;
  332.  
  333.         }while(j < Size);
  334.         gettime(&ROff);
  335.  
  336.         ReadSpd += finddiff(ROn, ROff);
  337.  
  338.         if(kbhit() && getch() == 27)
  339.             Abort(Handle, NULL, "\n\nAborted by user.", EX_ABORT);
  340.  
  341.         close(Handle);
  342.  
  343.         gotoxy(1, wherey() - 2);
  344.  
  345.     }
  346.  
  347.     gotoxy(1, wherey() - 2);
  348.     cprintf("Done.        \n\n\n\n");
  349.     _setcursortype(_NORMALCURSOR);
  350.  
  351.     nfree(buffer);
  352.  
  353.     return ReadSpd;
  354.  
  355. }
  356.  
  357.  
  358.  
  359. float TestFAS(char Drive){
  360.     char *FName, CF;
  361.     FName = FILE_NAME;
  362.     FName[0] = Drive;
  363.  
  364.     unsigned long RetVal = 0;
  365.     int Handle, flags_;
  366.     time_t TestOff;
  367.     FindLong f;
  368.  
  369.     f.Whole = (long)FName;
  370.  
  371.     //Set blinking ". . ."
  372.     gotoxy(56, wherey());
  373.     textcolor(128 + 7);
  374.     cprintf(". . .");
  375.     textcolor(7);
  376.     gotoxy(1, wherey());
  377.     _setcursortype(_NOCURSOR);
  378.  
  379.     cprintf("Performing File Access Speed (FAS) test - takes 15 sec");
  380.  
  381.     TestOff = time(NULL) + 15;
  382.     do{
  383.         //Create and open a file (Fn 6cH is only available from DOS 4.0)
  384.         asm{
  385.             mov AX, 0x6C00
  386.             mov BX, 0x40C2
  387.             mov CX, 0x20
  388.             mov DX, 0x12
  389.             push DS
  390.             push SI
  391.             mov DS, word ptr [f.Part.High]
  392.             mov SI, word ptr [f.Part.Low]
  393.             int 0x21
  394.             pop SI
  395.             pop DS
  396.             mov Handle, AX
  397.             pushf           //push Flags on stack
  398.             pop flags_      //read Flags
  399.         }
  400.         CF = flags_ & 0x01;
  401.  
  402.         if(CF)
  403.             Abort((CF ? 0 : Handle), FName, "\nCritical error while creating/opening a file.", EX_OPEN_ERR);
  404.  
  405.         //Commit cached data to file (only available from DOS 3.3)
  406.         asm{
  407.             mov AH, 0x68
  408.             mov BX, Handle
  409.             int 0x21
  410.         }
  411.  
  412.         //Close the file
  413.         asm{
  414.             mov AH, 0x3E
  415.             mov BX, Handle
  416.             int 0x21
  417.             pushf           //push Flags on stack
  418.             pop flags_      //read Flags
  419.         }
  420.         CF = flags_ & 0x01;
  421.  
  422.         if(CF)
  423.             Abort(Handle, FName, "\nCritical error while closing a file.", EX_CLOSE_ERR);
  424.  
  425.         //Delete the file
  426.         asm{
  427.             mov AH, 0x41
  428.             push DS
  429.             mov DS, word ptr [f.Part.High]
  430.             mov DX, word ptr [f.Part.Low]
  431.             int 0x21
  432.             pop DS
  433.             pushf           //push Flags on stack
  434.             pop flags_      //read Flags
  435.         }
  436.         CF = flags_ & 0x01;
  437.  
  438.         if(CF)
  439.             Abort(0, FName, "\nCritical error while deleting a file.", EX_DEL_ERR);
  440.  
  441.         RetVal++;
  442.     }while(TestOff >= time(NULL));
  443.  
  444.     unlink(FName);
  445.  
  446.     cprintf(" . . . done.\n\n");
  447.     _setcursortype(_NORMALCURSOR);
  448.  
  449.     //Compensate for the 4 operations that are performed
  450.     return (RetVal * 4.0) / 15.0;
  451. }
  452.  
  453.  
  454. float finddiff(struct time on, struct time off){
  455.     unsigned long start = (long)on.ti_hund +
  456.                           (long)on.ti_sec * 100 +
  457.                           (long)on.ti_min * 6000 +
  458.                           (long)on.ti_hour * 360000;
  459.     unsigned long stop =  (long)off.ti_hund +
  460.                           (long)off.ti_sec * 100 +
  461.                           (long)off.ti_min * 6000 +
  462.                           (long)off.ti_hour * 360000;
  463.  
  464.     return (stop - start) / 100.0;
  465.  
  466. }