Add Tizen specific tests.
authorMikhail Kurinnoi <m.kurinnoi@samsung.net>
Thu, 17 Oct 2019 16:16:39 +0000 (19:16 +0300)
committerAlexander Soldatov/AI Compiler Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Thu, 9 Apr 2020 09:41:08 +0000 (12:41 +0300)
Test tpk applications installation with and without NI generation (test debugger's pdb search routine).
Test launch_app work with debugger (in this way MSVS plugin work with debugger).

test-suite/TestApp1/Program.cs [new file with mode: 0644]
test-suite/TestApp1/TestApp1.csproj [new file with mode: 0644]
test-suite/TestApp1/tizen-manifest.xml [new file with mode: 0644]
test-suite/TestApp2/Program.cs [new file with mode: 0644]
test-suite/TestApp2/TestApp2.csproj [new file with mode: 0644]
test-suite/TestApp2/tizen-manifest.xml [new file with mode: 0644]
test-suite/sdb_run_tests.sh
test-suite/sdb_run_tizen_tests.sh [new file with mode: 0755]

diff --git a/test-suite/TestApp1/Program.cs b/test-suite/TestApp1/Program.cs
new file mode 100644 (file)
index 0000000..0fdcad8
--- /dev/null
@@ -0,0 +1,181 @@
+// Make sure, you have this file by-line-synced with ../TestApp2/Program.cs\r
+\r
+using System;\r
+using System.IO;\r
+\r
+using NetcoreDbgTest;\r
+using NetcoreDbgTest.MI;\r
+using NetcoreDbgTest.Script;\r
+\r
+using Xunit;\r
+\r
+namespace TestApp1\r
+{\r
+    class Program\r
+    {\r
+        static void Main(string[] args)\r
+        {\r
+            Label.Checkpoint("init", "bp_test", () => {\r
+                Context.Run();\r
+                Context.WasEntryPointHit();\r
+                Context.EnableBreakpoint("bp");\r
+                Context.Continue();\r
+            });\r
+\r
+            int i = 1;\r
+            i++;                                                        Label.Breakpoint("bp");\r
+\r
+            Label.Checkpoint("bp_test", "finish", () => {\r
+                Context.WasBreakpointHit(DebuggeeInfo.Breakpoints["bp"]);\r
+                Context.Continue();\r
+            });\r
+\r
+            i++;\r
+\r
+            Label.Checkpoint("finish", "", () => {\r
+                Context.WasExit();\r
+                Context.DebuggerExit();\r
+            });\r
+        }\r
+    }\r
+}\r
+\r
+namespace NetcoreDbgTest.Script\r
+{\r
+    // Context includes methods and constants which\r
+    // will be move to debugger API\r
+    class Context\r
+    {\r
+        public static void Run()\r
+        {\r
+            Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);\r
+        }\r
+\r
+        static bool IsStoppedEvent(MIOutOfBandRecord record)\r
+        {\r
+            if (record.Type != MIOutOfBandRecordType.Async) {\r
+                return false;\r
+            }\r
+\r
+            var asyncRecord = (MIAsyncRecord)record;\r
+\r
+            if (asyncRecord.Class != MIAsyncRecordClass.Exec ||\r
+                asyncRecord.Output.Class != MIAsyncOutputClass.Stopped) {\r
+                return false;\r
+            }\r
+\r
+            return true;\r
+        }\r
+\r
+        public static void WasEntryPointHit()\r
+        {\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
+                if (!IsStoppedEvent(record)) {\r
+                    return false;\r
+                }\r
+\r
+                var output = ((MIAsyncRecord)record).Output;\r
+                var reason = (MIConst)output["reason"];\r
+\r
+                if (reason.CString != "entry-point-hit") {\r
+                    return false;\r
+                }\r
+\r
+                var frame = (MITuple)(output["frame"]);\r
+                var func = (MIConst)(frame["func"]);\r
+                if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {\r
+                    return true;\r
+                }\r
+\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+        }\r
+\r
+        public static void WasBreakpointHit(Breakpoint breakpoint)\r
+        {\r
+            var bp = (LineBreakpoint)breakpoint;\r
+\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
+                if (!IsStoppedEvent(record)) {\r
+                    return false;\r
+                }\r
+\r
+                var output = ((MIAsyncRecord)record).Output;\r
+                var reason = (MIConst)output["reason"];\r
+\r
+                if (reason.CString != "breakpoint-hit") {\r
+                    return false;\r
+                }\r
+\r
+                var frame = (MITuple)(output["frame"]);\r
+                var fileName = (MIConst)(frame["file"]);\r
+                var numLine = (MIConst)(frame["line"]);\r
+\r
+                if (fileName.CString == bp.FileName &&\r
+                    numLine.CString == bp.NumLine.ToString()) {\r
+                    return true;\r
+                }\r
+\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+        }\r
+\r
+        public static void WasExit()\r
+        {\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
+                if (!IsStoppedEvent(record)) {\r
+                    return false;\r
+                }\r
+\r
+                var output = ((MIAsyncRecord)record).Output;\r
+                var reason = (MIConst)output["reason"];\r
+\r
+                if (reason.CString != "exited") {\r
+                    return false;\r
+                }\r
+\r
+                var exitCode = (MIConst)output["exit-code"];\r
+\r
+                if (exitCode.CString == "0") {\r
+                    return true;\r
+                }\r
+\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+        }\r
+\r
+        public static void DebuggerExit()\r
+        {\r
+            Assert.Equal(MIResultClass.Exit, Context.MIDebugger.Request("-gdb-exit").Class);\r
+        }\r
+\r
+        public static void EnableBreakpoint(string bpName)\r
+        {\r
+            Breakpoint bp = DebuggeeInfo.Breakpoints[bpName];\r
+\r
+            Assert.Equal(BreakpointType.Line, bp.Type);\r
+\r
+            var lbp = (LineBreakpoint)bp;\r
+\r
+            Assert.Equal(MIResultClass.Done,\r
+                         MIDebugger.Request("-break-insert -f "\r
+                                            + lbp.FileName + ":" + lbp.NumLine).Class);\r
+        }\r
+\r
+        public static void Continue()\r
+        {\r
+            Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-continue").Class);\r
+        }\r
+\r
+        static MIDebugger MIDebugger = new MIDebugger();\r
+    }\r
+}\r
diff --git a/test-suite/TestApp1/TestApp1.csproj b/test-suite/TestApp1/TestApp1.csproj
new file mode 100644 (file)
index 0000000..8d0a60e
--- /dev/null
@@ -0,0 +1,12 @@
+<Project Sdk="Tizen.NET.Sdk/1.0.3">\r
+\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\NetcoreDbgTest\NetcoreDbgTest.csproj" />\r
+  </ItemGroup>\r
+\r
+  <PropertyGroup>\r
+    <OutputType>Exe</OutputType>\r
+    <TargetFramework>netcoreapp2.1</TargetFramework>\r
+  </PropertyGroup>\r
+\r
+</Project>\r
diff --git a/test-suite/TestApp1/tizen-manifest.xml b/test-suite/TestApp1/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..e8bae62
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<manifest xmlns="http://tizen.org/ns/packages" api-version="5" package="org.tizen.example.TestApp1" version="1.0.0">\r
+  <profile name="common" />\r
+  <service-application appid="org.tizen.example.TestApp1"\r
+                                       exec="TestApp1.dll"\r
+                                       type="dotnet"\r
+                                       multiple="false"\r
+                                       taskmanage="false"\r
+                                       nodisplay="true">\r
+    <label>TestApp1</label>\r
+    <metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="false" />\r
+  </service-application>\r
+</manifest>\r
diff --git a/test-suite/TestApp2/Program.cs b/test-suite/TestApp2/Program.cs
new file mode 100644 (file)
index 0000000..b4781c6
--- /dev/null
@@ -0,0 +1,41 @@
+// Make sure, you have this file by-line-synced with ../TestApp1/Program.cs\r
+// This file should not contain 'command' test code!\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+namespace TestApp2\r
+{\r
+    class Program\r
+    {\r
+        static void Main(string[] args)\r
+        {\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+            int i = 1;\r
+            i++;\r
+\r
+\r
+\r
+\r
+\r
+\r
+            i++;\r
+\r
+\r
+\r
+\r
+\r
+        }\r
+    }\r
+}\r
diff --git a/test-suite/TestApp2/TestApp2.csproj b/test-suite/TestApp2/TestApp2.csproj
new file mode 100644 (file)
index 0000000..8d0a60e
--- /dev/null
@@ -0,0 +1,12 @@
+<Project Sdk="Tizen.NET.Sdk/1.0.3">\r
+\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\NetcoreDbgTest\NetcoreDbgTest.csproj" />\r
+  </ItemGroup>\r
+\r
+  <PropertyGroup>\r
+    <OutputType>Exe</OutputType>\r
+    <TargetFramework>netcoreapp2.1</TargetFramework>\r
+  </PropertyGroup>\r
+\r
+</Project>\r
diff --git a/test-suite/TestApp2/tizen-manifest.xml b/test-suite/TestApp2/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..15e8caa
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<manifest xmlns="http://tizen.org/ns/packages" api-version="5" package="org.tizen.example.TestApp2" version="1.0.0">\r
+  <profile name="common" />\r
+  <service-application appid="org.tizen.example.TestApp2"\r
+                                       exec="TestApp2.dll"\r
+                                       type="dotnet"\r
+                                       multiple="false"\r
+                                       taskmanage="false"\r
+                                       nodisplay="true">\r
+    <label>TestApp2</label>\r
+    <metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />\r
+  </service-application>\r
+</manifest>\r
index 3de3753157b1509d8e5c501ed3fb70527378ff46..9376610cced4e3d96962ff11aca18323c4104261 100755 (executable)
@@ -121,7 +121,7 @@ if [ -d "$SCRIPTDIR/unpacked" ]; then rm -rf "$SCRIPTDIR/unpacked"; fi
 mkdir "$SCRIPTDIR/unpacked" && cd "$SCRIPTDIR/unpacked"
 rpm2cpio "$RPMFILE" | cpio -idmv
 touch .$TOOLS_ABS_PATH/$PKGNAME/version-$PKGVERSION
