How to automatically test the initialization and image capture stability of the camera module

This document describes how to automatically test the initialization and image capture stability of the camera module.

The tests include:

  1. The camera module registers as a video device after the system boots up.

  2. Video capture by V4L2-ctl tool.

1 Test environment

Platform: sp7350

Rootfs: Yocto

Tools: v4l2-ctl, systemed, shell

First, it is necessary to confirm that the camera module has been properly initialized and the image capture is successful. This part refer to the camera module documentation. For example: Using Video Camera OV5640 on SP7350 Platforms - C3V Documentation - Confluence

NTP service working is preferred.

2 Prepare test resources

2.1 Config test script

Based on the camera module information, modify and save the test script.

vi /etc/init.d/v4l2_dev_test.sh

 

#!/bin/sh ######### test video params ######### test_video=/dev/video0 pixel_format=UYVY frame_width=1280 frame_height=720 v4l2_buffer_count=5 frame_size=1843200 capture_frame_count=30 test_video_target_size=$((frame_size*capture_frame_count)) test_video_info="$test_video $pixel_format $frame_width*$frame_height $capture_frame_count" ######### env set ######### test_timestamp=$(date +%Y%m%d%H%M%S) test_record_file=/var/v4l2_dev_test_record.log test_count_file=/var/v4l2_dev_test_count.log test_file_name=/tmp/$test_timestamp.raw system_reboot_delay=20 ######### test start ######### sleep 15 # wait other module init if [ -f "$test_count_file" ];then test_count=$(sed -n '1p' $test_count_file) success_count=$(sed -n '2p' $test_count_file) else test_count=0 success_count=0 $(touch $test_count_file) echo -e "0\n0" > $test_count_file echo "[v4l2_video_dev_test][env]$test_video_info" >> $test_record_file fi (sleep $system_reboot_delay; reboot) & test_count=$(($test_count+1)) sed -i "1c $test_count" $test_count_file echo "[v4l2_video_dev_test][$test_count][start][$test_timestamp]$test_video_info" test_record_start="[v4l2_video_dev_test][$test_count][$test_timestamp]" echo -n $test_record_start >> $test_record_file v4l2-ctl -d $test_video --set-fmt-video=width=$frame_width,height=$frame_height,pixelformat=$pixel_format --stream-mmap=$v4l2_buffer_count --stream-to=$test_file_name --stream-count=$capture_frame_count sleep 2 test_video_res_size=$(stat -c%s $test_file_name) if [ "$test_video_res_size" = "$test_video_target_size" ];then test_result="success" success_count=$(($success_count+1)) sed -i "2c $success_count" $test_count_file else echo "[v4l2_video_dev_test][$test_count][error][$test_timestamp]expect size:$test_video_target_size,capture size:$test_video_res_size" test_result="failed" fi echo " $test_result" >> $test_record_file echo "[v4l2_video_dev_test][$test_count][end][$test_timestamp]$test_result ($success_count/$test_count)"

Modify the following option values.

  • test_video: v4l2-ctl test device.

  • pixel_format:test camera video format.

  • frame_width:test frame width

  • frame_height:test frame height

  • frame_size:test frame size

In the default configuration, the test record file will be output to /var/v4l2_dev_test_record.log.

 

The process of the test script is as follows:

  1. get test environment information.

  2. set system reboot after system_reboot_delay second.

  3. use v4l2-ctl capturing video.

  4. record the test results.

 

Grant execution permissions to the test script.

chmod +x /etc/init.d/v4l2_dev_test.sh

2.2 Config test service

Save the service file.

In the default configuration, the standard output will be output to /var/v4l2_dev_test_standard_output.log.

Execute the command to reload the systemed service.

3 Test

3.1 Start test

Execute the command to start test.

The system will reboot after executing the above command. Then, the service will execute the test script, write the output content of the test to /var/v4l2_dev_test_standard_output.log, and record the test results to /var/v4l2_dev_test_record.log. After a delay of system_reboot_delay seconds, the system will reboot and perform the next test.

3.2 Stop test

After the system starts, immediately execute the following command to stop the test.

3.3 Analyse test result

In the default configuration, the test record file will be output to /var/v4l2_dev_test_record.log.

The first line contains information about automated testing, including test device, test format, resolution, and the number of captured frames.

For subsequent lines of data, each line contains the test serial number, test time, and result.There are three possible results.

  • success:successfully captured data and the data size is correct.

  • failed:capture completed but the captured data size is incorrect.

  • no data:capture blocked.

In the default configuration, the standard output will be output to /var/v4l2_dev_test_standard_output.log. For example:

If you need to redirect the standard output to the console, we can modify the /etc/systemd/system/v4l2_dev_test.service file. Use StandardOutput=tty replace StandardOutput=append:/var/v4l2_dev_test_standard_output.log.

After redirecting the standard output to the console, the logging option in the test code can be enabled to output more detailed information, and these logs can be stored using a PC terminal software.Utilizing these logs can help locate the more specific position of the low-probability capture failure.