关闭

手机软件自动化测试研究报告(下)

发表于:2010-2-24 13:11

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:张元礼/vincetest(CSD    来源:51Testing软件测试网采编

  四、关键技术

  1.  消息传送机制

  利用手机Modem中提供的AT Command通过串口向手机端建立命令消息通讯,目前手机厂商提供了常用的AT Command,基本满足普通的自动化测试需求,另外厂商还提供了用户自定义AT Command的功能,当标准的AT Command不能满足自动化测试需求时,我们可以利用自定义AT Command来实现我们自动化测试中所需要的消息通讯。如下为MTK平台上实现自定义AT Command的关键样例代码:

   1. //customer_at_command.c 
   2. #include "kal_non_specific_general_types.h" 
   3. #include "stdio.h" 
   4. #include "string.h" 
   5. 
   6. #define CUSTOM_SYMBOL  '^'   // '+'  and '/' and ' \ 'is NOT allowed    
   7. #define MAX_UART_LEN    128   
   8.  
   9. /*****************************************************************************
  10. * customer command
  11. *****************************************************************************/ 
  12. #define PLAY "play" 
  13. #define STOP "stop" 
  14.  
  15. kal_uint8 custom_get_atcmd_symbol(void); 
  16. void custom_command_hdlr(char *full_cmd_string); 
  17. extern void rmmi_write_to_uart(kal_uint8 * buffer, kal_uint16 length, kal_bool stuff);  
  18.  
  19. /*****************************************************************************
  20. * FUNCTION
  21. *     custom_command_hdlr()
  22. * DESCRIPTION
  23. *     This function should parse the custom AT command and do correspondent action.
  24. *     Customer should maintain and modify the code.
  25. * PARAMETERS
  26. *     kal_uint8 * cmd_string
  27. * RETURNS
  28. *     none
  29. *****************************************************************************/ 
  30. void custom_command_hdlr(char *full_cmd_string) 
  31. { 
  32.     char buffer[MAX_UART_LEN]; 
  33.     char cmd_name[15]; 
  34.     kal_uint8 index = 3;             // we start parsing index after the CUSTOM_SYMBOL  
  35.     kal_uint8 tmp_idx = 0; 
  36.  
  37.     while ((full_cmd_string[index] != '=' ) &&  //might be TEST command or EXE command 
  38.             (full_cmd_string[index] != '?' ) && // might be READ command 
  39.             (full_cmd_string[index] != 13 ))  //carriage return 
  40.     { 
  41.         cmd_name[tmp_idx] = full_cmd_string[index] ; 
  42.         tmp_idx ++; 
  43.         index ++; 
  44.     } 
  45.     cmd_name[tmp_idx] = '\0' ; 
  46.      
  47.     /* just a very basic example : customer can implement their own */ 
  48.     if (strcmp(cmd_name, PLAY) == 0) 
  49.     {        
  50.         /* BEGIN: do the following parsing and correspondent action */ 
  51.         /*                                                          */ 
  52.         /*                                                          */ 
  53.         /*                                                          */ 
  54.         /* END: do the following parsing and correspondent action   */ 
  55.         /* generate final result code: "OK" */ 
  56.         //Todo 实现消息分发或功能调用 
  57.         sprintf(buffer, "Hello Play"); 
  58.         printf("%s\n", "Hello Play"); 
  59.         rmmi_write_to_uart((kal_uint8*)buffer, (kal_uint16)strlen(buffer), KAL_TRUE); 
  60.     } 
  61.     else if (strcmp(cmd_name, STOP) == 0) 
  62.     {        
  63.         /* BEGIN: do the following parsing and correspondent action */ 
  64.         /*                                                          */ 
  65.         /*                                                          */ 
  66.         /*                                                          */ 
  67.         /* END: do the following parsing and correspondent action   */ 
  68.         /* generate final result code: "OK" */ 
  69.         //Todo 实现消息分发或功能调用 
  70.         sprintf(buffer, "Hello Stop"); 
  71.         printf("%s\n", "Hello Stop"); 
  72.         rmmi_write_to_uart((kal_uint8*)buffer, (kal_uint16)strlen(buffer), KAL_TRUE); 
  73.     } 
  74.     else 
  75.     { 
  76.         /* unrecognized command */ 
  77.         /* generate final result code: "ERROR" */ 
  78.         sprintf(buffer, "ERROR"); 
  79.         printf("%s\n", "ERROR"); 
  80.         rmmi_write_to_uart((kal_uint8*)buffer, (kal_uint16)strlen(buffer), KAL_TRUE); 
  81.     }    
  82.      
  83.     return; 
  84. } 
  85.  
  86. kal_uint8 custom_get_atcmd_symbol(void) 
  87. { 
  88.    return (CUSTOM_SYMBOL); 
  89. } 

21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号