Add CLI protocol tests.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Thu, 10 Aug 2023 14:08:25 +0000 (17:08 +0300)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Wed, 13 Sep 2023 11:46:47 +0000 (20:46 +0900)
src/protocols/cliprotocol.cpp
test-suite/CLITestBreakpoint/CLITestBreakpoint.csproj [new file with mode: 0644]
test-suite/CLITestBreakpoint/Program.cs [new file with mode: 0644]
test-suite/CLITestBreakpoint/commands.txt [new file with mode: 0644]
test-suite/CLITestBreakpoint/log_test.txt [new file with mode: 0644]
test-suite/run_cli_test.sh [new file with mode: 0755]
test-suite/run_tests.sh
test-suite/sdb_run_tests.sh
test-suite/test-suite.sln

index 91dabf5776417575f266cfde78fea99d45323b56..e72e326313192af875339e07f0b7537cba0f2cd1 100644 (file)
@@ -776,13 +776,6 @@ void CLIProtocol::EmitStoppedEvent(const StoppedEvent &event)
 {
     LogFuncEntry();
 
-    {
-      lock_guard lock(m_mutex);
-
-      m_processStatus = Paused;
-      m_state_cv.notify_all();
-    }
-
     // call repaint() at function exit
     std::unique_ptr<void, std::function<void(void*)> >
         on_exit(this, [&](void *)
@@ -834,7 +827,14 @@ void CLIProtocol::EmitStoppedEvent(const StoppedEvent &event)
             break;
         }
         default:
-            return;
+            break;
+    }
+
+    {
+      lock_guard lock(m_mutex);
+
+      m_processStatus = Paused;
+      m_state_cv.notify_all();
     }
 }
 
