Add the option to check Internet privilege in dotnettool for the FOTA
[platform/core/dotnet/launcher.git] / tests / TCs / 6_TOOL / TOOL.py
index e2ed2f8..ae53ce5 100755 (executable)
@@ -9,9 +9,10 @@ from Utils import *
 
 module_name = "TOOL"
 
+
 # The `dotnettool` works normally.
 def TC_01():
-    if not exist("/usr/bin/dotnettool")
+    if not exist("/usr/bin/dotnettool"):
         return "FAIL : The dotnettool works normally"
 
     raw = cmd(f"shell dotnettool")
@@ -29,17 +30,21 @@ def TC_02():
 
     raw = cmd(f"shell find {RUNTIME_DIR} -name *.ni.dll")
     lines1 = [l for l in raw.splitlines()]
-    raw = cmd(f"shell find {RUNTIME_DIR} -name *.dll -not -name *.ni.dll")
+    len1 = len(lines1) + 1 # System.Private.CoreLib.dll
+    raw = cmd(f"shell find {RUNTIME_DIR} -maxdepth 1 -name *.dll -not -name *.ni.dll")
     lines2 = [l for l in raw.splitlines()]
-    if (len(lines1) + 2) != len(lines2):
-        return "FAIL : The number of .dll and .ni.dll must match"
+    len2 = len(lines2)
+    if len1 != len2:
+        return f"FAIL : The number of .dll({len2}) and .ni.dll({len1}) must match in the {RUNTIME_DIR}"
 
     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.ni.dll")
     lines1 = [l for l in raw.splitlines()]
+    len1 = len(lines1)
     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.dll -not -name *.ni.dll")
     lines2 = [l for l in raw.splitlines() if "/ref/" not in l]
-    if len(lines1) != len(lines2):
-        return "FAIL : The number of .dll and .ni.dll must match"
+    len2 = len(lines2)
+    if len1 != len2:
+        return f"FAIL : The number of .dll({len2}) and .ni.dll({len1}) must match in the {FRAMEWORK_DIR}"
 
     for ni in lines1:
         is_same = False
@@ -68,8 +73,8 @@ def TC_04():
         cmd(f"shell mv {RUNTIME_DIR}{SPC_DLL}.Backup {RUNTIME_DIR}{SPC_DLL}")
 
     raw = cmd(f"shell dotnettool --ni-dll {RUNTIME_DIR}{SPC_DLL}")
-    if f"{SPC_DLL} (FNV)" not in raw and \
-       "System.Private.CoreLib.ni.dll generated successfully." not in raw:
+    if (f"{SPC_DLL}" not in raw) or \
+       ("System.Private.CoreLib.ni.dll generated successfully." not in raw):
         return f"FAIL : Create native image for {SPC_DLL}"
 
     if not exist(f"{RUNTIME_DIR}{SPC_DLL}.Backup"):
@@ -111,8 +116,8 @@ def TC_06():
 # Create native image for Tizen.dll in `R2R` mode.
 def TC_07():
     raw = cmd(f"shell dotnettool --r2r --ni-dll {FRAMEWORK_DIR}Tizen.dll")
-    if "Tizen.dll (R2R)" not in raw and \
-       "Tizen.ni.dll generated successfully." not in raw:
+    if ("Tizen.dll" not in raw) or \
+       ("Tizen.ni.dll generated successfully." not in raw):
         return "FAIL : Create native image for Tizen.dll in R2R mode"
 
     return "PASS"
@@ -120,16 +125,16 @@ def TC_07():
 # Displays detailed information while creating native image for Tizen.Log.dll.
 def TC_08():
     raw = cmd(f"shell dotnettool --verbose --ni-dll {FRAMEWORK_DIR}Tizen.Log.dll")
-    if ("Opening input file" not in raw) or \
-       ("Breakdown of Indirections" not in raw) or \
-       ("Tizen.Log.ni.dll generated successfully." not in raw):
+    if ("Tizen.Log.ni.dll generated successfully." not in raw) or \
+       ("Processing " not in raw) or \
+       (" dependencies" not in raw) or \
+       ("Moved to phase " not in raw):
         return "FAIL : Displays detailed information while creating native image for Tizen.Log.dll"
 
     return "PASS"
 
 # Create a native image for netstandard.dll by specifying the directory containing the IBC files.
 def TC_09():