-tar cfz ../$TARGZNAME --owner=root --group=root -C .$TOOLS_ABS_PATH .
+tar cfz ../$TARGZNAME --owner=owner --group=users -C .$TOOLS_ABS_PATH .
 cd ..
 
 # Upload TGZ to target and unpack
diff --git a/test-suite/sdb_run_tizen_tests.sh b/test-suite/sdb_run_tizen_tests.sh
new file mode 100755 (executable)
index 0000000..f38f669
--- /dev/null
@@ -0,0 +1,157 @@
+#!/bin/bash
+
+# This script tests:
+# - tpk applications installation with and without NI generation (test debugger's pdb search routine)
+# - launch_app work with debugger (in this way MSVS plugin work with debugger)
+
+print_help()
+{
+    echo "Usage: sdb_run_tizen_tests.sh [OPTION]..."
+    echo "Run functional tests on Tizen target device."
+    echo ""
+    echo "  -s, --sdb         sdb binary, \"sdb\" by default"
+    echo "  -p, --port        local tcp port, \"4712\" by default"
+    echo "  -d, --dotnet      dotnet binary, \"dotnet\" by default"
+    echo "      --repeat      repeat tests, \"1\" by default"
+    echo "  -g, --gbsroot     path to GBS root folder, \"\$HOME/GBS-ROOT\" by default"
+    echo "  -r, --rpm         path to netcordbg rmp file"
+    echo "      --help        display this help and exit"
+}
+
+# DO NOT CHANGE
+# we use first test control program for both tests, since we need NI generation in second test
+# make sure, that you have all sources synchronized
+ALL_TEST_NAMES=(
+    "TestApp1"
+    "TestApp2"
+)
+
+SDB=${SDB:-sdb}
+PORT=${PORT:-4712}
+DOTNET=${DOTNET:-dotnet}
+REPEAT=${REPEAT:-1}
+GBSROOT=${GBSROOT:-$HOME/GBS-ROOT}
+# launch_app have hardcoded path
+TOOLS_ABS_PATH=/home/owner/share/tmp/sdk_tools
+SCRIPTDIR=$(dirname $(readlink -f $0))
+
+for i in "$@"
+do
+case $i in
+    -s=*|--sdb=*)
+    SDB="${i#*=}"
+    shift
+    ;;
+    -p=*|--port=*)
+    PORT="${i#*=}"
+    shift
+    ;;
+    -d=*|--dotnet=*)
+    DOTNET="${i#*=}"
+    shift
+    ;;
+    --repeat=*)
+    REPEAT="${i#*=}"
+    shift
+    ;;
+    -g=*|--gbsroot=*)
+    GBSROOT="${i#*=}"
+    shift
+    ;;
+    -r=*|--rpm=*)
+    RPMFILE="${i#*=}"
+    shift
+    ;;
+    -h|--help)
+    print_help
+    exit 0
+    ;;
+    *)
+    echo "Error: unknown option detected"
+    exit 1
+    ;;
+esac
+done
+
+if [[ -z $RPMFILE ]]; then
+    # Detect target arch
+    if   $SDB shell lscpu | grep -q armv7l;  then ARCH=armv7l;
+    elif $SDB shell lscpu | grep -q aarch64; then ARCH=armv7l;
+    elif $SDB shell lscpu | grep -q i686;    then ARCH=i686;
+    else echo "Unknown target architecture"; exit 1; fi
+
+    # The following command assumes that GBS build was performed on a clean system (or in Docker),
+    # which means only one such file exists.
+    RPMFILE=$(find $GBSROOT/local/repos/ -type f -name netcoredbg-[0-9]\*$ARCH.rpm -print -quit)
+fi
+
+# Repackage RPM file as TGZ
+
+if [ ! -f "$RPMFILE" ]; then echo "Debugger RPM not found"; exit 1; fi
+PKGNAME=`rpm -q --qf "%{n}" -p $RPMFILE`
+PKGVERSION=`rpm -q --qf "%{v}" -p $RPMFILE`
+PKGARCH=`rpm -q --qf "%{arch}" -p $RPMFILE`
+TARGZNAME=$PKGNAME-$PKGVERSION-$PKGARCH.tar.gz
+if [ -d "$SCRIPTDIR/unpacked" ]; then rm -rf "$SCRIPTDIR/unpacked"; fi
+mkdir "$SCRIPTDIR/unpacked" && cd "$SCRIPTDIR/unpacked"
+rpm2cpio "$RPMFILE" | cpio -idmv
+touch .$TOOLS_ABS_PATH/$PKGNAME/version-$PKGVERSION
+tar cfz ../$TARGZNAME --owner=owner --group=users -C .$TOOLS_ABS_PATH .
+cd ..
+
+# Upload TGZ to target and unpack
+
+REMOTETESTDIR=$TOOLS_ABS_PATH/netcoredbg-tests
+
+$SDB shell rm -rf "$TOOLS_ABS_PATH/netcoredbg"
+$SDB shell mkdir -p $TOOLS_ABS_PATH/on-demand
+$SDB push $TARGZNAME $TOOLS_ABS_PATH/on-demand
+$SDB shell "cd $TOOLS_ABS_PATH && tar xf $TOOLS_ABS_PATH/on-demand/$(basename $TARGZNAME)"
+$SDB shell rm -rf "$REMOTETESTDIR"
+$SDB shell mkdir $REMOTETESTDIR
+
+NETCOREDBG=$TOOLS_ABS_PATH/netcoredbg/netcoredbg
+
+# Prepare
+$DOTNET build $SCRIPTDIR/TestRunner
+$SDB forward --remove tcp:$PORT
+$SDB forward tcp:$PORT tcp:4711
+
+test_pass=0
+test_fail=0
+test_list=""
+
+for i in $(eval echo {1..$REPEAT}); do
+# Build, install and run tests
+for TEST_NAME in ${ALL_TEST_NAMES[@]}; do
+    HOSTTESTDIR=$SCRIPTDIR/$TEST_NAME
+    $DOTNET build $HOSTTESTDIR
+    $SDB install $HOSTTESTDIR/bin/Debug/netcoreapp2.1/org.tizen.example.$TEST_NAME-1.0.0.tpk
+    $SDB shell launch_app org.tizen.example.$TEST_NAME  __AUL_SDK__ NETCOREDBG __DLP_DEBUG_ARG__ --server=4711,--
+
+    # DO NOT CHANGE
+    # we use first test control program for both tests, since we need NI generation in second test
+    # make sure, that you have all sources synchronized
+    dotnet run --project TestRunner -- \
+        --tcp localhost $PORT \
+        --test $TEST_NAME \
+        --sources "TestApp1/Program.cs" 
+
+    if [ "$?" -ne "0" ]; then
+        test_fail=$(($test_fail + 1))
+        test_list="$test_list$TEST_NAME ... failed\n"
+    else
+        test_pass=$(($test_pass + 1))
+        test_list="$test_list$TEST_NAME ... passed\n"
+    fi
+
+    $SDB shell pkgcmd -u -n org.tizen.example.$TEST_NAME
+done
+done # REPEAT
+
+echo ""
+echo -e $test_list
+echo "Total tests: $(($test_pass + $test_fail)). Passed: $test_pass. Failed: $test_fail."
+
+exit $test_fail