hw4 test
This commit is contained in:
@@ -47,8 +47,8 @@
|
||||
#include "sysdep.h"
|
||||
|
||||
// global variables
|
||||
Kernel *kernel;
|
||||
Debug *debug;
|
||||
Kernel* kernel;
|
||||
Debug* debug;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@@ -56,11 +56,11 @@ Debug *debug;
|
||||
// Delete kernel data structures; called when user hits "ctl-C".
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
Cleanup(int x)
|
||||
{
|
||||
static void
|
||||
Cleanup(int x)
|
||||
{
|
||||
cerr << "\nCleaning up after signal " << x << "\n";
|
||||
delete kernel;
|
||||
delete kernel;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -78,42 +78,42 @@ static const int TransferSize = 128;
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
Copy(char *from, char *to)
|
||||
Copy(char* from, char* to)
|
||||
{
|
||||
int fd;
|
||||
OpenFile* openFile;
|
||||
int amountRead, fileLength;
|
||||
char *buffer;
|
||||
char* buffer;
|
||||
|
||||
// Open UNIX file
|
||||
if ((fd = OpenForReadWrite(from,FALSE)) < 0) {
|
||||
// Open UNIX file
|
||||
if ((fd = OpenForReadWrite(from, FALSE)) < 0) {
|
||||
printf("Copy: couldn't open input file %s\n", from);
|
||||
return;
|
||||
}
|
||||
|
||||
// Figure out length of UNIX file
|
||||
Lseek(fd, 0, 2);
|
||||
// Figure out length of UNIX file
|
||||
Lseek(fd, 0, 2);
|
||||
fileLength = Tell(fd);
|
||||
Lseek(fd, 0, 0);
|
||||
|
||||
// Create a Nachos file of the same length
|
||||
DEBUG('f', "Copying file " << from << " of size " << fileLength << " to file " << to);
|
||||
// Create a Nachos file of the same length
|
||||
DEBUG('f', "Copying file " << from << " of size " << fileLength << " to file " << to);
|
||||
if (!kernel->fileSystem->Create(to, fileLength)) { // Create Nachos file
|
||||
printf("Copy: couldn't create output file %s\n", to);
|
||||
Close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
openFile = kernel->fileSystem->Open(to);
|
||||
ASSERT(openFile != NULL);
|
||||
|
||||
// Copy the data in TransferSize chunks
|
||||
buffer = new char[TransferSize];
|
||||
while ((amountRead=ReadPartial(fd, buffer, sizeof(char)*TransferSize)) > 0)
|
||||
openFile->Write(buffer, amountRead);
|
||||
delete [] buffer;
|
||||
|
||||
// Close the UNIX and the Nachos files
|
||||
// Copy the data in TransferSize chunks
|
||||
buffer = new char[TransferSize];
|
||||
while ((amountRead = ReadPartial(fd, buffer, sizeof(char) * TransferSize)) > 0)
|
||||
openFile->Write(buffer, amountRead);
|
||||
delete[] buffer;
|
||||
|
||||
// Close the UNIX and the Nachos files
|
||||
delete openFile;
|
||||
Close(fd);
|
||||
}
|
||||
@@ -126,22 +126,22 @@ Copy(char *from, char *to)
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void
|
||||
Print(char *name)
|
||||
Print(char* name)
|
||||
{
|
||||
OpenFile *openFile;
|
||||
OpenFile* openFile;
|
||||
int i, amountRead;
|
||||
char *buffer;
|
||||
char* buffer;
|
||||
|
||||
if ((openFile = kernel->fileSystem->Open(name)) == NULL) {
|
||||
printf("Print: unable to open file %s\n", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
buffer = new char[TransferSize];
|
||||
while ((amountRead = openFile->Read(buffer, TransferSize)) > 0)
|
||||
for (i = 0; i < amountRead; i++)
|
||||
printf("%c", buffer[i]);
|
||||
delete [] buffer;
|
||||
delete[] buffer;
|
||||
|
||||
delete openFile; // close the Nachos file
|
||||
return;
|
||||
@@ -164,19 +164,19 @@ Print(char *name)
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
int i;
|
||||
char *debugArg = "";
|
||||
char *userProgName = NULL; // default is not to execute a user prog
|
||||
char* debugArg = "";
|
||||
char* userProgName = NULL; // default is not to execute a user prog
|
||||
bool threadTestFlag = false;
|
||||
bool consoleTestFlag = false;
|
||||
bool networkTestFlag = false;
|
||||
#ifndef FILESYS_STUB
|
||||
char *copyUnixFileName = NULL; // UNIX file to be copied into Nachos
|
||||
char *copyNachosFileName = NULL; // name of copied file in Nachos
|
||||
char *printFileName = NULL;
|
||||
char *removeFileName = NULL;
|
||||
char* copyUnixFileName = NULL; // UNIX file to be copied into Nachos
|
||||
char* copyNachosFileName = NULL; // name of copied file in Nachos
|
||||
char* printFileName = NULL;
|
||||
char* removeFileName = NULL;
|
||||
bool dirListFlag = false;
|
||||
bool dumpFlag = false;
|
||||
#endif //FILESYS_STUB
|
||||
@@ -186,65 +186,65 @@ main(int argc, char **argv)
|
||||
// the Kernel constructor
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-d") == 0) {
|
||||
ASSERT(i + 1 < argc); // next argument is debug string
|
||||
ASSERT(i + 1 < argc); // next argument is debug string
|
||||
debugArg = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-z") == 0) {
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-z") == 0) {
|
||||
cout << copyright << "\n";
|
||||
}
|
||||
else if (strcmp(argv[i], "-x") == 0) {
|
||||
ASSERT(i + 1 < argc);
|
||||
userProgName = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-K") == 0) {
|
||||
threadTestFlag = TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-C") == 0) {
|
||||
consoleTestFlag = TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-N") == 0) {
|
||||
networkTestFlag = TRUE;
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], "-x") == 0) {
|
||||
ASSERT(i + 1 < argc);
|
||||
userProgName = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-K") == 0) {
|
||||
threadTestFlag = TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-C") == 0) {
|
||||
consoleTestFlag = TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-N") == 0) {
|
||||
networkTestFlag = TRUE;
|
||||
}
|
||||
#ifndef FILESYS_STUB
|
||||
else if (strcmp(argv[i], "-cp") == 0) {
|
||||
ASSERT(i + 2 < argc);
|
||||
copyUnixFileName = argv[i + 1];
|
||||
copyNachosFileName = argv[i + 2];
|
||||
i += 2;
|
||||
}
|
||||
else if (strcmp(argv[i], "-p") == 0) {
|
||||
ASSERT(i + 1 < argc);
|
||||
printFileName = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-r") == 0) {
|
||||
ASSERT(i + 1 < argc);
|
||||
removeFileName = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-l") == 0) {
|
||||
dirListFlag = true;
|
||||
}
|
||||
else if (strcmp(argv[i], "-D") == 0) {
|
||||
dumpFlag = true;
|
||||
}
|
||||
else if (strcmp(argv[i], "-cp") == 0) {
|
||||
ASSERT(i + 2 < argc);
|
||||
copyUnixFileName = argv[i + 1];
|
||||
copyNachosFileName = argv[i + 2];
|
||||
i += 2;
|
||||
}
|
||||
else if (strcmp(argv[i], "-p") == 0) {
|
||||
ASSERT(i + 1 < argc);
|
||||
printFileName = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-r") == 0) {
|
||||
ASSERT(i + 1 < argc);
|
||||
removeFileName = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else if (strcmp(argv[i], "-l") == 0) {
|
||||
dirListFlag = true;
|
||||
}
|
||||
else if (strcmp(argv[i], "-D") == 0) {
|
||||
dumpFlag = true;
|
||||
}
|
||||
#endif //FILESYS_STUB
|
||||
else if (strcmp(argv[i], "-u") == 0) {
|
||||
else if (strcmp(argv[i], "-u") == 0) {
|
||||
cout << "Partial usage: nachos [-z -d debugFlags]\n";
|
||||
cout << "Partial usage: nachos [-x programName]\n";
|
||||
cout << "Partial usage: nachos [-K] [-C] [-N]\n";
|
||||
cout << "Partial usage: nachos [-K] [-C] [-N]\n";
|
||||
#ifndef FILESYS_STUB
|
||||
cout << "Partial usage: nachos [-cp UnixFile NachosFile]\n";
|
||||
cout << "Partial usage: nachos [-p fileName] [-r fileName]\n";
|
||||
cout << "Partial usage: nachos [-l] [-D]\n";
|
||||
#endif //FILESYS_STUB
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
debug = new Debug(debugArg);
|
||||
|
||||
|
||||
DEBUG(dbgThread, "Entering main");
|
||||
|
||||
kernel = new Kernel(argc, argv);
|
||||
@@ -256,42 +256,42 @@ main(int argc, char **argv)
|
||||
// at this point, the kernel is ready to do something
|
||||
// run some tests, if requested
|
||||
if (threadTestFlag) {
|
||||
kernel->ThreadSelfTest(); // test threads and synchronization
|
||||
kernel->ThreadSelfTest(); // test threads and synchronization
|
||||
}
|
||||
if (consoleTestFlag) {
|
||||
kernel->ConsoleTest(); // interactive test of the synchronized console
|
||||
kernel->ConsoleTest(); // interactive test of the synchronized console
|
||||
}
|
||||
if (networkTestFlag) {
|
||||
kernel->NetworkTest(); // two-machine test of the network
|
||||
kernel->NetworkTest(); // two-machine test of the network
|
||||
}
|
||||
|
||||
#ifndef FILESYS_STUB
|
||||
if (removeFileName != NULL) {
|
||||
kernel->fileSystem->Remove(removeFileName);
|
||||
kernel->fileSystem->Remove(removeFileName);
|
||||
}
|
||||
if (copyUnixFileName != NULL && copyNachosFileName != NULL) {
|
||||
Copy(copyUnixFileName,copyNachosFileName);
|
||||
Copy(copyUnixFileName, copyNachosFileName);
|
||||
}
|
||||
if (dumpFlag) {
|
||||
kernel->fileSystem->Print();
|
||||
kernel->fileSystem->Print();
|
||||
}
|
||||
if (dirListFlag) {
|
||||
kernel->fileSystem->List();
|
||||
kernel->fileSystem->List();
|
||||
}
|
||||
if (printFileName != NULL) {
|
||||
Print(printFileName);
|
||||
Print(printFileName);
|
||||
}
|
||||
#endif // FILESYS_STUB
|
||||
|
||||
// finally, run an initial user program if requested to do so
|
||||
|
||||
kernel->ExecAll();
|
||||
kernel->ExecAll();
|
||||
// If we don't run a user program, we may get here.
|
||||
// Calling "return" would terminate the program.
|
||||
// Instead, call Halt, which will first clean up, then
|
||||
// terminate.
|
||||
// kernel->interrupt->Halt();
|
||||
|
||||
|
||||
ASSERTNOTREACHED();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user