first, the test program preparation Instructions
What we do is run the QT application on the end device, using a custom keyboard interface. After a long period of human-computer interaction testing, to determine whether the system functions to meet the requirements. Now you need to write an automated test program that can be executed according to a preset script, such as a key that needs to be executed 10,000 times in a row, or a specific business process 10W times through several keystrokes. Through such automated testing, you can reduce the burden of testers, you can also see the trigger n times after the screen to perform the system after n times of stability, such as memory usage, cup usage, and so on.
The device has a 4*4 keyboard, including 0-9,c (call), A,u (UP), D (down), f1,f2 function keys, and different screens on the screen according to the action of the aforementioned buttons to perform the corresponding response action.
Ii. structural analysis of the test procedure
According to the above simple requirements, the first analysis of the test program structure is as follows:
The read-in script file can be a txt file with the approximate structure as follows:
--------Script_Sample.txt------------
3A53256A3
The first line represents the following 5 actions performed, respectively, by pressing A, U, C, a key and resting the corresponding number of seconds after each keystroke (that is, the following value), where the R 5 1 lines indicate that 1 rows repeat and repeat 5 times. R does not write in the script file, and if it is not written, it is executed sequentially and there is no loop operation.
The test program constructs a linked list based on this script, and the nodes in the linked list represent the corresponding operations, and the loop action in the sequence of actions lists the one-way loop lists that make up the local.
third, the test program to achieve the main logic
1. Define the chain list
typedefstruct List { char operation; int seconds; FLAG c_flag; int i_repeatCnt; int i_repeatLines; struct//指针域 struct//指针域 }List; List *oprtData_Set;
2. Escalate Input Events
intReportkey (intFD, uint16_t type, uint16_t keycode, int32_tvalue) {structInput_eventEvent;Event. type = type;Event. Code = KeyCode;Event.value=value; Gettimeofday (&Event. Time,0);if(Write (FD, &Event,sizeof(structInput_event)) <0) {printf ("Report Key error!\n");return-1; }return 0; }
3. Use the tail interpolation method to construct the chain list of key actions according to the action in the script
voidTailcreatlist (List *l,Char* fname)//tail interpolation to create a linked list{List *tmpdata; List *tail; List *groupheader;intI_repeatnums =0;intI_repeatlines =0, i_repeatlines_tmp =0;CharC_repeatid; Flag flag = HEADER;//flag = 1 Header Charbuffer[ +];CharC_repeatflag; FILE *infile; Infile=fopen (fname,"R"); Tail=l;//nullgroupheader=tail->nextgp;//null if(Infile==null) {printf("\nfailed to open the file:%s \ n", fname);Exit(0); }Else{printf("Open success! \ n "); } fgets (Buffer,sizeof(buffer), infile);sscanf(Buffer,"%d", &i_stepmaxnum);printf("I_stepmaxnum =%d \ n", I_stepmaxnum);memset(Buffer,0,sizeof(buffer)); while(Fgets (Buffer,sizeof(buffer), infile)) {tmpdata= (structlist*)malloc(sizeof(structList));if(!tmpdata) {printf("malloc () [email protected] \ n");Exit(0); }memset(Tmpdata,0,sizeof(structList)); tmpdata->nextmemeber=null; tmpdata->nextgp=null;sscanf(Buffer,"%c", &c_repeatflag);if(C_repeatflag = =' R ') {sscanf(Buffer,"%c%d%d", &c_repeatid,&i_repeatnums,&i_repeatlines);printf("Repeat =%c, repeatnums =%d,repeatlines =%d \ n", C_repeatid,i_repeatnums,i_repeatlines);memset(Buffer,0,sizeof(buffer));Continue; }Else{sscanf(Buffer,"%c%d",& (tmpdata->operation),& (tmpdata->seconds));printf("operation =%c, seconds =%d\n", tmpdata->operation,tmpdata->seconds);if(I_repeatlines >0) {if(Flag==header) {groupheader=tmpdata; tmpdata->c_flag=flag; tmpdata->i_repeatcnt = I_repeatnums; flag = MEMBER; tmpdata->nextmemeber=groupheader; tmpdata->nextgp=null; tail->nextgp=tmpdata;//Pay attention to connecting congestion? The head of each group is connected with the NEXTGP pointer}Else{tmpdata->c_flag=flag; tmpdata->nextmemeber=groupheader; tmpdata->nextgp=null; tail->nextmemeber=tmpdata;members of the//group are connected with the Nextmemeber pointer} Tail=tmpdata;//Modify the position of the tail pointer. i_repeatlines--; }Else{//--ok!!Flag=header; GroupHeader = Tmpdata; Tmpdata->c_flag = Flag; tmpdata->nextmemeber=groupheader; tmpdata->nextgp=null; tail->nextgp=tmpdata; Tail=tmpdata; }if(i_repeatlines==0) {Flag=header; } }memset(Buffer,0,sizeof(buffer)); } tail->nextgp=null;//tail->nextmemeber=null;Fclose (infile);return;}
4. Construction of keyboard events, including pressing and lifting
int seconds){ uint16_t keycode; printf("Key-%c ,%3d Sec |",operation,seconds); keycode = KeyToVal(operation); reportkey(KB_Fd, EV_KEY, keycode, KEYDOWN); reportkey(KB_Fd, EV_KEY, keycode, KEYUP); sleep(seconds);}
5, according to the data in the linked list to send key events
void emitevent_test(List*L) {List*p=L->nextgp; int loop=0;Cycle_modeMode_flag =firstcycle; printf"-------emitevent_test-------\ n"); while (p!=NULL) {//printf ("[* *%d **,%c,%d,%d]", P->c_flag, p->operation,p->seconds,p->i_repeatcnt);presskeyevent(P->operation,p->seconds);if(P->nextmemeber->c_flag! =HEADER)//{p = p->nextmemeber; }Else{/* printf ("P->nextmemeber Node is [* *%d **,%c,%d,%d]", P->nextmemeber->c_flag, P->nextmemeber->operation, P->nextmemeber->seconds, p->nextmemeber->i_repeatcnt); */if(Mode_flag = =firstcycle&& p->nextmemeber->i_repeatcnt >0) {loop = p->nextmemeber->i_repeatcnt; Mode_flag =othercycle; p = p->nextmemeber; Loop--;printf"\ n----------------\ n"); Continue }if(Loop >0&& Mode_flag = =othercycle)//not repeated {p = p->nextmemeber; Loop--;printf"\ n----------------\ n"); Continue } Mode_flag =firstcycle;//restore default value p = p->nextgp; printf"\ n"); } } }
Iv. Reference source Program
http://download.csdn.net/detail/flyeagle022/8799555
Automated test program One of the custom keyboard simulation test program (C language)