xref: /OK3568_Linux_fs/external/rk_pcba_test/echo_camera_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 <sys/types.h>
29 #include <sys/wait.h>
30 
31 #include <unistd.h>
32 
33 
34 #define LOG_TAG "camera_test"
35 #include "common.h"
36 
37 /*���������*/
main(int argc,char * argv[])38 int main(int argc, char *argv[])
39 {
40     int test_flag = 0,err_code = 0;
41     char buf[COMMAND_VALUESIZE] = "camera_test";
42     char result[COMMAND_VALUESIZE] = RESULT_FAIL;
43     int ret;
44     int exit_status;
45 
46 
47 	log_info("=============== camera test start...============\n");
48 
49     pid_t fpid;
50 
51     fpid = fork();
52     if (fpid < 0) {
53         printf("error in fork!\n");
54         return fpid;
55     } else if (fpid == 0) {
56         pid_t child_pid;
57 
58         child_pid = fork();
59         if (child_pid < 0) {
60             printf("error in fork,fork error in child pid!\n");
61             return child_pid;
62         } else if (child_pid == 0) {
63             //child process, capture one frame camera data,save to /tmp/camera_data.
64             char *argv0[]={"./v4l2_test", NULL};
65             char *envp0[]={"/data",NULL}; //���ݸ�ִ���ļ��µĻ�����������
66             ret = execve("/data/v4l2_test", argv0, envp0);
67             if(ret == -1) {
68                 printf("######## v4l2_test run error : %s ###### \n", strerror(errno));
69             } else {
70                 printf("######## v4l2_test run... ######\n");
71             }
72         } else {
73             //father process
74             int status;
75 
76             ret = wait(&status);
77             if (ret < 0) {
78                 log_err("ERR: wait child failed: (%d)\n", ret);
79                 return ret;
80             }
81 
82             log_info("process(%d) wait child(%d) status: %d\n",
83                    getpid(), ret, status);
84 
85             if (WIFEXITED(status)) {
86                 exit_status = WEXITSTATUS(status);
87                 log_info(" v412_test run success and exit. exit_status = %d \n",exit_status);
88             } else {
89                 log_info(" v412_test run seem no good....\n");
90                 return -1;
91             }
92 
93             /* nv12 transform to bmp */
94             char *argv1[]={"./nv12_to_bmp_main", "/tmp/camera_data", "720", "576", NULL};
95             char *envp1[]={"/data",NULL}; //���ݸ�ִ���ļ��µĻ�����������
96             ret = execve("/data/nv12_to_bmp_main", argv1, envp1);
97             if (ret == -1) {
98                 printf("######## nv12_to_bmp_main run error : %s ###### \n", strerror(errno));
99             } else {
100                 printf("######## nv12_to_bmp_main run... ######\n");
101             }
102         }
103     } else {
104         //father process
105         int status;
106 
107         ret = wait(&status);
108         if (ret < 0) {
109             log_err("ERR: wait child failed: (%d)\n", ret);
110             return ret;
111         }
112 
113         log_info("process(%d) wait child(%d) status: %d\n",
114                getpid(), ret, status);
115 
116         if (WIFEXITED(status)) {
117             exit_status = WEXITSTATUS(status);
118             log_info(" All run success and exit. exit_status = %d \n",exit_status);
119         } else {
120             log_info(" Somethings run seem no good....\n");
121             err_code = CAMERA_PROC_ERR;
122         }
123 
124         if (err_code)
125 	        strcpy(result, RESULT_FAIL);
126         else
127             strcpy(result, RESULT_PASS);
128 
129         printf("######## send msg to server... ######\n");
130         send_msg_to_server(buf, result, err_code);
131     }
132 
133     return 0;
134 }
135 
136 
137 
138 
139