1 #include <ctype.h>
2 #include <errno.h>
3 #include <fcntl.h>
4 #include <getopt.h>
5 #include <limits.h>
6 #include <linux/input.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <time.h>
13 #include <unistd.h>
14 #include <dirent.h>
15 #include <inttypes.h>
16 #include <errno.h>
17
18
19 #include "minui/minui.h"
20 #include "common.h"
21 #include "minzip/DirUtil.h"
22 #include "recovery_ui.h"
23
24 #include "script.h"
25 #include "test_case.h"
26 #include "script_parser.h"
27 #include "debug.h"
28
29 #include "Language/language.h"
30
31
32 #include "rtc_test.h"
33 #include "wlan_test.h"
34 #include "ddr_test.h"
35 #include "bt_test.h"
36 #include "sdcard_test.h"
37 #include "udisk_test.h"
38 #include "key_test.h"
39 #include "screen_test.h"
40 #include "emmc_test.h"
41 #include "audio_play_test.h"
42 #include "audio_record_test.h"
43
44 #define SCRIPT_NAME "/data/test_config.cfg"
45
46 int manual_p_y = 1;
47 /* current position for auto test tiem in y direction */
48 int cur_p_y;
49
50 pthread_t rtc_tid;
51 char *rtc_res;
52 char dt[30] = { "20120927.143045" };
53 struct rtc_msg *rtc_msg;
54 int err_rtc;
55 int rtc_p_y;
56
57 pthread_t screen_tid;
58 pthread_t wlan_tid;
59 pthread_t bt_tid;
60 pthread_t sd_tid;
61 pthread_t udisk_tid;
62 pthread_t ddr_tid;
63 pthread_t emmc_tid;
64 pthread_t led_tid;
65 pthread_t key_tid;
66
67 pthread_t audioplay_tid;
68 pthread_t audiorecord_tid;
69
70 static int total_testcases;
71 static struct testcase_base_info *base_info;
72 static struct list_head auto_test_list_head;
73 static struct list_head manual_test_list_head;
74
75
76 static pthread_mutex_t gCur_p_y = PTHREAD_MUTEX_INITIALIZER;
77
get_cur_print_y(void)78 int get_cur_print_y(void)
79 {
80 int tmp;
81
82 pthread_mutex_lock(&gCur_p_y);
83 /*if (gr_fb_height() > 1080)
84 cur_p_y--;
85 tmp = cur_p_y--;*/
86 tmp = cur_p_y++;
87
88 pthread_mutex_unlock(&gCur_p_y);
89 printf("cur_print_y:%d\n", tmp);
90 return tmp;
91 }
92
parse_testcase(void)93 static int parse_testcase(void)
94 {
95 int i, j, mainkey_cnt;
96 struct testcase_base_info *info;
97 char mainkey_name[32], display_name[64], binary[16];
98 int activated, category, run_type, sim_counts;
99 int len;
100
101 mainkey_cnt = script_mainkey_cnt();
102 info = (struct testcase_base_info *)
103 malloc(sizeof(struct testcase_base_info) * mainkey_cnt);
104 if (info == NULL) {
105 db_error("core: allocate memory for temporary test case basic "
106 "information failed(%s)\n", strerror(errno));
107 return -1;
108 }
109 memset(info, 0, sizeof(struct testcase_base_info) * mainkey_cnt);
110
111 for (i = 0, j = 0; i < mainkey_cnt; i++) {
112 struct testcase_info *tc_info;
113
114 memset(mainkey_name, 0, 32);
115 script_mainkey_name(i, mainkey_name);
116
117 if (script_fetch
118 (mainkey_name, "display_name", (int *)display_name, 16))
119 continue;
120
121 if (script_fetch(mainkey_name, "activated", &activated, 1))
122 continue;
123
124 if (display_name[0] && activated == 1) {
125 strncpy(info[j].name, mainkey_name, 32);
126 strncpy(info[j].display_name, display_name, 64);
127 info[j].activated = activated;
128
129 if (script_fetch
130 (mainkey_name, "program", (int *)binary, 4) == 0) {
131 strncpy(info[j].binary, binary, 16);
132 }
133
134 info[j].id = j;
135
136 if (script_fetch(mainkey_name, "category", &category, 1)
137 == 0) {
138 info[j].category = category;
139 }
140
141 if (script_fetch(mainkey_name, "run_type", &run_type, 1)
142 == 0) {
143 info[j].run_type = run_type;
144 }
145
146 /*
147 if (script_fetch
148 (mainkey_name, "sim_counts", &sim_counts, 1) == 0) {
149 simCounts = sim_counts;
150 }
151 */
152
153 tc_info = (struct testcase_info *)
154 malloc(sizeof(struct testcase_info));
155 if (tc_info == NULL) {
156 printf("malloc for tc_info[%d] fail\n", j);
157 return -1;
158 }
159 tc_info->x = 0;
160 tc_info->y = 0;
161 tc_info->base_info = &info[j];
162 if (tc_info->base_info->category) //manual test
163 list_add(&tc_info->list, &manual_test_list_head);
164 else //auto test
165 list_add(&tc_info->list, &auto_test_list_head);
166 j++;
167 }
168 }
169 total_testcases = j;
170
171 db_msg("core: total test cases #%d\n", total_testcases);
172 if (total_testcases == 0)
173 return 0;
174
175 len = sizeof(struct testcase_base_info) * total_testcases;
176
177 return total_testcases;
178 }
179
start_test_pthread(struct testcase_info * tc_info)180 int start_test_pthread(struct testcase_info *tc_info)
181 {
182 int err;
183 printf(">>> Currnet test is : [ %s ]\n", tc_info->base_info->name);
184
185 #if 1
186 if (!strcmp(tc_info->base_info->name, "rtc")) {
187 err = pthread_create(&rtc_tid, NULL, rtc_test, tc_info);
188 if (err != 0) {
189 printf("create screen test thread error: %s/n",
190 strerror(err));
191 return -1;
192 }
193 } if (!strcmp(tc_info->base_info->name, "Lcd")) {
194 err = pthread_create(&screen_tid, NULL, screen_test, tc_info);
195 if (err != 0) {
196 printf("create screen test thread error: %s/n",
197 strerror(err));
198 return -1;
199 }
200 } else if (!strcmp(tc_info->base_info->name, "wifi")) {
201 err = pthread_create(&wlan_tid, NULL, wlan_test, tc_info);
202 if (err != 0) {
203 printf("create screen test thread error: %s/n",
204 strerror(err));
205 return -1;
206 }
207 } else if (!strcmp(tc_info->base_info->name, "ddr")) {
208 err = pthread_create(&ddr_tid, NULL, ddr_test, tc_info);
209 if (err != 0) {
210 printf("create screen test thread error: %s/n",
211 strerror(err));
212 return -1;
213 }
214 }else if (!strcmp(tc_info->base_info->name, "bluetooth")) {
215 err = pthread_create(&bt_tid, NULL, bt_test, tc_info);
216 if (err != 0) {
217 printf("create screen test thread error: %s/n",
218 strerror(err));
219 return -1;
220 }
221 } else if (!strcmp(tc_info->base_info->name, "sdcard")) {
222 err = pthread_create(&sd_tid, NULL, sdcard_test, tc_info);
223 if (err != 0) {
224 printf("create sdcard test thread error: %s/n",
225 strerror(err));
226 return -1;
227 }
228 } else if (!strcmp(tc_info->base_info->name, "emmc")) {
229 err = pthread_create(&emmc_tid, NULL, emmc_test, tc_info);
230 if (err != 0) {
231 printf("create sdcard test thread error: %s/n",
232 strerror(err));
233 return -1;
234 }
235 } else if (!strcmp(tc_info->base_info->name, "udisk")) {
236 err = pthread_create(&udisk_tid, NULL, udisk_test, tc_info);
237 if (err != 0) {
238 printf("create usb host test thread error: %s/n",
239 strerror(err));
240 return -1;
241 }
242 } else if (!strcmp(tc_info->base_info->name, "play")) {
243 err = pthread_create(&audioplay_tid, NULL, audio_play_test, tc_info);
244 if (err != 0) {
245 printf("create audio play test thread error: %s/n",
246 strerror(err));
247 return -1;
248 }
249 } else if (!strcmp(tc_info->base_info->name, "record")) {
250 err = pthread_create(&audiorecord_tid, NULL, audio_record_test, tc_info);
251 if (err != 0) {
252 printf("create audio record test thread error: %s/n",
253 strerror(err));
254 return -1;
255 }
256 } else if (!strcmp(tc_info->base_info->name, "Key")) {
257 err = pthread_create(&key_tid, NULL, key_test, tc_info);
258 if (err != 0) {
259 printf("create key test thread error: %s/n",
260 strerror(err));
261 return -1;
262 }
263 } else {
264 printf(">>> unsupport test item: [ %s ] for now!\n", tc_info->base_info->name);
265 return -1;
266 }
267 #endif
268
269
270 #if 0
271
272 if (!strcmp(tc_info->base_info->name, "Lcd")) {
273 err = pthread_create(&screen_tid, NULL, screen_test, tc_info);
274 if (err != 0) {
275 printf("create screen test thread error: %s/n",
276 strerror(err));
277 return -1;
278 }
279 } else if (!strcmp(tc_info->base_info->name, "rtc")) {
280 err = pthread_create(&rtc_tid, NULL, rtc_test, tc_info);
281 if (err != 0) {
282 printf("create rtc test thread error: %s/n",
283 strerror(err));
284 return -1;
285 }
286 } else if (!strcmp(tc_info->base_info->name, "battery")) {
287 err = pthread_create(&battery_tid, NULL, battery_test, tc_info);
288 if (err != 0) {
289 printf("create battery_test test thread error: %s/n",
290 strerror(err));
291 return -1;
292 }
293 } else if (!strcmp(tc_info->base_info->name, "ddr_emmc")) {
294 err = pthread_create(&ddr_emmc_tid, NULL,
295 ddr_emmc_test, tc_info);
296 if (err != 0) {
297 printf("create ddr_emmc test thread error: %s/n",
298 strerror(err));
299 return -1;
300 }
301 } else if (!strcmp(tc_info->base_info->name, "Codec")) {
302 hasCodec = 1;
303 err = pthread_create(&codec_tid, NULL, codec_test, tc_info);
304 if (err != 0) {
305 printf("create codec test thread error: %s/n",
306 strerror(err));
307 return -1;
308 }
309 } else if (!strcmp(tc_info->base_info->name, "Key")) {
310 err = pthread_create(&key_tid, NULL, key_test, tc_info);
311 if (err != 0) {
312 printf("create key test thread error: %s/n",
313 strerror(err));
314 return -1;
315 }
316 } else if (!strcmp(tc_info->base_info->name, "fm")) {
317 err = pthread_create(&fm_tid, NULL, fm_test, tc_info);
318 if (err != 0) {
319 printf("create fm test thread error: %s/n",
320 strerror(err));
321 return -1;
322 }
323 } else if (!strcmp(tc_info->base_info->name, "camera")) {
324 tc_info->dev_id = 0;
325 err = pthread_create(&camera_tid, NULL, camera_test, tc_info);
326 if (err != 0) {
327 printf("create camera test thread error: %s/n",
328 strerror(err));
329 return -1;
330 }
331 }
332 else if (!strcmp(tc_info->base_info->name, "wifi")) {
333 err = pthread_create(&wlan_tid, NULL, wlan_test, tc_info);
334 if (err != 0) {
335 printf("create wifi test thread error: %s/n",
336 strerror(err));
337 }
338 } else if (!strcmp(tc_info->base_info->name, "nand")) {
339 err = pthread_create(&nand_tid, NULL, nand_test, tc_info);
340 if (err != 0) {
341 printf("create nandflash test thread error: %s/n",
342 strerror(err));
343 }
344 } else if (!strcmp(tc_info->base_info->name, "bluetooth")) {
345 printf("bluetooth_test thread created\n");
346
347 err = pthread_create(&bt_tid, NULL, bt_test, tc_info);
348 if (err != 0) {
349 printf("create bt(bluetooth) test thread error: %s/n",
350 strerror(err));
351 }
352 } else if (!strcmp(tc_info->base_info->name, "gsensor")) {
353 err = pthread_create(&gsensor_tid, NULL, gsensor_test, tc_info);
354 if (err != 0) {
355 printf("create gsensor test thread error: %s/n",
356 strerror(err));
357 return -1;
358 }
359 } else if (!strcmp(tc_info->base_info->name, "allsensor")) {
360 err = pthread_create(&sensor_tid, NULL,
361 all_sensor_test, tc_info);
362 if (err != 0) {
363 printf("create sensor test thread error: %s/n",
364 strerror(err));
365 return -1;
366 }
367 } else if (!strcmp(tc_info->base_info->name, "lsensor")) {
368 err =
369 pthread_create(&lsensor_tid, NULL, lightsensor_test,
370 tc_info);
371 if (err != 0) {
372 printf("create lsensor test thread error: %s/n",
373 strerror(err));
374 return -1;
375 }
376 } else if (!strcmp(tc_info->base_info->name, "gps")) {
377 err = pthread_create(&gps_tid, NULL, gps_test, tc_info);
378 if (err != 0) {
379 printf("create gps test thread error: %s/n",
380 strerror(err));
381 return -1;
382 }
383 } else if (!strcmp(tc_info->base_info->name, "psensor")) {
384 err = pthread_create(&psensor_tid, NULL, psensor_test, tc_info);
385 if (err != 0) {
386 printf("create psensor test thread error: %s/n",
387 strerror(err));
388 return -1;
389 }
390 } else if (!strcmp(tc_info->base_info->name, "compass")) {
391 err = pthread_create(&compass_tid, NULL, compass_test, tc_info);
392 if (err != 0) {
393 printf("create ST compass test thread error: %s/n",
394 strerror(err));
395 return -1;
396 }
397 } else if (!strcmp(tc_info->base_info->name, "udisk")) {
398 err = pthread_create(&udisk_tid, NULL, udisk_test, tc_info);
399 if (err != 0) {
400 printf("create sdcard test thread error: %s/n",
401 strerror(err));
402 return -1;
403 }
404 } else if (!strcmp(tc_info->base_info->name, "sdcard")) {
405 sd_err = pthread_create(&sd_tid, NULL, sdcard_test, tc_info);
406 if (sd_err != 0) {
407 printf("create sdcard test thread error: %s/n",
408 strerror(sd_err));
409 return -1;
410 }
411 } else if (!strcmp(tc_info->base_info->name, "hdmi")) {
412 hdmi_err = pthread_create(&hdmi_tid, NULL, hdmi_test, tc_info);
413 if (hdmi_err != 0) {
414 printf("create hdmi test thread error: %s/n",
415 strerror(hdmi_err));
416 return -1;
417 }
418 } else if (!strcmp(tc_info->base_info->name, "sim")) {
419 err = pthread_create(&sim_tid, NULL, sim_test, tc_info);
420 if (err != 0) {
421 printf("create sim test thread error: %s/n",
422 strerror(err));
423 return -1;
424 }
425 } else if (!strcmp(tc_info->base_info->name, "vibrator")) {
426 err =
427 pthread_create(&vibrator_tid, NULL, vibrator_test, tc_info);
428 if (err != 0) {
429 printf("create vibrator test thread error: %s/n",
430 strerror(err));
431 return -1;
432 }
433 } else if (!strcmp(tc_info->base_info->name, "falshlight")) {
434 err =
435 pthread_create(&falshlight_tid, NULL, flashlight_test,
436 tc_info);
437 if (err != 0) {
438 printf("create flashlight test thread error: %s/n",
439 strerror(err));
440 return -1;
441 }
442 } else if (!strcmp(tc_info->base_info->name, "ddr")) {
443 ddr_err = pthread_create(&ddr_tid, NULL, ddr_test, tc_info);
444 if (ddr_err != 0) {
445 printf("create ddr test thread error: %s/n",
446 strerror(ddr_err));
447 return -1;
448 }
449 } else if (!strcmp(tc_info->base_info->name, "cpu")) {
450 cpu_err = pthread_create(&cpu_tid, NULL, cpu_test, tc_info);
451 if (cpu_err != 0) {
452 printf("create cpu test thread error: %s/n",
453 strerror(cpu_err));
454 return -1;
455 }
456 } else if (!strcmp(tc_info->base_info->name, "lan")) {
457 lan_err = pthread_create(&lan_tid, NULL, lan_test, tc_info);
458 if (lan_err != 0) {
459 printf("create lan test thread error: %s/n",
460 strerror(lan_err));
461 return -1;
462 }
463 } else {
464 printf("unsupport test item:%s\n", tc_info->base_info->name);
465 return -1;
466 }
467 #endif
468 return 0;
469 }
470
471
init_manual_test_item(struct testcase_info * tc_info)472 int init_manual_test_item(struct testcase_info *tc_info)
473 {
474 int err = 0;
475 printf("start_manual_test_item : %d, %s \r\n", tc_info->y,
476 tc_info->base_info->name);
477
478 manual_p_y += 1;
479 tc_info->y = manual_p_y;
480
481 start_test_pthread(tc_info);
482
483 return 0;
484 }
485
start_manual_test_item(int x,int y)486 int start_manual_test_item(int x, int y)
487 {
488 return 1;
489 // Camera_Click_Event(x, y);
490 }
491
start_auto_test_item(struct testcase_info * tc_info)492 int start_auto_test_item(struct testcase_info *tc_info)
493 {
494 printf("start_auto_test_item : LINE:%d, %s \r\n", tc_info->y,
495 tc_info->base_info->name);
496
497 start_test_pthread(tc_info);
498
499 return 0;
500 }
501
run_test_item_cmd(char * item_bin)502 int run_test_item_cmd(char* item_bin)
503 {
504 int ret = 0;
505 int status = 0;
506 if (item_bin == NULL)
507 return -1;
508
509 status = system(item_bin);
510 if (status == -1) {
511 printf("system cmd run :%s error...\n", item_bin);
512 ret = -1;
513 } else {
514 printf("exit status value = [0x%x]\n", status);
515 if (WIFEXITED(status)) {
516 if (0 == WEXITSTATUS(status)) {
517 printf("run item bin successfully.\n");
518 ret = 0;
519 } else {
520 printf("run item bin fail, script exit code: %d\n", WEXITSTATUS(status));
521 ret = -2;
522 }
523 } else {
524 printf("exit status = [%d]\n", WEXITSTATUS(status));
525 ret = -1;
526 }
527 }
528
529 return ret;
530 }
531
parse_test_result(char * rst_filename,char * test_item,char * para0)532 int parse_test_result(char* rst_filename, char* test_item, char* para0)
533 {
534 int ret = -1;
535 char read_buf[128];
536 char test_buf[10];
537 int flag = 0;
538
539 if (rst_filename == NULL || test_item == NULL)
540 return -1;
541
542 //read test result from /tmp dir
543 if(access(rst_filename, F_OK) == 0) {
544 //have find result file. we read this result file and parse.
545 FILE *fp;
546
547 fp = fopen(rst_filename, "r");
548 memset(read_buf, 0 ,sizeof(read_buf));
549 if (!fp) {
550 printf("%s fopen err:%s\n",__func__,strerror(errno));
551 return ret;
552 }
553
554 while(!feof(fp)) {
555 char* test_ret= NULL;
556 fgets(read_buf,sizeof(read_buf),fp);
557
558 if((strstr(read_buf,test_item))!= NULL) {
559 char *result = NULL;
560 char delims[] = ",";
561
562 result = strtok(read_buf, delims );
563 while( result != NULL ) {
564 if(para0 != NULL && !flag) {
565 //just get extrernal first string, do'nt care others.
566 printf(">>>>> will get extern param is %s \n", result);
567 memcpy(para0, result, strlen(result));
568 flag = 1;
569 }
570
571 if(strstr(result,"PASS")!= NULL ||
572 strstr(result,"FAIL")!= NULL) {
573 test_ret = result;
574 break;
575 }
576 result = strtok( NULL, delims );
577 }
578
579 if(test_ret) {
580 char ch;
581 int i = 0;
582 ch = *test_ret;
583 while(ch != '\0') {
584 if (isalpha(ch)) {
585 test_buf[i++] = ch;
586 ch = *test_ret++;
587 } else {
588 ch = *test_ret++;
589 }
590 }
591 //printf(" >>>>> We get test result is %s <<<<<\n", test_buf);
592
593 if(0 == strcmp(test_buf, "PASS")) {
594 //pass
595 ret = 0;
596 } else if (0 == strcmp(test_buf, "FAIL")) {
597 //fail
598 ret= -1;
599 }
600 } else {
601 printf(" >>>>> Error!!! wrong test result format. <<<<<\n");
602 }
603 }
604 }
605 fclose(fp);
606 }
607
608 return ret;
609 }
610
main(int argc,char ** argv)611 int main(int argc, char **argv)
612 {
613 int ret, w;
614 char *script_buf;
615 struct list_head *pos;
616 int success = 0;
617 char rfCalResult[10];
618
619 #if 0
620 freopen("/dev/ttyFIQ0", "a", stdout);
621 setbuf(stdout, NULL);
622 freopen("/dev/ttyFIQ0", "a", stderr);
623 setbuf(stderr, NULL);
624 #endif
625 printf("*****************************************\n");
626 printf("*** pcba test start ***\n");
627 printf("*** Rockchip.Co.Ld. ***\n");
628 printf("*****************************************\n");
629
630 ui_init();
631 ui_set_background(BACKGROUND_ICON_INSTALLING);
632 ui_print_init();
633 w = gr_fb_width();
634 printf(" @@@ w= %d \n", w);
635 ui_print_xy_rgba((((w >> 1) - strlen(PCBA_VERSION_NAME)*CHAR_WIDTH/2)
636 /CHAR_WIDTH), 0, 0, 255, 0, 255, "%s\n", PCBA_VERSION_NAME);
637
638 // printf("Now in PCBA_test %d\n",__LINE__);
639 ui_print_xy_rgba(((w >> 2) / CHAR_WIDTH - 4), 1, 255, 255, 0, 255,
640 "%s\n", PCBA_MANUAL_TEST);
641 // printf("Now in PCBA_test %d\n",__LINE__);
642
643 // drawline_4(255, 255, 0, 255, 0, (1 * CHAR_HEIGHT - (CHAR_HEIGHT>>2)),
644 // w>>1, CHAR_HEIGHT, 3);
645
646 // printf("Now in PCBA_test %d\n",__LINE__);
647 //return 0;
648
649 /*cur_p_y = (gr_fb_height() / CHAR_HEIGHT) - 1;*/
650
651 INIT_LIST_HEAD(&manual_test_list_head);
652 INIT_LIST_HEAD(&auto_test_list_head);
653 script_buf = parse_script(SCRIPT_NAME);
654 if (!script_buf) {
655 printf("parse script failed\n");
656 return -1;
657 }
658
659 ret = init_script(script_buf);
660 if (ret) {
661 db_error("core: init script failed(%d)\n", ret);
662 return -1;
663 }
664
665 ret = parse_testcase();
666 if (ret < 0) {
667 db_error("core: parse all test case from script failed(%d)\n",
668 ret);
669 return -1;
670 } else if (ret == 0) {
671 db_warn("core: NO TEST CASE to be run\n");
672 return -1;
673 }
674
675 printf("\n\t manual testcase:\n");
676 list_for_each(pos, &manual_test_list_head) {
677 struct testcase_info *tc_info =
678 list_entry(pos, struct testcase_info, list);
679 init_manual_test_item(tc_info);
680 }
681 manual_p_y += 1;
682
683 // cur_p_y = manual_p_y+1; /*for auto add items*/
684 cur_p_y = MAX_ROWS / 2;
685 ui_print_xy_rgba(((w >> 2) / CHAR_WIDTH - 4), cur_p_y - 1, 255, 255,
686 0, 255, "%s\n", PCBA_AUTO_TEST);
687
688
689
690 // ui_print_xy_rgba(((w >> 2) / CHAR_WIDTH - 4), manual_p_y, 255, 255,
691 // 0, 255, "%s\n", PCBA_AUTO_TEST);
692 // drawline_4(255, 255, 0, 255, 0,
693 // (CHAR_HEIGHT * (manual_p_y) - (CHAR_HEIGHT>>2)), w>>1,
694 // CHAR_HEIGHT, 3);
695
696 printf("\n\t auto testcase:\n");
697 list_for_each(pos, &auto_test_list_head) {
698 struct testcase_info *tc_info =
699 list_entry(pos, struct testcase_info, list);
700 start_auto_test_item(tc_info);
701 }
702
703 start_input_thread();
704
705 printf("pcba test over!\n");
706
707 //clear misc, and ready to entern main system.
708
709 return success;
710 }
711
712