-    current_path = os.path.abspath(__file__)
     packaging_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../packaging"))
     ibcdata_zip = ""
 
@@ -150,7 +155,7 @@ def TC_09():
         return "FAIL : The netstandard.ibc file should exist"
 
     raw = cmd(f"shell dotnettool --ibc-dir /usr/share/dotnet.tizen/ibcdata/ --ni-dll {RUNTIME_DIR}netstandard.dll")
-    if ("netstandard.dll (FNV)" not in raw) or \
+    if ("netstandard.dll" not in raw) or \
        ("netstandard.ni.dll generated successfully." not in raw):
         return "FAIL : Create native image for netstandard.dll"
 
@@ -283,8 +288,8 @@ def TC_13():
         return f"FAIL : Install the application for {tpk_path}"
 
     raw = cmd(f"shell dotnettool --tac-regen-all")
-    if ".dll (FNV)" not in raw and \
-       ".ni.dll generated successfully." not in raw:
+    if (".dll" not in raw) or \
+       (".ni.dll generated successfully." not in raw):
         return "FAIL : Create native image for TAC"
 
     return "PASS"
@@ -404,8 +409,12 @@ def TC_16():
     raw = subprocess.run((f"sdb -s {serial} shell sqlite3 {DOTNET_DIR}.TAC.App.list.db").split(), stdout=subprocess.PIPE, input=f"select * from TAC;\n.q\n", encoding="utf-8").stdout
     lines = [l for l in raw.splitlines() if f"{pkg_id}" in l]
     for rcd in lines:
-        if ("SkiaSharp/2.80.2" not in rcd) and \
-           ("Xamarin.Forms/4.6.0.967" not in rcd):
+        is_exist = False
+        if ("SkiaSharp/2.80.2" in rcd) or \
+           ("Xamarin.Forms/4.6.0.967" in rcd):
+            is_exist = True
+            continue
+        if not is_exist:
             return "FAIL : TAC database must have a valid value"
 
     raw = subprocess.run((f"sdb -s {serial} shell sqlite3 {DOTNET_DIR}.TLC.App.list.db").split(), stdout=subprocess.PIPE, input=f"select * from TLC;\n.q\n", encoding="utf-8").stdout
@@ -424,11 +433,15 @@ def TC_17():
     if tpk_path == None:
         return f"FAIL : Get the tpk path for {sln_name}"
 
+    cmd(f"shell mount -o remount,rw /")
+
     raw = cmd(f"push {tpk_path} /usr/apps/.preload-tpk/")
     if "1 file(s) pushed. 0 file(s) skipped." in raw:
         cmd(f"shell install_preload_pkg")
 
-    cmd(f"shell dotnettool --ni-regen-all-ro-app")
+    cmd(f"shell mount -o remount,ro /")
+
+    cmd(f"shell dotnettool --ni-regen-all-app")
 
     raw = subprocess.run((f"sdb -s {serial} shell pkginfo --metadata-flt").split(), stdout=subprocess.PIPE, input=f"http://tizen.org/metadata/prefer_dotnet_aot\ntrue\n", encoding="utf-8").stdout
     lines = [l for l in raw.splitlines() if "appid" in l]
@@ -487,9 +500,149 @@ def TC_17_18():
 
     return "PASS"
 
