From 98d69bee0d81480017224aef992902c830d4af7b Mon Sep 17 00:00:00 2001
From: "D'Abrantes, Felipe (UG - Computer Science)" <fd00246@surrey.ac.uk>
Date: Sun, 31 May 2020 17:29:25 +0100
Subject: [PATCH] Application can now be installed and ran from terminal.

Tests can now be run from application's terminal.
---
 .../{OSInput.txt.txt => PSSInput.txt}         |   0
 .../assignment/IOsystem/JavaIOSystem.java     |  43 ++-
 .../assignment/IOsystem/MemoryMappedFile.java |   6 +-
 .../com1032/assignment/IOsystem/TestIO.java   | 248 ------------------
 .../processscheduler/CPUSimulator.java        |   7 +-
 .../assignment/processscheduler/Clock.java    |  17 +-
 .../assignment/processscheduler/Hardware.java |  24 +-
 .../processscheduler/IOProcessManager.java    |  18 +-
 .../assignment/processscheduler/OS.java       |  40 ++-
 .../processscheduler/OSCommandLine.java       |  51 +++-
 .../processscheduler/ProcessCreation.java     |  40 ++-
 .../processscheduler/ProcessDispatcher.java   |   9 +-
 .../processscheduler/ProcessScheduler.java    |  24 +-
 .../com1032/assignment/tests/AllTests.java    |  26 ++
 .../assignment/tests}/IOSystemTest.java       |  65 +++--
 .../assignment/tests}/PSAlgorithmsTest.java   |  81 +++---
 .../assignment/tests}/PSBlockedTest.java      |  80 +++---
 .../src/main/java/com/com1032/pss/OSSim.java  |   5 +-
 .../pss/ProcessSchedulerSimulator.java        |   4 -
 .../java/com/com1032/assignment/AllTests.java |  11 -
 20 files changed, 380 insertions(+), 419 deletions(-)
 rename os-simulator/{OSInput.txt.txt => PSSInput.txt} (100%)
 delete mode 100644 os-simulator/src/main/java/com/com1032/assignment/IOsystem/TestIO.java
 create mode 100644 os-simulator/src/main/java/com/com1032/assignment/tests/AllTests.java
 rename os-simulator/src/{test/java/com/com1032/assignment => main/java/com/com1032/assignment/tests}/IOSystemTest.java (58%)
 rename os-simulator/src/{test/java/com/com1032/assignment => main/java/com/com1032/assignment/tests}/PSAlgorithmsTest.java (87%)
 rename os-simulator/src/{test/java/com/com1032/assignment => main/java/com/com1032/assignment/tests}/PSBlockedTest.java (86%)
 delete mode 100644 os-simulator/src/test/java/com/com1032/assignment/AllTests.java

