xref: /OK3568_Linux_fs/external/rk_pcba_test/pcba_minui/udisk_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include"common.h"
6 //#include"extra-functions.h"
7 
8 #include"udisk_test.h"
9 #include"test_case.h"
10 #include "language.h"
11 
12 #define SCAN_RESULT_LENGTH 128
13 #define SCAN_RESULT_FILE "/data/udisk_capacity.txt"
14 
15 #define LOG(x...)   printf("[UDISK_TEST] "x)
16 
17 
udisk_test(void * argv)18 void * udisk_test(void * argv)
19 {
20 	struct testcase_info *tc_info = (struct testcase_info*)argv;
21 	int ret,y;
22 	double cap;
23 	FILE *fp;
24 	char results[SCAN_RESULT_LENGTH];
25 
26 	/*remind ddr test*/
27 	if(tc_info->y <= 0)
28 		tc_info->y  = get_cur_print_y();
29 
30 	y = tc_info->y;
31 
32 #if 0   //Android pcba test
33 
34 #ifdef SOFIA3GR_PCBA
35 	ui_print_xy_rgba(0,y,255,255,0,255,"%s:[%s..] \n",PCBA_UCARD,PCBA_TESTING);
36 #else
37 	ui_print_xy_rgba(0,y,255,255,0,255,"%s \n",PCBA_UCARD);
38 #endif
39 
40 
41 	#ifdef SOFIA3GR_PCBA
42 		ret =  __system("busybox chmod 777 /system/bin/udisktester.sh");
43 	#else
44 		ret =  __system("busybox chmod 777 /res/udisktester.sh");
45 
46 	if(ret)
47 		printf("chmod udisktester.sh failed :%d\n",ret);
48 	#endif
49 
50 	#ifdef SOFIA3GR_PCBA
51 		//ret = __system("/system/bin/udisktester.sh");
52 			int testCounts =0;
53 			while(1)
54 			{
55 				fp = NULL;
56 				LOG("%s::wait for insert udisk card...\n", __FUNCTION__);
57 				__system("/system/bin/udisktester.sh");
58 
59 				fp = fopen(SCAN_RESULT_FILE, "r");
60 				if(fp != NULL)
61 				{
62 					LOG("%s line=%d find result file! \n", __FUNCTION__, __LINE__);
63 					break;
64 				}
65 
66 				LOG("%s line=%d can't find result file! continue ... \n", __FUNCTION__, __LINE__);
67 
68 				if(testCounts++ > 3)
69 				{
70 					LOG("can not open %s.\n", SCAN_RESULT_FILE);
71 					ui_print_xy_rgba(0,y,255,0,0,255,"%s:[%s]\n",PCBA_UCARD,PCBA_FAILED);
72 					tc_info->result = -1;
73 					return argv;
74 				}
75 				sleep(1);
76 			}
77 
78 			//disable by wjh
79 			/*
80 			memset(results, 0, SCAN_RESULT_LENGTH);
81 			//fread(results, 1, SCAN_RESULT_LENGTH, fp);
82 			fgets(results,50,fp);
83 			//fgets(wlan_msg->ssid,50,fp); //we assume tha a AP's name is less of 50 charactes
84 
85 			//LOG("%s.\n", results);
86 
87 			cap = strtod(results,NULL);
88 			if(cap) {
89 				ui_print_xy_rgba(0,y,0,255,0,255,"%s:[%s] { %2fG } \n",PCBA_UCARD,PCBA_SECCESS,cap*1.0);
90 				tc_info->result = 0;
91 			}*/
92 
93 			ui_print_xy_rgba(0,y,0,255,0,255,"%s:[%s]\n",PCBA_UCARD,PCBA_SECCESS);
94 				tc_info->result = 0;
95 		    fclose(fp);
96 
97 			return argv;
98 	#else
99 		ret = __system("/res/udisktester.sh");
100 	if(ret < 0) {
101 		printf("udisk test failed.\n");
102 		ui_print_xy_rgba(0,y,255,0,0,255,"%s:[%s]\n",PCBA_UCARD,PCBA_FAILED);
103 		tc_info->result = -1;
104 		return argv;
105 	}
106 	#endif
107 
108 
109 	fp = fopen(SCAN_RESULT_FILE, "r");
110 	if(fp == NULL) {
111 		printf("can not open %s.\n", SCAN_RESULT_FILE);
112 		ui_print_xy_rgba(0,y,255,0,0,255,"%s:[%s]\n",PCBA_UCARD,PCBA_FAILED);
113 		tc_info->result = -1;
114 		return argv;
115 	}
116 
117   	memset(results, 0, SCAN_RESULT_LENGTH);
118 	fgets(results,50,fp);
119 
120 	cap = strtod(results,NULL);
121     printf("capacity : %s\n", results);
122 	if(cap > 0) {
123 		ui_print_xy_rgba(0,y,0,255,0,255,"%s:[%s] { %2fG }\n",PCBA_UCARD,PCBA_SECCESS,cap*1.0/1024/1024);
124 		tc_info->result = 0;
125 	}
126     else {
127         ui_print_xy_rgba(0,y,0,0,255,255,"%s:[%s]\n",PCBA_UCARD,PCBA_FAILED);
128 		tc_info->result = -1;
129     }
130 
131         fclose(fp);
132 
133 #else   //Linux pcba test
134 
135     int rst;
136     char usbhost_buf[128]= {0};
137     char usbhost_size[32] = {0};
138     char result_filename[100] = {0};
139 
140     ui_print_xy_rgba(0,y,255,255,0,255,"%s:[wait %s..] : Pls plug usb host devices.\n",PCBA_UCARD,PCBA_TESTING);
141 
142     LOG("============= start udisk test==============\n");
143     rst = run_test_item_cmd("echo_auto_test echo_usbhost_test");
144 
145     if(rst == 0) {
146         snprintf(result_filename, sizeof(result_filename),
147                 "%s/echo_usbhost_test_result", "/tmp");
148         ret = parse_test_result(result_filename, "usbhost_test", usbhost_buf);
149 
150     }else  {
151         return NULL;
152     }
153 
154     if(ret == 0) {
155         if(strstr(usbhost_buf, "capacity") != NULL) {
156             char *result = NULL;
157             char delims[] = " ";
158 
159             memset(usbhost_size, 0, sizeof(usbhost_size));
160             result = strtok(usbhost_buf, delims );
161             while( result != NULL ) {
162                 LOG("result is \"%s\"\n", result);
163 
164                 if(strstr(result,"capacity")!= NULL){
165                     strcat(usbhost_size, result);
166                 }
167 
168                 result = strtok( NULL, delims );
169             }
170         }
171         ui_print_xy_rgba(0, y, 0, 255, 0, 255, "%s:[%s] { %s }\n", PCBA_UCARD,
172                  PCBA_SECCESS, usbhost_size);
173         tc_info->result = 0;
174         LOG("usbhost_test success.\n");
175     } else {
176         ui_print_xy_rgba(0, y, 225, 0, 0, 255, "%s:[%s]\n", PCBA_UCARD,
177                  PCBA_FAILED, usbhost_size);
178         tc_info->result = -1;
179         LOG("usbhost_test failed.\n");
180     }
181 
182 #endif
183 	return argv;
184 
185 }
186