-#def TC_19():
-#dotnettool --resolve-all-app
+# The `Launcher_TC_TOOL_09` application of read-only type generates native image.
+def TC_19():
+    sln_name = "Launcher_TC_TOOL_09.Tizen"
+
+    tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
+    if tpk_path == None:
+        return f"FAIL : Get the tpk path for {sln_name}"
+
+    cmd(f"shell mount -o remount,rw /")
+    raw = cmd(f"push {tpk_path} /usr/apps/.preload-tpk/")
+    if "1 file(s) pushed. 0 file(s) skipped." in raw:
+        cmd(f"shell install_preload_pkg")
+    cmd(f"shell mount -o remount,ro /")
+
+    pkg_id = f"org.tizen.example.Launcher_TC_TOOL_09.Tizen"
+
+    root_path = get_root_path(f"{pkg_id}")
+    if root_path == "None":
+        return f"FAIL : Get the root path for {pkg_id}"
+
+    if exist(f"{root_path}/bin/.native_image"):
+        return "FAIL : The .native_image folder not should exist"
+
+    cmd(f"shell dotnettool --ni-pkg {pkg_id}")
+
+    if not exist(f"{DOTNET_DIR}apps/{pkg_id}/bin/.native_image"):
+        return "FAIL : The .native_image folder should exist"
+
+    raw = cmd(f"shell find {DOTNET_DIR}apps/{pkg_id}/bin/.native_image/ -name *.ni.dll")
+    lines1 = [l for l in raw.splitlines()]
+    raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
+    lines2 = [l for l in raw.splitlines()]
+    if len(lines1) != len(lines2):
+        return "FAIL : The number of .dll and .ni.dll must match in the application"
+
+    for ni in lines1:
+        is_same = False
+        for dll in lines2:
+            if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
+                is_same = True
+                break
+        if not is_same:
+            return "FAIL : The file name of .dll and .ni.dll must match in the application"
+
+    return "PASS"
+
+# Print command and option while creating native image for Tizen.dll.
+def TC_20():
+    cmd(f"shell mount -o remount,rw /")
+    raw = cmd(f"shell dotnettool --print-cmd --ni-dll {FRAMEWORK_DIR}Tizen.dll")
+    if ("Tizen.ni.dll generated successfully." not in raw) or \
+       ("==================== NI Commands =========================" not in raw) or \
+       ("+ /usr/share/dotnet.tizen/netcoreapp/corerun" not in raw) or \
+       ("+ /usr/share/dotnet.tizen/netcoreapp/crossgen2/crossgen2.dll" not in raw) or \
+       ("+ --jitpath" not in raw) or \
+       ("+ /usr/share/dotnet.tizen/netcoreapp/libclrjit.so" not in raw) or \
+       ("+ --targetarch" not in raw) or \
+       ("+ --out-near-input" not in raw) or \
+       ("+ --single-file-compilation" not in raw) or \
+       ("+ --resilient" not in raw) or \
+       ("+ --Ot" not in raw) or \
+       (f"+ {FRAMEWORK_DIR}Tizen.dll" not in raw) or \
+       ("+ (null)" not in raw):
+        return "FAIL : Print command and option while creating native image for Tizen.dll"
+
+    return "PASS"
+
+# Create native image for netstandard.dll by adding options --inputbubble and --compilebubblegenerics.
+def TC_21():
+    cmd(f"shell mount -o remount,rw /")
+    raw = cmd(f"shell dotnettool --inputbubble --inputbubbleref \'{RUNTIME_DIR}*.dll\' --print-cmd --ni-dll {RUNTIME_DIR}netstandard.dll")
+    if ("netstandard.ni.dll generated successfully." not in raw) or \
+       ("+ --inputbubble" not in raw) or \
+       ("+ --compilebubblegenerics" not in raw):
+        return "FAIL : Create native image for netstandard.dll by adding options --inputbubble and --compilebubblegenereics"
+
+    return "PASS"
+
+# Create native image for System.dll by adding options --inputbubble and --inputbubbleref.
+def TC_22():
+    cmd(f"shell mount -o remount,rw /")
+    raw = cmd(f"shell dotnettool --inputbubble --inputbubbleref \'{RUNTIME_DIR}crossgen2/*.dll\' --print-cmd --ni-dll {RUNTIME_DIR}System.dll")
+    if ("System.ni.dll generated successfully." not in raw) or \
+       ("+ --inputbubble" not in raw) or \
+       ("+ --inputbubbleref:/usr/share/dotnet.tizen/netcoreapp/crossgen2/*.dll" not in raw):
+        return "FAIL : Create native image for System.dll by adding options --inputbubble and --inputbubbleref"
+
+    return "PASS"
+
+# Create native image for System.Console.dll by adding option --ref.
+def TC_23():
+    cmd(f"shell mount -o remount,rw /")
+    raw = cmd(f"shell dotnettool --ref \'{RUNTIME_DIR}*.dll:{RUNTIME_DIR}crossgen2/*.dll\' --print-cmd --ni-dll {RUNTIME_DIR}System.Console.dll")
+    if ("System.Console.ni.dll generated successfully." not in raw) or \
+       (f"+ -r:/usr/share/dotnet.tizen/netcoreapp/*.dll" not in raw) or \
+       (f"+ -r:/usr/share/dotnet.tizen/netcoreapp/crossgen2/*.dll" not in raw):
+        return "FAIL : Create native image for System.Console.dll by adding option --ref"
+
+    return "PASS"
+
+# Create native image for mscorlib.dll by adding option --no-pipeline
+def TC_24():
+    cmd(f"shell mount -o remount,rw /")
+    raw = cmd(f"shell dotnettool --ni-dll --no-pipeline --print-cmd {RUNTIME_DIR}mscorlib.dll")
+    if ("mscorlib.ni.dll generated successfully." not in raw) or \
+       ("+ -o" not in raw) or \
+       ("/mscorlib.ni.dll" not in raw):
+        return "FAIL : Create native image for mscorlib.dll by adding option --no-pipeline"
+
+    return "PASS"
+
+# Applications that do not have Internet privilege must have ._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6 file created.
+def TC_25():
+    sln_name = "Launcher_TC_TOOL_10.Tizen"
+
+    tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
+    if tpk_path == None:
+        return f"FAIL : Get the tpk path for {sln_name}"
+
+    if "OK" not in app_install(f"{tpk_path}"):
+        return f"FAIL : Install the application for {tpk_path}"
+
+    pkg_id = f"org.tizen.example.Launcher_TC_TOOL_10.Tizen"
+
+    root_path = get_root_path(f"{pkg_id}")
+    if root_path == "None":
+        return f"FAIL : Get the root path for {pkg_id}"
+
+    if not exist(f"{root_path}/bin/._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6"):
+        return "FAIL : The ._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6 file should exist"
+
+    cmd(f"shell mount -o remount,rw /")
+    cmd(f"shell rm {root_path}/bin/._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6")
+
+    cmd(f"shell dotnettool --check-all-app-privilege")
+    if not exist(f"{root_path}/bin/._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6"):
+        return "FAIL : The ._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6 file should exist"
+
+    return "PASS"
 
