From 0642a244d18dcd4a0d3a13d0695fd603e46e3079 Mon Sep 17 00:00:00 2001 From: greatim Date: Tue, 15 Jul 2014 11:18:21 +0900 Subject: [PATCH] COMM: bug fix in communicator bug fix for app inst, and md5sum comparison Change-Id: I37a2cd335311d145300dd9cb31781ae36daced6b Signed-off-by: greatim --- .../swap/communicator/Communicator30.java | 97 +++++++++------------- 1 file changed, 41 insertions(+), 56 deletions(-) diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java index fa06a32..6bbe871 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java @@ -204,8 +204,7 @@ public class Communicator30 extends BaseCommunicator { } try { - printWriter = new PrintWriter( - new BufferedWriter(new FileWriter(logPath)), true); + printWriter = new PrintWriter(new BufferedWriter(new FileWriter(logPath)), true); } catch (IOException e) { e.printStackTrace(); } @@ -215,8 +214,7 @@ public class Communicator30 extends BaseCommunicator { Thread dataThread = new Thread(null, new DataChannelThread(), AnalyzerConstants.COMMUNICATOR_RECEIVE_THREAD); // start message send - HostResult result = handleControlMessage( - GlobalInformation.getCurrentDeviceInfo(), ret); + HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), ret); DA_LOG.performance("TEST", "Start Trace", "Make and Send start message"); // FIX @@ -228,8 +226,7 @@ public class Communicator30 extends BaseCommunicator { if (result.isSuccess()) { if (!isCorrectAck(MSG_START_ACK, result)) { HostResult failResult = HostResult.ERR_MSG_START_FAIL; - failResult.setMessage(ErrorCode.getError(getReturnId(result.getRet())) - .toString()); + failResult.setMessage(ErrorCode.getError(getReturnId(result.getRet())).toString()); DACommunicator.setRunning(false); dataThread = null; return failResult; @@ -296,13 +293,14 @@ public class Communicator30 extends BaseCommunicator { // TODO : make new protocol field or message for launched app and // instrucmented app - if (!app.getAppId().equals(app.getPackageId())) { + if (!app.getAppId().startsWith(app.getPackageId())) { continue; } BinaryInfo binInfo = AnalyzerManager.getProject().getDeviceStatusInfo() .getBinaryInfo(app.getExecPath()); - if (binInfo.getTempBinaryPath() == null) { + String temppath = binInfo.getTempBinaryPath(); + if (temppath == null) { // this means the app binary does not exist in device continue; } @@ -327,7 +325,7 @@ public class Communicator30 extends BaseCommunicator { appInst.setExecutablePath(app.getExecPath()); DA_LOG.debug("Set execute path : " + app.getExecPath()); - List symbols = app.getSymbols(binInfo.getTempBinaryPath()); + List symbols = app.getSymbols(temppath); List functionInstList = appInst.getFunctionInstList(); int size = (symbols == null) ? 0 : symbols.size(); @@ -434,13 +432,12 @@ public class Communicator30 extends BaseCommunicator { } @Override - public HostResult sendConfigurationMessage(DeviceInfo devInfo, int type, - String message) { + public HostResult sendConfigurationMessage(DeviceInfo devInfo, int type, String message) { // send config message byte[] config = ByteUtil.toBytes(AnalyzerConstants.MSG_CONFIG); RunTimeConfiguration rt = new RunTimeConfiguration(); - rt.setFeatures(ConfigureManager.getInstance().getConfiguration(devInfo), - ConfigureManager.getInstance().getPreConfiguration(devInfo)); + rt.setFeatures(ConfigureManager.getInstance().getConfiguration(devInfo), ConfigureManager + .getInstance().getPreConfiguration(devInfo)); rt.setSystemTracePeriod(ConfigureManager.getInstance().getSystemPeriod()); rt.setSamplingPeriod(ConfigureManager.getInstance().getSamplingPeriod()); byte[] rtByte = rt.toByteStream(); @@ -483,8 +480,8 @@ public class Communicator30 extends BaseCommunicator { byte[] stop = ByteUtil.toBytes(AnalyzerConstants.MSG_STOP_SWAP); int length = 0; byte[] stopMsg = ByteUtil.getByte(stop, length); - HostResult result = handleControlMessage( - GlobalInformation.getCurrentDeviceInfo(), stopMsg); + HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), + stopMsg); if (result.isSuccess()) { if (isCorrectAck(MSG_STOP_ACK, result)) { @@ -602,8 +599,7 @@ public class Communicator30 extends BaseCommunicator { HostResult result = HostResult.SUCCESS; Socket controlSock = null; try { - controlSock = new Socket(CommonConstants.LOCAL_HOST, - CommunicatorUtils.LOCAL_PORT); + controlSock = new Socket(CommonConstants.LOCAL_HOST, CommunicatorUtils.LOCAL_PORT); controlSock.setSoTimeout(AnalyzerConstants.CONTROL_SOCKET_TIMEOUT); controlSock.setReuseAddress(true); controlSock.setTcpNoDelay(true); @@ -631,8 +627,7 @@ public class Communicator30 extends BaseCommunicator { HostResult result = HostResult.SUCCESS; Socket dataSock = null; try { - dataSock = new Socket(CommonConstants.LOCAL_HOST, - CommunicatorUtils.LOCAL_PORT); + dataSock = new Socket(CommonConstants.LOCAL_HOST, CommunicatorUtils.LOCAL_PORT); dataSock.setSoTimeout(AnalyzerConstants.DATA_SOCKET_TIMEOUT); dataSock.setReuseAddress(true); dataSock.setTcpNoDelay(true); @@ -718,8 +713,7 @@ public class Communicator30 extends BaseCommunicator { return GlobalInformation.getCurrentDeviceInfo().getDataSock(); } - private void processTargetInfo(byte[] payload, int index, - DeviceStatusInfo tInfo) { + private void processTargetInfo(byte[] payload, int index, DeviceStatusInfo tInfo) { long systemMemorySize = 0; long storageSize = 0; int bluetoothSupport = 0; @@ -939,8 +933,7 @@ public class Communicator30 extends BaseCommunicator { size = size - exSize; libInst = ByteUtil.getByte(libInst, binaryPath, size); for (int i = 0; i < size; i++) { - libInst = ByteUtil.getByte(libInst, functionInstList.get(i) - .toByteStream()); + libInst = ByteUtil.getByte(libInst, functionInstList.get(i).toByteStream()); } } count = count - failedCount; @@ -949,8 +942,7 @@ public class Communicator30 extends BaseCommunicator { msg = ByteUtil.getByte(msg, length, libInst); // ByteUtils.printByteArrayForStart(msg); - HostResult result = handleControlMessage( - GlobalInformation.getCurrentDeviceInfo(), msg); + HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), msg); int ackMsg = AnalyzerConstants.MSG_SWAP_INST_ADD_ACK; if (messageId == AnalyzerConstants.MSG_SWAP_INST_REMOVE) { @@ -978,11 +970,10 @@ public class Communicator30 extends BaseCommunicator { String targetPath = binPaths.get(i); sendBin = ByteUtil.getByte(sendBin, targetPath); } - + int length = sendBin.length; byte[] msg = ByteUtil.getByte(AnalyzerConstants.MSG_BINARY_INFO, length, sendBin); - HostResult result = handleControlMessage( - GlobalInformation.getCurrentDeviceInfo(), msg); + HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), msg); if (!result.isSuccess() || !isCorrectAck(MSG_BINARY_INFO_ACK, result)) { return HostResult.ERR_BIN_INFO_GET_FAIL; @@ -1010,8 +1001,7 @@ public class Communicator30 extends BaseCommunicator { for (int i = 0; i < count; i++) { String targetPath = targetPaths.get(i); - BinaryInfo binInfo = curDevice.getDeviceStatusInfo() - .getBinaryInfo(targetPath); + BinaryInfo binInfo = curDevice.getDeviceStatusInfo().getBinaryInfo(targetPath); int binaryType = ByteUtil.toInt(payload, index); index += INT_SIZE; @@ -1025,19 +1015,18 @@ public class Communicator30 extends BaseCommunicator { outBinaries.add(binInfo); if (binaryType < 0) { + // binary does not exist in target return; } - String[] splitLocalBinaryPath = localBinaryPath - .split(CommonConstants.SLASH); + String[] splitLocalBinaryPath = localBinaryPath.split(CommonConstants.SLASH); if (CommonUtil.isLinux()) { // check local binary path validation // host has no binary file - pull binary file from target - if (splitLocalBinaryPath.length < 3 - || !(new File(localBinaryPath)).exists()) { - localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH - + File.separator + getFileName(targetPath); + if (splitLocalBinaryPath.length < 3 || !(new File(localBinaryPath)).exists()) { + localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + + getFileName(targetPath); result = pullTheFile(targetPath, localBinaryPath); if (result.isSuccess()) { binInfo.setTempBinaryPath(localBinaryPath); @@ -1048,21 +1037,19 @@ public class Communicator30 extends BaseCommunicator { try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec(new String[] { - AnalyzerShellCommands.CMD_MD_5_SUM, - localBinaryPath }); + AnalyzerShellCommands.CMD_MD_5_SUM, localBinaryPath }); process.waitFor(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(process.getInputStream())); - BufferedReader error = new BufferedReader( - new InputStreamReader(process.getErrorStream())); + BufferedReader reader = new BufferedReader(new InputStreamReader( + process.getInputStream())); + BufferedReader error = new BufferedReader(new InputStreamReader( + process.getErrorStream())); String line = reader.readLine(); String errorStr = error.readLine(); if (null == line) { DA_LOG.debug("host md5sum get failed : " + errorStr); result = HostResult.ERR_BIN_INFO_GET_FAIL; } else { - String[] splitResult = line.trim().split( - CommonConstants.SPACE); + String[] splitResult = line.trim().split(CommonConstants.SPACE); localHashCode = new String(splitResult[0]); } } catch (IOException e) { @@ -1073,23 +1060,21 @@ public class Communicator30 extends BaseCommunicator { result = HostResult.ERR_BIN_INFO_GET_FAIL; } - if (localHashCode != null) { - String targetHashCode = binInfo.getMd5sumValue(); - if (0 != targetHashCode.compareTo(localHashCode)) { - localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH - + File.separator + getFileName(targetPath); - result = pullTheFile(targetPath, localBinaryPath); - if (result.isSuccess()) { - binInfo.setTempBinaryPath(localBinaryPath); - } - } else { + if (localHashCode == null + || 0 != localHashCode.compareTo(binInfo.getMd5sumValue())) { + localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + + getFileName(targetPath); + result = pullTheFile(targetPath, localBinaryPath); + if (result.isSuccess()) { binInfo.setTempBinaryPath(localBinaryPath); } + } else { + binInfo.setTempBinaryPath(localBinaryPath); } } } else { // if not linux - localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH - + File.separator + getFileName(targetPath); + localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + + getFileName(targetPath); result = pullTheFile(targetPath, localBinaryPath); if (result.isSuccess()) { binInfo.setTempBinaryPath(localBinaryPath); -- 2.7.4