#include #include #include /* SpeedTestr A very simple ANSI C app to run a device through it's paces and ensure data integrety, then shutdown the machine if it passes. Originally idea came from Tom to help test his BlueSCSI's because he couldnt reach the keyboard to doubleclick on SCSI Director... This should not be used (in it's current form) as a speed testing tool. It provides a rough idea but the calls could be optomized more. This also does not test through direct SCSI calls, just via stdlib file API. Copyright Eric Helgeson 1.0 - It works! Basics done. */ #define SIZE 1024 // Prototypes unsigned int IntPow(unsigned int x, unsigned int times); short writeFile(unsigned int times); short readFile(unsigned int times); short verifyFile(void); // Buffer and pattern. char const gPattern = 85; //1010101 char gBuff[SIZE]; void main() { unsigned int i = 1; unsigned int p = 0; short err = 0; // Fill buffer with pattern for(i = 0; i < SIZE ; i++) { gBuff[i] = gPattern; } for(i = 1; i < 15; i++) { p = IntPow(2, i); printf("Writing: %d kb ", p); err = writeFile(p); if(err) { printf("Error writing file: %d", err); return; } printf(" - Verifiying: %d kb ", p); err = verifyFile(); if(err) { printf("Error verifying file: %d", err); return; } printf(" - Reading: %d kb ", p); err = readFile(p); if(err) { printf("Error reading file: %d", err); return; } remove("testfile.bin"); } printf("\nSuccess, Shutting down..."); // Uncomment if you want the machine to shutdown right after test. //ShutDwnPower(); } /* Blindly read the contents of the file n * SIZE */ short readFile(unsigned int times) { FILE * fp; unsigned int i; long beginTick = 0; long endTick = 0; int result; fp = fopen("testfile.bin", "r"); if(fp == NULL) return -2; rewind(fp); beginTick = TickCount(); for(i = 0; i != times; i++) { result = fread(gBuff, SIZE, 1, fp); if(result != 1) { fclose(fp); return -1; } } endTick = TickCount(); fclose(fp); printf(" took - %lu.%lus\n", (endTick - beginTick) / 60, (endTick - beginTick) % 60); return 0; } /* Verify the contents of the file match the pattern */ short verifyFile() { FILE * fp; char c; fp = fopen("testfile.bin", "r"); if(fp == NULL) return -2; rewind(fp); while(true) { c = fgetc(fp); if(c == EOF) break; if(c != gPattern) { printf("VERIFY PATTERN ERR - expected %c, got %c", gPattern, c); fclose(fp); return -1; } } printf("Verified OK\n"); fclose(fp); return 0; } /* Write a file with buffer n times */ short writeFile(unsigned int times) { FILE * fp; unsigned int i; int result; long beginTick = 0; long endTick = 0; fp = fopen("testfile.bin", "w+"); if(fp == NULL) return -2; beginTick = TickCount(); for(i = 0; i != times; i++) { result = fwrite(gBuff, SIZE, 1, fp); if(result != 1) { fclose(fp); return -1; } } endTick = TickCount(); fclose(fp); // TickCount's are 1/60th of a second. printf(" took - %lu.%lus\n", (endTick - beginTick) / 60, (endTick - beginTick) % 60); return 0; } /* Calculate power for two ints */ unsigned int IntPow(unsigned int x, unsigned int times) { unsigned int result = 1; unsigned int l = 0; for(l = 1; l < times + 1; l++) { result = result * x; } return result; }