@@ -2168,7 +2168,7 @@ HRESULT CLIProtocol::execCommands(LineReader&& lr, bool printCommands)
     {
         unique_lock lock(m_mutex);
 
-       // TODO move this out here
+        // TODO move this out here
         // deactivate debugger on process exit (deffered, can't call this in callback)
         if(!exited && m_processStatus == Exited)
         {
@@ -2195,6 +2195,9 @@ HRESULT CLIProtocol::execCommands(LineReader&& lr, bool printCommands)
 
             case IDebugger::AsyncResult::Eof:
                 {
+                if (dynamic_cast<FileLineReader*>(line_reader) != nullptr)
+                    break;
+
                 static const auto ErrorMsg =
                     tty::bold + tty::brown + literal("EOF") + tty::reset + literal("\n");
 
diff --git a/test-suite/CLITestBreakpoint/CLITestBreakpoint.csproj b/test-suite/CLITestBreakpoint/CLITestBreakpoint.csproj
new file mode 100644 (file)
index 0000000..d453e9a
--- /dev/null
@@ -0,0 +1,8 @@
+<Project Sdk="Microsoft.NET.Sdk">\r
+\r
+  <PropertyGroup>\r
+    <OutputType>Exe</OutputType>\r
+    <TargetFramework>netcoreapp3.1</TargetFramework>\r
+  </PropertyGroup>\r
+\r
+</Project>\r
diff --git a/test-suite/CLITestBreakpoint/Program.cs b/test-suite/CLITestBreakpoint/Program.cs
new file mode 100644 (file)
index 0000000..f97c3a2
--- /dev/null
@@ -0,0 +1,12 @@
+using System;\r
+\r
+namespace CLITestBreakpoint\r
+{\r
+    class Program\r
+    {\r
+        static void Main(string[] args)\r
+        {\r
+            Console.WriteLine("Hello World!");      // BREAK1\r
+        }\r
+    }\r
+}\r
diff --git a/test-suite/CLITestBreakpoint/commands.txt b/test-suite/CLITestBreakpoint/commands.txt
new file mode 100644 (file)
index 0000000..39f5ceb
--- /dev/null
@@ -0,0 +1,7 @@
+set just-my-code 1
+b Program.cs:9
+r
+s
+bt
+c
+
diff --git a/test-suite/CLITestBreakpoint/log_test.txt b/test-suite/CLITestBreakpoint/log_test.txt
new file mode 100644 (file)
index 0000000..f301989
--- /dev/null
@@ -0,0 +1,17 @@
+set just-my-code 1
+b Program.cs:9
+ Breakpoint 1 at Program.cs:9 --pending, warning: No executable code of the debugger's target code type is associated with this line.
+r
+\^running
+breakpoint modified,  Breakpoint 1 at .*CLITestBreakpoint/Program.cs:9
+stopped, reason: breakpoint 1 hit, thread id: .*, stopped threads: all, times= 1, frame=\{CLITestBreakpoint\.Program\.Main\(\) at .*CLITestBreakpoint/Program.cs:9\}
+s
+\^running
+Hello World!
+stopped, reason: end stepping range, thread id: .*, stopped threads: all, frame=\{CLITestBreakpoint\.Program\.Main\(\) at .*CLITestBreakpoint/Program.cs:10\}
+bt
+#0 CLITestBreakpoint\.Program\.Main\(\) at .*CLITestBreakpoint/Program.cs:10
+c
+\^running
+stopped, reason: exited, exit-code: 0
+\^exit
diff --git a/test-suite/run_cli_test.sh b/test-suite/run_cli_test.sh
new file mode 100755 (executable)
index 0000000..47116d8
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+NETCOREDBG=$1
+TEST_NAME=$2
+ASSEMB_PATH=$3
+FILE_COMMANDS=$4
+
+file_log=$(mktemp)
+file_test="$TEST_NAME/log_test.txt"
+
+$NETCOREDBG --interpreter=cli -ex "source $FILE_COMMANDS" -- dotnet "$ASSEMB_PATH" 2>&1 | tee "$file_log"
+
+echo ""
+echo "CLI LOG INTERPRET START"
+
+skip_line()
+{
+    local line=$1
+
+    if [[ -z "$line" ]] ||
+       [[ "$line" == "library loaded:"* ]] ||
+       [[ "$line" == "no symbols loaded, base address:"* ]] ||
+       [[ "$line" == "symbols loaded, base address:"* ]] ||
+       [[ "$line" == "thread created, id:"* ]] ;
+    then
+        echo "1"
+    else
+        echo "0"
+    fi
+}
+
+# Remove ^M ('\r') from each line in file, if have it ("sdb shell" usually add this one).
+mv "$file_log" "$file_log"2
+sed -e 's/\r//g' "$file_log"2 > "$file_log"
+rm -f "$file_log"2
+
+log_current_line=1
+test_current_line=1
+log_line_count=$(awk 'END{print NR}' "$file_log")
+log_line_count=$((log_line_count+1))
+test_line_count=$(awk 'END{print NR}' "$file_test")
+test_line_count=$((test_line_count+1))
+
+while [[ "$log_current_line" -lt "$log_line_count" ]] && [[ "$test_current_line" -lt "$test_line_count" ]]
+do
+    log_line=$(sed "$log_current_line"'q;d' "$file_log")
+    log_current_line=$((log_current_line+1))
+
+    test_line=$(sed "$test_current_line"'q;d' "$file_test")
+    test_current_line=$((test_current_line+1))
+
+    while [[ $(skip_line "$log_line") -eq "1" ]] && [[ "$log_current_line" -lt "$log_line_count" ]]
+    do
+        log_line=$(sed "$log_current_line"'q;d' "$file_log")
+        log_current_line=$((log_current_line+1))
+    done
+
+    echo "TEST"
+    echo "  log line   =""$log_line" | cat -v
+    echo "  test regex =""$test_line" | cat -v
+
+    # Note, "test_line" provide regex that have '\^' first symbol  instead of '^'.
+    if [[ "$log_line" == "^exit" ]] && [[ "$test_line" == "\^exit" ]]
+    then
+        echo "OK"
+        rm -f "$file_log"
+        exit 0
+    fi
+
+    # Note, we don't include in test log file '^' (start string marker) and '$' (end string marker), but add them in comparation directly.
+    if [[ "$log_line" =~ ^$test_line$ ]]
+    then
+        echo "OK"
+    else
+        echo "FAIL"
+        rm -f "$file_log"
+        exit 1
+    fi
+
+done
+
+echo "FAIL"
+rm -f "$file_log"
+exit 1
+
index 4515c8dac0e960cf0f54c2d5a31e37cc75c32042..b2dd3411efb521b89a329dc4bc9a1cd2b7d62f1a 100755 (executable)
@@ -15,6 +15,7 @@ ${testnames}        </testsuite>
 }
 
 ALL_TEST_NAMES=(
+    "CLITestBreakpoint"
     "MIExampleTest"
     "MITestBreakpoint"
     "MITestExpression"
@@ -177,19 +178,33 @@ for TEST_NAME in $TEST_NAMES; do
         SOURCE_FILES="${SOURCE_FILES}${file};"
     done
 
-    PROTO="mi"
-    if  [[ $TEST_NAME == VSCode* ]] ;
+    # Check, that test shell run in terminal (returns 0 (succeeds), if the descriptors are hooked up to a terminal).
+    test -t 0 -a -t 1 -a -t 2
+    # Skip CLI tests on MacOS (kernel "Darwin") in jenkins.
+    if [[ "$?" != "0" ]] && [[ $TEST_NAME == CLI* ]] && [[ "$(uname)" == "Darwin" ]] ;
     then
-        PROTO="vscode"
+        continue
+    fi
+
+    if [[ $TEST_NAME == CLI* ]] ;
+    then
+        ./run_cli_test.sh "$NETCOREDBG" "$TEST_NAME" "$TEST_NAME/bin/Debug/netcoreapp3.1/$TEST_NAME.dll" "$TEST_NAME/commands.txt"
+    else
+        PROTO="mi"
+        if  [[ $TEST_NAME == VSCode* ]] ;
+        then
+            PROTO="vscode"
+        fi
+
+        test_timeout $TIMEOUT dotnet run --project TestRunner -- \
+            --local $NETCOREDBG \
+            --proto $PROTO \
+            --test $TEST_NAME \
+            --sources "$SOURCE_FILES" \
+            --assembly $TEST_NAME/bin/Debug/netcoreapp3.1/$TEST_NAME.dll \
+            "${LOGOPTS[@]}"
     fi
 
-    test_timeout $TIMEOUT dotnet run --project TestRunner -- \
-        --local $NETCOREDBG \
-        --proto $PROTO \
-        --test $TEST_NAME \
-        --sources "$SOURCE_FILES" \
-        --assembly $TEST_NAME/bin/Debug/netcoreapp3.1/$TEST_NAME.dll \
-        "${LOGOPTS[@]}"
 
     res=$?
 
index 37ea6ba49da544663334af1bc701a2b31da996c3..201718efbb1dec13949032620d3b765aa6bb61e5 100755 (executable)
@@ -31,6 +31,7 @@ generate_xml()
 }
 
 ALL_TEST_NAMES=(
+    "CLITestBreakpoint"
     "MIExampleTest"
     "MITestBreakpoint"
     "MITestExpression"
@@ -238,7 +239,18 @@ for TEST_NAME in $TEST_NAMES; do
     HOSTTESTDIR=$SCRIPTDIR/$TEST_NAME
     SOURCE_FILES=$(find $HOSTTESTDIR \! -path "$HOSTTESTDIR/obj/*" -type f -name "*.cs" -printf '%p;')
 
-    if  [[ $TEST_NAME == VSCode* ]] ;
+    RC="0"
+
+    if [[ $TEST_NAME == CLI* ]] ;
+    then
+
+        $SDB push $SCRIPTDIR/$TEST_PROJ_NAME/commands.txt $REMOTETESTDIR
+        $SDB root on
+        ./run_cli_test.sh "$SDB shell $NETCOREDBG" "$TEST_NAME" "$REMOTETESTDIR/$TEST_NAME.dll" "$REMOTETESTDIR/commands.txt"
+        let RC=$?
+        $SDB root off
+
+    elif  [[ $TEST_NAME == VSCode* ]] ;
     then
         PROTO="vscode"
 
@@ -255,6 +267,7 @@ for TEST_NAME in $TEST_NAMES; do
             --test $TEST_NAME \
             --sources $SOURCE_FILES \
             --assembly $REMOTETESTDIR/$TEST_PROJ_NAME.dll
+        let RC=$?
     else
         PROTO="mi"
 
@@ -271,9 +284,10 @@ for TEST_NAME in $TEST_NAMES; do
             --test $TEST_NAME \
             --sources "$SOURCE_FILES" \
             --assembly $REMOTETESTDIR/$TEST_PROJ_NAME.dll
+        let RC=$?
     fi
 
-    if [ "$?" -ne "0" ]; then
+    if [ "$RC" -ne "0" ]; then
         test_fail=$(($test_fail + 1))
         test_list="$test_list$TEST_NAME ... failed\n"
         test_xml+="<testcase name=\"$TEST_NAME\"><failure></failure></testcase>"
index b427f4d41e88c68c6bf969ab633dabbc3556ea9c..2a663560a74a24307a7df74e32afc105e5fa72d7 100644 (file)
@@ -127,6 +127,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSCodeTestBreakpointWithout
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MITestBreakpointUpdate", "MITestBreakpointUpdate\MITestBreakpointUpdate.csproj", "{440BEDAD-6094-4FCA-A941-E44300A378C9}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLITestBreakpoint", "CLITestBreakpoint\CLITestBreakpoint.csproj", "{3F7823C7-880F-4CD3-931B-86B0F4F05423}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
@@ -896,5 +898,17 @@ Global
                {440BEDAD-6094-4FCA-A941-E44300A378C9}.Release|x64.Build.0 = Release|Any CPU
                {440BEDAD-6094-4FCA-A941-E44300A378C9}.Release|x86.ActiveCfg = Release|Any CPU
                {440BEDAD-6094-4FCA-A941-E44300A378C9}.Release|x86.Build.0 = Release|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Debug|x64.ActiveCfg = Debug|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Debug|x64.Build.0 = Debug|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Debug|x86.ActiveCfg = Debug|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Debug|x86.Build.0 = Debug|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Release|Any CPU.Build.0 = Release|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Release|x64.ActiveCfg = Release|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Release|x64.Build.0 = Release|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Release|x86.ActiveCfg = Release|Any CPU
+               {3F7823C7-880F-4CD3-931B-86B0F4F05423}.Release|x86.Build.0 = Release|Any CPU
        EndGlobalSection
 EndGlobal