+#def TC_26():
+#dotnettool --rm-app-profile
+#dotnettool --rm-all-app-profile
 
 # Run the test
 def run():
@@ -499,10 +652,14 @@ def run():
     global tpk_list
     tpk_list = search_tpk(f"{module_name}")
 
-    p = run_tc_array(module_name, tc_array)
-    f = len(tc_array) - p
-    r = round(((p / len(tc_array)) * 100), 2)
-    print(f"--- {module_name} TCT Result ---\nFAIL : [{f}] / PASS : [{p}] - [{r}%]\n")
+    pn = run_tc_array(module_name, tc_array)
+    n = int(pn.split(":")[0])
+    f = int(pn.split(":")[1])
+    p = int(pn.split(":")[2])
+    r = 0.0
+    if (len(tc_array) - n) != 0:
+        r = round(((p / (len(tc_array) - n)) * 100), 2)
+    print(f"--- {module_name} TCT Result ---\nNONE : [{n}] / FAIL : [{f}] / PASS : [{p}] - [{r}%]\n")
 
 # Uninstall the application and restore to original state
 def clean():
@@ -513,14 +670,19 @@ def clean():
     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_05.Tizen")
     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_06.Tizen")
     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_07.Tizen")
+    cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_10.Tizen")
 
     cmd(f"shell rm {FRAMEWORK_DIR}Tizen.ni.dll")
     cmd(f"shell rm {FRAMEWORK_DIR}Tizen.Log.ni.dll")
     cmd(f"shell rm {RUNTIME_DIR}netstandard.ni.dll")
