vsp-lib: Support optional features for tests
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Fri, 27 May 2016 08:50:07 +0000 (11:50 +0300)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Sun, 19 Jun 2016 12:26:01 +0000 (15:26 +0300)
Add a third argument to test_init() to pass a list of optional features.
If more than one media device supports all the required features, select
the one that supports the highest number of optional features.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
scripts/vsp-lib.sh

index c5db772..d48108a 100755 (executable)
@@ -460,10 +460,13 @@ format_configure() {
 test_init() {
        logfile=${1/sh/log}
        features=$2
+       optional_features=$3
 
        rm -f $logfile
        rm -f *.bin
 
+       best_features_count=0
+
        for mdev in /dev/media* ; do
                match='true'
                for feature in $features ; do
@@ -473,17 +476,37 @@ test_init() {
                        }
                done
 
-               if [ $match == 'true' ] ; then
+               if [ $match == 'false' ] ; then
+                       continue
+               fi
+
+               if [ -z "$optional_features" ] ; then
+                       best_mdev=$mdev
                        break
                fi
+
+               features_count=0
+               for feature in $optional_features ; do
+                       $(vsp1_has_feature $feature) && {
+                               features_count=$((features_count+1))
+                               match='false';
+                               break;
+                       }
+               done
+
+               if [ $features_count -ge $best_features_count ] ; then
+                       best_mdev=$mdev
+                       best_features_count=$features_count
+               fi
        done
 
-       if [ $match == 'false' ] ; then
+       if [ -z $best_mdev ] ; then
                echo "No device found with feature set $features" | ./logger.sh config >> $logfile
                exit 1
        fi
 
-       dev=$(vsp1_device $mdev)
+       mdev=$best_mdev
+       dev=$(vsp1_device $best_mdev)
        echo "Using device $mdev ($dev)" | ./logger.sh config >> $logfile
 
        vsp_runner=./vsp-runner.sh