From 5aa8b31da6f7b579151f57947922b36082df6981 Mon Sep 17 00:00:00 2001 From: zlovarp <arpad.lovassy@semcon.com> Date: Tue, 26 Jan 2021 00:51:19 +0100 Subject: [PATCH] fixed comment, removed import, indentation, removed extra ws Signed-off-by: zlovarp <arpad.lovassy@semcon.com> --- .../TITAN_Executor_API/create_jni_header.sh | 2 +- .../titan/executorapi/HostController.java | 24 +- .../executorapi/IJniExecutorObserver.java | 11 +- .../titan/executorapi/JniExecutor.java | 212 +++++++++--------- .../JniExecutorJniLoadException.java | 4 +- .../eclipse/titan/executorapi/util/Log.java | 90 ++++---- .../titan/executorapi/util/StringUtil.java | 38 ++-- 7 files changed, 190 insertions(+), 191 deletions(-) diff --git a/titan_executor_api/TITAN_Executor_API/create_jni_header.sh b/titan_executor_api/TITAN_Executor_API/create_jni_header.sh index b16202f0d..d871376da 100755 --- a/titan_executor_api/TITAN_Executor_API/create_jni_header.sh +++ b/titan_executor_api/TITAN_Executor_API/create_jni_header.sh @@ -12,7 +12,7 @@ ############################################################################### # Creates C++ header from the Java code for Java to C++ JNI function calls. -# This must run if any of the native Java methods change (in org.eclipse.titan.executor.jni.JNIMiddleWare). +# This must be run if any of the native Java methods change (in org.eclipse.titan.executor.jni.JNIMiddleWare). # A C++ function header is generated for each native Java method. # Native Java method: declared with native keyword without implementation # This script generates these files into ../../JNI/ directory: diff --git a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/HostController.java b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/HostController.java index 4681a52a1..a672b493e 100644 --- a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/HostController.java +++ b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/HostController.java @@ -20,9 +20,9 @@ import org.eclipse.titan.executorapi.exception.JniExecutorIllegalArgumentExcepti * Contains the data describing a Host Controller. */ public final class HostController { - + // Exception texts - + /** Used by the constructor */ private static final String EXCEPTION_TEXT_ILLEGAL_ARG_WORKINGDIR_NULL = "Working directory is null"; /** Used by the constructor */ @@ -31,17 +31,17 @@ public final class HostController { private static final String EXCEPTION_TEXT_ILLEGAL_ARG_WORKINGDIR_NOT_EXIST = "Working directory does NOT exists"; /** Used by the constructor */ private static final String EXCEPTION_TEXT_ILLEGAL_ARG_EXECUTABLE_NOT_EXIST = "Executable does NOT exists"; - + /** * The name of the host, it can be null, default: null (localhost) */ private String mHost = null; - + /** * The working directory to use when executing commands */ private String mWorkingDirectory; - + /** * The executable if the Host Controller. * This executable is started (with 2 parameters: MC host, MC port) @@ -66,7 +66,7 @@ public final class HostController { } else if ( aExecutable == null ) { throw new JniExecutorIllegalArgumentException( EXCEPTION_TEXT_ILLEGAL_ARG_EXECUTABLE_NULL ); } - + if ( isLocalhost(aHost) ) { // if working directory directory is local, it must exist final File workingDir = new File(aWorkingdirectory); @@ -81,12 +81,12 @@ public final class HostController { throw new JniExecutorIllegalArgumentException( EXCEPTION_TEXT_ILLEGAL_ARG_EXECUTABLE_NOT_EXIST ); } } - + this.mHost = aHost; this.mWorkingDirectory = aWorkingdirectory; this.mExecutable = aExecutable; } - + public String getHost() { return mHost; } @@ -115,10 +115,10 @@ public final class HostController { commandSb.append( mHost ); commandSb.append( " " ); } - + // local host // cd %Workingdirectory; %Executable %MCHost %MCPort - + commandSb.append( "cd " ); commandSb.append( mWorkingDirectory ); commandSb.append( "; ./" ); @@ -129,7 +129,7 @@ public final class HostController { commandSb.append( aMcPort ); return commandSb.toString(); } - + /** * Checks if the host name is localhost * @param aHostName the host name, it can be IP address, it can be null @@ -142,7 +142,7 @@ public final class HostController { "localhost".equalsIgnoreCase( aHostName ) || "0.0.0.0".equalsIgnoreCase( aHostName ) || "NULL".equalsIgnoreCase( aHostName ) - ); + ); } } diff --git a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/IJniExecutorObserver.java b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/IJniExecutorObserver.java index 7b8d72db1..0f11a0add 100644 --- a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/IJniExecutorObserver.java +++ b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/IJniExecutorObserver.java @@ -12,7 +12,6 @@ ******************************************************************************/ package org.eclipse.titan.executorapi; -import java.util.List; import java.util.Map; import org.eclipse.titan.executor.jni.McStateEnum; @@ -24,7 +23,7 @@ import org.eclipse.titan.executor.jni.VerdictTypeEnum; * @see JniExecutor */ public interface IJniExecutorObserver { - + /** * Notification about status change. It also means, that the asynchronous request is finished successfully, if aNewState is the final state. * @param aNewState the new MC state @@ -41,20 +40,20 @@ public interface IJniExecutorObserver { /** * Notification callback, information comes from MC * @param aTime timestamp - * @param aSource source, the machine identifier of MC + * @param aSource source, the machine identifier of MC * @param aSeverity message severity * @param aMsg message text */ void notify(final Timeval aTime, final String aSource, final int aSeverity, final String aMsg); - + /** * Verdict notification, that comes after execution of a testcase. * If a test control is executed, this notification is sent multiple times after each testcase. * @param aTestcase name of the testcase * @param aVerdictType verdict type - */ + */ void verdict( final String aTestcase, final VerdictTypeEnum aVerdictType ); - + /** * Verdict statistics notification, that comes after executing all the testcases after exit MTC. * This notification is sent only once for a MTC session. diff --git a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/JniExecutor.java b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/JniExecutor.java index 4b401f3a1..07544bc4d 100644 --- a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/JniExecutor.java +++ b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/JniExecutor.java @@ -88,9 +88,9 @@ import org.eclipse.titan.executorapi.util.Log; * <img src="../../../../../doc/uml/TITAN_Executor_API_state_diagram_simple.png"/> */ public class JniExecutor implements IJNICallback { - + // Exception texts - + /** Used by checkConnection() */ private static final String EXCEPTION_TEXT_WRONG_STATE_CONNECTED = "Executor is already initialized."; /** Used by checkConnection() */ @@ -99,7 +99,7 @@ public class JniExecutor implements IJNICallback { private static final String EXCEPTION_TEXT_WRONG_STATE_PART_1 = "Method cannot be called in this state. Current state: "; /** Used by buildWrongStateMessage() */ private static final String EXCEPTION_TEXT_WRONG_STATE_PART_2 = ", expected state(s): "; - + /** Used by setConfigFileName() */ private static final String EXCEPTION_TEXT_ILLEGAL_ARG_CFG_FILENAME_NULL = "Configuration file name is null."; /** Used by setConfigFileName() */ @@ -112,10 +112,10 @@ public class JniExecutor implements IJNICallback { private static final String EXCEPTION_TEXT_ILLEGAL_ARG_TEST_CASE_NAME_NULL_OR_EMPTY = "Test case name is null or empty."; /** Used by executeCfg() */ private static final String EXCEPTION_TEXT_ILLEGAL_ARG_TEST_CFG_INDEX_OUT_OF_BOUND = "Test index is out of bound."; - + /** Used by startSession() */ private static final String EXCEPTION_TEXT_START_SESSION = "Start session failed. Error code: "; - + // Error texts /** Used by runCommand() */ @@ -127,14 +127,14 @@ public class JniExecutor implements IJNICallback { /** Used by runCommand() */ private static final String ERROR_TEXT_RUN_COMMAND_INTERRUPTED = "The following command is interrupted: "; - + /** * Default config string for JNIMiddleWare.configure(). This is used, if {@link #setConfigFileName(String)} is not called. */ private static final String DEFAULT_CONFIG_STRING = "//This part was added by the TITAN Executor API.\n" + - "[LOGGING]\n" + - "LogFile := \"./../log//%e.%h-part%i-%r.%s\"\n"; - + "[LOGGING]\n" + + "LogFile := \"./../log//%e.%h-part%i-%r.%s\"\n"; + /** * Default TCP listen port. TCP listen port is needed as an input parameter to start a new session. */ @@ -145,12 +145,12 @@ public class JniExecutor implements IJNICallback { * NULL is translated to 0.0.0.0 when it is sent to MainController */ private static final String DEFAULT_LOCAL_HOST_ADDRESS = "NULL"; - + /** * JNI middleware instance. OWNED */ private final JNIMiddleWare mJniMw; - + /** * API observer for notifications and callbacks. NOT OWNED */ @@ -162,19 +162,19 @@ public class JniExecutor implements IJNICallback { * -1 means uninitialized/invalid value */ private int mMcPort = -1; - + /** * Local host address. It is needed as an input parameter to start a new HC. * Default value: NULL, which is translated to 0.0.0.0 when it is sent to MainController */ private String mMcHost = DEFAULT_LOCAL_HOST_ADDRESS; - + /** * List of host controllers, which are started and connected with MainController by {@link #startHostControllers()}. OWNED * @see #startHostControllers() */ private List<HostController> mHostControllers = null; - + /** * true, if {@link #setConfigFileName(String)} is called, so config file is pre-processed by MainController, * and the result config data is stored in MC. @@ -185,7 +185,7 @@ public class JniExecutor implements IJNICallback { * in this class (private static final ... DEFAULT_*) */ private boolean mCfgFilePreprocessed = false; - + /** * true, if {@link #shutdownSession()} is called, false otherwise. * <p> @@ -194,12 +194,12 @@ public class JniExecutor implements IJNICallback { * and we need to remember that during the whole process. */ private boolean mShutdownRequested = false; - + /** * Lock object for waitForCompletion() */ private final Object mLockCompletion = new Object(); - + /** * Pattern for verdict, that comes as a notification after execution of a testcase. * If a test control is executed, this notification is sent multiple times after each testcase. @@ -212,12 +212,12 @@ public class JniExecutor implements IJNICallback { */ private static final Pattern PATTERN_VERDICT = Pattern.compile("Test case (.*) finished\\. Verdict: (none|pass|inconc|fail|error)"); - + // Group indexes for this pattern // It is stored here, because group indexes must be synchronized with the pattern. private static final int PATTERN_VERDICT_GROUP_INDEX_TESTCASE = 1; private static final int PATTERN_VERDICT_GROUP_INDEX_VERDICTTYPENAME = 2; - + /** * Pattern for dynamic testcase error, that comes as a notification after unsuccessful execution of a testcase. * If a test control is executed, this notification is sent multiple times after each testcase. @@ -228,12 +228,12 @@ public class JniExecutor implements IJNICallback { */ private static final Pattern PATTERN_DYNAMIC_TESTCASE_ERROR = Pattern.compile("Dynamic test case error: (.*)"); - + // Group indexes for this pattern // It is stored here, because group indexes must be synchronized with the pattern. private static final int PATTERN_DYNAMIC_TESTCASE_ERROR_GROUP_INDEX_ERROR_TEXT = 1; - - + + /** * Pattern for verdict statistics, that comes as a notification after executing all the testcases after exit MTC. * This notification is sent only once for a MTC session. @@ -251,7 +251,7 @@ public class JniExecutor implements IJNICallback { + "(\\d+) inconc[^,]*, " + "(\\d+) fail[^,]*, " + "(\\d+) error.*"); - + // Group indexes for this pattern // It is stored here, because group indexes must be synchronized with the pattern. private static final int PATTERN_VERDICT_STATS_GROUP_INDEX_NONE = 1; @@ -259,7 +259,7 @@ public class JniExecutor implements IJNICallback { private static final int PATTERN_VERDICT_STATS_GROUP_INDEX_INCONC = 3; private static final int PATTERN_VERDICT_STATS_GROUP_INDEX_FAIL = 4; private static final int PATTERN_VERDICT_STATS_GROUP_INDEX_ERROR = 5; - + /** * Pattern for error outside of test cases, that comes as a notification after executing all the testcases after exit MTC. * This notification is sent only once for a MTC session after PATTERN_VERDICT_STATS. @@ -272,11 +272,11 @@ public class JniExecutor implements IJNICallback { */ private static final Pattern PATTERN_ERRORS_OUTSIDE_OF_TESTCASES = Pattern.compile("Number of errors outside test cases: (\\d+)"); - + // Group indexes for this pattern // It is stored here, because group indexes must be synchronized with the pattern. private static final int PATTERN_ERRORS_OUTSIDE_OF_TESTCASES_GROUP_INDEX_ERRORS = 1; - + /** * Pattern for overall verdict, that comes as a notification after executing all the testcases after exit MTC. * This notification is sent only once for a MTC session after PATTERN_VERDICT_STATS and PATTERN_ERRORS_OUTSIDE_OF_TESTCASES (optional). @@ -287,19 +287,19 @@ public class JniExecutor implements IJNICallback { */ private static final Pattern PATTERN_OVERALL_VERDICT = Pattern.compile("Test case (.*) finished\\. Verdict: (none|pass|inconc|fail|error)"); - + // Group indexes for this pattern // It is stored here, because group indexes must be synchronized with the pattern. private static final int PATTERN_OVERALL_VERDICT_GROUP_INDEX_NUMBER_OF_TESTCASE = 1; private static final int PATTERN_OVERALL_VERDICT_GROUP_INDEX_VERDICTTYPENAME = 2; - + /** * Private constructor, because it is a singleton. */ private JniExecutor() { mJniMw = new JNIMiddleWare(this); } - + /** * Lazy holder for the singleton (Bill Pugh solution) * Until we need an instance, the holder class will not be initialized until required and you can still use other static members of the singleton class. @@ -309,7 +309,7 @@ public class JniExecutor implements IJNICallback { /** Singleton instance */ private static final JniExecutor mInstance = new JniExecutor(); } - + /** * @return the singleton instance */ @@ -323,7 +323,7 @@ public class JniExecutor implements IJNICallback { if ( mShutdownRequested ) { continueShutdown( aState ); } - + observerStatusChanged( aState ); Log.fo(); } @@ -345,7 +345,7 @@ public class JniExecutor implements IJNICallback { } catch (Exception e) { timestamp = new Timeval(); } - + final String source = n[2]; int severity; try { @@ -353,7 +353,7 @@ public class JniExecutor implements IJNICallback { } catch (Exception e) { severity = 0; } - + final String message = n[4]; notifyCallback(timestamp, source, severity, message ); } @@ -376,7 +376,7 @@ public class JniExecutor implements IJNICallback { public final Object getLock() { return mJniMw.getLock(); } - + /** * Gets connection state. SYNCHRONOUS * @return true, if connected (connection to MC is initialized (after init() is called) and not yet terminated (before asynchronous shutdownSession() is completed)) @@ -437,10 +437,10 @@ public class JniExecutor implements IJNICallback { mHostControllers.add( aHc ); } } - + /** - * @return added host controllers. It can be null - */ + * @return added host controllers. It can be null + */ public List<HostController> getHostControllers() { return mHostControllers; } @@ -481,7 +481,7 @@ public class JniExecutor implements IJNICallback { } Log.fo(); } - + /** * Sets the API observer for notifications and callbacks. SYNCHRONOUS * <p> @@ -493,7 +493,7 @@ public class JniExecutor implements IJNICallback { checkConnection(true); mObserver = aObserver; } - + /** * Starts MC session. SYNCHRONOUS * <p> @@ -509,16 +509,16 @@ public class JniExecutor implements IJNICallback { Log.fi(); synchronized (getLock()) { checkState( McStateEnum.MC_INACTIVE ); - + // DEFAULT_LOCAL_HOST_ADDRESS is used by default if config file is not provided ( setConfigFileName() is not called ) String localAddress = ( mCfgFilePreprocessed ? mJniMw.do_get_mc_host() : DEFAULT_LOCAL_HOST_ADDRESS ); - + // TCP listening port // DEFAULT_TCP_LISTEN_PORT is used by default if config file is not provided ( setConfigFileName() is not called ) int tcpport = ( mCfgFilePreprocessed ? mJniMw.do_get_port() : DEFAULT_TCP_LISTEN_PORT ); - + mMcHost = localAddress; - + // 3rd parameter should be true on Linux, false on Windows int port = mJniMw.do_start_session(localAddress, tcpport, !JNIMiddleWare.isWin() ); if (port <= 0) { @@ -532,7 +532,7 @@ public class JniExecutor implements IJNICallback { } Log.fo(); } - + /** * Start the Host Controllers. ASYNCHRONOUS * <p> @@ -558,7 +558,7 @@ public class JniExecutor implements IJNICallback { } Log.fo(); } - + /** * Starts the given Host Controller. ASYNCHRONOUS * <p> @@ -575,12 +575,12 @@ public class JniExecutor implements IJNICallback { * So runCommand() function ends right after shutdown_session() is called. */ new Thread() { - public void run() { - runCommand( command ); - } + public void run() { + runCommand( command ); + } }.start(); } - + /** * Runs a system command. SYNCHRONOUS * <p> @@ -588,28 +588,28 @@ public class JniExecutor implements IJNICallback { * @param aCommand The system command. sh -c is added at the beginning of the command. */ private void runCommand( final String aCommand ) { - Log.fi(aCommand); + Log.fi(aCommand); Runtime run = Runtime.getRuntime(); Process p = null; try { String[] cmd = { "sh", "-c", aCommand }; - p = run.exec(cmd); - - p.getErrorStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); - String s; - while ((s = br.readLine()) != null) { - Log.f("line: " + s); - //send output to observer with notify() - notifyCallback( new Timeval(), mMcHost, 0, s); - } - p.waitFor(); - final int exitValue = p.exitValue(); - Log.f("exit: " + exitValue); - if ( exitValue != 0 ) { - errorCallback(0, ERROR_TEXT_RUN_COMMAND_EXIT_CODE_NOT_0_PART_1 + aCommand + - ERROR_TEXT_RUN_COMMAND_EXIT_CODE_NOT_0_PART_2 + exitValue); - } + p = run.exec(cmd); + + p.getErrorStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + String s; + while ((s = br.readLine()) != null) { + Log.f("line: " + s); + //send output to observer with notify() + notifyCallback( new Timeval(), mMcHost, 0, s); + } + p.waitFor(); + final int exitValue = p.exitValue(); + Log.f("exit: " + exitValue); + if ( exitValue != 0 ) { + errorCallback(0, ERROR_TEXT_RUN_COMMAND_EXIT_CODE_NOT_0_PART_1 + aCommand + + ERROR_TEXT_RUN_COMMAND_EXIT_CODE_NOT_0_PART_2 + exitValue); + } } catch (IOException e) { Log.f(e.toString()); @@ -619,11 +619,11 @@ public class JniExecutor implements IJNICallback { errorCallback(0, ERROR_TEXT_RUN_COMMAND_INTERRUPTED + aCommand); } finally { - p.destroy(); + p.destroy(); } Log.fo(); } - + /** * Set parameters of the execution, which was pre-processed by setConfigFileName(). ASYNCHRONOUS * <p> @@ -648,13 +648,13 @@ public class JniExecutor implements IJNICallback { public void configure() throws JniExecutorWrongStateException { synchronized (getLock()) { checkState( McStateEnum.MC_HC_CONNECTED, McStateEnum.MC_LISTENING, McStateEnum.MC_LISTENING_CONFIGURED ); - + // DEFAULT_CONFIG_STRING is used by default if config file is not provided ( setConfigFileName() is not called ) // otherwise empty string is sent to MC, which means MC will used its stored config data mJniMw.do_configure( mCfgFilePreprocessed ? null : DEFAULT_CONFIG_STRING ); } } - + /** * Creates Main Test Component (MTC), which is the last step before we can execute the tests. ASYNCHRONOUS * <p> @@ -669,7 +669,7 @@ public class JniExecutor implements IJNICallback { mJniMw.do_create_mtc(0); } } - + /** * Executes a test control by module name. ASYNCHRONOUS * <p> @@ -713,7 +713,7 @@ public class JniExecutor implements IJNICallback { mJniMw.do_execute_testcase( aModule, aTestcase ); } } - + /** * Gets the length of the execute list. SYNCHRONOUS * <p> @@ -733,7 +733,7 @@ public class JniExecutor implements IJNICallback { return mJniMw.do_get_execute_cfg_len(); } } - + /** * Executes the index-th element of the execute list. ASYNCHRONOUS * <p> @@ -756,7 +756,7 @@ public class JniExecutor implements IJNICallback { mJniMw.do_execute_cfg( aIndex ); } } - + /** * Switches the "pause after testcase" flag on or off. By default it is off. SYNCHRONOUS * <p> @@ -779,7 +779,7 @@ public class JniExecutor implements IJNICallback { mJniMw.do_stop_after_testcase( aNewState ); } } - + /** * Gets the "pause after testcase" flag. SYNCHRONOUS * <p> @@ -794,7 +794,7 @@ public class JniExecutor implements IJNICallback { return mJniMw.do_get_stop_after_testcase(); } } - + /** * Continues execution if test control is paused, it executes the next testcase from the control. ASYNCHRONOUS * <p> @@ -808,7 +808,7 @@ public class JniExecutor implements IJNICallback { mJniMw.do_continue_testcase(); } } - + /** * Stops execution of a running or paused test. ASYNCHRONOUS * <p> @@ -825,7 +825,7 @@ public class JniExecutor implements IJNICallback { // otherwise do nothing, MC would do the same, but there is no point to call it in this state } } - + /** * Stops MTC. ASYNCHRONOUS * <p> @@ -840,7 +840,7 @@ public class JniExecutor implements IJNICallback { mJniMw.do_exit_mtc(); } } - + /** * Shuts down MC session. ASYNCHRONOUS * <p> @@ -928,7 +928,7 @@ public class JniExecutor implements IJNICallback { return mJniMw.do_get_nof_hosts(); } } - + /** * Gets host data. SYNCHRONOUS * <p> @@ -955,7 +955,7 @@ public class JniExecutor implements IJNICallback { return copy; } } - + /** * Gets component data. SYNCHRONOUS * <p> @@ -982,7 +982,7 @@ public class JniExecutor implements IJNICallback { return copy; } } - + /** * Gets MC state from MainController. SYNCHRONOUS * <p> @@ -994,7 +994,7 @@ public class JniExecutor implements IJNICallback { return mJniMw.do_get_state(); } } - + /** * Checks if connected state. * We are connected between init() and shutdownSession(). @@ -1008,7 +1008,7 @@ public class JniExecutor implements IJNICallback { throw new JniExecutorWrongStateException( connected ? EXCEPTION_TEXT_WRONG_STATE_CONNECTED : EXCEPTION_TEXT_WRONG_STATE_NOT_CONNECTED ); } } - + /** * Checks if we are in any of the expected states * @param aExpectedStates array of the expected states @@ -1046,10 +1046,10 @@ public class JniExecutor implements IJNICallback { } sb.append( aExpectedStates[ i ] ); } - + return sb.toString(); } - + /** * Error handling for incorrect state * @param aActualState the actual state @@ -1096,7 +1096,7 @@ public class JniExecutor implements IJNICallback { } Log.fo(); } - + /** * Reset member variables to initial state */ @@ -1111,7 +1111,7 @@ public class JniExecutor implements IJNICallback { mLockCompletion.notifyAll(); } } - + /** * If notification from MC is special (it must be handled differently) * @param aMsg notification from MC, which is a possible special notification. @@ -1120,13 +1120,13 @@ public class JniExecutor implements IJNICallback { */ private boolean processSpecialNotifications( final String aMsg ) { return processVerdict(aMsg) - //|| processDynamicTestcaseError(aMsg) - || processVerdictStats(aMsg) - //|| processErrorsOutsideOfTestcases(aMsg) - //|| processOverallVerdict(aMsg) - || false; + //|| processDynamicTestcaseError(aMsg) + || processVerdictStats(aMsg) + //|| processErrorsOutsideOfTestcases(aMsg) + //|| processOverallVerdict(aMsg) + || false; } - + /** * If notification from MC matches to the verdict pattern, * verdict notification is sent instead of general notification. @@ -1207,7 +1207,7 @@ public class JniExecutor implements IJNICallback { } return false; } - + /** * If notification from MC matches to the PATTERN_ERRORS_OUTSIDE_OF_TESTCASES pattern, * special notification is sent instead of general notification. @@ -1229,7 +1229,7 @@ public class JniExecutor implements IJNICallback { } return false; } - + /** * If notification from MC matches to the overall verdict pattern, * overall verdict notification is sent instead of general notification. @@ -1253,7 +1253,7 @@ public class JniExecutor implements IJNICallback { } return false; } - + /** * Converts verdict type name to verdict type * @param aVerdictTypeName verdict type name candidate @@ -1282,12 +1282,12 @@ public class JniExecutor implements IJNICallback { } return verdictType; } - + // observer callbacks. all the callbacks go through these methods to make sure, that // - observer is not called if it's null // - exception/error, which is thrown by the observer is ignored, // this class provides a service, it has no idea how to handle client's exception/error - + /** * Notification about status change. It also means, that the asynchronous request is finished successfully, if aNewState is the final state. * @param aNewState the new MC state @@ -1313,7 +1313,7 @@ public class JniExecutor implements IJNICallback { private void observerError( final int aSeverity, final String aMsg ) { Log.fi(aSeverity, aMsg); if ( mObserver != null ) { - try { + try { mObserver.error(aSeverity, aMsg); } catch (Throwable e) { Log.i(e.toString()); @@ -1333,7 +1333,7 @@ public class JniExecutor implements IJNICallback { private void observerNotify(final Timeval aTime, final String aSource, final int aSeverity, final String aMsg) { Log.fi(aTime, aSource, aSeverity, aMsg); if ( mObserver != null ) { - try { + try { mObserver.notify(aTime, aSource, aSeverity, aMsg); } catch (Throwable e) { Log.i(e.toString()); @@ -1342,7 +1342,7 @@ public class JniExecutor implements IJNICallback { } Log.fo(); } - + /** * Verdict notification, that comes after execution of a testcase. * If a test control is executed, this notification is sent multiple times after each testcase. @@ -1352,7 +1352,7 @@ public class JniExecutor implements IJNICallback { private void observerVerdict( final String aTestcase, final VerdictTypeEnum aVerdictType ) { Log.fi(aTestcase, aVerdictType); if ( mObserver != null ) { - try { + try { mObserver.verdict(aTestcase, aVerdictType); } catch (Throwable e) { Log.i(e.toString()); @@ -1361,7 +1361,7 @@ public class JniExecutor implements IJNICallback { } Log.fo(); } - + /** * Verdict statistics notification, that comes after executing all the testcases after exit MTC. * This notification is sent only once for a MTC session. @@ -1370,7 +1370,7 @@ public class JniExecutor implements IJNICallback { private void observerVerdictStats( final Map<VerdictTypeEnum, Integer> aVerdictStats ) { Log.fi(aVerdictStats); if ( mObserver != null ) { - try { + try { mObserver.verdictStats(aVerdictStats); } catch (Throwable e) { Log.i(e.toString()); diff --git a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/exception/JniExecutorJniLoadException.java b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/exception/JniExecutorJniLoadException.java index 3e9cc3f5a..73248dd5e 100644 --- a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/exception/JniExecutorJniLoadException.java +++ b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/exception/JniExecutorJniLoadException.java @@ -25,7 +25,7 @@ import org.eclipse.titan.executorapi.JniExecutor; * @see JniExecutor#init() */ public class JniExecutorJniLoadException extends JniExecutorException { - + /** * Generated serial version ID * (to avoid warning) @@ -35,7 +35,7 @@ public class JniExecutorJniLoadException extends JniExecutorException { public JniExecutorJniLoadException( final String aMsg ) { super( aMsg ); } - + public JniExecutorJniLoadException(String aMsg, final Throwable aCause) { super( aMsg, aCause ); diff --git a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/Log.java b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/Log.java index c1f644055..35ef59e2b 100644 --- a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/Log.java +++ b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/Log.java @@ -52,7 +52,7 @@ import java.util.Map; * </pre> */ public class Log { - + /** * Severity of the log message, log level * @see "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html" @@ -60,40 +60,40 @@ public class Log { private enum Severity { /** The OFF has the highest possible rank and is intended to turn off logging. */ OFF, - + /** The FATAL level designates very severe error events that will presumably lead the application to abort. */ FATAL, - + /** The ERROR level designates error events that might still allow the application to continue running. */ ERROR, - + /** The WARN level designates potentially harmful situations. */ WARN, - + /** The INFO level designates informational messages that highlight the progress of the application at coarse-grained level. */ INFO, - + /** The DEBUG Level designates fine-grained informational events that are most useful to debug an application. */ DEBUG, - + /** The TRACE Level designates finer-grained informational events than the DEBUG */ TRACE, - + /** The ALL has the lowest possible rank and is intended to turn on all logging. */ ALL; }; - + /** * Global log level. * It effects all the projects that use Log. */ private static Severity sLogLevel = Severity.OFF; - + /** * Date format for function related logging functions: fi(), fo(), f() */ private static final SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - + /** * Keeps track the call level for each thread. * Call level is a number, that is increased, when a function entry point is logged (fi() is called), @@ -102,13 +102,13 @@ public class Log { * Negative call level is treated as 0. */ private static Map<Long, Integer> sCallLevels = new HashMap<Long, Integer>(); - + /** * Logging states separately for each thread. * Logging can be switched off separately for each thread. true: on, false: off. Default value: true. */ private static Map<Long, Boolean> sLoggingStates = new HashMap<Long, Boolean>(); - + /** * Function in. * Logs the entry and the given parameter(s) of the method in DEBUG level. @@ -120,20 +120,20 @@ public class Log { if ( !checkLogLevel( Severity.DEBUG ) || isThreadLoggingOff() ) { return; } - + StringBuilder sb = new StringBuilder(); logDateAndThreadId(sb); sb.append(" -> "); - + final int callLevel = getCallLevel(); setCallLevel( callLevel + 1 ); for (int i = 0; i < callLevel; i++) { - sb.append(" "); + sb.append(" "); } - + // 0: getStackTrace(), 1: logMethodName(), 2: fi(), 3: this is the caller function we want to log logMethodName( sb, 3 ); - + // log parameters sb.append("("); if ( aParams.length > 0 ) { @@ -147,10 +147,10 @@ public class Log { sb.append(" "); } sb.append(")"); - + printLog( sb ); } - + /** * Function out. * Logs the exit and the given return value of the method in DEBUG level. @@ -162,20 +162,20 @@ public class Log { if ( !checkLogLevel( Severity.DEBUG ) || isThreadLoggingOff() ) { return; } - + StringBuilder sb = new StringBuilder(); logDateAndThreadId(sb); sb.append( " <- " ); - + int callLevel = getCallLevel(); setCallLevel( --callLevel ); for (int i = 0; i < callLevel; i++) { sb.append(" "); } - + // 0: getStackTrace(), 1: logMethodName(), 2: fo (this private), 3: fo (one of the public ones), 4: this is caller the function we want to log logMethodName( sb, 4 ); - + // log return value (if any) sb.append("()"); if ( aHasReturnValue ) { @@ -184,7 +184,7 @@ public class Log { } printLog( sb ); } - + /** * Function out. * Logs the exit of the method (but not the return value) in DEBUG level. @@ -193,7 +193,7 @@ public class Log { public static void fo() { fo( false, null ); } - + /** * Function out. * Logs the exit and the given return value of the method in DEBUG level. @@ -203,7 +203,7 @@ public class Log { public static void fo( final Object aReturnValue ) { fo( true, aReturnValue ); } - + /** * function log (just a general log within the function) * @param aMsg log message @@ -212,16 +212,16 @@ public class Log { if ( !checkLogLevel( Severity.TRACE ) || isThreadLoggingOff() ) { return; } - + StringBuilder sb = new StringBuilder(); logDateAndThreadId(sb); sb.append( " " ); - + final int callLevel = getCallLevel(); for (int i = 0; i < callLevel; i++) { - sb.append(" "); + sb.append(" "); } - + if ( aMsg != null && aMsg.contains( "\n" ) ) { // in case of multiline message other lines are also indented with the same number of spaces final int len = sb.length(); @@ -230,9 +230,9 @@ public class Log { StringBuilder sbSpaces = new StringBuilder( len ); sbSpaces.append("\n"); for (int i = 0; i < len; i++) { - sbSpaces.append(" "); + sbSpaces.append(" "); } - + // replace \n -> sbSpaces in sbMsg StringUtil.replaceString( sbMsg, "\n", sbSpaces.toString() ); sb.append( sbMsg ); @@ -240,7 +240,7 @@ public class Log { else { sb.append( aMsg ); } - + printLog( sb ); } @@ -257,7 +257,7 @@ public class Log { sb.append( " " + aMsg ); printLog( sb ); } - + /** * info unformatted (without datetime) * @param aMsg log message @@ -269,7 +269,7 @@ public class Log { StringBuilder sb = new StringBuilder( aMsg ); printLog( sb ); } - + /** * Switch on logging for the current thread */ @@ -285,7 +285,7 @@ public class Log { final long threadId = Thread.currentThread().getId(); sLoggingStates.put(threadId, false); } - + /** * Adds full datetime and thread id to the log string. * @param aSb [in/out] the log string, where new strings are added @@ -294,7 +294,7 @@ public class Log { final long threadId = Thread.currentThread().getId(); aSb.append( sFormat.format( new Date() ) + " " + String.format( "%3d", threadId ) ); } - + /** * Checks if the global static log level reaches the minimum required log level, * @param aMinRequired minimum required log level @@ -303,7 +303,7 @@ public class Log { private static boolean checkLogLevel( final Severity aMinRequired ) { return sLogLevel.ordinal() >= aMinRequired.ordinal(); } - + /** * Adds class and method name to the log string. * Short class name is used without full qualification. @@ -318,21 +318,21 @@ public class Log { final String methodName = ste.getMethodName(); aSb.append( shortClassName + "." + methodName ); } - + /** * @return true if logging for the current thread switched off. * If there is no info for this thread, a new (<current thread>, true) item is added to the map */ private static boolean isThreadLoggingOff() { final long threadId = Thread.currentThread().getId(); - + if(!sLoggingStates.containsKey(threadId)) { sLoggingStates.put(threadId, true); } - + return !sLoggingStates.get( threadId ); } - + /** * @return Call level for the current thread. * If there is no info for this thread, a new (<current thread>, 0) item is added to the map @@ -345,7 +345,7 @@ public class Log { final int callLevel = sCallLevels.get( threadId ); return callLevel; } - + /** * Sets the call level of the current thread. * If sCallLevels does NOT contain current thread as key, it creates it. @@ -355,7 +355,7 @@ public class Log { final long threadId = Thread.currentThread().getId(); sCallLevels.put( threadId, aNewValue ); } - + /** * prints the log string to the output * @param aLogString the log string, it can be multiline diff --git a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/StringUtil.java b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/StringUtil.java index bd6a959e8..657cc4dce 100644 --- a/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/StringUtil.java +++ b/titan_executor_api/TITAN_Executor_API/src/org/eclipse/titan/executorapi/util/StringUtil.java @@ -27,7 +27,7 @@ import java.util.Map; * replaceString(): indent(), Log.f() */ public class StringUtil { - + /** * Replaces all the occurrences of a given string * @param aSb [in/out] the string to modify @@ -37,12 +37,12 @@ public class StringUtil { public static void replaceString( final StringBuilder aSb, final String aFrom, final String aTo ) { int index = aSb.indexOf( aFrom ); while (index != -1) { - aSb.replace( index, index + aFrom.length(), aTo ); - index += aTo.length(); // Move to the end of the replacement - index = aSb.indexOf( aFrom, index ); - } + aSb.replace( index, index + aFrom.length(), aTo ); + index += aTo.length(); // Move to the end of the replacement + index = aSb.indexOf( aFrom, index ); + } } - + /** * Appends any Object to the given StringBuilder. * <p> @@ -131,7 +131,7 @@ public class StringUtil { public static void indent( final StringBuilder aSb, final String aIndentString ) { replaceString( aSb, "\n", "\n" + aIndentString ); } - + /** * @param aPrimitiveArrayCandidate the object to check * @return true, if aPrimitiveArrayCandidate is a primitive array, like int[], boolean[], ... @@ -139,10 +139,10 @@ public class StringUtil { */ private static boolean isPrimitiveArray( final Object aPrimitiveArrayCandidate ) { return aPrimitiveArrayCandidate != null && - aPrimitiveArrayCandidate.getClass().isArray() && - aPrimitiveArrayCandidate.getClass().getComponentType().isPrimitive(); + aPrimitiveArrayCandidate.getClass().isArray() && + aPrimitiveArrayCandidate.getClass().getComponentType().isPrimitive(); } - + /** * Converts primitive array to Object array. * <p> @@ -153,15 +153,15 @@ public class StringUtil { * @see #isPrimitiveArray(Object) */ private static Object[] toObjectArray( final Object aPrimitiveArray ) { - if ( aPrimitiveArray instanceof Object[] ) { - return ( Object[] )aPrimitiveArray; - } - int arrlength = Array.getLength( aPrimitiveArray ); - Object[] outputArray = new Object[ arrlength ]; - for(int i = 0; i < arrlength; ++i) { - outputArray[i] = Array.get( aPrimitiveArray, i ); - } - return outputArray; + if ( aPrimitiveArray instanceof Object[] ) { + return ( Object[] )aPrimitiveArray; + } + int arrlength = Array.getLength( aPrimitiveArray ); + Object[] outputArray = new Object[ arrlength ]; + for(int i = 0; i < arrlength; ++i) { + outputArray[i] = Array.get( aPrimitiveArray, i ); + } + return outputArray; } } -- GitLab