xref: /OK3568_Linux_fs/external/rk_pcba_test/echo_usbhost_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  echo_usbhost_test.c  --  usbhosttest application
3  *
4  *  Copyright (c) 2017 Rockchip Electronics Co. Ltd.
5  *  Author:
6  *  Author:
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * 	 http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <linux/input.h>
27 #include <signal.h>
28 
29 #define LOG_TAG "usbhost_test"
30 #include "common.h"
31 
32 
33 char result[COMMAND_VALUESIZE] = RESULT_FAIL;
34 
35 
36 //* �źŴ��������ڽ�������ǰ��Ϊ�������Է���һ�������
37 //static int usbhost_result_send(int sign_no)
38 //{
39 //    int err_code =0;
40 //    printf("====================function : %s start =================\n",__func__);
41 //    if(!memcmp(result,RESULT_FAIL,strlen(RESULT_FAIL))){
42 //        err_code = KEY_QUERY_FAIL;
43 //    }
44 //    send_msg_to_server("usbhost_test", result, err_code);
45 //
46 //    printf("====================function : %s finished =================\n",__func__);
47 //    exit(0);
48 //}
49 
usbhost_auto_test()50 int usbhost_auto_test()
51 {
52     int ret = 0;
53     int status = 0;
54     status = system("/data/usbhost_test.sh");
55     if (status == -1) {
56         log_info("system cmd run error...\n");
57         ret = -1;
58     }
59     else
60     {
61         log_info("exit status value = [0x%x]\n", status);
62         if (WIFEXITED(status))
63         {
64             if (0 == WEXITSTATUS(status))
65             {
66                 log_info("run shell script successfully.\n");
67                 ret = 0;
68             }
69             else
70             {
71                 if (1 == WEXITSTATUS(status)) {
72                     log_info("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
73                     ret = 1;
74                 } else if (2 == WEXITSTATUS(status)) {
75                     log_info("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
76                     ret = 2;
77                 }
78             }
79         }
80         else
81         {
82             log_info("exit status = [%d]\n", WEXITSTATUS(status));
83             ret = -1;
84         }
85     }
86 
87     if (ret != 0)
88         log_info("usbhost test failed. ret = %d\n", ret);
89 
90     return ret;
91 }
92 
main(int argc,char * argv[])93 int main(int argc, char *argv[])
94 {
95     int test_flag = 0,err_code = 0;
96     char buf[COMMAND_VALUESIZE] = "usbhost_test";
97 
98 	log_info("usbhost test process start...\n");
99     //* ע���źŴ�����
100 	//signal(SIGTERM,usbhost_result_send);
101 
102     test_flag = usbhost_auto_test();
103     if(test_flag == 0) {
104         strcpy(result,RESULT_PASS);
105         err_code = 0;
106         log_info("usbhost test Pass\n");
107     } else if (test_flag == 1) {
108         strcpy(result,RESULT_FAIL);
109         err_code = SDCARD_MOUNT_ERR;
110         log_info("usbhost test MountErr...\n");
111     } else if (test_flag == 2) {
112         strcpy(result,RESULT_FAIL);
113         err_code = SDCARD_TIMEOUT_ERR;
114         log_info("usbhost test Timgout...\n");
115     }
116 
117     if (test_flag == 0) {
118         int fd = -1;
119         double cap;
120         char usbhost_size[32] = {0};
121         fd = open("/run/usbhost_capacity", O_RDONLY);
122         memset(usbhost_size, 0 ,sizeof(usbhost_size));
123         int r_len = read(fd, usbhost_size, sizeof(usbhost_size));
124         if (r_len <= 0) {
125 			log_err("read %s fail, errno = %d\n", "/run/usbhost_capacity", errno);
126 		}
127         //fgets(sdcard_size, 32, fd);
128         cap = strtod(usbhost_size, NULL);
129         snprintf(usbhost_size, sizeof(usbhost_size), "capacity:%.4fG ", cap * 1.0 / 1024 / 1024);
130         strcat(buf,": ");
131         strcat(buf, usbhost_size);
132     }
133 
134     //strcat(buf, result);
135     send_msg_to_server(buf, result, err_code);
136     return 0;
137 }
138 
139