[Title] Add test option
authorshihyun <shihyun@shihyun-Samsung-Desktop-System.(none)>
Fri, 26 Jul 2013 02:17:07 +0000 (11:17 +0900)
committershihyun <shihyun@shihyun-Samsung-Desktop-System.(none)>
Fri, 26 Jul 2013 02:17:07 +0000 (11:17 +0900)
[Desc.]
* Save test result in "tizen-sdk-data/test/install-manager/{date}.txt"

InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java
InstallManager_java/src/org/tizen/installmanager/core/OptionConstant.java
InstallManager_java/src/org/tizen/installmanager/core/Options.java
InstallManager_java/src/org/tizen/installmanager/core/Performance.java
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java

index abda8c4..de99c59 100644 (file)
@@ -26,11 +26,17 @@ public class InstallManagerConstants {
        final static public String WINDOWS_DEFAULT_DATA_PATH = "C:\\tizen-sdk-data";
        
        //sdk configuration file
+       final static public String SDK_DATA_DIR_NAME = "tizen-sdk-data";
+       final static public String SDK_DATA_PATH = getSDKDataPath();
        final static public String SDK_CONFIGURATION_DIR = ".info";
        final static public String SDK_INFORMATION_FILE_NAME = "sdk.info";
        final static public String SDK_INSTALLED_PACKAGE_LIST_FILE = "installedpackage.list";
        final static public String SDK_INSTALLED_PACKAGE_LIST_PATH = PathUtil.get(SDK_CONFIGURATION_DIR, SDK_INSTALLED_PACKAGE_LIST_FILE);
        
+       //test file
+       final static public String SDK_TEST_DIR_NAME = "test";
+       final static public String SDK_INSTALLMANAGER_TEST_RESULT_DIR_PATH = PathUtil.get(SDK_DATA_PATH, SDK_TEST_DIR_NAME, INSTALLMANAGER_DIRECTORY_NAME);
+       
        
        static String getInstallManagerBinaryName() {
                if (Platform.isLinux()) {
@@ -44,6 +50,16 @@ public class InstallManagerConstants {
                }
        }
        
+       static String getSDKDataPath() {
+               if (Platform.isLinux() || Platform.isMacOS()) {
+                       return PathUtil.getFromHome(SDK_DATA_DIR_NAME);
+               } else if (Platform.isWindows()) {
+                       return PathUtil.getFromAppData(SDK_DATA_DIR_NAME);
+               } else {
+                       throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+               }
+       }
+       
        static String getIntallManagerShortcutImageName() {
                if (Platform.isLinux()) {
                        return "tizen-sdk-installmanager.png";
index f1668f0..5c5a7b2 100644 (file)
@@ -3,6 +3,8 @@ package org.tizen.installmanager.core;
 public class OptionConstant {
        //Option naming
        public final static String OPTION_DISTRIBUTION = "-distribution";
+       public final static String OPTION_INIT_TEST = "-initTest";
+       public final static String OPTION_TEST = "-test";
        
        //Option error message
        public final static String MSG_DISTRIBUTION_NOT_PROVIDED = "Distribution setting is missing. Use the '-distribution <distribution>' option.";
index 27d0dc6..004e682 100644 (file)
@@ -117,6 +117,13 @@ public class Options {
        public static boolean printDepGraph = false;
        
        /**
+        * Initialize and exit install-manager for test.
+        */
+       public static boolean doInitTest = false;
+       
+       public static boolean doTest = false;
+       
+       /**
         * Use Snapshot file.
         */
        public static boolean snapshot = false;
@@ -327,6 +334,10 @@ public class Options {
                                        Log.err("-distribution requires distribution description");
                                        throw new IMFatalException(OptionConstant.MSG_DISTRIBUTION_NOT_PROVIDED);
                                }
+                       } else if (arg.equals(OptionConstant.OPTION_INIT_TEST)) {
+                               doInitTest = true;
+                       } else if (arg.equals(OptionConstant.OPTION_TEST)) {
+                               doTest = true;
                        } else if (arg.equals("-removeOldSDK")) {
                                doRemoveOldSDK = true;
                        } else if (arg.equals("-property")) {
index a8ce9de..b6d9875 100644 (file)
@@ -1,8 +1,14 @@
 package org.tizen.installmanager.core;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.tizen.installmanager.lib.Log;
+import org.tizen.installmanager.util.PathUtil;
 
 public class Performance {
        private static Date imStartTime = null;
@@ -42,6 +48,59 @@ public class Performance {
                }
        }
        
+       public static void printTestResult() {
+               //get file name of test result
+               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+               String testFileName = formatter.format(imStartTime) + ".txt";
+               
+               String testResultFilePath = PathUtil.get(InstallManagerConstants.SDK_INSTALLMANAGER_TEST_RESULT_DIR_PATH, testFileName);
+               File testResultFile = new File(testResultFilePath);
+               
+               if (!testResultFile.getParentFile().exists()) {
+                       testResultFile.getParentFile().mkdirs();
+               }
+               
+               BufferedWriter out = null;
+               try {
+                       out = new BufferedWriter(new FileWriter(testResultFile));
+                       
+                       out.write("*** InstallManager performance test ***");
+                       out.newLine();
+                       out.newLine();
+                       out.write("The installmanager start time\t: " + imStartTime);
+                       out.newLine();
+                       out.write("The installmanager end time\t: " + imEndTime);
+                       out.newLine();
+                       out.write("The installation start time\t: " + installationStartTime);
+                       out.newLine();
+                       out.write("The installation end time\t: " + installationEndTime);
+                       out.newLine();
+                       out.newLine();
+                       
+                       long progressSecond = getProgressTimeOfInstallation()/1000;
+                       
+                       if (progressSecond >= 0) {
+                               out.write("* Total time to install : About " + progressSecond/60 + " minutes"
+                                               +"(" + progressSecond + " seconds)");
+                               out.newLine();
+                       } else {
+                               out.write("* Total time to install : Installation fail");
+                               out.newLine();
+                       }
+                                                       
+               } catch (IOException e) {
+                       Log.ExceptionLog(e);
+               }
+               
+               if (out != null) {
+                       try {
+                               out.close();
+                       } catch (IOException e) {
+                               Log.ExceptionLog(e);
+                       }
+               }
+       }
+       
        private static long getProgressTimeOfInstallation() {
                if (installationStartTime == null || installationEndTime == null) {
                        return -1;
index 55ce20e..fb743c7 100644 (file)
@@ -170,7 +170,9 @@ public class InstallManagerWindow extends ApplicationWindow {
                shell.getDisplay().asyncExec(new Runnable(){
                        public void run() {                             
                                //initialize installmanager
-                               progressbar.updateName("Connecting to package server.\nIt may take a minute...");
+                               if (!Options.doInitTest) {
+                                       progressbar.updateName("Connecting to package server.\nIt may take a minute...");
+                               }
                                
                                shell.getDisplay().asyncExec(new Runnable() {
                                        public void run() {
@@ -180,12 +182,16 @@ public class InstallManagerWindow extends ApplicationWindow {
                                });
                                
                                //init end
-                               progressbar.finish();
+                               if (!Options.doInitTest) {
+                                       progressbar.finish();
+                               }
                        }
                });
                
                if (!shell.isDisposed()) {
-                       progressbar.open();
+                       if (!Options.doInitTest) {
+                               progressbar.open();
+                       }
                }
 
                Log.log("Window init end");
@@ -866,6 +872,10 @@ public class InstallManagerWindow extends ApplicationWindow {
                        
                        window.init();
                        
+                       if (Options.doInitTest) {
+                               System.exit(0);
+                       }
+                       
                        Log.log("after init");
                        if (Options.checkPackageUpdate) {
                                checkMetaPackageUpdate();
@@ -921,6 +931,10 @@ public class InstallManagerWindow extends ApplicationWindow {
                        Performance.setIMEndTime();
                        Performance.printToLogFile();
                        
+                       if (Options.doTest) {
+                               Performance.printTestResult();
+                       }
+                       
                        Log.LogTitle("Installmanager finish");
                        Log.close();