This document describes how to automatically test the initialization and image capture stability of the camera module.
The tests include:
The camera module registers as a video device after the system boots up
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:
get test environment information.
set system reboot after system_reboot_delay second.
use v4l2-ctl capturing video.
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.
vi /etc/systemd/system/v4l2_dev_test.service
[Unit] Description=v4l2 camera device init and capture auto test service [Service] StandardOutput=journal+console Type=forking ExecStart=/etc/init.d/v4l2_dev_test.sh #StandardOutput=tty # console output #StandardError=tty # console output StandardOutput=append:/var/v4l2_dev_test_standard_output.log StandardError=append:/var/v4l2_dev_test_standard_error.log [Install] WantedBy=multi-user.target
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.
sudo systemctl daemon-reload
3 Test
3.1 Start test
Execute the command to start test.
sudo systemctl enable v4l2_dev_test.service reboot
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.
sudo systemctl disable v4l2_dev_test.service sudo systemctl stop v4l2_dev_test.service
3.3 Analyse test result
In the default configuration, the test record file will be output to /var/v4l2_dev_test_record.log.
[v4l2_video_dev_test][env]/dev/video0 UYVY 1280*720 30 [v4l2_video_dev_test][1][20240515095910] success [v4l2_video_dev_test][2][20240305100103] success [v4l2_video_dev_test][3][20240305100219] success ..... [v4l2_video_dev_test][456][20210305095650] success .....
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:
[v4l2_video_dev_test][54][start][20210305095650]/dev/video0 UYVY 1280*720 30 [v4l2_video_dev_test][54][end][20210305095650]success (3/3) ... [v4l2_video_dev_test][114][start][20210305095650]/dev/video0 UYVY 1280*720 30 [v4l2_video_dev_test][114][end][20210305095650]success (113/114) ...
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.