1 /*
2 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13 * Neither the name of Code Aurora Forum, Inc. nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <pthread.h>
31 #include "mm_camera_dbg.h"
32 #include <errno.h>
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <poll.h>
38 #include "mm_qcamera_unit_test.h"
39
40 #define MM_QCAMERA_APP_UTEST_MAX_MAIN_LOOP 4
41 #define MM_QCAM_APP_TEST_NUM 128
42
43 #define MM_QCAMERA_APP_INTERATION 5
44 #define MM_QCAMERA_APP_WAIT_TIME 1000000000
45
46 static mm_app_tc_t mm_app_tc[MM_QCAM_APP_TEST_NUM];
47 static int num_test_cases = 0;
48
mm_app_dtc_0(mm_camera_app_t * cam_apps)49 int mm_app_dtc_0(mm_camera_app_t *cam_apps)
50 {
51 int rc = MM_CAMERA_OK;
52 int i,j;
53 int result = 0;
54 int front_camera = 1;
55 int back_camera = 0;
56
57 printf("\n Verifying Preview on back Camera and RDI on Front camera...\n");
58
59 if(mm_app_open(back_camera) != MM_CAMERA_OK) {
60 CDBG_ERROR("%s:mm_app_open() back camera err=%d\n",__func__, rc);
61 rc = -1;
62 goto end;
63 }
64 if(system_dimension_set(back_camera) != MM_CAMERA_OK){
65 CDBG_ERROR("%s:system_dimension_set() err=%d\n",__func__, rc);
66 rc = -1;
67 goto end;
68 }
69
70 if( MM_CAMERA_OK != (rc = startPreview(back_camera))) {
71 CDBG_ERROR("%s: back camera startPreview() err=%d\n", __func__, rc);
72 goto end;
73 }
74
75 mm_camera_app_wait();
76 if(mm_app_open(front_camera) != MM_CAMERA_OK) {
77 CDBG_ERROR("%s:mm_app_open() front camera err=%d\n",__func__, rc);
78 rc = -1;
79 goto end;
80 }
81 if(system_dimension_set(front_camera) != MM_CAMERA_OK){
82 CDBG_ERROR("%s:system_dimension_set() err=%d\n",__func__, rc);
83 rc = -1;
84 goto end;
85 }
86
87 if( MM_CAMERA_OK != (rc = startRdi(front_camera))) {
88 CDBG_ERROR("%s: startPreview() backcamera err=%d\n", __func__, rc);
89 goto end;
90 }
91 mm_camera_app_wait();
92
93 if( MM_CAMERA_OK != (rc = stopRdi(front_camera))) {
94 CDBG_ERROR("%s: startPreview() backcamera err=%d\n", __func__, rc);
95 goto end;
96 }
97
98 if( MM_CAMERA_OK != (rc = stopPreview(my_cam_app.cam_open))) {
99 CDBG("%s: startPreview() err=%d\n", __func__, rc);
100 goto end;
101 }
102
103 if( mm_app_close(my_cam_app.cam_open) != MM_CAMERA_OK) {
104 CDBG_ERROR("%s:mm_app_close() err=%d\n",__func__, rc);
105 rc = -1;
106 goto end;
107 }
108 end:
109 if(rc == 0) {
110 printf("\nPassed\n");
111 }else{
112 printf("\nFailed\n");
113 }
114 CDBG("%s:END, rc = %d\n", __func__, rc);
115 return rc;
116 }
117
mm_app_dtc_1(mm_camera_app_t * cam_apps)118 int mm_app_dtc_1(mm_camera_app_t *cam_apps)
119 {
120 int rc = MM_CAMERA_OK;
121 int i,j;
122 int result = 0;
123
124 printf("\n Verifying Snapshot on front and back camera...\n");
125 for(i = 0; i < cam_apps->num_cameras; i++) {
126 if( mm_app_open(i) != MM_CAMERA_OK) {
127 CDBG_ERROR("%s:mm_app_open() err=%d\n",__func__, rc);
128 rc = -1;
129 goto end;
130 }
131 if(system_dimension_set(my_cam_app.cam_open) != MM_CAMERA_OK){
132 CDBG_ERROR("%s:system_dimension_set() err=%d\n",__func__, rc);
133 rc = -1;
134 goto end;
135 }
136
137 if( MM_CAMERA_OK != (rc = startPreview(my_cam_app.cam_open))) {
138 CDBG_ERROR("%s: startPreview() err=%d\n", __func__, rc);
139 break;
140 }
141 for(j = 0; j < MM_QCAMERA_APP_INTERATION; j++) {
142 if( MM_CAMERA_OK != (rc = takePicture_yuv(my_cam_app.cam_open))) {
143 CDBG_ERROR("%s: TakePicture() err=%d\n", __func__, rc);
144 break;
145 }
146 /*if(mm_camera_app_timedwait() == ETIMEDOUT) {
147 CDBG_ERROR("%s: Snapshot/Preview Callback not received in time or qbuf Faile\n", __func__);
148 break;
149 }*/
150 mm_camera_app_wait();
151 result++;
152 }
153 if( MM_CAMERA_OK != (rc = stopPreview(my_cam_app.cam_open))) {
154 CDBG("%s: startPreview() err=%d\n", __func__, rc);
155 break;
156 }
157 if( mm_app_close(my_cam_app.cam_open) != MM_CAMERA_OK) {
158 CDBG_ERROR("%s:mm_app_close() err=%d\n",__func__, rc);
159 rc = -1;
160 goto end;
161 }
162 if(result != MM_QCAMERA_APP_INTERATION) {
163 printf("%s: Snapshot Start/Stop Fails for Camera %d in %d iteration", __func__, i,j);
164 rc = -1;
165 break;
166 }
167
168 result = 0;
169 }
170 end:
171 if(rc == 0) {
172 printf("\t***Passed***\n");
173 }else{
174 printf("\t***Failed***\n");
175 }
176 CDBG("%s:END, rc = %d\n", __func__, rc);
177 return rc;
178 }
179
mm_app_dtc_2(mm_camera_app_t * cam_apps)180 int mm_app_dtc_2(mm_camera_app_t *cam_apps)
181 {
182 int rc = MM_CAMERA_OK;
183 int i,j;
184 int result = 0;
185
186 printf("\n Verifying Video on front and back camera...\n");
187 for(i = 0; i < cam_apps->num_cameras; i++) {
188 if( mm_app_open(i) != MM_CAMERA_OK) {
189 CDBG_ERROR("%s:mm_app_open() err=%d\n",__func__, rc);
190 rc = -1;
191 goto end;
192 }
193 if(system_dimension_set(my_cam_app.cam_open) != MM_CAMERA_OK){
194 CDBG_ERROR("%s:system_dimension_set() err=%d\n",__func__, rc);
195 rc = -1;
196 goto end;
197 }
198
199 if( MM_CAMERA_OK != (rc = startPreview(my_cam_app.cam_open))) {
200 CDBG_ERROR("%s: startPreview() err=%d\n", __func__, rc);
201 break;
202 }
203 for(j = 0; j < MM_QCAMERA_APP_INTERATION; j++) {
204 if( MM_CAMERA_OK != (rc = startRecording(my_cam_app.cam_open))) {
205 CDBG_ERROR("%s: StartVideorecording() err=%d\n", __func__, rc);
206 break;
207 }
208
209 /*if(mm_camera_app_timedwait() == ETIMEDOUT) {
210 CDBG_ERROR("%s: Video Callback not received in time\n", __func__);
211 break;
212 }*/
213 mm_camera_app_wait();
214 if( MM_CAMERA_OK != (rc = stopRecording(my_cam_app.cam_open))) {
215 CDBG_ERROR("%s: Stopvideorecording() err=%d\n", __func__, rc);
216 break;
217 }
218 result++;
219 }
220 if( MM_CAMERA_OK != (rc = stopPreview(my_cam_app.cam_open))) {
221 CDBG("%s: startPreview() err=%d\n", __func__, rc);
222 break;
223 }
224 if( mm_app_close(my_cam_app.cam_open) != MM_CAMERA_OK) {
225 CDBG_ERROR("%s:mm_app_close() err=%d\n",__func__, rc);
226 rc = -1;
227 goto end;
228 }
229 if(result != MM_QCAMERA_APP_INTERATION) {
230 printf("%s: Video Start/Stop Fails for Camera %d in %d iteration", __func__, i,j);
231 rc = -1;
232 break;
233 }
234
235 result = 0;
236 }
237 end:
238 if(rc == 0) {
239 printf("\nPassed\n");
240 }else{
241 printf("\nFailed\n");
242 }
243 CDBG("%s:END, rc = %d\n", __func__, rc);
244 return rc;
245 }
246
mm_app_dtc_3(mm_camera_app_t * cam_apps)247 int mm_app_dtc_3(mm_camera_app_t *cam_apps)
248 {
249 int rc = MM_CAMERA_OK;
250 int i,j;
251 int result = 0;
252
253 printf("\n Verifying RDI Stream on front and back camera...\n");
254 if(cam_apps->num_cameras == 0) {
255 CDBG_ERROR("%s:Query Failed: Num of cameras = %d\n",__func__, cam_apps->num_cameras);
256 rc = -1;
257 goto end;
258 }
259 for(i = 0; i < cam_apps->num_cameras; i++) {
260 if( mm_app_open(i) != MM_CAMERA_OK) {
261 CDBG_ERROR("%s:mm_app_open() err=%d\n",__func__, rc);
262 rc = -1;
263 goto end;
264 }
265 if(system_dimension_set(my_cam_app.cam_open) != MM_CAMERA_OK){
266 CDBG_ERROR("%s:system_dimension_set() err=%d\n",__func__, rc);
267 rc = -1;
268 goto end;
269 }
270 for(j = 0; j < MM_QCAMERA_APP_INTERATION; j++) {
271 if( MM_CAMERA_OK != (rc = startRdi(my_cam_app.cam_open))) {
272 CDBG_ERROR("%s: StartVideorecording() err=%d\n", __func__, rc);
273 break;
274 }
275
276 /*if(mm_camera_app_timedwait() == ETIMEDOUT) {
277 CDBG_ERROR("%s: Video Callback not received in time\n", __func__);
278 break;
279 }*/
280 mm_camera_app_wait();
281 if( MM_CAMERA_OK != (rc = stopRdi(my_cam_app.cam_open))) {
282 CDBG_ERROR("%s: Stopvideorecording() err=%d\n", __func__, rc);
283 break;
284 }
285 result++;
286 }
287 if( mm_app_close(my_cam_app.cam_open) != MM_CAMERA_OK) {
288 CDBG_ERROR("%s:mm_app_close() err=%d\n",__func__, rc);
289 rc = -1;
290 goto end;
291 }
292 if(result != MM_QCAMERA_APP_INTERATION) {
293 printf("%s: Video Start/Stop Fails for Camera %d in %d iteration", __func__, i,j);
294 rc = -1;
295 break;
296 }
297
298 result = 0;
299 }
300 end:
301 if(rc == 0) {
302 printf("\nPassed\n");
303 }else{
304 printf("\nFailed\n");
305 }
306 CDBG("%s:END, rc = %d\n", __func__, rc);
307 return rc;
308 }
309
mm_app_dtc_4(mm_camera_app_t * cam_apps)310 int mm_app_dtc_4(mm_camera_app_t *cam_apps)
311 {
312 int rc = MM_CAMERA_OK;
313 int i;
314 printf("Running %s - open/close ,video0, open/close preview channel only\n", __func__);
315 #if 0
316 for(i = 0; i < MM_QCAMERA_APP_UTEST_MAX_MAIN_LOOP; i++) {
317 if ( 0 != (rc = mm_app_open(cam_id, MM_CAMERA_OP_MODE_NOTUSED))) {
318 CDBG("%s: open cam %d at opmode = %d err, loop=%d, rc=%d\n", __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
319 goto end;
320 }
321 if(0 != (rc = mm_app_open_preview(cam_id))) {
322 goto end;
323 }
324 if(0 != (rc = mm_app_close_preview(cam_id))) {
325 goto end;
326 }
327 if ( 0 != (rc = mm_app_close(cam_id))) {
328 CDBG("%s: close cam %d at opmode = %d err,loop=%d, rc=%d\n", __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
329 goto end;
330 }
331 }
332 end:
333 #endif
334 CDBG("%s:END, rc=%d\n", __func__, rc);
335 return rc;
336 }
337
338
339
mm_app_dtc_5(mm_camera_app_t * cam_apps)340 int mm_app_dtc_5(mm_camera_app_t *cam_apps)
341 {
342 int rc = MM_CAMERA_OK;
343 int i;
344 printf("Running %s - open/close ,video0, open/close snapshot channel only\n", __func__);
345 #if 0
346 for(i = 0; i < MM_QCAMERA_APP_UTEST_MAX_MAIN_LOOP; i++) {
347 if ( 0 != (rc = mm_app_open(cam_id, MM_CAMERA_OP_MODE_NOTUSED))) {
348 CDBG("%s: open cam %d at opmode = %d err, loop=%d, rc=%d\n",
349 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
350 goto end;
351 }
352 if(0 != (rc = mm_app_open_snapshot(cam_id))) {
353 goto end;
354 }
355 if(0 != (rc = mm_app_close_snapshot(cam_id))) {
356 goto end;
357 }
358 if ( 0 != (rc = mm_app_close(cam_id))) {
359 CDBG("%s: close cam %d at opmode = %d err,loop=%d, rc=%d\n",
360 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
361 goto end;
362 }
363 }
364 end:
365 #endif
366 CDBG("%s:END, rc=%d\n", __func__, rc);
367 return rc;
368 }
369
mm_app_dtc_6(mm_camera_app_t * cam_apps)370 int mm_app_dtc_6(mm_camera_app_t *cam_apps)
371 {
372 int rc = MM_CAMERA_OK;
373 int i;
374 printf("Running %s - simple preview \n", __func__);
375 #if 0
376 if ( 0 != (rc = mm_app_open(cam_id, MM_CAMERA_OP_MODE_NOTUSED))) {
377 CDBG("%s: open cam %d at opmode = %d err, loop=%d, rc=%d\n",
378 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
379 goto end;
380 }
381
382 for(i = 0; i < MM_QCAMERA_APP_UTEST_MAX_MAIN_LOOP; i++) {
383 if(0 != (rc = mm_app_init_preview(cam_id))) {
384 goto end;
385 }
386 if(0 != (rc = mm_app_start_preview(cam_id))) {
387 goto end;
388 }
389 /* sleep 8 seconds */
390 usleep(8000000);
391 if(0 != (rc = mm_app_stop_preview(cam_id))) {
392 goto end;
393 }
394 if(0 != (rc=mm_app_deinit_preview(cam_id))) {
395 goto end;
396 }
397 if(0 != (rc = mm_app_close_preview(cam_id))) {
398 goto end;
399 }
400 }
401 if ( 0 != (rc = mm_app_close(cam_id))) {
402 CDBG("%s: close cam %d at opmode = %d err,loop=%d, rc=%d\n",
403 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
404 goto end;
405 }
406 end:
407 #endif
408 CDBG("%s:END, rc=%d\n", __func__, rc);
409 return rc;
410 }
411
mm_app_dtc_7(mm_camera_app_t * cam_apps)412 int mm_app_dtc_7(mm_camera_app_t *cam_apps)
413 {
414 int rc = MM_CAMERA_OK;
415 int i;
416 printf("Running %s - simple preview and recording \n", __func__);
417 #if 0
418 if ( 0 != (rc = mm_app_open(cam_id, MM_CAMERA_OP_MODE_NOTUSED))) {
419 CDBG("%s: open cam %d at opmode = %d err, loop=%d, rc=%d\n",
420 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
421 goto end;
422 }
423
424 for(i = 0; i < MM_QCAMERA_APP_UTEST_MAX_MAIN_LOOP; i++) {
425 if(0 != (rc = mm_app_init_preview(cam_id))) {
426 goto end;
427 }
428 if(0 != (rc = mm_app_start_preview(cam_id))) {
429 goto end;
430 }
431 /* sleep 8 seconds */
432 usleep(8000000);
433 if(0 != (rc = mm_app_start_recording(cam_id))) {
434 goto end;
435 }
436 usleep(1000000);
437 if(0 != (rc = mm_app_stop_recording(cam_id))) {
438 goto end;
439 }
440 usleep(8000000);
441 if(0 != (rc = mm_app_stop_preview(cam_id))) {
442 goto end;
443 }
444 if(0 != (rc=mm_app_deinit_preview(cam_id))) {
445 goto end;
446 }
447 if(0 != (rc = mm_app_close_preview(cam_id))) {
448 goto end;
449 }
450 }
451 if ( 0 != (rc = mm_app_close(cam_id))) {
452 CDBG("%s: close cam %d at opmode = %d err,loop=%d, rc=%d\n",
453 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
454 goto end;
455 }
456 end:
457 #endif
458 CDBG("%s:END, rc=%d\n", __func__, rc);
459 return rc;
460 }
461
mm_app_dtc_8(mm_camera_app_t * cam_apps)462 int mm_app_dtc_8(mm_camera_app_t *cam_apps)
463 {
464 int rc = MM_CAMERA_OK;
465 int i;
466 printf("Running %s - preview, recording, and snapshot, then preview again \n", __func__);
467 #if 0
468 if ( 0 != (rc = mm_app_open(cam_id, MM_CAMERA_OP_MODE_NOTUSED))) {
469 CDBG("%s: open cam %d at opmode = %d err, loop=%d, rc=%d\n",
470 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
471 goto end;
472 }
473
474 for(i = 0; i < MM_QCAMERA_APP_UTEST_MAX_MAIN_LOOP; i++) {
475 if(0 != (rc = mm_app_init_preview(cam_id))) {
476 goto end;
477 }
478 if(0 != (rc = mm_app_start_preview(cam_id))) {
479 goto end;
480 }
481 /* sleep 8 seconds */
482 usleep(8000000);
483 if(0 != (rc = mm_app_start_recording(cam_id))) {
484 goto end;
485 }
486 usleep(1000000);
487 if(0 != (rc = mm_app_stop_recording(cam_id))) {
488 goto end;
489 }
490 if(0 != (rc = mm_app_stop_preview(cam_id))) {
491 goto end;
492 }
493 if(0!=(rc=mm_app_init_snapshot(cam_id))) {
494 goto end;
495 }
496 if(0 != (rc=mm_app_take_picture(cam_id))) {
497 goto end;
498 }
499 if( 0 != (rc = mm_app_deinit_snahspot(cam_id))) {
500 goto end;
501 }
502 if(0 != (rc = mm_app_start_preview(cam_id))) {
503 goto end;
504 }
505 usleep(8000000);
506 if(0 != (rc=mm_app_deinit_preview(cam_id))) {
507 goto end;
508 }
509 if(0 != (rc = mm_app_close_preview(cam_id))) {
510 goto end;
511 }
512 }
513 if ( 0 != (rc = mm_app_close(cam_id))) {
514 CDBG("%s: close cam %d at opmode = %d err,loop=%d, rc=%d\n",
515 __func__, cam_id, MM_CAMERA_OP_MODE_NOTUSED, i, rc);
516 goto end;
517 }
518 end:
519 #endif
520 CDBG("%s:END, rc=%d\n", __func__, rc);
521 return rc;
522 }
523
524
mm_app_gen_dual_test_cases()525 int mm_app_gen_dual_test_cases()
526 {
527 int tc = 0;
528 memset(mm_app_tc, 0, sizeof(mm_app_tc));
529 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_0;
530 /*if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_1;
531 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_2;
532 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_3;
533 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_4;
534 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_5;
535 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_6;
536 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_7;
537 if(tc < MM_QCAM_APP_TEST_NUM) mm_app_tc[tc++].f = mm_app_dtc_8;*/
538 return tc;
539 }
540
mm_app_dual_test_entry(mm_camera_app_t * cam_app)541 int mm_app_dual_test_entry(mm_camera_app_t *cam_app)
542 {
543 int rc = MM_CAMERA_OK;
544 int i, tc = 0;
545 int cam_id = 0;
546
547 tc = mm_app_gen_dual_test_cases();
548 CDBG("Running %d test cases\n",tc);
549 for(i = 0; i < tc; i++) {
550 mm_app_tc[i].r = mm_app_tc[i].f(cam_app);
551 if(mm_app_tc[i].r != MM_CAMERA_OK) {
552 printf("%s: test case %d error = %d, abort unit testing engine!!!!\n",
553 __func__, i, mm_app_tc[i].r);
554 rc = mm_app_tc[i].r;
555 goto end;
556 }
557 }
558 end:
559 printf("nTOTAL_TSET_CASE = %d, NUM_TEST_RAN = %d, rc=%d\n", tc, i, rc);
560 return rc;
561 }
562
563
564
565
566