Main Page   Compound List   File List   Compound Members   File Members  

fstest.cc File Reference

#include "copyright.h"
#include "utility.h"
#include "filesys.h"
#include "system.h"
#include "thread.h"
#include "disk.h"
#include "stats.h"

Go to the source code of this file.

Defines

#define TransferSize   10
#define FileName   "TestFile"
#define Contents   "1234567890"
#define ContentSize   strlen(Contents)
#define FileSize   ((int)(ContentSize * 5000))

Functions

void Copy (char *from, char *to)
void Print (char *name)
void FileWrite ()
void FileRead ()
void PerformanceTest ()


Define Documentation

#define Contents   "1234567890"
 

Definition at line 112 of file fstest.cc.

Referenced by FileRead, and FileWrite.

#define ContentSize   strlen(Contents)
 

Definition at line 113 of file fstest.cc.

Referenced by FileRead, and FileWrite.

#define FileName   "TestFile"
 

Definition at line 111 of file fstest.cc.

Referenced by FileRead, FileWrite, and PerformanceTest.

#define FileSize   ((int)(ContentSize * 5000))
 

Definition at line 114 of file fstest.cc.

Referenced by FileRead, and FileWrite.

#define TransferSize   10
 

Definition at line 24 of file fstest.cc.

Referenced by Copy, and Print.


Function Documentation

void Copy char *    from,
char *    to
 

Definition at line 32 of file fstest.cc.

References ASSERT, DEBUG, NULL, TransferSize, and OpenFile::Write.

00033 {
00034     FILE *fp;
00035     OpenFile* openFile;
00036     int amountRead, fileLength;
00037     char *buffer;
00038 
00039 // Open UNIX file
00040     if ((fp = fopen(from, "r")) == NULL) {       
00041         printf("Copy: couldn't open input file %s\n", from);
00042         return;
00043     }
00044 
00045 // Figure out length of UNIX file
00046     fseek(fp, 0, 2);            
00047     fileLength = ftell(fp);
00048     fseek(fp, 0, 0);
00049 
00050 // Create a Nachos file of the same length
00051     DEBUG('f', "Copying file %s, size %d, to file %s\n", from, fileLength, to);
00052     if (!fileSystem->Create(to, fileLength)) {   // Create Nachos file
00053         printf("Copy: couldn't create output file %s\n", to);
00054         fclose(fp);
00055         return;
00056     }
00057     
00058     openFile = fileSystem->Open(to);
00059     ASSERT(openFile != NULL);
00060     
00061 // Copy the data in TransferSize chunks
00062     buffer = new char[TransferSize];
00063     while ((amountRead = fread(buffer, sizeof(char), TransferSize, fp)) > 0)
00064         openFile->Write(buffer, amountRead);    
00065     delete [] buffer;
00066 
00067 // Close the UNIX and the Nachos files
00068     delete openFile;
00069     fclose(fp);
00070 }

void FileRead   [static]
 

Definition at line 145 of file fstest.cc.

References Contents, ContentSize, FileName, FileSize, NULL, and OpenFile::Read.

Referenced by PerformanceTest.

00146 {
00147     OpenFile *openFile;    
00148     char *buffer = new char[ContentSize];
00149     int i, numBytes;
00150 
00151     printf("Sequential read of %d byte file, in %d byte chunks\n", 
00152         FileSize, (int) ContentSize);
00153 
00154     if ((openFile = fileSystem->Open(FileName)) == NULL) {
00155         printf("Perf test: unable to open file %s\n", FileName);
00156         delete [] buffer;
00157         return;
00158     }
00159     for (i = 0; i < FileSize; i += ContentSize) {
00160         numBytes = openFile->Read(buffer, ContentSize);
00161         if ((numBytes < 10) || strncmp(buffer, Contents, ContentSize)) {
00162             printf("Perf test: unable to read %s\n", FileName);
00163             delete openFile;
00164             delete [] buffer;
00165             return;
00166         }
00167     }
00168     delete [] buffer;
00169     delete openFile;    // close file
00170 }

void FileWrite   [static]
 

Definition at line 117 of file fstest.cc.

References Contents, ContentSize, FileName, FileSize, NULL, and OpenFile::Write.

Referenced by PerformanceTest.

00118 {
00119     OpenFile *openFile;    
00120     int i, numBytes;
00121 
00122     printf("Sequential write of %d byte file, in %d byte chunks\n", 
00123         FileSize, (int) ContentSize);
00124     if (!fileSystem->Create(FileName, 0)) {
00125       printf("Perf test: can't create %s\n", FileName);
00126       return;
00127     }
00128     openFile = fileSystem->Open(FileName);
00129     if (openFile == NULL) {
00130         printf("Perf test: unable to open %s\n", FileName);
00131         return;
00132     }
00133     for (i = 0; i < FileSize; i += ContentSize) {
00134         numBytes = openFile->Write(Contents, ContentSize);
00135         if (numBytes < 10) {
00136             printf("Perf test: unable to write %s\n", FileName);
00137             delete openFile;
00138             return;
00139         }
00140     }
00141     delete openFile;    // close file
00142 }

void PerformanceTest void   
 

Definition at line 173 of file fstest.cc.

References FileName, FileRead, and FileWrite.

Referenced by main.

00174 {
00175     printf("Starting file system performance test:\n");
00176     stats->Print();
00177     FileWrite();
00178     FileRead();
00179     if (!fileSystem->Remove(FileName)) {
00180       printf("Perf test: unable to remove %s\n", FileName);
00181       return;
00182     }
00183     stats->Print();
00184 }

void Print char *    name
 

Definition at line 78 of file fstest.cc.

References NULL, OpenFile::Read, and TransferSize.

00079 {
00080     OpenFile *openFile;    
00081     int i, amountRead;
00082     char *buffer;
00083 
00084     if ((openFile = fileSystem->Open(name)) == NULL) {
00085         printf("Print: unable to open file %s\n", name);
00086         return;
00087     }
00088     
00089     buffer = new char[TransferSize];
00090     while ((amountRead = openFile->Read(buffer, TransferSize)) > 0)
00091         for (i = 0; i < amountRead; i++)
00092             printf("%c", buffer[i]);
00093     delete [] buffer;
00094 
00095     delete openFile;            // close the Nachos file
00096     return;
00097 }


Generated on Mon Feb 10 09:54:49 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees