[embodiment]
See also shown in Figure 1ly, the invention provides a kind of system pressure method of testing based on Android, described method of testing comprises the in no particular order application program pressure test of order, the test of one-level sleep standby wakeup, reboot pattern automatic on/off test of computer; It will define elementary instruction and function, the basic function of one-level sleep standby wakeup test and the basic function of reboot pattern automatic on/off test of computer that comprises the application program pressure test, write corresponding shell script according to basic function and relevant case, take the shell script as automatic test script, Run Script is realized pressure test when the Android system moves, according to the analysis of script design concept with check test result.
Its Android system pressure is tested most important part and is system stability, the key point of system stability is the long-time use of application program and power management (standby wakeup, switching on and shutting down) part, according to the above characteristics of pressure test and demand, this invention is take the shell script as the basis, from the application program pressure test, the test of one-level sleep standby wakeup, reboot pattern automatic on/off test of computer sets out.
A kind of system pressure method of testing based on Android of the present invention, described method of testing comprise the in no particular order application program pressure test of order, the test of one-level sleep standby wakeup, reboot pattern automatic on/off test of computer;
Described application program pressure test: define first simulation touch screen function and an analog physical button function; Described simulation touch screen function is used for realizing a series of touch screen events of Android system; Described analog physical button function is used for realizing the physical button event of Android system; The application program that starts the Android system namely starts application program by input am order line in the Android system, create one and be used for statistical test number of times and the first file of test duration, produce respectively corresponding test event the Android system is carried out repeatedly loop test by calling simulation touch screen function and analog physical button function, loop test checks that running status, operation result and first file of Android system equipment known test case after finishing; Wherein, when each time loop test finishes in the described application program pressure test, call the sleep function that carries in the Android system and control the time that enters next time application program pressure test circulation, be beneficial to better analytical test situation.
Described one-level sleep standby wakeup test: definition one simulation power button function, described simulation power button function is used for realizing the automatic stand-by of Android system and the event of waking up, create one and be used for statistical test number of times and the second file of test duration, by calling that simulation power button function produces automatic stand-by and the event waken up is carried out repeatedly loop test to the Android system, after loop test finishes, check that the running status of Android system equipment and the second file obtain standby and time of waking up is known test case; Wherein, when each time loop test finishes in the test of described one-level sleep standby wakeup, call the sleep function that carries in the Android system and control the time that enters automatic stand-by next time and wake test loop up, be beneficial to better analytical test situation.
Described reboot pattern automatic on/off test of computer: definition one realizes the script of reboot function, the code that in the boot.img of Android system file, adds the script of starting up reboot function, and amended boot.img file is compiled into executable file; Create one and be used for statistical test number of times and the 3rd file of test duration, the time that the sleep function that carries in the Android system is controlled automatic switching is called first after opening by the Android system, the cycling switch machine operation that is undertaken repeatedly by the script of carrying out realization reboot function is again tested, and knows test case by running status and the 3rd file of checking the Android system equipment.
Wherein, described application program pressure test, the test of one-level sleep standby wakeup, reboot pattern automatic on/off test of computer is write by shell script (the shell script is a kind of programming language).
The invention will be further described below in conjunction with three implementation examples:
As shown in Figure 2, example one: case(carries out pressure test to the camera camera function, realizes automatic camera 2000 times, and interval 2 second beats are shone once)
1, this example is write the shell script that possesses automatic photo function by the elementary instruction and the function (am order line, simulation touch screen function (being the touch function), sleep function, while circulation and counter) that define in the invention, and this script realizes that camera is carried out interval 2 second beats to be tested according to 2000 times robotization pressure.
2, this example at first calls the am order line to open application program (camera), create the file that is used for counting after opening camera, script executes and enters while circulation and beginning after these preconditions and frequently take pictures and count, this circulation intrinsic call touch function touches the coordinate position of taking pictures to realize camera function, and call the sleep function and carry out time control, realize 2 second beats photograph once, when cycle index reaches setting value (2000 times), circulation finishes, script is out of service, test finishes to camera robotization pressure, and whether the people is stable for checking that the rear camera state of test end and the result that takes pictures can draw the camera photo module.
As shown in Figure 3, example two: standby wakeup is 300 times in the case(Web page loading process)
1, this example is write the shell script by elementary instruction and the function (am order line, while circulation, simulation power button function (being the awaken function), analog physical button function (being the input program) and counter) of definition in the invention, and realization automatic stand-by in the Web page loading process wakes 300 times pressure test up.
2, this example is at first opened application program (browser) by calling the am function, create the text that is used for counting after the open any browser, carry out and enter while after these preconditions and circulate to realize standby wakeup 300 times, this circulation intrinsic call counter and awaken function, every circulation primary count value adds 1, every circulation primary, system call awaken function once, automatic stand-by wakes up once, in the awaken function, call the input program, use the release of input program, input network address and load this webpage, make system carry out standby at this loading procedure awaken function, sleep3 wakes and again carries out release among the input up after second, input network address and load this webpage, repetitive cycling circulates after cycle index reaches setting value (300 times) and finishes successively, and script is out of service, automatic stand-by wakes test up to be finished, and the people checks that SOT state of termination can draw the result of this robotization pressure test.
As shown in Figure 4, example three: automatic switching during the case(displaying video)
1, this example passes through to revise in the invention the rear automatically Run Script of method realization start of boot, and the pressure test of automatic switching when realizing video playback by the elementary instruction in the invention and function (am order line, the script of simulating touch screen function (being the touch function), sleep function, reboot function).
2, this example loops the switching on and shutting down operation after revising the automatic Run Script of init.rc file realization start, at first call the sleep function after the start with the control time, after being started fully, system carries out again next step operation, the design of calling the switching on and shutting down counter after system starts fully realizes the statistics of switching on and shutting down number of times, then call am order line and touch function and realize the environment of video playback, calling reboot realization system under this environment restarts, again call the sleep function after restarting, successively circulation, automatic switching robotization pressure test during with the realization video playback.
Here it is worth mentioning that:
Start the Activity(that application program need find out in the corresponding Android system with the am order line movable) and the Action(action).
Search Activity and Action method: 1, check the android source code, each corresponding APP has the AndroidManifest.xml file in package directory A PP, corresponding package and Activity are arranged in this document code, use am start-n " package+activity " order can realize the startup of this APP, in this document, have equally Action corresponding to application program.2, adb enters terminal, inputs logcat in system, manually boots program, checks the start { Activity } that prints among the adb, and this activity is equally applicable to am start[-n<COMPONENT 〉].
The code that in the boot.img of Android system file, adds the script of starting up reboot function, and amended boot.img file is compiled into executable file; Namely the init.rc file is the configuration file of program start in boot, by adding the script startup parameter, and will the Run Script program when kernel starts.
At first in the init.rc file, add code, then be compiled into the boot for automatic switching.
Init.rc adds at last:
The script (reboot.sh) of simple realization reboot function is:
#!/system/bin/sh
sleep30
reboot
Use adb can realize system's automatic switching to reboot.sh push to terminal/data/ catalogue.
Wherein, all use repeatedly circulation, counter and sleep function in each test mode.
1, circulation (while)
For pressure test, circulation is absolutely necessary, and also is the key of script, below uses for example the enough loop statement in all kinds of pressure tests of realization of while circulation.
The usage of While:
while?test-command
do
commands
done
If test-command is true, then move the commands order.
As: for realize 100 times circulation of click coordinate " 388 " " 508 " in conjunction with simulation touch screen function (touch function)
This circulation is applicable to all shell scripts.
2, counter
For automatic test, design a counter, statistical test number of times and test duration are necessary, and extremely important to test result analysis.
Below be shell script counter implementation procedure:
1, creates the file count.txt of counting
2, testing time is write this document
3, check that this document just can obtain testing time after test finishes, just can obtain altogether test duration according to script cycling time and testing time.
This Counter Design thinking write to realize number of times statistics in the test loop.
Aspect the automatic switching counting, owing to restarting script after the start, so need read last count value (j=`busybox head-1/data/countreboot.txt`), up cumulative to realize counting again, therefore need to create an accounting file (countreboot.txt), setting initial value is 1, and be kept at formulate catalogue (/data/).
j=`busybox?head-1/data/countmyshell.txt`
j=$((j+1))
echo"$j">/data/countreboot.txt
3, sleep function
The Sleep function is the android internal processes, calls this function and can realize that terminal is in sleep state within a certain period of time, does not do any operation, and this function can well make test process have procedure.
In a word, method of testing of the present invention comprises the in no particular order application program pressure test of order, the test of one-level sleep standby wakeup, reboot pattern automatic on/off test of computer; It is tested the Android system pressure from three aspects, its test is more comprehensive, above-mentioned test is write by the shell script, and the shell script is in the inner execution of program, it is write simply, can not be subject to external interference, the present invention has well realized Android system pressure automatic test is increased substantially testing efficiency.
The above only is preferred embodiment of the present invention, and all equalizations of doing according to the present patent application claim change and modify, and all should belong to covering scope of the present invention.