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