<commit_before>package dk.aau.d101f14.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

public class InformationCollector {
	
	public static void main(String[] args) {
		ArrayList<String> errorList = new ArrayList<String>();
		HashMap<String,Integer> faultList = new HashMap<String,Integer>();
		int normalTermination = 0;
        int silentDataCorruption = 0;
        int tinyVMNullReferenceException = 0;
        int javaNullPointerException = 0;
        int tinyVMOutOfMemoryException = 0;
        int javaOutOfMemoryException = 0;
        int tinyVMDivisionByZeroException = 0;
        int tinyVMInvalidField = 0;
        int javaArrayIndexOutOfBoundsException = 0;
        int unknown = 0;
        int masked = 0;
        int correctRecovery = 0;
		
        String pathToRootDirectoryForVM = args[0];
        String pathToVMJarFile = args[1];
        String pathToScript = args[2];
        int numberOfTimesToRun = Integer.parseInt(args[3]);
        String byteManPath = args[4];
        
        int progress = 0;
        int tempProgress = 0;
        
        for(int i = 0; i < numberOfTimesToRun;i++){
	        ProcessBuilder pb = new ProcessBuilder("java", "-javaagent:"+byteManPath +"\\lib\\byteman.jar=script:"+pathToScript, "-jar", pathToVMJarFile, pathToRootDirectoryForVM, ""+(int)(Math.random()*11298));
	        pb.redirectErrorStream();
	        try {
	        	tempProgress = i * 100 / numberOfTimesToRun;
	        	if(tempProgress/5 > progress/5){
	        		progress = tempProgress;
	        		System.out.println(progress + "%");
	        	}
	            Process p = pb.start();
	            
	            StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(),"");
	            StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(),"");
	            
	            errorGobbler.start();
	            outputGobbler.start();
	            
	            p.waitFor();
	            
	            errorGobbler.join();
	            outputGobbler.join();
	            
	            String errorText = errorGobbler.getString();
	            String output = outputGobbler.getString();	            
	            String returnText = "";
	            String expectedResult = "0123456789";
	            
	            if(output.contains("#")){
	            	returnText = output.split("#")[1].replace("\n", "");
	            }
	            
	            
	            String flip = identifyFault(output);
	            String fault = "";
	            int count = 0;
	            
	            if(p.exitValue() == returnValues.NORMAL.getCode()){
	            	if(returnText.contentEquals(expectedResult) && output.contains("ROLLBACK")){
	            		correctRecovery++;
	            		fault = "Recovery";
	            		errorList.add(fault+"\n"+output);
	            	}else if(returnText.contentEquals(expectedResult) && output.contains("After instruction") && !output.contains("ROLLBACK")){
	            		masked++;
	            		fault = "Masked";
	            		errorList.add("Masked:\n"+output);
	            	}else if(returnText.contentEquals(expectedResult) && !output.contains("After instruction") && !output.contains("ROLLBACK")){
	            		normalTermination++;
	            		fault = "No bitflip";
	            		errorList.add("No bitflip:\n"+output);
	            	}else if(!returnText.contentEquals(expectedResult) && output.contains("After instruction") && output.contains("ROLLBACK")){
	            		silentDataCorruption++;
	            		fault = "Silent Data Corruption";
	            		errorList.add("Silent Data Corruption:\n"+output);
	            	}else{
	            		System.out.println("No idea what went wrong here:");
	            		System.out.println(output);
	            	}
	            }else if(p.exitValue() == returnValues.JAVAFAULT.getCode()){           
	                if(errorText.contains("NullPointerException")){
	                	javaNullPointerException++;<commit_msg>Sorry, I made poop in code. This will fix<commit_after>package dk.aau.d101f14.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

public class InformationCollector {
	
	public static void main(String[] args) {
		ArrayList<String> errorList = new ArrayList<String>();
		HashMap<String,Integer> faultList = new HashMap<String,Integer>();
		int normalTermination = 0;
        int silentDataCorruption = 0;
        int tinyVMNullReferenceException = 0;
        int javaNullPointerException = 0;
        int tinyVMOutOfMemoryException = 0;
        int javaOutOfMemoryException = 0;
        int tinyVMDivisionByZeroException = 0;
        int tinyVMInvalidField = 0;
        int javaArrayIndexOutOfBoundsException = 0;
        int unknown = 0;
        int masked = 0;
        int correctRecovery = 0;
		
        String pathToRootDirectoryForVM = args[0];
        String pathToVMJarFile = args[1];
        String pathToScript = args[2];
        int numberOfTimesToRun = Integer.parseInt(args[3]);
        String byteManPath = args[4];
        
        int progress = 0;
        int tempProgress = 0;
        
        for(int i = 0; i < numberOfTimesToRun;i++){
	        ProcessBuilder pb = new ProcessBuilder("java", "-javaagent:"+byteManPath +"\\lib\\byteman.jar=script:"+pathToScript, "-jar", pathToVMJarFile, pathToRootDirectoryForVM, ""+(int)(Math.random()*11298));
	        pb.redirectErrorStream();
	        try {
	        	tempProgress = i * 100 / numberOfTimesToRun;
	        	if(tempProgress/5 > progress/5){
	        		progress = tempProgress;
	        		System.out.println(progress + "%");
	        	}
	            Process p = pb.start();
	            
	            StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(),"");
	            StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(),"");
	            
	            errorGobbler.start();
	            outputGobbler.start();
	            
	            p.waitFor();
	            
	            errorGobbler.join();
	            outputGobbler.join();
	            
	            String errorText = errorGobbler.getString();
	            String output = outputGobbler.getString();	            
	            String returnText = "";
	            String expectedResult = "0123456789";
	            
	            if(output.contains("#")){
	            	returnText = output.split("#")[1].replace("\n", "");
	            }
	            
	            
	            String flip = identifyFault(output);
	            String fault = "";
	            int count = 0;
	            
	            if(p.exitValue() == returnValues.NORMAL.getCode()){
	            	if(returnText.contentEquals(expectedResult) && output.contains("ROLLBACK")){
	            		correctRecovery++;
	            		fault = "Recovery";
	            		errorList.add(fault+"\n"+output);
	            	}else if(returnText.contentEquals(expectedResult) && output.contains("After instruction") && !output.contains("ROLLBACK")){
	            		masked++;
	            		fault = "Masked";
	            		errorList.add("Masked:\n"+output);
	            	}else if(returnText.contentEquals(expectedResult) && !output.contains("After instruction") && !output.contains("ROLLBACK")){
	            		normalTermination++;
	            		fault = "No bitflip";
	            		errorList.add("No bitflip:\n"+output);
	            	}else if(!returnText.contentEquals(expectedResult) && output.contains("After instruction")){
	            		silentDataCorruption++;
	            		fault = "Silent Data Corruption";
	            		errorList.add("Silent Data Corruption:\n"+output);
	            	}else{
	            		System.out.println("No idea what went wrong here:");
	            		System.out.println(output);
	            	}
	            }else if(p.exitValue() == returnValues.JAVAFAULT.getCode()){           
	                if(errorText.contains("NullPointerException")){
	                	javaNullPointerException++;
{'fraction_non_alphanumeric': 0.11661915974718057, 'fraction_numerical': 0.0116495228652869, 'mean_word_length': 1.9988851727982162, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4548730', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2178, 'n_words': 412}