4月 07

android的monkey测试简单记录

  需要对android的一个软软件做个疲劳测试,使用android SDK自带的工具最为方便。所就开始做monkey测试,调用和回播的脚本是从网上搜集而来,自己做了小修改。原始脚本的网页url忘记记录,所以不能提供参考网连接。下面开始对我所做的简单测试做个记录。
  首先是在系统上安装java运行环境,这个比较简单。下载android SDK包,直接解压后就可以使用非常方便。
  进入android-sdk-windows/tools目录,在其下面写两个脚本。
录脚本的启动脚本名monkey_recorder.py脚本内容如下:

#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# 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.

from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder

device = mr.waitForConnection()
recorder.start(device)

回放脚本名为monkey_playback.py脚本内容如下:

#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# 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.

import sys
from com.android.monkeyrunner import MonkeyRunner

# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command.  The line is split into 2
# parts with a | character.  Text to the left of the pipe denotes
# which command to run.  The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command.  In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command. 

# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
    'TOUCH': lambda dev, arg: dev.touch(**arg),
    'DRAG': lambda dev, arg: dev.drag(**arg),
    'PRESS': lambda dev, arg: dev.press(**arg),
    'TYPE': lambda dev, arg: dev.type(**arg),
    'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
    }

# Process a single file for the specified device.
def process_file(fp, device):
    for line in fp:
        (cmd, rest) = line.split('|')
        try:
            # Parse the pydict
            rest = eval(rest)
        except:
            print 'unable to parse options'
            continue

        if cmd not in CMD_MAP:
            print 'unknown command: ' + cmd
            continue
        CMD_MAP[cmd](device, rest)
        
def go(file,num):
    n = num
    device = MonkeyRunner.waitForConnection()
    for i in range(int(n)):
        print 'now %s'%i
        fp = open(file, 'r')
        process_file(fp, device)
        fp.close();

def main():
    file = sys.argv[1]
    try :
        number = sys.argv[2]
    except :
        number = 1
    go(file,number)
 
if __name__ == '__main__':
    main()

  到此环境和脚本就算部署完了。下面开始记录脚本使用。
  首先将手机和电脑用usb线连好,使用“cmd”调出命令行,然后进入“android-sdk-windows/tools”目录。输入命令:
monkeyrunner.bat monkey_recorder.py
如果没有报错,并且出现以下界面,就可以开始录制脚本了。

  “wait”为每步操作间的等待时间。“Press a Button“发送,MENU,HOME,or SEARCH 按钮。“Type Something”为输入文字。“Fling”为模拟滑动操作。“Export Actions”为保存刚才录制的脚本。最后一个为刷新。   
  保存的脚本可以直接用文本编辑器手动编辑。假如我们录制的脚本为text.txt。下一步就是回放脚本,使用命令为:
monkeyrunner.bat monkey_playback.py test.txt 100
  最后的数字是将这个脚本循环100次。
  我只需要到此即可了。如果需要抓图片\照相\判断等高级功能,将来需要时再学习。

4月 06

读《稻盛和夫》

  稻盛和夫的经营哲学被众人推崇,中国的国学大师季羡林对其也有高度评价。此书是曹岫云著,记录了稻盛和夫生平的经典事迹,和稻盛和夫经营哲学的实践。
  书中的“恩师”一节讲述了稻盛和夫起初在一家经营管理都不好的工厂工作。后来遇到国到日本外寻找技术的人,此人很赏识稻盛和夫的技术,开出了丰厚的待遇,稻盛和夫非常高兴,感觉这是一个极好的机会。但是在高兴之余盗圣有找到老师,告知当前的事情,并希望得到指点。老师讲,到国外去就是卖技术,时间久了国内技术发展迅速,就失去了学习新知识的机会,几年后再回来就会落后。稻盛和夫经过思考,最终留在了日本。多年后回忆起这件事,非常感谢老师的指导。
  现在很多人为了增加几百或一两千就要跳槽,工作不了一年就觉得能力受到了限制就要另谋高就。放映出来的就是浮躁,既然不能踏踏实实的工作\学习,即使换了“更好”的地方也是一时之幸。如果需要换工作我想应该有两中情况:一\公司转换经营方向,与自己的职业规划不符。二\公司经营不善,已经不能满足自己的最低生活开支。有许多人认为自己就是因为这两点才离职,这时需要思考,这个是不是自己的底线。公司是不是跨行业转变了,是不是连住地下室一天吃三顿饼的工资都开不出来了。如果不是这两点,如果公司经营不善是无能所致,那自己也应该承担一部分责任,并且知道自己也是无能的。  
image

4月 05

越来越慢的java问题

  新上线了一个接口,但是导致整个服务越来越慢。之前所做的压力测试结果也不错,五百并发只要十几秒。因为没有做疲劳测试,当前看来还是有问题。但是具体哪里出了问题还不清楚,需要详细查看。我也不是java开发所以只能是协助分析,先找了个分析工具看看导致瓶颈的主要原因。下载http://java.net/projects/visualvm/downloads/download/release134/visualvm_134.zip,解压缩后直接使用。
  解压缩后在文件夹的bin目录下有两个可执行文件,一个是exe的windows下使用的,另一个是linux下使用的。直接将解压的目录上传到linux操作系统中。准备运行,需要注意的是,linux下运行需要用到图形化,所以要用putty这类的小工具需要开启X11。
  启动# sh visualvm。在左侧可以看到已经启动的容器,打开resin服务。等待运行一段时间如图:
  经过更长时间对比,确定应该是内存泄露问题。因为内存值不断在增长,直至将系统资源占满。正常的接口,进行压力测试时,内存和CPU的值均比较平衡。具体问题使用sampler进行分析,应该是字符转换存在问题,并且没有释放。我直接反馈给开发人员,具体问题就不清楚了,在此做个简单记录。

4月 04

最接地气的娱乐节目

  为了争夺晚间黄金时间,娱乐节目竞争也很激烈。我很少看,但是有些娱乐节目想不知道也很难,并且也需要看看,不要在聊天时像个外星人。回老家的时候,因为家里没有交有线电视费,以为不能看了,偶然发现在和河北省可以看河北电视台。看到节目“家政女皇”,主要介绍生活中的小窍门和生活相关的科学知识。之前也很过,但是没有太在意,今天一看还添加了一个学新闻类的片段,太搞笑了。推荐大家看看。在加上河北台的“村里那点事”。我和老婆讨论了一下,将河北电视台评委最接地气的娱乐节目。推荐中。