The Elements of Computing Systems / Nisan
& Schocken / www.idc.ac.il/tecs
Project 12: The Operating
System
Objective: Implement the Jack OS described in Chapter 12. The OS is a collection of 8 classes. Each class can be implemented and unit-tested in isolation, and in any particular order.
Resources:
The
main tool needed is Jack -- the language in which you
will develop the OS. Therefore, you will also need the supplied Jack compiler
or Jack IDE,
to compile your OS implementation as well as the supplied test programs. In
order to facilitate gradual unit-testing of the OS, you will also need the complete executable
OS, consisting of a collection of .vm
files (one for each OS class). Finally, you will need the supplied VM Emulator. This program will be used as the platform on which the actual tests
take place.
Contract:
Write a Jack OS implementation and test it using the programs and testing
scenarios described below. Each test program uses a certain subset of OS
services.
Testing Strategy
We suggest developing and unit-testing
each OS class in isolation. This can be done by compiling the OS class that you
write and then putting the resulting .vm
file in a directory that contains the supplied .vm files of the rest of the OS. In
particular, it is recommended to use the routine described below.
Start by creating a directory named projects/12 on your computer and extracting project 12.zip to it (preserving the directory structure embedded in the zip file).
To develop, compile, and test, each OS
class Xxx.jack
in isolation:
1.
Put, in the same directory, the following items: the OS class Xxx.jack
that you are developing, all the supplied executable OS .vm
files, and the relevant test program (a collection of one or more .jack
files);
2.
Compile the directory using the supplied Jack compiler or Jack IDE. This will result
in compiling your Xxx.jack
OS class as well as the class files of the test program. In the process, a new Xxx.vm
file will be created, replacing the originally supplied OS class. That�s
exactly what we want the directory to contain: the executable test program,
the complete executable OS minus the original Xxx.vm, plus your version of Xxx.vm.
3.
Load the directory�s code (OS + test program) into the VM Emulator;
4.
Execute the code and check if the OS services are working properly
according to the guidelines given below for each OS class.
OS Classes and Test Programs
There are eight OS classes: Memory, Array, Math, String, Screen, Keyboard, and Sys. For each OS class Xxx we supply a skeletal Xxx.jack class file with all the required subroutine signatures, a corresponding test class named Main.jack, and related test scripts.
OS module |
Comments |
Memory.jack (OS class) Main.jack (test class) |
To
test your implementation of this OS class, compile the directory, execute
the test script on the VM Emulator, and make sure that the comparison with
the compare file ends successfully. |
Ditto.
|
|
Ditto.
|
The test programs supplied above don�t provide a full test of the Memory.alloc
and Memory.deAlloc
functions. A complete test of these memory management functions requires
inspecting internal implementation details not visible in user-level testing.
Thus it is recommended to test these two functions using step-by-step debugging
in the VM Emulator.
The remaining test programs in this project do not include test scripts. They should be compiled and executed on the VM Emulator as follows.
OS module |
Desired Test Results (Actual Screen Shots) |
String.jack (OS class) Main.jack (test class)
Execution of the test program should yield this output: |
|
|
|
|
|
|
This OS class is tested using a test program that effects some
user-program interaction. For each function in the Keyboard class (keyPressed,
readChar,
readLine,
readInt)
the program requests the user to press some keyboard keys. If the function
is implemented correctly and the requested keys are pressed, the program
prints the text �ok�
and proceeds to test the next function. If not, the program repeats the
request for the same function. If all requests end successfully, the
program prints �Test
ended
successfully�,
at which point the screen may look as follows:
|
Only
two functions in this class can be tested: Sys.init
and Sys.wait.
The supplied test program tests the Sys.wait function by requesting
the user to press any key, waiting two seconds (using Sys.wait)
and then printing another message on the screen. The time that elapses
from the moment the key is released until the next message is printed
should be two seconds. The Sys.init
function is not tested explicitly. However, recall that it performs all
the necessary OS initializations and then calls the Main.main
function of each test program. Therefore, we can assume that nothing would
work properly unless Sys.init
is implemented correctly. A simple way to test Sys.init
in isolation is to run Pong using your Sys.vm
file. |
Complete test: After testing successfully each OS class in isolation, test your entire OS implementation using the Pong game, whose source code is available in projects/11/Pong. Put all your OS .jack files in the Pong directory, compile the directory, and execute the game in the VM Emulator. If the game works, then congratulations: you are the proud owner of an operating system written entirely by you.