diff --git a/os-simulator/OSInput.txt.txt b/os-simulator/PSSInput.txt
similarity index 100%
rename from os-simulator/OSInput.txt.txt
rename to os-simulator/PSSInput.txt
diff --git a/os-simulator/src/main/java/com/com1032/assignment/IOsystem/JavaIOSystem.java b/os-simulator/src/main/java/com/com1032/assignment/IOsystem/JavaIOSystem.java
index 0a27edf..3ae883d 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/IOsystem/JavaIOSystem.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/IOsystem/JavaIOSystem.java
@@ -3,48 +3,43 @@ package com.com1032.assignment.IOsystem;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Scanner;
+
+import com.com1032.assignment.processscheduler.Hardware;
 
 
 public class JavaIOSystem implements IOSystem{
 	/**A list of peripherals stored as Memory Mapped Files.*/
 	private ArrayList<MemoryMappedFile> peripherals = new ArrayList<MemoryMappedFile>();
 	
+	/**Directory name of folder locations to create.*/
+	private String directoryName = null;
 	
 	/**
 	 * Constructor. Initialises fields.
-	 * @throws IOException 
+	 * 
+	 * @param directoryName 
 	 * 
 	 * @throws IOException if there is an error accessing hardware file.
 	 * @throws IndexOutOfBoundsException if there is an error with hardware file parameters.
 	 */
-    public JavaIOSystem() throws IOException, IndexOutOfBoundsException {
+    public JavaIOSystem(String directoryName, Hardware hardware) throws IOException, IndexOutOfBoundsException {
+    	
+    	this.directoryName = directoryName;
 		try {
-			
-			for(File file: (new File("Peripherals/Buffers")).listFiles()) {
+			new File(directoryName + "/Peripherals/Buffers").mkdirs();
+
+			for(File file: (new File(directoryName + "/Peripherals/Buffers")).listFiles()) {
 				if(!file.isDirectory()) {
-					
 					file.delete();
 				}
 			}
 			
-			File file = new File("hardware.txt");
-			Scanner fileReader = new Scanner(file);
-			
-			//First four lines are internal hardware info. 
-			for(int i = 0; i < 4; i++) {
-				fileReader.nextLine();
-			}
-			
-			while(fileReader.hasNextLine()) {
-				String next = fileReader.nextLine();
-				
-				String deviceName = next.split(" ")[0];
-				String bufferFileName = next.split(" ")[1];
+			for(String peripheralInfo: hardware.getPeripheralsInfo()) {
+				String deviceName = peripheralInfo.split(" ")[0];
+				String bufferFileName = peripheralInfo.split(" ")[1];
 				IOType deviceType;
-            	
 				
-            	if(next.split(" ")[2].toLowerCase().equals("i")) {
+            	if(peripheralInfo.split(" ")[2].toLowerCase().equals("i")) {
             		deviceType = IOType.INPUT;
             	}
             	else {
@@ -54,12 +49,10 @@ public class JavaIOSystem implements IOSystem{
             	this.addDevice(deviceName, bufferFileName, deviceType);
 			}
 			
-			//Closes file.
-			fileReader.close();
 		}
 		
 		catch(IOException e) {
-			throw new IOException("Error using Hardware file.");
+			throw new IOException("Error adding buffer folders.");
 		}
 		catch(IndexOutOfBoundsException e) {
 			throw new IndexOutOfBoundsException("Error with Hardware file parameters.");
@@ -95,7 +88,7 @@ public class JavaIOSystem implements IOSystem{
     	}
     	
     	if(error == false) {
-    		MemoryMappedFile newPeripheral = new MemoryMappedFile(deviceName, bufferFileName, deviceType);
+    		MemoryMappedFile newPeripheral = new MemoryMappedFile(this.directoryName + "/Peripherals/Buffers/", deviceName, bufferFileName, deviceType);
     		this.peripherals.add(newPeripheral);	
     	}
     }
diff --git a/os-simulator/src/main/java/com/com1032/assignment/IOsystem/MemoryMappedFile.java b/os-simulator/src/main/java/com/com1032/assignment/IOsystem/MemoryMappedFile.java
index 90fe045..b8e9caa 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/IOsystem/MemoryMappedFile.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/IOsystem/MemoryMappedFile.java
@@ -18,7 +18,7 @@ public class MemoryMappedFile {
 	private IOType type;
 	
 	
-	private final String BUFFERS_DIRECTORY = "Peripherals/Buffers/";
+	private final String BUFFERS_DIRECTORY;
 	
 	/**
 	 * Constructor. Initialises fields.
@@ -29,7 +29,9 @@ public class MemoryMappedFile {
 	 * @throws IOException if there is an error interacting with memory file.
 	 * 
 	 */
-	public MemoryMappedFile (String deviceName, String filename, IOType type) throws IOException {
+	public MemoryMappedFile (String bufferDirectory, String deviceName, String filename, IOType type) throws IOException {
+		this.BUFFERS_DIRECTORY = bufferDirectory;
+		
 		if (deviceName != null)
 			this.setDeviceName(deviceName);
 		else
diff --git a/os-simulator/src/main/java/com/com1032/assignment/IOsystem/TestIO.java b/os-simulator/src/main/java/com/com1032/assignment/IOsystem/TestIO.java
deleted file mode 100644
index 8c0557f..0000000
--- a/os-simulator/src/main/java/com/com1032/assignment/IOsystem/TestIO.java
+++ /dev/null
@@ -1,248 +0,0 @@
-package com.com1032.assignment.IOsystem;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-
-/**
- **    It can be run in two modes:
- **        Interactive:         java TestIO 
- **        With a test file:    java TestIO testfile    
- **     
- **    To get a list of supported commands, type 'help' at the command line.
- **
- **    The testfile consists of commands to the driver program (one per line)
- **      as well as comments.  Comments beginning with /* will be ignored
- **      completely by the driver.  Comments beginning with // will be echoed
- **      to the output.  See the sample testfile for an example.
- */
-
-public class TestIO 
-{
-    /** File System object to be used for the function calls.*/
-    private static JavaIOSystem io;
-    
-    /**Table mapping variables to values.*/
-    private static Hashtable vars = new Hashtable();
-
-    
-    /**
-     * The main method ran when running application.
-     * 
-     * @param args
-     * @throws Exception 
-     */
-    public static void main(String [] args) throws Exception{
-
-        // Check for correct number of arguments
-        if (args.length > 1) System.err.println ("Usage: TestFS [filename]");
-
-        // Is the input coming from a file
-        boolean fromFile = (args.length==1);
-
-        // Create our test fileSystem
-        io = new JavaIOSystem();
-
-        // Create a stream for input
-        BufferedReader data = null;
-
-        // Open our input stream
-        if (fromFile) {
-            try {
-                data = new BufferedReader (new FileReader(new File(args[0])));
-            }
-            catch (FileNotFoundException e) {
-                System.err.println("Error: File " + args[0] + " not found.");
-                System.exit(1);
-            }
-        }
-        else data = new BufferedReader (new InputStreamReader(System.in));
-
-        // Cycle through user or file input
-        while (true) {
-            try {
-                // Print out the prompt for the user
-                if (!fromFile) {
-                    System.out.print("--> ");
-                    System.out.flush();
-                }
-
-                // Read in a line
-                String line = data.readLine();
-                //System.out.println(line);
-
-                // Check for various conditions
-                if (line == null) System.exit(0);  // Ctrl-D check
-                line = line.trim();                // Trim off extra whitespace
-                if (line.length() == 0) {          // Is anything left?
-                    System.out.println();
-                    continue;
-                }
-
-                // Handle comments and file input
-                if (line.startsWith("//")) {
-                    if (fromFile)
-                        System.out.println(line);
-                    continue;
-                }
-                if (line.startsWith("/*")) continue;
-                if (fromFile) System.out.println("--> " + line);
-
-                // See if the command has the format of an assignment
-                String target = null;
-                int equals = line.indexOf('=');
-                if (equals > 0) {
-                    target = line.substring(0,equals).trim();
-                    line = line.substring(equals+1).trim();
-                }
-
-                // Tokenize command line
-                StringTokenizer cmds = new StringTokenizer (line);
-                String cmd = cmds.nextToken();
-
-                // Call the function that corresponds to the command
-                int result = 0;
-                if (cmd.equalsIgnoreCase("addDevice") || cmd.equalsIgnoreCase("format")) {
-                	String deviceName = cmds.nextToken();
-                	String bufferFileName = cmds.nextToken();
-                	IOType deviceType;
-                	
-                	String next = cmds.nextToken();
-                	
-                	if(next.toLowerCase().equals("i")) {
-                		deviceType = IOType.INPUT;
-                	}
-                	else if(next.toLowerCase().equals("o")) {
-                		deviceType = IOType.OUTPUT;
-                	}
-                	else {
-                		throw new IllegalArgumentException("Invalid IO Type.");
-                	}
-                	
-                	io.addDevice(deviceName, bufferFileName, deviceType);
-                	
-                	System.out.println("Added device.");
-                }
-            
-                else if (cmd.equalsIgnoreCase("read")) {
-                	String deviceName = cmds.nextToken();
-                    int size = nextValue(cmds);
-                    
-                    String wantedData = io.read(deviceName, size);
-                    
-                    System.out.println(wantedData);
-                }
-                
-                else if (cmd.equalsIgnoreCase("write")) {
-                	String inputData = "";
-                	
-                	//Access device name.
-                	String deviceName = cmds.nextToken();
-                    
-                    //Cycles all text input.
-                    while (cmds.hasMoreTokens()) {
-                    	inputData += cmds.nextToken();
-                    	
-                    	//Adds space if there is another word.
-                    	if(cmds.hasMoreTokens()) {
-                    		inputData += " ";
-                    	}
-                    }
-                    
-                    io.write(deviceName, inputData);
-                    
-                    System.out.println("Written.");
-                }
-                
-                else if (cmd.equalsIgnoreCase("clear")) {
-                	//Access device name.
-                	String deviceName = cmds.nextToken();
-                    
-                    io.clear(deviceName);
-                } 
-        
-                else if (cmd.equalsIgnoreCase("removeDevice")) {
-                    io.removeDevice(cmds.nextToken());
-                }
-                
-                else if (cmd.equalsIgnoreCase("quit")) {
-                    System.exit(0);
-                }
-                
-                else if (cmd.equalsIgnoreCase("vars")) {
-                    for (Enumeration e = vars.keys(); e.hasMoreElements(); ) {
-                        Object key = e.nextElement();
-                        Object val = vars.get(key);
-                        System.out.println("\t" + key + " = " + val);
-                    }
-                    continue;
-                }
-                
-                else if (cmd.equalsIgnoreCase("help")) {
-                    help();
-                    continue;
-                }
-                
-                else {
-                    System.out.println("Unknown command.");
-                    continue;
-                }
-                
-                // Print out the result of the function call
-                if (target != null) {
-                    vars.put(target,new Integer(result));
-                    System.out.println("    " + target + " = " + result);
-                }
-            }
-            
-            // Handler for Integer.parseInt(...)
-            catch (NumberFormatException e) {
-                System.out.println("Incorrect argument type.");
-            }
-            // Handler for nextToken()
-            catch (NoSuchElementException e) {
-                System.out.println("Incorrect number of elements.");
-            }
-            // Handler for IOType
-            catch (IllegalArgumentException e) {
-            	System.out.println(e.getMessage());
-            }
-            catch (IOException e) {
-                System.err.println(e);
-            }
-        }
-    }
-
-    
-    /** Helper function for main, to interpret a command argument */
-    static private int nextValue(StringTokenizer cmds)
-    {
-        String arg = cmds.nextToken();
-        Object val = vars.get(arg);
-        return
-            (val == null) ?  Integer.parseInt(arg) : ((Integer)val).intValue();
-    }
-
-    
-    /**
-     * Help will just print out a listing of the commands available on the system.
-     */
-    private static void help() {
-        System.out.println ("\taddDevice DeviceName DeviceBufferFileName");
-        System.out.println ("\tremoveDevice deviceName");
-        System.out.println ("\tread deviceName size");
-        System.out.println ("\twrite deviceName data1 data2 ...");
-        System.out.println ("\tclear deviceName");
-        System.out.println ("\tquit");
-        System.out.println ("\tvars");
-        System.out.println ("\thelp");
-    }
-
-}
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/CPUSimulator.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/CPUSimulator.java
index 189a7d2..0391ab3 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/CPUSimulator.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/CPUSimulator.java
@@ -6,6 +6,7 @@ package com.com1032.assignment.processscheduler;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * @author felipedabrantes
@@ -24,6 +25,8 @@ public class CPUSimulator extends Thread{
 	/**The hardware to use.*/
 	private Hardware hardware = null;
 
+	/**Variable used to stop thread running.*/
+	protected final AtomicBoolean running = new AtomicBoolean(false);
 	
 	/**
 	 * Constructor. Initialises fields.
@@ -41,7 +44,9 @@ public class CPUSimulator extends Thread{
 	
 	@Override
 	public void run() {
-		while(true) {
+		this.running.set(true);
+		
+		while(this.running.get()) {
 			
 			//Temporarily stop executing for however milliseconds.
 			try {
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Clock.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Clock.java
index ef73455..612abc6 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Clock.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Clock.java
@@ -10,6 +10,7 @@ package com.com1032.assignment.processscheduler;
 public class Clock {
 	
 	private int time = 0;
+	private int cycle = 0;
 	
 	@Override
 	public String toString() {
@@ -17,11 +18,25 @@ public class Clock {
 	}
 	
 	public int getTime() {
-		return time;
+		return this.time;
+	}
+	
+	public int getCycle() {
+		return this.cycle;
 	}
 	
 	public void increaseTime(int time) {
 		this.time += time;
+		
+		if(this.time == Integer.MAX_VALUE) {
+			this.time = 0;
+			this.cycle ++;
+		}
+	}
+	
+	public void resetTime() {
+		this.time = 0;
+		this.cycle = 0;
 	}
 
 }
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Hardware.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Hardware.java
index 043ba5c..6c488b6 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Hardware.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/Hardware.java
@@ -5,6 +5,8 @@ package com.com1032.assignment.processscheduler;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Scanner;
 
 /**
@@ -18,6 +20,8 @@ public class Hardware {
 	private int RAMSize = 0;
 	private int diskSize = 0;
 	
+	private List<String> peripheralsInfo = new ArrayList<String> ();
+	
 	
 	/**
 	 * Constructor. Initialises fields.
@@ -43,10 +47,10 @@ public class Hardware {
 	 * @throws IOException if there is an error accessing hardware file.
 	 * @throws NumberFormatException if there is an error with hardware file parameters.
 	 */
-	public Hardware() throws IOException, NumberFormatException {
+	public Hardware(String fileName) throws IOException, NumberFormatException {
 		try {
 			
-			File file = new File("hardware.txt");
+			File file = new File(fileName);
 			Scanner fileReader = new Scanner(file);
 			
 			this.processorNum = Integer.valueOf(fileReader.nextLine());
@@ -54,8 +58,17 @@ public class Hardware {
 			this.RAMSize = Integer.valueOf(fileReader.nextLine());
 			this.diskSize = Integer.valueOf(fileReader.nextLine());
 			
+			while(fileReader.hasNext()) {
+				this.peripheralsInfo.add(fileReader.nextLine());
+			}
+			
 			//Closes file.
 			fileReader.close();
+			
+			//Cores per processor cannot be more than 4.
+			if(this.coresPerProcessor > 4) {
+				throw new NumberFormatException();
+			}
 		}
 		
 		catch(IOException e) {
@@ -97,5 +110,12 @@ public class Hardware {
 	}
 	
 	
+	/**
+	 * @return the peripheralsInfo
+	 */
+	public List<String> getPeripheralsInfo(){
+		return this.peripheralsInfo;
+	}
+	
 	
 }
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/IOProcessManager.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/IOProcessManager.java
index b4af56c..9255142 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/IOProcessManager.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/IOProcessManager.java
@@ -7,6 +7,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import com.com1032.assignment.IOsystem.JavaIOSystem;
 
@@ -28,33 +29,36 @@ public class IOProcessManager extends Thread {
 	/**The IO System used to control peripherals.*/
 	private JavaIOSystem IOSystem = null;
 	
+	/**Variable used to stop thread running.*/
+	protected final AtomicBoolean running = new AtomicBoolean(false);
 	
 	/**
 	 * Constructor. Initialises fields.
 	 * 
-	 * @param globalTime
-	 * @param cores
-	 * @param readyQueue
+	 * @param directoryName
+	 * @param errorReport
+	 * @param IOReport
 	 * @param blockedQueue
-	 * @param terminatedQueue
 	 * 
 	 * @throws IOException if there is an error accessing hardware file.
 	 * @throws IndexOutOfBoundsException if there is an error with hardware file parameters.
 	 * 
 	 */
-	public IOProcessManager(StringBuffer errorReport, StringBuffer IOReport, List<PCB> blockedQueue) throws IndexOutOfBoundsException, IOException {
+	public IOProcessManager(String directoryName, Hardware hardware, 
+			StringBuffer errorReport, StringBuffer IOReport, List<PCB> blockedQueue) throws IndexOutOfBoundsException, IOException {
 		this.errorReport = errorReport;
 		this.blockedQueue = blockedQueue;
 		this.IOReport = IOReport;
 		
-		this.IOSystem = new JavaIOSystem();
+		this.IOSystem = new JavaIOSystem(directoryName, hardware);
 	}
 	
 	
 	@Override
 	public void run() {
+		this.running.set(true);
 		
-		while(true) {
+		while(this.running.get()) {
 			try {
 				Thread.sleep(50);
 			} catch (InterruptedException e) {
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OS.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OS.java
index abe449f..60f9686 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OS.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OS.java
@@ -3,6 +3,9 @@ package com.com1032.assignment.processscheduler;
  * OS.java
  */
 
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
 /**
  * @author felipedabrantes
  *
@@ -15,18 +18,18 @@ public class OS {
 	private Hardware hardware = null;
 	/**The class the handles the process scheduling.*/
 	private ProcessScheduler ps = null;
+	/**Directory name of folder locations to create.*/
+	private final String directoryName;
 
 	
 	/**
 	 * Constructor. Initialises fields.
+	 * @throws IOException 
+	 * @throws NumberFormatException 
 	 */
-	public OS() {
-		this.ps = new ProcessScheduler(this);
-		try {
-			this.hardware = new Hardware();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
+	public OS(String hardwareFileName, String directoryName) throws NumberFormatException, IOException {
+		this.hardware = new Hardware(hardwareFileName);
+		this.directoryName = directoryName;
 	}
 
 	
@@ -34,8 +37,10 @@ public class OS {
 	 * Runs process scheduling simulation with processes in OS.
 	 */
 	public void turnOn(SchedulingAlgorithm algorithm, int quantum) {
+		this.ps = new ProcessScheduler(this, this.directoryName);
+		
 		try {
-			this.ps.startThreads(algorithm, quantum);	
+			this.ps.startThreads(algorithm, quantum);
 		}
 		catch(Exception e) {
 			e.printStackTrace();
@@ -45,11 +50,24 @@ public class OS {
 	
 	/**
 	 * Stop running threads.
+	 * @throws InterruptedException 
 	 */
-	public void turnOff() {
+	public void turnOff() throws InterruptedException {
 		ps.stopThreads();
+		
+		TimeUnit.MILLISECONDS.sleep(2000);
+		
+		this.ps = null;
+		this.globalTime.resetTime();
+	}
+	
+	
+	public void resetOS(SchedulingAlgorithm algorithm, int quantum) throws InterruptedException {
+		this.turnOff();
+		this.turnOn(algorithm, quantum);
 	}
 	
+	
 	/**
 	 * @return the globalTime
 	 */
@@ -73,5 +91,9 @@ public class OS {
 		return this.ps;
 	}
 	
+	public String getDirectoryName() {
+		return this.directoryName;
+	}
+	
 
 }
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OSCommandLine.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OSCommandLine.java
index c89b6c5..19dafef 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OSCommandLine.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/OSCommandLine.java
@@ -9,6 +9,8 @@ import java.io.InputStreamReader;
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
 
+import com.com1032.assignment.tests.AllTests;
+
 /**
  * @author felipedabrantes
  *
@@ -16,10 +18,20 @@ import java.util.StringTokenizer;
 public class OSCommandLine {
 	
 	/**
-	 * @param args
+	 * @param args[0] hardware file
+	 * @param args[1] location to store folders
 	 */
 	public static void main(String[] args) {
-		OS os = new OS();
+		OS os = null;
+		try {
+			os = new OS(args[0], args[1]);
+			System.out.println("Located hardware file!");
+		}
+		catch(Exception e){
+			System.out.println(e);
+			System.exit(0);
+		}
+		
 		os.turnOn(SchedulingAlgorithm.FIFO, 5);
 		
         // Create a stream for input
@@ -91,8 +103,35 @@ public class OSCommandLine {
                 	
                 }
                 
+                else if (cmd.equalsIgnoreCase("test")) {
+                	System.out.println("Running Tests, OS will reset after completion...");
+                	os.turnOff();
+                    AllTests all = new AllTests();
+                    try {
+						all.runAllTests(os);
+						System.out.println("Completed Tests Successfully!");
+						System.out.println("\nResetting OS...");
+						os.turnOn(SchedulingAlgorithm.FIFO, 5);
+						
+					} catch (Exception e) {
+						System.out.println("Tests failed.");
+//						e.printStackTrace();
+						System.exit(0);
+					}
+                    
+                }
+                
+                else if (cmd.equalsIgnoreCase("reset")) {
+                	System.out.println("Reseting...");
+                    os.resetOS(SchedulingAlgorithm.FIFO, 5);
+                    System.out.println("Complete!");
+                }
+                
                 else if (cmd.equalsIgnoreCase("quit")) {
+                	System.out.println("Quitting...");
                     os.turnOff();
+                    System.out.println("Bye!");
+                    System.exit(0);
                 }
                 
                 else if (cmd.equalsIgnoreCase("help")) {
@@ -119,8 +158,11 @@ public class OSCommandLine {
             	System.out.println(e.getMessage());
             }
             catch (IOException e) {
-                System.err.println(e);
-            }
+                System.out.println(e);
+            } 
+            catch (InterruptedException e) {
+				System.out.println(e);
+			}
         }
 
 	}
@@ -134,6 +176,7 @@ public class OSCommandLine {
         System.out.println (" - errorReport");
         System.out.println (" - ioReport");
         System.out.println (" - algorithm");
+        System.out.println (" - reset");
         System.out.println (" - quit");
         System.out.println (" - help");
     }
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessCreation.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessCreation.java
index 28a20e5..c2ef36e 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessCreation.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessCreation.java
@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Scanner;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * @author felipedabrantes
@@ -31,16 +32,25 @@ public class ProcessCreation extends Thread {
 	/**The global time of the system.*/
 	private Clock globalTime = null;
 	
+	/**Directory name of folder locations to create.*/
+	private String directoryName = null;
+	
+	/**Variable used to stop thread running.*/
+	protected final AtomicBoolean running = new AtomicBoolean(false);
+	
 	/**
 	 * Constructor. Initialises fields.
 	 * 
 	 * @param jobQueue of the system.
 	 */
-	public ProcessCreation(StringBuffer errorReport, Clock globalTime, List<PCB> jobQueue) {
+	public ProcessCreation(String directoryName, StringBuffer errorReport, Clock globalTime, List<PCB> jobQueue) {
 		this.jobQueue = jobQueue;
 		this.errorReport = errorReport;
 		this.globalTime = globalTime;
 		
+		this.directoryName = directoryName;
+		
+		this.createFolders();
 		this.clearFolders();
 	}
 	
@@ -49,8 +59,10 @@ public class ProcessCreation extends Thread {
 	 * Function ran when thread starts.
 	 */
 	@Override
-	public void run() {		
-		while(true) {
+	public void run() {
+		this.running.set(true);
+		
+		while(this.running.get()) {
 			//Fetches files where new processes are added.
 			this.fetchFiles();
 			
@@ -59,7 +71,7 @@ public class ProcessCreation extends Thread {
 			
 			//Temporarily stop executing for however milliseconds.
 			try {
-				Thread.sleep(10);
+				Thread.sleep(0);
 			} catch (InterruptedException e) {
 				e.printStackTrace();
 			}
@@ -73,7 +85,7 @@ public class ProcessCreation extends Thread {
 	 * If it finds any, it will store the file.
 	 */
 	public void fetchFiles() {
-		File folder = new File("Processes/New_Processes");
+		File folder = new File(this.directoryName + "/Processes/New_Processes");
 		File[] listOfFiles = folder.listFiles();
 		
 		
@@ -162,10 +174,10 @@ public class ProcessCreation extends Thread {
 			//New file name in case file is not unique.
 			String newFileName = null;
 			if(valid) {
-				newFileName = "Processes/Valid_Processes/" + file.getName();
+				newFileName = this.directoryName + "/Processes/Valid_Processes/" + file.getName();
 			}
 			else {
-				newFileName = "Processes/Invalid_Processes/" + file.getName();
+				newFileName = this.directoryName + "/Processes/Invalid_Processes/" + file.getName();
 			}
 			
 			//Removes .txt extension before changing name.
@@ -199,11 +211,21 @@ public class ProcessCreation extends Thread {
 	}
 	
 	
+	/**
+	 * Makes folders.
+	 */
+	public void createFolders() {
+		new File(this.directoryName +  "/Processes/New_Processes").mkdirs();
+		new File(this.directoryName +  "/Processes/Valid_Processes").mkdirs();
+		new File(this.directoryName +  "/Processes/Invalid_Processes").mkdirs();
+	}
+	
+	
 	/**
 	 * Clears folders in Valid_Processes and Invalid_Processes.
 	 */
 	public void clearFolders() {
-		File folder = new File("Processes/Valid_Processes");
+		File folder = new File(this.directoryName + "/Processes/Valid_Processes");
 		File[] listOfFiles = folder.listFiles();
 		
 		//Cycles through folder 'Valid_Processes' to look for files.
@@ -214,7 +236,7 @@ public class ProcessCreation extends Thread {
 			}
 		}
 		
-		folder = new File("Processes/Invalid_Processes");
+		folder = new File(this.directoryName + "/Processes/Invalid_Processes");
 		listOfFiles = folder.listFiles();
 		
 		//Cycles through folder 'Valid_Processes' to look for files.
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessDispatcher.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessDispatcher.java
index 28f26d7..a26a370 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessDispatcher.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessDispatcher.java
@@ -5,10 +5,11 @@ package com.com1032.assignment.processscheduler;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * @author felipedabrantes
- *
+ 
  */
 public class ProcessDispatcher extends Thread {
 
@@ -37,6 +38,9 @@ public class ProcessDispatcher extends Thread {
 	/**The quantum used.*/
 	private int quantum = 0;
 	
+	/**Variable used to stop thread running.*/
+	protected final AtomicBoolean running = new AtomicBoolean(false);
+	
 	/**
 	 * Constructor. Initialises fields
 	 * 
@@ -73,8 +77,9 @@ public class ProcessDispatcher extends Thread {
 	 */
 	@Override
 	public void run() {
+		this.running.set(true);
 		
-		while(true) {
+		while(this.running.get()) {
 			try {
 				Thread.sleep(0);
 			} catch (InterruptedException e) {
diff --git a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessScheduler.java b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessScheduler.java
index f74f407..4da551e 100644
--- a/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessScheduler.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/processscheduler/ProcessScheduler.java
@@ -44,13 +44,17 @@ public class ProcessScheduler {
 	/**The global time of the system.*/
 	private OS os = null;
 	
+	/**The directory to make all folders in.*/
+	private String directoryName = null;
+	
 	private ProcessCreation pc = null;
 	private ProcessDispatcher pd = null;
 	private CPUSimulator cpu = null;
 	private IOProcessManager io = null;
 	
-	public ProcessScheduler(OS os) {
+	public ProcessScheduler(OS os, String directoryName) {
 		this.os = os;
+		this.directoryName = directoryName;
 	}
 	
 	
@@ -65,7 +69,7 @@ public class ProcessScheduler {
 	 */
 	public void startThreads(SchedulingAlgorithm algorithm, int quantum) throws IndexOutOfBoundsException, IOException {
 		//Thread responsible for creating processes from files.
-		this.pc = new ProcessCreation(this.errorReport, this.os.getGlobalTime(), this.jobQueue);
+		this.pc = new ProcessCreation(this.directoryName, this.errorReport, this.os.getGlobalTime(), this.jobQueue);
 		
 		//Thread responsible for handling processes states.
 		this.pd = new ProcessDispatcher(this.os.getGlobalTime(), this.os.getHardware(), 
@@ -79,7 +83,7 @@ public class ProcessScheduler {
 		this.cpu = new CPUSimulator(this.errorReport, this.os.getGlobalTime(), this.cpuQueue, this.os.getHardware());
 		
 		//Thread responsible for running blocked processes.
-		this.io = new IOProcessManager(this.errorReport, this.IOReport, this.blockedQueue);
+		this.io = new IOProcessManager(this.directoryName, this.os.getHardware(), this.errorReport, this.IOReport, this.blockedQueue);
 		
 		//Start threads.
 		pc.start();
@@ -88,11 +92,17 @@ public class ProcessScheduler {
 		io.start();
 	}
 	
+
 	public void stopThreads() {
-		pc.stop();
-		pd.stop();
-		cpu.stop();
-		io.stop();
+		this.pc.running.set(false);
+		this.pd.running.set(false);
+		this.cpu.running.set(false);
+		this.io.running.set(false);
+		
+		this.pc = null;
+		this.pd = null;
+		this.cpu = null;
+		this.io = null;
 	}
 	
 	
diff --git a/os-simulator/src/main/java/com/com1032/assignment/tests/AllTests.java b/os-simulator/src/main/java/com/com1032/assignment/tests/AllTests.java
new file mode 100644
index 0000000..d0c61eb
--- /dev/null
+++ b/os-simulator/src/main/java/com/com1032/assignment/tests/AllTests.java
@@ -0,0 +1,26 @@
+/**
+ * 
+ */
+package com.com1032.assignment.tests;
+
+import java.io.IOException;
+
+import com.com1032.assignment.processscheduler.OS;
+
+/**
+ * @author felipedabrantes
+ *
+ */
+public class AllTests {
+	
+	public void runAllTests(OS os) throws IOException, InterruptedException {
+		IOSystemTest ioTest = new IOSystemTest(os);
+		PSAlgorithmsTest PSAlgorithmsTest = new PSAlgorithmsTest(os);
+		PSBlockedTest PSBlockedTest = new PSBlockedTest(os);
+		
+		ioTest.allTests();
+		PSAlgorithmsTest.allTests();
+		PSBlockedTest.allTests();
+	}
+
+}
diff --git a/os-simulator/src/test/java/com/com1032/assignment/IOSystemTest.java b/os-simulator/src/main/java/com/com1032/assignment/tests/IOSystemTest.java
similarity index 58%
rename from os-simulator/src/test/java/com/com1032/assignment/IOSystemTest.java
rename to os-simulator/src/main/java/com/com1032/assignment/tests/IOSystemTest.java
index 205b875..83a0f9f 100644
--- a/os-simulator/src/test/java/com/com1032/assignment/IOSystemTest.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/tests/IOSystemTest.java
@@ -1,9 +1,7 @@
 /**
  * 
  */
-package com.com1032.assignment;
-
-import static org.junit.Assert.*;
+package com.com1032.assignment.tests;
 
 import java.io.BufferedWriter;
 import java.io.File;
@@ -16,8 +14,6 @@ import java.nio.file.StandardCopyOption;
 import java.util.Scanner;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.Test;
-
 import com.com1032.assignment.processscheduler.OS;
 import com.com1032.assignment.processscheduler.SchedulingAlgorithm;
 
@@ -27,12 +23,28 @@ import com.com1032.assignment.processscheduler.SchedulingAlgorithm;
  */
 public class IOSystemTest {
 
-	@Test
+	private OS os;
+	
+	public IOSystemTest(OS os) {
+		this.os = os;
+	}
+	
+	
+	public void allTests() throws IOException, InterruptedException {
+		try {
+			this.OutputDeviceTest();
+			this.InputDeviceTest();
+		}
+		catch(AssertionError e) {
+			e.printStackTrace();
+		}
+	}
+	
+	
 	public void OutputDeviceTest() throws IOException, InterruptedException {
-		OS os = new OS();
-		
 		//Start OS with FIFO algorithm..
 		os.turnOn(SchedulingAlgorithm.FIFO, 5);
+		os.getPs().setAlgorithm(SchedulingAlgorithm.FIFO, 5);
 		
 		//Copy files from test.
 		//File contains a print statement to device printer.
@@ -41,28 +53,27 @@ public class IOSystemTest {
 		//Wait for processes to execute.
 		TimeUnit.MILLISECONDS.sleep(2000);
 		
-		os.turnOff();
-		
-		File file = new File("Peripherals/Buffers/printerBuffer.txt");
+		File file = new File(os.getDirectoryName() + "/Peripherals/Buffers/printerBuffer.txt");
 		Scanner fileReader = new Scanner(file);
 		String actualResult = fileReader.nextLine();
 		String expectedResult = "1";
 		fileReader.close();
 		
-		assertEquals(expectedResult, actualResult);
+		if(!actualResult.equals(expectedResult)) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
 	
-	@Test
 	public void InputDeviceTest() throws IOException, InterruptedException {
-		OS os = new OS();
-		
 		//Start OS with FIFO algorithm..
 		os.turnOn(SchedulingAlgorithm.FIFO, 5);
 		
 		//Write to keyboard.
 		String textToAppend = "20";
-		BufferedWriter writer = new BufferedWriter(new FileWriter("Peripherals/Buffers/keyboardBuffer.txt", true));
+		BufferedWriter writer = new BufferedWriter(new FileWriter(os.getDirectoryName() + "/Peripherals/Buffers/keyboardBuffer.txt", true));
 		writer.write(textToAppend);
 		writer.close();
 		
@@ -73,22 +84,30 @@ public class IOSystemTest {
 		//Wait for processes to execute.
 		TimeUnit.MILLISECONDS.sleep(2000);
 		
-		os.turnOff();
-		
-		File file = new File("Peripherals/Buffers/printerBuffer.txt");
+		File file = new File(os.getDirectoryName() + "/Peripherals/Buffers/printerBuffer.txt");
 		Scanner fileReader = new Scanner(file);
 		String actualResult = fileReader.nextLine();
 		String expectedResult = "20";
 		fileReader.close();
 		
-		assertEquals(expectedResult, actualResult);
+		if(!actualResult.equals(expectedResult)) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 
 	
 	
 	public void copyProcessFile(String fileName) throws IOException {
-		Path testSource = Paths.get("Processes/_Tests/" + fileName);
-		Path target = Paths.get("Processes/New_Processes/" + fileName);
-		Files.copy(testSource, target, StandardCopyOption.REPLACE_EXISTING);
+		try {
+			Path testSource = Paths.get(os.getDirectoryName() + "/Processes/_Tests/" + fileName);
+			Path target = Paths.get(os.getDirectoryName() + "/Processes/New_Processes/" + fileName);
+			Files.copy(testSource, target, StandardCopyOption.REPLACE_EXISTING);
+		}
+		catch(IOException e) {
+			throw new IOException("Error with _Tests folder. Make sure it is added to Processes folder.");
+		}
+
 	}
 }
diff --git a/os-simulator/src/test/java/com/com1032/assignment/PSAlgorithmsTest.java b/os-simulator/src/main/java/com/com1032/assignment/tests/PSAlgorithmsTest.java
similarity index 87%
rename from os-simulator/src/test/java/com/com1032/assignment/PSAlgorithmsTest.java
rename to os-simulator/src/main/java/com/com1032/assignment/tests/PSAlgorithmsTest.java
index 23c9ac4..efdd52d 100644
--- a/os-simulator/src/test/java/com/com1032/assignment/PSAlgorithmsTest.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/tests/PSAlgorithmsTest.java
@@ -1,9 +1,7 @@
 /**
  * 
  */
-package com.com1032.assignment;
-
-import static org.junit.Assert.*;
+package com.com1032.assignment.tests;
 
 import java.io.IOException;
 import java.nio.file.Files;
@@ -12,8 +10,6 @@ import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.Test;
-
 import com.com1032.assignment.processscheduler.OS;
 import com.com1032.assignment.processscheduler.SchedulingAlgorithm;
 
@@ -22,11 +18,31 @@ import com.com1032.assignment.processscheduler.SchedulingAlgorithm;
  *
  */
 public class PSAlgorithmsTest {
-
-	@Test
-	public void FIFOProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
+	
+	private OS os = null;
+	/**
+	 * 
+	 */
+	public PSAlgorithmsTest(OS os) {
+		this.os = os;
+	}
+	
+	
+	public void allTests() throws IOException, InterruptedException {
+		try {
+			this.FIFOProcessTest();
+			this.SPFProcessTest();
+			this.SRTFProcessTest();
+			this.RRProcessTest();
+		}
 		
+		catch(AssertionError e) {
+			e.printStackTrace();
+		}
+
+	}
+	
+	public void FIFOProcessTest() throws IOException, InterruptedException {		
 		//Start OS with FIFO algorithm..
 		os.turnOn(SchedulingAlgorithm.FIFO, 5);
 		
@@ -37,13 +53,11 @@ public class PSAlgorithmsTest {
 		TimeUnit.MILLISECONDS.sleep(100);
 		this.copyProcessFile("terminate4.txt");
 		
-		TimeUnit.MILLISECONDS.sleep(5000);
+		TimeUnit.MILLISECONDS.sleep(6000);
 		
 		String actualReport = os.getPs().getProcessReport();	
 		String simpleReport = this.simplifyReport(actualReport);
 		
-		os.turnOff();
-		
 		StringBuffer expectedReport = new StringBuffer();
 		expectedReport.append("Ready terminate14 NEW false\n");
 		expectedReport.append("Schedule terminate14 NEW false\n");
@@ -55,19 +69,22 @@ public class PSAlgorithmsTest {
 		expectedReport.append("Schedule terminate4 NEW false\n");
 		expectedReport.append("Terminated terminate4 TERMINATED false\n");
 		
-		assertEquals(expectedReport.toString(), simpleReport);
+		if(!simpleReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
-	@Test
+	
 	public void SPFProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
-		
-		//Copy files from test first.
-		this.copyProcessFile("terminate70.txt");
 		
 		//Start OS with SPF algorithm.
 		os.turnOn(SchedulingAlgorithm.SPF, 5);
 		
+		//Copy files from test first.
+		this.copyProcessFile("terminate70.txt");
+		TimeUnit.MILLISECONDS.sleep(500);
 		this.copyProcessFile("terminate14.txt");
 		TimeUnit.MILLISECONDS.sleep(100);
 		this.copyProcessFile("terminate4.txt");
@@ -79,8 +96,6 @@ public class PSAlgorithmsTest {
 		String actualReport = os.getPs().getProcessReport();	
 		String simpleReport = this.simplifyReport(actualReport);
 		
-		os.turnOff();
-		
 		StringBuffer expectedReport = new StringBuffer();
 		expectedReport.append("Ready terminate70 NEW false\n");
 		expectedReport.append("Schedule terminate70 NEW false\n");
@@ -95,12 +110,14 @@ public class PSAlgorithmsTest {
 		expectedReport.append("Schedule terminate28 NEW false\n");
 		expectedReport.append("Terminated terminate28 TERMINATED false\n");
 		
-		assertEquals(expectedReport.toString(), simpleReport);
+		if(!simpleReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
-	@Test
 	public void SRTFProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
 		
 		//Start OS with SPF algorithm.
 		os.turnOn(SchedulingAlgorithm.SRTF, 5);
@@ -132,12 +149,12 @@ public class PSAlgorithmsTest {
 		expectedReport.append("Schedule terminate28 NEW false\n");
 		expectedReport.append("Terminated terminate28 TERMINATED false\n");
 		
-		assertEquals(expectedReport.toString(), simpleReport);
+		if(!simpleReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
 	}
 	
-	@Test
 	public void RRProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
 		
 		//Start OS with SPF algorithm.
 		os.turnOn(SchedulingAlgorithm.RR, 5);
@@ -154,8 +171,6 @@ public class PSAlgorithmsTest {
 		String actualReport = os.getPs().getProcessReport();	
 		String simpleReport = this.simplifyReport(actualReport);
 		
-		os.turnOff();
-		
 		StringBuffer expectedReport = new StringBuffer();
 		expectedReport.append("Ready terminate14 NEW false\n");
 		expectedReport.append("Schedule terminate14 NEW false\n");
@@ -175,13 +190,17 @@ public class PSAlgorithmsTest {
 		expectedReport.append("Schedule terminate28 READY false\n");
 		expectedReport.append("Terminated terminate28 TERMINATED false\n");
 		
-		assertEquals(expectedReport.toString(), simpleReport);
+		if(!simpleReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
 	
 	public void copyProcessFile(String fileName) throws IOException {
-		Path testSource = Paths.get("Processes/_Tests/" + fileName);
-		Path target = Paths.get("Processes/New_Processes/" + fileName);
+		Path testSource = Paths.get(os.getDirectoryName() + "/Processes/_Tests/" + fileName);
+		Path target = Paths.get(os.getDirectoryName() + "/Processes/New_Processes/" + fileName);
 		Files.copy(testSource, target, StandardCopyOption.REPLACE_EXISTING);
 	}
 	
diff --git a/os-simulator/src/test/java/com/com1032/assignment/PSBlockedTest.java b/os-simulator/src/main/java/com/com1032/assignment/tests/PSBlockedTest.java
similarity index 86%
rename from os-simulator/src/test/java/com/com1032/assignment/PSBlockedTest.java
rename to os-simulator/src/main/java/com/com1032/assignment/tests/PSBlockedTest.java
index 18fc164..6feb1fe 100644
--- a/os-simulator/src/test/java/com/com1032/assignment/PSBlockedTest.java
+++ b/os-simulator/src/main/java/com/com1032/assignment/tests/PSBlockedTest.java
@@ -1,9 +1,7 @@
 /**
  * 
  */
-package com.com1032.assignment;
-
-import static org.junit.Assert.*;
+package com.com1032.assignment.tests;
 
 import java.io.IOException;
 import java.nio.file.Files;
@@ -12,8 +10,6 @@ import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.Test;
-
 import com.com1032.assignment.processscheduler.OS;
 import com.com1032.assignment.processscheduler.SchedulingAlgorithm;
 
@@ -22,10 +18,32 @@ import com.com1032.assignment.processscheduler.SchedulingAlgorithm;
  *
  */
 public class PSBlockedTest {
+
+	private OS os = null;
+	
+	/**
+	 * 
+	 */
+	public PSBlockedTest(OS os) {
+		this.os = os;
+	}
+
+	
+	public void allTests() throws IOException, InterruptedException {
+		try {
+			this.FIFOBlockedProcessTest();
+			this.RRBlockedProcessTest();
+			this.ErrorBlockedProcessTest();
+			this.ErrorReportBlockedProcessTest();
+		}
+		
+		catch(AssertionError e) {
+			e.printStackTrace();
+		}
+	}
+	
 	
-	@Test
 	public void FIFOBlockedProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
 		
 		//Start OS with FIFO algorithm..
 		os.turnOn(SchedulingAlgorithm.FIFO, 5);
@@ -43,8 +61,6 @@ public class PSBlockedTest {
 		String actualReport = os.getPs().getProcessReport();	
 		String simpleReport = this.simplifyReport(actualReport);
 		
-		os.turnOff();
-		
 		StringBuffer expectedReport = new StringBuffer();
 		expectedReport.append("Ready blocked4_1 NEW false\n");
 		expectedReport.append("Schedule blocked4_1 NEW false\n");
@@ -65,12 +81,14 @@ public class PSBlockedTest {
 		expectedReport.append("Blocking blocked18_3 BLOCKED false\n");
 		expectedReport.append("Terminated blocked18_3 TERMINATED false\n");
 		
-		assertEquals(expectedReport.toString(), simpleReport);
+		if(!simpleReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
-	@Test
 	public void RRBlockedProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
 		
 		//Start OS with FIFO algorithm..
 		os.turnOn(SchedulingAlgorithm.FIFO, 5);
@@ -89,8 +107,6 @@ public class PSBlockedTest {
 		String actualReport = os.getPs().getProcessReport();	
 		String simpleReport = this.simplifyReport(actualReport);
 		
-		os.turnOff();
-		
 		StringBuffer expectedReport = new StringBuffer();		
 			
 		expectedReport.append("Ready blocked18_3 NEW false\n");
@@ -111,16 +127,17 @@ public class PSBlockedTest {
 		expectedReport.append("Blocking blocked18_3 BLOCKED false\n");
 		expectedReport.append("Terminated blocked18_3 TERMINATED false\n");
 		
-		assertEquals(expectedReport.toString(), simpleReport);
+		if(!simpleReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
 	
-	@Test
 	public void ErrorBlockedProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
-		
 		//Start OS with FIFO algorithm..
-		os.turnOn(SchedulingAlgorithm.FIFO, 3);
+		os.turnOn(SchedulingAlgorithm.FIFO, 5);
 		
 		//Copy files from test.
 		//Code has a device not in hardware file.
@@ -132,8 +149,6 @@ public class PSBlockedTest {
 		String actualProcessReport = os.getPs().getProcessReport();
 		String simpleProcessReport = this.simplifyReport(actualProcessReport);
 		
-		os.turnOff();
-		
 
 		StringBuffer expectedReport = new StringBuffer();
 		expectedReport.append("Ready blockedInvalid6_1 NEW false\n");
@@ -141,16 +156,17 @@ public class PSBlockedTest {
 		expectedReport.append("Blocking blockedInvalid6_1 BLOCKED false\n");
 		expectedReport.append("Terminated blockedInvalid6_1 TERMINATED true\n");
 		
-		assertEquals(expectedReport.toString(), simpleProcessReport);
+		if(!simpleProcessReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
 	
-	@Test
 	public void ErrorReportBlockedProcessTest() throws IOException, InterruptedException {
-		OS os = new OS();
-		
 		//Start OS with FIFO algorithm..
-		os.turnOn(SchedulingAlgorithm.FIFO, 3);
+		os.turnOn(SchedulingAlgorithm.FIFO, 5);
 		
 		//Copy files from test.
 		//Code has a device not in hardware file.
@@ -161,19 +177,22 @@ public class PSBlockedTest {
 		
 		String actualErrorReport = os.getPs().getErrorReport();
 		String simpleErrorReport = this.simplifyErrorReport(actualErrorReport);
-		os.turnOff();
 		
 		StringBuffer expectedReport = new StringBuffer();
 		expectedReport.append("3: blockedInvalid6_1 BLOCKED");
 		
-		assertEquals(expectedReport.toString(), simpleErrorReport);
+		if(!simpleErrorReport.equals(expectedReport.toString())) {
+			throw new IOException();
+		}
+		
+		os.turnOff();
 	}
 	
 	
 	
 	public void copyProcessFile(String fileName) throws IOException {
-		Path testSource = Paths.get("Processes/_Tests/" + fileName);
-		Path target = Paths.get("Processes/New_Processes/" + fileName);
+		Path testSource = Paths.get(os.getDirectoryName() + "/Processes/_Tests/" + fileName);
+		Path target = Paths.get(os.getDirectoryName() + "/Processes/New_Processes/" + fileName);
 		Files.copy(testSource, target, StandardCopyOption.REPLACE_EXISTING);
 	}
 	
@@ -244,4 +263,5 @@ public class PSBlockedTest {
 		return simpleReport.toString();
 		
 	}
+	
 }
diff --git a/os-simulator/src/main/java/com/com1032/pss/OSSim.java b/os-simulator/src/main/java/com/com1032/pss/OSSim.java
index 34aefcf..597af28 100644
--- a/os-simulator/src/main/java/com/com1032/pss/OSSim.java
+++ b/os-simulator/src/main/java/com/com1032/pss/OSSim.java
@@ -33,7 +33,6 @@ public class OSSim {
 	 * Constructor. Initialises fields.
 	 */
 	public OSSim() {
-		
 		this.pss = new ProcessSchedulerSimulator(this.globalTime);
 	}
 
@@ -99,10 +98,10 @@ public class OSSim {
 	/**
 	 * Runs process scheduling simulation with processes in OS.
 	 */
-	public void runProcessScheduling() {
+	public String runProcessScheduling() {
 		pss.addProcessToJob(this.processes);
 		pss.run(SchedulingAlgorithm.SPF, 3);
-		System.out.println(pss.getReport());
+		return pss.getReport();
 	}
 
 }
\ No newline at end of file
diff --git a/os-simulator/src/main/java/com/com1032/pss/ProcessSchedulerSimulator.java b/os-simulator/src/main/java/com/com1032/pss/ProcessSchedulerSimulator.java
index d9c2b6b..85252c2 100644
--- a/os-simulator/src/main/java/com/com1032/pss/ProcessSchedulerSimulator.java
+++ b/os-simulator/src/main/java/com/com1032/pss/ProcessSchedulerSimulator.java
@@ -66,10 +66,6 @@ public class ProcessSchedulerSimulator {
 		
 		//Adding configuration info.
 		this.report.insert(0, "---Process Scheduler---\n* Algorithm: " + algorithm + "\n* Quantum: " + quantum + "\n\n");
-//		this.report.append("Process Scheduler");
-//		this.report.append("\n* Algorithm: " + algorithm);
-//		this.report.append("\n* Quantum: " + quantum);
-		
 		
 		while(!this.jobQueue.isEmpty() || !this.readyQueue.isEmpty() || this.scheduledProcess != null) {		
 			
diff --git a/os-simulator/src/test/java/com/com1032/assignment/AllTests.java b/os-simulator/src/test/java/com/com1032/assignment/AllTests.java
deleted file mode 100644
index a2c6951..0000000
--- a/os-simulator/src/test/java/com/com1032/assignment/AllTests.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.com1032.assignment;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-@RunWith(Suite.class)
-@SuiteClasses({ IOSystemTest.class, PSAlgorithmsTest.class, PSBlockedTest.class })
-public class AllTests {
-
-}
-- 
GitLab