Skip to content

Commit

Permalink
second release
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoCouto committed Mar 10, 2015
1 parent bff875e commit b0b72b6
Show file tree
Hide file tree
Showing 28 changed files with 1,017 additions and 87 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Its workflow is the following:
7. Runs an algorithm to detect methods associated with anomalous energy consumption;
8. Classify each method analyzed, and generate the result to a JSON file;

The JSON file contains data to be displayed in a sunburst diagram. That diagram can be found [here](http://bl.ocks.org/mbostock/4348373), and a version edited by us can be found [here](https://github.com/MarcoCouto/GreenDroid/tree/master/auxiliar/sunburst/)
The JSON file contains data to be displayed in a sunburst diagram. That diagram can be found [here](http://bl.ocks.org/mbostock/4348373), and a version edited by us can be found [here](https://github.com/greensoftwarelab/GreenDroid/tree/master/auxiliar/sunburst/)

# Current status

Expand Down
4 changes: 4 additions & 0 deletions build/built-jar.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Tue, 24 Feb 2015 13:44:01 +0000


C\:\\Users\\User\\Documents\\NetBeansProjects\\GreenDroid\ Analyzer=
Binary file modified build/classes/greendroid/Main.class
Binary file not shown.
Binary file modified build/classes/greendroid/ProjectAnalyser.class
Binary file not shown.
Binary file added build/classes/greendroid/project/Project.class
Binary file not shown.
Binary file modified build/classes/greendroid/result/Result.class
Binary file not shown.
Binary file modified build/classes/greendroid/result/ResultClass.class
Binary file not shown.
Binary file modified build/classes/greendroid/result/ResultPackage.class
Binary file not shown.
Binary file modified build/classes/greendroid/tools/Util.class
Binary file not shown.
Binary file added build/classes/greendroid/trace/Consumption.class
Binary file not shown.
Binary file added build/classes/greendroid/trace/TestCase.class
Binary file not shown.
Binary file added build/classes/greendroid/trace/TracedMethod.class
Binary file not shown.
Binary file modified build/classes/instrumentation/transform/InstrumentHelper.class
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
</bookmark>
</file>
</editor-bookmarks>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/C:/Users/User/Documents/NetBeansProjects/GreenDroid%20Analyzer/src/greendroid/Main.java</file>
<file>file:/C:/Users/User/Documents/NetBeansProjects/GreenDroid%20Analyzer/src/greendroid/ProjectAnalyser.java</file>
<file>file:/C:/Users/User/Documents/NetBeansProjects/GreenDroid%20Analyzer/src/greendroid/trace/TracedMethod.java</file>
<file>file:/C:/Users/User/Documents/NetBeansProjects/GreenDroid%20Analyzer/src/greendroid/trace/TestCase.java</file>
<file>file:/C:/Users/User/Documents/NetBeansProjects/GreenDroid%20Analyzer/src/greendroid/tools/Util.java</file>
</open-files>
</project-private>
10 changes: 10 additions & 0 deletions projects.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Every line describing a project must follow the same template
#name of the project,name of the package, path to the project folder (ending with a /), path to the test folder (ending with a /)

authenticator,com.google.android.apps.authenticator2,C:/Users/User/workspace/Google Authenticator/,C:/Users/User/workspace/Google Authenticator/tests/
newsblur,com.newsblur,C:/Users/User/Desktop/Thesis/App's Source Code/NewsBlur-master/clients/android/NewsBlur/,C:/Users/User/Desktop/Thesis/App's Source Code/NewsBlur-master/clients/android/NewsBlurTest/
apptracker,com.nolanlawson.apptracker,C:/Users/User/Desktop/Thesis/App's Source Code/AppTracker-master/AppTracker/,C:/Users/User/Desktop/Thesis/App's Source Code/AppTracker-master/AppTrackerTest/
chordreader,com.nolanlawson.chordreader,C:/Users/User/Desktop/Thesis/App's Source Code/ChordReaderRoot-master/ChordReader/,C:/Users/User/Desktop/Thesis/App's Source Code/ChordReaderRoot-master/ChordReaderTest/
logcat,com.nolanlawson.logcat,C:/Users/User/Desktop/Thesis/App's Source Code/Catlog-master/Catlog/,C:/Users/User/Desktop/Thesis/App's Source Code/Catlog-master/CatlogTest/
connectbot,org.connectbot,C:/Users/User/workspace/connectbot/,C:/Users/User/workspace/connectbot/tests/
#duckduckgo,com.duckduckgo.mobile.android,C:/Users/User/Desktop/Thesis/App's Source Code/duckduckgo/,C:/Users/User/Desktop/Thesis/App's Source Code/duckduckgo/tests/
141 changes: 109 additions & 32 deletions src/greendroid/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package greendroid;

import greendroid.project.Project;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -12,7 +13,11 @@
import instrumentation.transform.InstrumentHelper;
import instrumentation.util.FileUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -21,8 +26,13 @@
* @author User
*/
public class Main {
private static int extFlag = 0;

public static String tName = "_TRANSFORMED_";

//public static String configFile = "";
public static String projectsFile = "projects.csv";

private static ArrayList<Project> projects = new ArrayList<Project>();
private static LinkedList<ProjectAnalyser> analysers = new LinkedList<ProjectAnalyser>();

Expand All @@ -31,10 +41,45 @@ public class Main {

public static long averageSecond = 0;

public static void instrument(String app, String tests) throws Exception{
//InstrumentHelper helper = new InstrumentHelper(tName, workspace, app, tests);
//helper.generateTransformedProject();
//helper.generateTransformedTests();
private static void parseProjects(String csvfile) {
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
int cont = 0;
try {
br = new BufferedReader(new FileReader(csvfile));
while ((line = br.readLine()) != null) {
cont++;
// use comma as separator
if(!line.startsWith("#") && !line.isEmpty()){
String[] tokens = line.split(cvsSplitBy);
if(tokens.length != 4){
System.err.println("ERROR: Bad parsing for the projects file!!!");
System.out.println("W: Project described in line "+cont+" will not be considered!");
}else{
projects.add(new Project(tokens[0], tokens[1], tokens[2], tokens[3], tName));
}
}
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

private static void instrument(String app, String tests) throws Exception{
InstrumentHelper helper = new InstrumentHelper(tName, workspace, app, tests);
helper.generateTransformedProject();
helper.generateTransformedTests();
}

private static void executeTests(String pack, String testPack, String pathProject, String pathTests) throws IOException {
Expand All @@ -53,6 +98,15 @@ private static void executeTests(String pack, String testPack, String pathProjec

for(int i=0; i<7; i++){
System.out.println("RUNNING: "+commands[i]);
//Can't figure why the connectbot test project keeps generating a tests-debug.apk
//This 'if' is to get the only file ending in *-debug.apk
if(i == 2){
File apk;
if((apk = Util.getFileWithName(pathTests+"/bin/", "*-debug.apk")) != null){
String ax = apk.getName();
commands[i] = "adb install -r \""+pathProject+"/bin/Green-debug.apk\" && adb install -r \""+pathTests+"/bin/"+ax+"\"";
}
}
executeCommand(commands[i]);
try {
Thread.sleep(5000);
Expand All @@ -73,17 +127,38 @@ private static void executeTests(String pack, String testPack, String pathProjec

}

public static void executeCommand(String command) throws IOException{
private static void executeCommand(String command){
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd /c "+command);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

String line=null;

while((line=input.readLine()) != null) {
System.out.println(line);
try {
Process pr = rt.exec("cmd /c "+command);
BufferedReader input;
BufferedReader errors;
if(extFlag == 0){
input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
errors = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
}else{
errors = new BufferedReader(new InputStreamReader(pr.getInputStream()));
input = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
}
String line=null, err=null;
while(((line=input.readLine()) != null) || ((err=errors.readLine()) != null)) {
if(line != null){
System.out.println(line);
}

if(err != null){
System.out.println(err);
}
}

errors.close();
input.close();

pr.waitFor();

} catch (Exception e) {
e.printStackTrace();
}
input.close();
}

private static void runAnalyser(String name, String pack) throws IOException {
Expand All @@ -98,26 +173,23 @@ private static void extractFiles() throws IOException {

public static void main(String[] args){
workspace = "C:/Users/User/workspace/";
resFolder = "D:/tests/";
//projects.add(new Project("authenticator", "com.google.android.apps.authenticator2", "C:/Users/User/workspace/Google Authenticator/", "C:/Users/User/workspace/Google Authenticator/tests/", tName));
//projects.add(new Project("newsblur", "com.newsblur", "C:/Users/User/Desktop/Thesis/App's Source Code/NewsBlur-master/clients/android/NewsBlur/", "C:/Users/User/Desktop/Thesis/App's Source Code/NewsBlur-master/clients/android/NewsBlurTest/", tName));
//projects.add(new Project("apptracker", "com.nolanlawson.apptracker", "C:/Users/User/Desktop/Thesis/App's Source Code/AppTracker-master/AppTracker/", "C:/Users/User/Desktop/Thesis/App's Source Code/AppTracker-master/AppTrackerTest/", tName));
//projects.add(new Project("chordreader", "com.nolanlawson.chordreader", "C:/Users/User/Desktop/Thesis/App's Source Code/ChordReaderRoot-master/ChordReader/", "C:/Users/User/Desktop/Thesis/App's Source Code/ChordReaderRoot-master/ChordReaderTest/", tName));
//projects.add(new Project("logcat", "com.nolanlawson.logcat", "C:/Users/User/Desktop/Thesis/App's Source Code/Catlog-master/Catlog/", "C:/Users/User/Desktop/Thesis/App's Source Code/Catlog-master/CatlogTest/", tName));
projects.add(new Project("connectbot", "org.connectbot", "C:/Users/User/workspace/connectbot/", "C:/Users/User/workspace/connectbot/tests/", tName));
resFolder = "D:\\tests\\";

//projects.add(new Project("benchmark", "org.zeroxlab.zeroxbenchmark", "C:/Users/User/workspace/bench/", "C:/Users/User/workspace/bench/tests/", tName));

parseProjects(projectsFile);
System.out.println("GREENDROID - Testing Framework for Android Applications\n");
System.out.println("Using "+projects.size()+" projects to be analyzed");

try{
//instrument();
if(projects.size() > 0){
try{
/* //instrument();
System.out.println("INSTRUMENTATION");
for(Project p : projects){
System.out.println("Instrumenting "+p.getName()+" project...");
instrument(p.getPathProject(), p.getPathTests());
System.out.println("DONE!");
}

/*
//executeTests();
System.out.println("TEST EXECUTION");
for(Project p : projects){
Expand All @@ -128,29 +200,34 @@ public static void main(String[] args){
//extractFiles();
System.out.println("FILE EXTRACTION");
//extractFiles();
extFlag = 1;
extractFiles();
extFlag = 0;
System.out.println("DONE");
/*
//getFinalResults();
System.out.println("ANALIZE RESULTS");
/**/
//This section runs the analyzer for each project,
// //parsing the trace files and generating consumption per second
/**/ System.out.println("ANALIZE RESULTS");
for(Project p : projects){
System.out.println("Analyzing "+p.getName()+" project");
runAnalyser(p.getName(), p.getPackage());
System.out.println("DONE!");
}
averageSecond = Util.readLongsFromFile("D:/meansSecond.txt");
List<Long> means = Util.readLongsFromFile("D:/meansSecond.txt");
averageSecond = Util.average(means);
System.out.println("Average Consumption p/ second: "+averageSecond);
/**/
System.out.println("GETTING FINAL RESULTS");
for(ProjectAnalyser pa : analysers){
System.out.println("Generating results for ");
pa.createFinalResults();
System.out.println("DONE!");
}*/
//load the results???
}
//load the results???*/
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}


Expand Down
Loading

0 comments on commit b0b72b6

Please sign in to comment.