+    cmd(f"shell rm {RUNTIME_DIR}System.ni.dll")
+    cmd(f"shell rm {RUNTIME_DIR}System.Console.ni.dll")
+    cmd(f"shell rm {RUNTIME_DIR}mscorlib.ni.dll")
 
-    cmd(f"shell rm -rf {IBCDATA_DIR}")
+#    cmd(f"shell rm -rf {IBCDATA_DIR}")
 
     cmd(f"shell rm -rf {DOTNET_DIR}apps/org.tizen.example.Launcher_TC_TOOL_08.Tizen")
+    cmd(f"shell rm -rf {DOTNET_DIR}apps/org.tizen.example.Launcher_TC_TOOL_09.Tizen")
 
 # Main entry point
 def main():
@@ -538,7 +700,8 @@ def main():
             else:
                 tc_array.append(funcMap[tc_num])
     else:
-        tc_array = [TC_01, TC_02, TC_03, TC_04, TC_05, TC_06, TC_07, TC_08, TC_09, TC_10, TC_11, TC_12, TC_13, TC_14, TC_15, TC_16, TC_17, TC_18]
+        # skip TC_07 (--r2r), TC_09 (--ibc-dir)
+        tc_array = [TC_01, TC_02, TC_03, TC_04, TC_05, TC_06, TC_08, TC_10, TC_11, TC_12, TC_13, TC_14, TC_15, TC_16, TC_17, TC_18, TC_19, TC_20, TC_21, TC_22, TC_23, TC_24, TC_25]
 
     global serial
     if len(sys.argv) >= 2 and "TC_" not in sys.argv[1]:
@@ -561,9 +724,11 @@ funcMap = {
 'TC_01': TC_01, 'TC_02': TC_02, 'TC_03': TC_03, 'TC_04': TC_04, 'TC_05': TC_05, 'TC_06': TC_06,
 'TC_07': TC_07, 'TC_08': TC_08, 'TC_09': TC_09, 'TC_10': TC_10, 'TC_11': TC_11, 'TC_12': TC_12,
 'TC_13': TC_13, 'TC_14': TC_14, 'TC_15': TC_15, 'TC_16': TC_16, 'TC_17': TC_17, 'TC_18': TC_17_18,
+'TC_19': TC_19, 'TC_20': TC_20, 'TC_21': TC_21, 'TC_22' : TC_22, 'TC_23' : TC_23, 'TC_24' : TC_24, 'TC_25' : TC_25,
 'TOOL_TC_01': TC_01, 'TOOL_TC_02': TC_02, 'TOOL_TC_03': TC_03, 'TOOL_TC_04': TC_04, 'TOOL_TC_05': TC_05, 'TOOL_TC_06': TC_06,
 'TOOL_TC_07': TC_07, 'TOOL_TC_08': TC_08, 'TOOL_TC_09': TC_09, 'TOOL_TC_10': TC_10, 'TOOL_TC_11': TC_11, 'TOOL_TC_12': TC_12,
-'TOOL_TC_13': TC_13, 'TOOL_TC_14': TC_14, 'TOOL_TC_15': TC_15, 'TOOL_TC_16': TC_16, 'TOOL_TC_17': TC_17, 'TOOL_TC_18': TC_17_18
+'TOOL_TC_13': TC_13, 'TOOL_TC_14': TC_14, 'TOOL_TC_15': TC_15, 'TOOL_TC_16': TC_16, 'TOOL_TC_17': TC_17, 'TOOL_TC_18': TC_17_18,
+'TOOL_TC_19': TC_19, 'TOOL_TC_20': TC_20, 'TOOL_TC_21': TC_21, 'TOOL_TC_22' : TC_22, 'TOOL_TC_23' : TC_23, 'TOOL_TC_24' : TC_24, 'TOOL_TC_25' : TC_25
 }