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
/*
 *  sdcard_test.c  --  sdcardtest application
 *
 *  Copyright (c) 2017 Rockchip Electronics Co. Ltd.
 *  Author:
 *  Author:
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
#include <signal.h>
#include <unistd.h>
 
#define LOG_TAG "sdcard_test"
#include "common.h"
 
 
char result[COMMAND_VALUESIZE] = RESULT_FAIL;
 
 
//* ÐźŴ¦Àíº¯Êý£¬ÔÚ½áÊø½ø³Ìǰ£¬Îª°´¼ü²âÊÔ·µ»ØÒ»¸ö½á¹û£»
//static int sdcard_result_send(int sign_no)
//{
//    int err_code =0;
//    printf("====================function : %s start =================\n",__func__);
//    if(!memcmp(result,RESULT_FAIL,strlen(RESULT_FAIL))){
//        err_code = KEY_QUERY_FAIL;
//    }
//    send_msg_to_server("sdcard_test", result, err_code);
//
//    printf("====================function : %s finished =================\n",__func__);
//    exit(0);
//}
 
int sdcard_auto_test()
{
    int ret = 0;
    int status = 0;
    status = system("/data/sdcard_test.sh");
    if (status == -1) {
        log_info("system cmd run error...\n");
        ret = -1;
    } else {
        log_info("exit status value = [0x%x]\n", status);
        if (WIFEXITED(status)) {
            if (0 == WEXITSTATUS(status)) {
                log_info("run shell script successfully.\n");
                ret = 0;
            } else {
                if (1 == WEXITSTATUS(status)) {
                    log_info("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
                    ret = 1;
                } else if (2 == WEXITSTATUS(status)) {
                    log_info("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
                    ret = 2;
                }
            }
        } else {
            log_info("exit status = [%d]\n", WEXITSTATUS(status));
            ret = -1;
        }
    }
 
    if (ret != 0)
        log_info("sdcard test failed. ret = %d\n", ret);
 
    return ret;
}
 
int main(int argc, char *argv[])
{
    int test_flag = 0,err_code = 0;
    char buf[COMMAND_VALUESIZE] = "sdcard_test";
 
   log_info("sdcard test process start...\n");
    //* ×¢²áÐźŴ¦Àíº¯Êý
   //signal(SIGTERM,sdcard_result_send);
 
    test_flag = sdcard_auto_test();
    if(test_flag == 0) {
        strcpy(result,RESULT_PASS);
        err_code = 0;
        log_info("sdcard test Pass\n");
    } else if (test_flag == 1) {
        strcpy(result,RESULT_FAIL);
        err_code = SDCARD_MOUNT_ERR;
        log_info("sdcard test MountErr...\n");
    } else if (test_flag == 2) {
        strcpy(result,RESULT_FAIL);
        err_code = SDCARD_TIMEOUT_ERR;
        log_info("sdcard test Timgout...\n");
    }
 
    if (test_flag == 0) {
        int fd = -1;
        double cap;
        char sdcard_size[32] = {0};
        fd = open("/run/sd_capacity", O_RDONLY);
        memset(sdcard_size, 0 ,sizeof(sdcard_size));
        int r_len = read(fd, sdcard_size, sizeof(sdcard_size));
        if (r_len <= 0) {
           log_err("read %s fail, errno = %d\n", "/run/sd_capacity", errno);
       }
        //fgets(sdcard_size, 32, fd);
        cap = strtod(sdcard_size, NULL);
        snprintf(sdcard_size, sizeof(sdcard_size), "capacity:%.4fG ", cap * 1.0 / 1024 / 1024);
        strcat(buf,": ");
        strcat(buf, sdcard_size);
    }
    //strcat(buf, result);
    send_msg_to_server(buf, result, err_code);
    return 0;
}