[TCT][scripts][Non-ACR] Script to show purpose in report page 07/319507/1 tizen_9.0
authorAbuzar Maqsood <abuzar.m@samsung.com>
Tue, 11 Feb 2025 05:40:22 +0000 (11:10 +0530)
committerAbuzar Maqsood <abuzar.m@samsung.com>
Wed, 12 Feb 2025 05:02:12 +0000 (05:02 +0000)
Change-Id: Ifea7dedcf7fafb6a56ee0095560ae2a73a085932
Signed-off-by: Abuzar Maqsood <abuzar.m@samsung.com>
(cherry picked from commit f421bff1105fd3d41627cbd19ea61aedf5c3e075)

scripts_tpk/tctestsgen.py

index fe7bde086e6a3f5e8e98fcf14d6bab6b033609c0..f98ea0525331ecb6e331bbfea9ccf8d26a822f6a 100755 (executable)
@@ -35,7 +35,6 @@ def gen(tcfile):
        set=''
        tfile=open(TFILE)
        fil=open(FILE, 'w')
-
        # begin
        fil.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        fil.write('    <?xml-stylesheet type="text/xsl" href="./testcase.xsl"?>\n')
@@ -56,9 +55,63 @@ def gen(tcfile):
                                for element in feature:
                                        fil.write('        <capability name="'+element+'"/>\n')
                                fil.write('      </capabilities>\n')
+
                tcname=fields[0]
                tcname=tcname.strip()
+
                tcpurpose=''
+
+               script_dir = os.path.dirname(os.path.abspath(__file__))
+               api_dir = os.path.dirname(script_dir)
+               path_to_tc = os.path.join(api_dir, f'src/{BUILD_TYPE}/{MODULE_NAME}')
+
+               if os.path.isdir(path_to_tc):
+                       c_files = [f for f in os.listdir(path_to_tc) if f.endswith('.c')]
+                       if c_files:
+                               grep_command = ['grep', '-B', '20', '-w', tcname] + [os.path.join(path_to_tc, f) for f in c_files]
+                       else:
+                               return
+               else:
+                       return
+
+               try:
+                       result = subprocess.run(grep_command, capture_output=True, text=True, check=True)
+               except subprocess.CalledProcessError as e:
+                       print("Command failed with error: " + e.stderr + "\n")
+
+               except Exception as e:
+                       print("An unexpected error occurred: " + str(e) + "\n")
+
+               output = result.stdout.strip()
+               lines = output.split('\n')
+               reversed_output = '\n'.join(reversed(lines))
+
+               purpose_pattern = re.compile(r'//& purpose:\s*(.*)')
+               description_pattern = re.compile(r'\* @description\s*(.*)')
+
+               purpose_match = purpose_pattern.search(reversed_output)
+               if purpose_match:
+                       tcpurpose = purpose_match.group(1).strip()
+                       if tcpurpose.startswith('/'):
+                               tcpurpose = ""
+               if tcpurpose == "":
+                       description_match = description_pattern.search(reversed_output)
+                       if description_match:
+                               tcpurpose = description_match.group(1).strip()
+                       else:
+                               tcpurpose = ""
+               if tcpurpose.startswith('/'):
+                       tcpurpose = ""
+
+               pattern = r'[&]'
+               tcpurpose = re.sub(pattern, '&amp;', tcpurpose)
+               pattern = r'[<]'
+               tcpurpose = re.sub(pattern, '&lt;', tcpurpose)
+               pattern = r'[>]'
+               tcpurpose = re.sub(pattern, '&gt;', tcpurpose)
+               pattern = r'["]'
+               tcpurpose = re.sub(pattern, '&quot;', tcpurpose)
+
                fil.write('      <testcase component="NativeAPI/'+MODULE_NAME_C+'/'+set+'" execution_type="auto" id="'+tcname+'" purpose="'+tcpurpose+'">\n')
                fil.write('        <description>\n')
                fil.write('          <test_script_entry test_script_expected_result="0">'+'{DEVICE_SUITE_TARGET_30}/external_wrapper.sh '+MODULE_FULL_NAME+' '+tcname+' '+BUILD_TYPE+'</test_script_entry>\n')
@@ -184,4 +237,4 @@ if os.path.exists('exclude.list'):
        shutil.copy(NEWFILE,TFILE)
 #####exclude.list#####
 
-gen(TFILE)
+gen(TFILE)
\ No newline at end of file