Here is a sample user program. You should make up your own test programs and include them in your submission. Your user programs should demonstrate that your system call implementation works. We will run these programs to test your code.
// printa.c -- a program to test I/O // Reads and writes to stdin and stdout. // Opens a file and writes stuff to it. #include "syscall.h" #define numloop 500 int main() { int i; char *ch = "A"; OpenFileId fd; char buffer[24]; i = Read(buffer,2,0); // Read from console Write(buffer,2,1); // Write the same thing to console fd = Open("pa.c.bak"); // Open a file i = Read(buffer,7,fd); // Read from it Write(buffer,i,1); // Write the chars just read from file Close(fd); // to the screen // Write a bunch of A's on the screen for (i=0;i<numloop;i++) Write(ch,1,1); Exit(0); }
Here is a sample script (test.script) to automatically run the above user program, called printa.c. Since the nachos executable is present in the userprog directory, execute the script in the userprog directory.
echo "Compiling test directory.." cd ../test make all echo "Testing system calls in Nachos" echo "Getting printa from the test directory echo "pa prints A cp printa ../userprog cd ../userprog echo "Running the program printa" nachos -time 30 -x printa
In order to run the script, you will have to make it executable. Type chmod 754 test.script at the prompt. This command makes test.script executable for you and the group. To run the script, you can simply type test.script at the prompt.
Finally, here are the changes to the Makefile in the test directory you need to compile the user program printa.c:
all: halt shell matmult sort printa printa.o: printa.c $(CC) $(CFLAGS) -c printa.c pa: printa.o start.o $(LD) $(LDFLAGS) start.o printa.o -o printa.coff ../bin/coff2noff printa.coff printa
In order to compile your user programs, make appropriate changes to the Makefile in the test directory and type make all at the prompt while in the test directory. Of course, if you set up scripts like the above, you can place them in your userprog directory and simply run the script.