From ee1ef69ab0f9271f06a500cc15b758d869d66878 Mon Sep 17 00:00:00 2001 From: wuliushuan Date: Thu, 13 Jul 2023 09:37:59 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuliushuan Change-Id: Iff2db399bf15c8b9394782c9d34e3182ff84f013 --- cases/smoke/basic/screenshot32/acls_check/acl_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cases/smoke/basic/screenshot32/acls_check/acl_check.py b/cases/smoke/basic/screenshot32/acls_check/acl_check.py index 3a12bb5..a6781a1 100644 --- a/cases/smoke/basic/screenshot32/acls_check/acl_check.py +++ b/cases/smoke/basic/screenshot32/acls_check/acl_check.py @@ -32,7 +32,7 @@ def whitelist_check(whitelist, acls): for acl in v: if acl not in temp: check_pass = False - set_log_content(LogLevel(2).name, log_tag, log_tag + '->whitelist_check', + set_log_content(LogLevel(2).name, log_tag + '->whitelist_check', 'precessName = {} the acl = {} trustlist is not configured.'.format(k, acl)) else: check_pass = False -- Gitee From fa90a9f6dedfb7434bf467f09717318292a74463 Mon Sep 17 00:00:00 2001 From: wuliushuan Date: Tue, 18 Jul 2023 08:37:31 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20apl=20=E9=97=A8?= =?UTF-8?q?=E7=A6=81=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuliushuan Change-Id: I4d02b68f76eae1d8201d19fcae66a2487b763d32 --- ...\272\277\346\240\207\345\207\206v1.0.json" | 47 ++++ .../screenshot32/APL_compare_03/apl_config.py | 61 ++++++ .../screenshot32/APL_compare_03/common.py | 95 +++++++++ .../screenshot32/APL_compare_03/compare.py | 200 ++++++++++++++++++ .../APL_compare_03/read_device.py | 83 ++++++++ .../screenshot32/APL_compare_03/read_excel.py | 81 +++++++ .../screenshot32/APL_compare_03/readme.md | 121 +++++++++++ .../screenshot32/APL_compare_03/temp.json | 75 +++++++ .../screenshot32/acls_check/acl_check.py | 2 +- 9 files changed, 764 insertions(+), 1 deletion(-) create mode 100644 "cases/smoke/basic/screenshot32/APL_compare_03/APL\345\237\272\347\272\277\346\240\207\345\207\206v1.0.json" create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/apl_config.py create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/common.py create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/compare.py create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/read_device.py create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/read_excel.py create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/readme.md create mode 100644 cases/smoke/basic/screenshot32/APL_compare_03/temp.json diff --git "a/cases/smoke/basic/screenshot32/APL_compare_03/APL\345\237\272\347\272\277\346\240\207\345\207\206v1.0.json" "b/cases/smoke/basic/screenshot32/APL_compare_03/APL\345\237\272\347\272\277\346\240\207\345\207\206v1.0.json" new file mode 100644 index 0000000..7f7eec0 --- /dev/null +++ "b/cases/smoke/basic/screenshot32/APL_compare_03/APL\345\237\272\347\272\277\346\240\207\345\207\206v1.0.json" @@ -0,0 +1,47 @@ +[ + { + "bundle&processName": "com.ohos.launcher", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.settings", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.systemui", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.screenlock", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.adminprovisioning", + "apl": "2" + }, + { + "bundle&processName": "edm", + "apl": "3" + }, + { + "bundle&processName": "com.ohos.settings.faceauth", + "apl": "2" + }, + { + "bundle&processName": "cn.openharmony.inputmethodchoosedialog", + "apl":"3" + }, + { + "bundle&processName":"media_service", + "apl":"3" + }, + { + "bundle&processName":"com.ohos.amsdialog", + "apl":"3" + }, + { + "bundle&processName":"com.ohos.useriam.authwidget", + "apl":"2" + } + +] \ No newline at end of file diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/apl_config.py b/cases/smoke/basic/screenshot32/APL_compare_03/apl_config.py new file mode 100644 index 0000000..b6bc30b --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/apl_config.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import os +# PATH='D:\\repo_test\\APL_compare_02\\' +# PATH=os.getcwd()+'/' +PATH = os.path.dirname(os.path.realpath(__file__)) + os.sep +# read_excel.py +''' +SHEET_NAME:excel中的表名,中英文都可 +COLS:excel中的列号,从0开始 +SVN:SVN的安装目录下/bin目录(SVN在环境变量中的位置) +SVN_URL:excel文件对应的url +USER:svn的用户名 +PWD:svn的密码 +FILE_PATH:本地下载文件的路径 +''' +SHEET_NAME="Sheet1" +COLS=[1,3] + +SVN='D:/TortoiseSVN/bin' +SVN_URL='https://PMAIL_2140981.china.huawei.com/svn/test测试/01 目录/01_1 目录/APL基线标准v1.0.xlsx' +USER='hhhhs' +PWD='123456' +FILE_PATH=PATH+SVN_URL.split('/')[-1] + +# read_device.py +''' +SQL_SRC:设备上的数据库路径 +SQL_DES:本地下载文件路径 +DOWNLOAD_DB:从设备下载的hdc命令 +QUERY_HAP_APL:查询HAP APL的sql语句(查询多列可以依次添加字段,添加字段的顺序为比较时的字段优先级) +QUERY_NATIVE_APL:查Native APL的sql语句 +''' +SQL_SRC=" /data/service/el1/public/access_token/access_token.db" +SQL_DES=PATH +DOWNLOAD_DB="hdc -t {} file recv" +QUERY_HAP_APL="select bundle_name,apl from hap_token_info_table" +QUERY_NATIVE_APL="select process_name,apl from native_token_info_table" + +''' +APL_LOG_FILE:执行脚本的日志信息 +APL_RECORD_PATH:APL对比记录的日志信息 +IS_OVERWRITE:是否覆盖之前的APL日志,w表示覆盖,a表示追加 +''' +APL_LOG_FILE=PATH+'apl_compare.log' +APL_RECORD_PATH=PATH+'apl_record.txt' +IS_OVERWRITE='w' \ No newline at end of file diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/common.py b/cases/smoke/basic/screenshot32/APL_compare_03/common.py new file mode 100644 index 0000000..2cf1c74 --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/common.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#!/usr/bin/python3 +import math +import enum +import time +import logging +import threading +from apl_config import * + +log_tag = 'common' + +apl_file_log = logging.FileHandler(filename=APL_LOG_FILE, mode='a', encoding='utf-8') +fmt = logging.Formatter(fmt="%(asctime)s %(message)s", datefmt='%Y-%m-%d %H:%M:%S %a') +apl_file_log.setFormatter(fmt) + +# 定义日志 +apl_logger = logging.Logger(name = 'apl_compare_log', level=logging.INFO) +apl_logger.addHandler(apl_file_log) + +class ErrorType(enum.Enum): + not_in_apl_table = 1 + apl_is_invalid = 2 + +class ApiLevel(enum.Enum): + normal = 1 + system_basic = 2 + system_core = 3 + +class LogLevel(enum.Enum): + Error = 1 + Info = 2 + +class AplCompareException(Exception): + def __init__(self, msg): + self.msg = msg + +class AplCompareThread(threading.Thread): + def __init__(self, func, args=()): + super(AplCompareThread, self).__init__() + self.func = func + self.args = args + self.result = None + def run(self): + self.result = self.func(*self.args) + def get_result(self): + threading.Thread.join(self) + try: + return self.result + except Exception as e: + apl_set_log_content(LogLevel(1).name, log_tag, '{}'.format(e.args[0])) + return None + +def apl_log(msg): + # 写日志 + apl_logger.info(msg) + +def apl_set_log_content(level, tag, msg): + log_content = timestamp() + ' {}'.format(level) + ' [{}]'.format(tag) + ' {}'.format(msg) + print(log_content) + apl_log(log_content) + return(log_content) + +def set_error_record(name,error): + return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())+' %(name)-50s: %(error)-50s\n'%{'name':name,'error':error} + +def set_map(results): + if results == None: + return None + res_map = {} + for result in results: + res_map[result[0]] = set_value(result[1:]) + return res_map + +def set_value(result): + value = [] + for res in result: + if math.isnan(res): + res = 0 + value.append(res) + return value + +def timestamp(): + return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/compare.py b/cases/smoke/basic/screenshot32/APL_compare_03/compare.py new file mode 100644 index 0000000..8ee180f --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/compare.py @@ -0,0 +1,200 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#!/usr/bin/python3 +import time +import sys +import os +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + os.sep) +from read_device import * +from read_excel import * +from apl_config import * + +def whitelist_check(apl, value, fields_from_whitelist): + # True 包含在白名单内 + check = value in fields_from_whitelist.keys() + is_pass = False + if check and str(apl) == fields_from_whitelist[value]: + is_pass = True + return is_pass + +def compare_hap_apl(fields_from_device, fields_from_whitelist): + records = [] + log_tag = 'compare_hap_apl' + hap_check = True + for value in fields_from_device: + apl = fields_from_device[value][0] + if apl > 1: + is_pass = whitelist_check(apl, value, fields_from_whitelist) + info = 'bundleName = {} apl = {}'.format(value, str(apl)) + if is_pass == False: + hap_check = False + # info = value + # info = 'bundleName = {} apl = {}'.format(value, str(apl)) + log_content = apl_set_log_content(LogLevel(1).name, log_tag, info) + records.append(log_content) + else: + apl_set_log_content(LogLevel(2).name, log_tag, info) + return records, hap_check + +def compare_native_apl(fields_from_device, fields_from_whitelist): + records = [] + log_tag = 'compare_native_apl' + native_check = True + for value in fields_from_device: + apl = fields_from_device[value][0] + if apl > 2: + info = 'processName = {} apl = {}'.format(value, str(apl)) + is_pass = whitelist_check(apl, value, fields_from_whitelist) + if is_pass == False: + native_check = False + log_content = apl_set_log_content(LogLevel(1).name, log_tag, info) + records.append(log_content) + else: + apl_set_log_content(LogLevel(2).name, log_tag, info) + return records, native_check + +def fields_compare_write_once(fields_from_device,fields_from_excel): + records=[] + for bundle_name in fields_from_device.keys(): + if bundle_name not in fields_from_excel.keys(): + record=(bundle_name,ErrorType(1).name) + records.append(record) + continue + + fields=fields_from_device[bundle_name] + standard_fields=fields_from_excel[bundle_name] + if not isInvalid(fields,standard_fields): + record=(bundle_name,ErrorType(2).name) + records.append(record) + print('Compare successful!') + return records + + +def isInvalid(fields,standard_fields): + if len(fields) == 1: + return fields[0] <= standard_fields[0] + + for field, standard_field in fields, standard_fields: + if field>standard_field: + return False + return True + +def write_record(name,error): + try: + file = open(APL_RECORD_PATH,'a') + err_record = set_error_record(name, error) + file.write(err_record) + file.close() + except Exception as e: + log_content=apl_set_log_content(str(s)) + apl_log(log_content) + +def write_record_once(err_records,is_overwrite): + try: + file=open(APL_RECORD_PATH,is_overwrite) + for record in err_records: + err_record = set_error_record(record[0],record[1]) + file.write(err_record) + file.close() + except Exception as e: + log_content=apl_set_log_content(str(e)) + apl_log(log_content) + +def excel_thread(): + try: + # settings={ + # ' svn': SVN, + # 'url': url_encode(SVN_URL), + # 'user': USER, + # 'pwd': PWD, + # 'dir': FILE_PATH, + # } + # excel_file = FILE_PATH #svn_checkout(settings) + log_tag = 'excel_thread' + # if excel_file == None: + # apl_set_log_content(LogLevel(2).name, log_tag, 'svn_checkoutc failed') #raise + # apl_from_excel = read_excel(excel_file, sheet = SHEET_NAME, cols = COLS) + # path = PATH + 'APL基线标准v1.0.json' + path = PATH + 'temp.json' + apl_from_json = read_json(path) + return apl_from_json + except Exception as e: + apl_set_log_content(LogLevel(1).name, log_tag, 'excel_thread catch error: {}'.format(e.args[0])) + return None + +def sql_thread(sn, sn2): + try: + print(DOWNLOAD_DB.format(sn)+' ' + SQL_SRC + ' ' + SQL_DES) + print() + log_tag = 'sql_thread' + sql_file = download_from_device(DOWNLOAD_DB.format(sn), SQL_SRC, SQL_DES) + if sql_file == None: + raise + query_hap_apl_thread = AplCompareThread(query_hap_apl, (sql_file, QUERY_HAP_APL)) + query_native_apl_thread = AplCompareThread(query_native_apl, (sql_file, QUERY_NATIVE_APL)) + + query_hap_apl_thread.start() + query_native_apl_thread.start() + + query_native_apl_thread.join() + query_native_apl_thread.join() + + hap_apl_map = query_hap_apl_thread.get_result() + native_apl_map = query_native_apl_thread.get_result() + + return hap_apl_map, native_apl_map + except: + apl_set_log_content(LogLevel(1).name, log_tag, 'download_from_device failed') + return None,None + +def apl_check_main(sn): + try: + log_tag = 'Main' + apl_set_log_content(LogLevel(2).name, log_tag, '--------APL Check Begin!--------') + excel_thr = AplCompareThread(excel_thread) + sql_thr = AplCompareThread(sql_thread, (sn, sn)) + + excel_thr.start() + sql_thr.start() + + excel_thr.join() + sql_thr.join() + + apl_from_excel = excel_thr.get_result() + hap_apl_map, native_apl_map = sql_thr.get_result() + + if apl_from_excel == None or hap_apl_map == None or native_apl_map == None: + raise + hap_results, hap_check = compare_hap_apl(hap_apl_map, apl_from_excel) + native_results, native_check = compare_native_apl(native_apl_map, apl_from_excel) + write_record_once(hap_results, IS_OVERWRITE) + write_record_once(native_results, 'a') + if native_check == False or hap_check == False: + apl_set_log_content(LogLevel(1).name, log_tag, '--------APL Check failed![hap = {}, native = {}] --------'.format(hap_check, native_check)) + apl_set_log_content(LogLevel(2).name, log_tag, '--------APL Check End! --------') + except Exception as e: + apl_set_log_content(LogLevel(1).name, log_tag, '--------APL Check failed![hap = False, native = False] --------') + apl_set_log_content(LogLevel(1).name, log_tag, "{}".format(e.args[0])) + +if __name__ == '__main__': + try: + sn = sys.argv[1] + except: + sn_list = [] + result = os.popen('hdc list targets') + res = result.read() + for line in res.splitlines(): + sn_list.append(line) + sn = sn_list[0] + apl_check_main(sn) diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/read_device.py b/cases/smoke/basic/screenshot32/APL_compare_03/read_device.py new file mode 100644 index 0000000..114a731 --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/read_device.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#!/usr/bin/python3 + +from subprocess import run +import os +import sqlite3 + +import sys +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + os.sep) +from common import * +from apl_config import * +log_tag = 'read_device' + +#从设备中导出数据库 +def download_from_device(cmd,sql_src,sql_des): + download_cmd=cmd+' '+sql_src+' '+sql_des + apl_set_log_content(LogLevel(2).name, log_tag, 'database start downloading!') + try: + result = os.popen(download_cmd) + stdout = result.read() + print(stdout) + if 'Fail' in stdout: + raise AplCompareException(stdout.replace('\n\n','').replace('[Fail]', '')) + #sql_file=sql_des+'\\'+sql_src.split('/').pop() + sql_file = sql_des+sql_src.split('/').pop() + apl_set_log_content(LogLevel(2).name, log_tag, '{} download successful!'.format(sql_file)) + return sql_file + except Exception as e: + apl_set_log_content(LogLevel(1).name, log_tag, '{}'.format(e.msg)) + return None + + +def sql_connect(db): + try: + if not os.path.exists(db): + raise AplCompareException('{} is not exists!'.format(db)) + conn = sqlite3.connect(db) + return conn + except AplCompareException as e: + apl_set_log_content(LogLevel(1).name, log_tag, '{}'.format(e.msg)) + return None + +#数据库语句查询 +def query_records(db,sql): + log_content = '' + try: + conn = sql_connect(db) + if conn == None: + raise AplCompareException('{} cannot connect!'.format(db)) + cursor = conn.cursor() + cursor.execute(sql) + results = cursor.fetchall() + conn.close() + apl_set_log_content(LogLevel(2).name, log_tag, '"{}" query successful!'.format(sql)) + return results + except sqlite3.OperationalError as e: + apl_set_log_content(LogLevel(2).name, log_tag, 'database {}'.format(e.args[0])) + return None + except AplCompareException as e: + apl_set_log_content(LogLevel(1).name, log_tag, '{}'.format(e.msg)) + return None + +#查询hap_token_info_table中的bundle_name和apl +def query_hap_apl(db,sql): + results = query_records(db, sql) + return set_map(results) + +#查询native_token_info_table中的process_name和apl +def query_native_apl(db,sql): + results = query_records(db, sql) + return set_map(results) diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/read_excel.py b/cases/smoke/basic/screenshot32/APL_compare_03/read_excel.py new file mode 100644 index 0000000..20b6a25 --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/read_excel.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#!/usr/bin/python3 + +import subprocess +import pandas as pd +import urllib.parse +import os +import sys +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + os.sep) +from common import * +from apl_config import * +import json +log_tag = 'read_whitelist' + +# 全部文件夹检出(本地已经安装svn) +def svn_checkout(settings): + try: + print(settings['url']) + print(settings['dir']) + os.chdir(settings['svn']) + cmd = 'svn export --force %(url)s %(dir)s --username %(user)s --password %(pwd)s'%settings + p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + stdout,stderr = p.communicate() + print(stderr) + if stderr != b'': + raise AplCompareException(str(stderr,'utf-8').replace('\r\n','\t')) + apl_set_log_content(LogLevel(2).name, log_tag, '{} export successful!'.format(settings['dir'])) + return settings['dir'] + except Exception as e: + apl_set_log_content(LogLevel(1).name, log_tag, "{}".format(e.msg)) + return None + +#url编码 +def url_encode(url): + partions=url.split("/",3) + encode_url=partions[0] + partions[-1]=urllib.parse.quote(partions[-1]) + for partion in partions[1:]: + encode_url=encode_url+'/'+partion + return encode_url + +def read_excel(file, sheet, cols): + try: + df = pd.read_excel(file, sheet_name = sheet, usecols = cols) + data_list = df.values.tolist() + apl_map = set_map(data_list) + apl_set_log_content(LogLevel(2).name, log_tag, '{} read successful!'.format(file)) + return apl_map + except (ValueError,FileNotFoundError) as e: + apl_set_log_content(LogLevel(1).name, log_tag, "{}".format(e.msg)) + return None + + +def read_json(path): + try: + with open(path, 'r') as f: + file = f.read() + data_list = json.loads(file) + res_dict = set_dict(data_list) + return res_dict + except Exception as e: + apl_set_log_content(LogLevel(1).name, log_tag, '{}'.format(e.msg)) + return None + +def set_dict(data_list: list()): + res_dict = {} + for res in data_list: + res_dict[res['bundle&processName']] = res['apl'] + return res_dict \ No newline at end of file diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/readme.md b/cases/smoke/basic/screenshot32/APL_compare_03/readme.md new file mode 100644 index 0000000..80db383 --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/readme.md @@ -0,0 +1,121 @@ +## 版本 +python版本:3.8.10 +pip版本:22.1.2 +python依赖: + +``` +pip install pandas +pip install openpyxl +pip install subprocess +``` +## 使用 +`python compare.py` + +## 目录 +``` +APL_compare +├── apl_config.py # 整个目录中的常量定义 +├── read_device.py # 从设备中下载db并解析表和字段的函数 +├── read_excel.py # 从excel中解析表和字段的函数 +├── compare.py # 脚本运行入口 +└── common.py # 公共需要用到的函数 +``` +## apl_config.py +常量定义 +`PATH`:当前目录的地址 +### read_excel.py +`SHEET_NAME`:excel中的表名 +`COLS`:excel中的列名,下标从0开始 +`SVN`:SVN的安装目录下的bin目录 +`SVN_URL`:excel文件在SVN上对应的url +`USER`:svn的用户名 +`PWD`:svn的密码 +`FILE_PATH`:本地下载文件的路径 +`SQL_SRC`:设备上的数据库路径 +`SQL_DES`:本地下载文件路径 +`DOWNLOAD_DB`:从设备下载的hdc命令 +`QUERY_HAP_APL`:查询HAP APL的sql语句(查询多列可以依次添加字段,添加字段的顺序为比较时的字段优先级) +`QUERY_NATIVE_APL`:查Native APL的sql语句 +`APL_LOG_FILE`:执行脚本的日志路径 +`APL_RECORD_PATH`:APL对比记录的日志路径 +`IS_OVERWRITE`:是否覆盖之前的APL日志,w表示覆盖,a表示追加 + +## read_device.py +用于从设备上导出数据库,并解析表和字段 +### 数据库导出 +函数:`download_from_device(cmd,sql_src,sql_des)` +hdc命令:`cmd` +设备中数据库路径:`sql_src` +本地数据库路径:`sql_des` +执行命令:`hdc file recv sql_src sql_des` +### 连接数据库 +相关函数:`sql_connect(db)` +传入参数:`db`--db文件存放路径 +返回结果:`conn`--数据库的连接 +### sql语句查询 +相关函数:`query_records(db,sql)` +传入参数:`db`--需要连接的数据库;`sql`:sql查询语句 +返回结果:`results`--查询结果 +### 查hap_token_info_table中的bundle_name和apl +sql语句:`QUERY_HAP_APL="select bundle_name,apl from hap_token_info_table"` +相关函数:`query_hap_apl(db,sql)` +传入参数:`db`--需要连接的数据库;`sql`:sql查询语句 +返回结果:`res_map`--查询结果转化为的字典(map,key是bundle_name,value是apl) +### 查询native_token_info_table中的process_name和apl +sql语句:`QUERY_NATIVE_APL="select process_name,apl from native_token_info_table"` +相关函数:`query_native_apl(db,sql)` +传入参数:`db`--需要连接的数据库;`sql`--sql查询语句 +返回结果:`res_map`--查询结果转化为的字典(map,key是process_name,value是apl) + +## read_excel.py +### 从svn上下载excel +相关函数:`syn_checkout(settings)` +传入参数:`settings`--包含svn上文件路径,本地路径,用户名,密码 +返回结果:`settings['dir']`--本地下载路径 +### url编码 +相关函数:`url_encode(url)` +传入参数:`url` +返回结果:`encode_url` + +### 解析excel +相关函数:`read_excel(file,sheet,cols)` +传入参数:`file`--excel文件,`sheet`--表名,`cols`--列名 +返回结果:`apl_map`----查询结果转化为的字典(map,key是bundle/process_name,value是apl) + +## common.py +### 脚本执行过程中的错误日志 +相关函数:`log(msg)` +相关参数:`msg`--错误信息 +### 设置脚本执行过程中的日志信息 +相关函数:`apl_set_log_content(msg)` +相关参数:`msg`--日志信息,`is_error`--用于判断是执行失败、成功 +返回结果:带时间戳的日志信息 + +### 设置apl记录的格式 +相关函数:set_error_record(name,error) +相关参数:`name`--bundle name或者native name,`error`--错误原因 +返回结果:带时间戳的记录 + +### 将查询结果转化成map的结构 +相关函数:`set_map(results)` +传入参数:`results`--查询结果的列表 +返回结果:`res_map` +### 转换查询结果map的value格式 +相关函数:`set_value(result)` +传入参数:`result`--查询到的每一行结果 +返回结果:`value`--包含查询到的字段的列表 +### 时间戳 +相关函数:`timestamp()` +返回结果:时间戳 + +### 错误类型 +`ErrorType`:枚举类 + +### 自定义异常 +`AplCompareException` + +### 自定义线程 +`AplCompareThread` + +### 日志格式设置 +`logging.basicConfig` \ No newline at end of file diff --git a/cases/smoke/basic/screenshot32/APL_compare_03/temp.json b/cases/smoke/basic/screenshot32/APL_compare_03/temp.json new file mode 100644 index 0000000..15eb949 --- /dev/null +++ b/cases/smoke/basic/screenshot32/APL_compare_03/temp.json @@ -0,0 +1,75 @@ +[ + { + "bundle&processName": "com.ohos.launcher", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.settings", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.systemui", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.screenlock", + "apl": "2" + }, + { + "bundle&processName": "com.ohos.adminprovisioning", + "apl": "2" + }, + { + "bundle&processName": "edm", + "apl": "3" + }, + { + "bundle&processName": "com.ohos.settings.faceauth", + "apl": "2" + }, + { + "bundle&processName": "cn.openharmony.inputmethodchoosedialog", + "apl":"3" + }, + { + "bundle&processName":"media_service", + "apl":"3" + }, + { + "bundle&processName":"com.ohos.amsdialog", + "apl":"3" + }, + { + "bundle&processName":"com.ohos.useriam.authwidget", + "apl":"2" + }, + { + "bundle&processName":"com.ohos.powerdialog", + "apl":"2" + }, + { + "bundle&processName":"com.ohos.filepicker", + "apl":"2" + }, + { + "bundle&processName":"com.ohos.camera", + "apl":"3" + }, + { + "bundle&processName":"com.ohos.smartperf", + "apl":"2" + }, + { + "bundle&processName":"com.ohos.devicemanagerui", + "apl":"2" + }, + { + "bundle&processName":"ohos.telephony.resources", + "apl":"3" + }, + { + "bundle&processName":"com.ohos.notificationdialog", + "apl":"2" + } + +] \ No newline at end of file diff --git a/cases/smoke/basic/screenshot32/acls_check/acl_check.py b/cases/smoke/basic/screenshot32/acls_check/acl_check.py index a6781a1..3a12bb5 100644 --- a/cases/smoke/basic/screenshot32/acls_check/acl_check.py +++ b/cases/smoke/basic/screenshot32/acls_check/acl_check.py @@ -32,7 +32,7 @@ def whitelist_check(whitelist, acls): for acl in v: if acl not in temp: check_pass = False - set_log_content(LogLevel(2).name, log_tag + '->whitelist_check', + set_log_content(LogLevel(2).name, log_tag, log_tag + '->whitelist_check', 'precessName = {} the acl = {} trustlist is not configured.'.format(k, acl)) else: check_pass = False -- Gitee