1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (C) 2024 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15import time 16import pytest 17import re 18import os 19import subprocess 20import colorama 21from utils import * 22 23class TestHicheckerjssdk: 24 @pytest.mark.L0 25 def test_hichecker_leakwatchersdk(self): 26 subprocess.check_call("hdc shell rm -rf /data/app/el2/100/base/com.example.myapplication/haps/entry/files", shell=True) 27 subprocess.check_call("hdc install testModule/resource/jsleakwatchr.hap", shell=True) 28 time.sleep(3) 29 subprocess.check_call("hdc shell aa start -a EntryAbility -b com.example.myapplication", shell=True) 30 time.sleep(3) 31 TouchButtonByText("dump") 32 time.sleep(10) 33 command = "ls -l /data/app/el2/100/base/com.example.myapplication/haps/entry/files|grep heapsnapshot" 34 output = subprocess.check_output(f"hdc shell \"{command}\"", shell=True, text=True, encoding="utf-8") 35 assert "heapsnapshot" in output 36 filename = output.strip().split(" ")[-1] 37 subprocess.check_call(f"hdc file recv /data/app/el2/100/base/com.example.myapplication/haps/entry/files/{filename}", shell=True) 38 output = subprocess.check_output(f"certutil -hashfile {filename} SHA256") 39 sha256_lower = output.splitlines()[1].decode('utf-8') 40 sha256_upper = sha256_lower.upper() 41 42 command = "ls -l /data/app/el2/100/base/com.example.myapplication/haps/entry/files|grep jsleaklist" 43 output = subprocess.check_output(f"hdc shell \"{command}\"", shell=True, text=True, encoding="utf-8") 44 assert "jsleaklist" in output 45 filename = output.strip().split(" ")[-1] 46 47 output = subprocess.check_output(f"hdc shell cat /data/app/el2/100/base/com.example.myapplication/haps/entry/files/{filename}", shell=True, text=True, encoding="utf-8") 48 assert sha256_upper in output 49 print(sha256_upper) 50 subprocess.check_call("hdc uninstall com.example.myapplication", shell=True)