1 /*
2 * sdcard_test.c -- sdcardtest 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 #include <unistd.h>
29
30 #define LOG_TAG "sdcard_test"
31 #include "common.h"
32
33
34 char result[COMMAND_VALUESIZE] = RESULT_FAIL;
35
36
37 //* �źŴ��������ڽ�������ǰ��Ϊ�������Է���һ�������
38 //static int sdcard_result_send(int sign_no)
39 //{
40 // int err_code =0;
41 // printf("====================function : %s start =================\n",__func__);
42 // if(!memcmp(result,RESULT_FAIL,strlen(RESULT_FAIL))){
43 // err_code = KEY_QUERY_FAIL;
44 // }
45 // send_msg_to_server("sdcard_test", result, err_code);
46 //
47 // printf("====================function : %s finished =================\n",__func__);
48 // exit(0);
49 //}
50
sdcard_auto_test()51 int sdcard_auto_test()
52 {
53 int ret = 0;
54 int status = 0;
55 status = system("/data/sdcard_test.sh");
56 if (status == -1) {
57 log_info("system cmd run error...\n");
58 ret = -1;
59 } else {
60 log_info("exit status value = [0x%x]\n", status);
61 if (WIFEXITED(status)) {
62 if (0 == WEXITSTATUS(status)) {
63 log_info("run shell script successfully.\n");
64 ret = 0;
65 } else {
66 if (1 == WEXITSTATUS(status)) {
67 log_info("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
68 ret = 1;
69 } else if (2 == WEXITSTATUS(status)) {
70 log_info("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
71 ret = 2;
72 }
73 }
74 } else {
75 log_info("exit status = [%d]\n", WEXITSTATUS(status));
76 ret = -1;
77 }
78 }
79
80 if (ret != 0)
81 log_info("sdcard test failed. ret = %d\n", ret);
82
83 return ret;
84 }
85
main(int argc,char * argv[])86 int main(int argc, char *argv[])
87 {
88 int test_flag = 0,err_code = 0;
89 char buf[COMMAND_VALUESIZE] = "sdcard_test";
90
91 log_info("sdcard test process start...\n");
92 //* ע���źŴ�����
93 //signal(SIGTERM,sdcard_result_send);
94
95 test_flag = sdcard_auto_test();
96 if(test_flag == 0) {
97 strcpy(result,RESULT_PASS);
98 err_code = 0;
99 log_info("sdcard test Pass\n");
100 } else if (test_flag == 1) {
101 strcpy(result,RESULT_FAIL);
102 err_code = SDCARD_MOUNT_ERR;
103 log_info("sdcard test MountErr...\n");
104 } else if (test_flag == 2) {
105 strcpy(result,RESULT_FAIL);
106 err_code = SDCARD_TIMEOUT_ERR;
107 log_info("sdcard test Timgout...\n");
108 }
109
110 if (test_flag == 0) {
111 int fd = -1;
112 double cap;
113 char sdcard_size[32] = {0};
114 fd = open("/run/sd_capacity", O_RDONLY);
115 memset(sdcard_size, 0 ,sizeof(sdcard_size));
116 int r_len = read(fd, sdcard_size, sizeof(sdcard_size));
117 if (r_len <= 0) {
118 log_err("read %s fail, errno = %d\n", "/run/sd_capacity", errno);
119 }
120 //fgets(sdcard_size, 32, fd);
121 cap = strtod(sdcard_size, NULL);
122 snprintf(sdcard_size, sizeof(sdcard_size), "capacity:%.4fG ", cap * 1.0 / 1024 / 1024);
123 strcat(buf,": ");
124 strcat(buf, sdcard_size);
125 }
126 //strcat(buf, result);
127 send_msg_to_server(buf, result, err_code);
128 return 0;
129 }
130
131