VirtualBox

Changeset 39220 in vbox


Ignore:
Timestamp:
Nov 7, 2011 11:07:39 PM (13 years ago)
Author:
vboxsync
Message:

Installer/linux: clean up tests.

Location:
trunk/src/VBox/Installer/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/installer-utils.sh

    r38385 r39220  
    1414#
    1515
    16 setup_normal_input_install_udev() {
    17     # The udev rule setup functions contain some aliases which are used for unit
    18     # testing purposes.  This function sets up the aliases to point to the real
    19     # commands for "normal" use.
    20     eval 'my_which() { which "$@" ; }'
    21     eval 'my_test() { test "$@" ; }'
    22     eval 'my_rm() { rm "$@" ; }'
    23 }
    24 
    25 # Needs to be done before the udev setup functions are called "normally" (i.e.
    26 # not in a unit testing context).  Will be overridden later in a unit test.
    27 setup_normal_input_install_udev
    28 
    29 setup_test_input_install_udev() {
    30     # Set up unit testing environment for the "install_udev" function below.
    31     TEST_NAME="$1"          # used to identify the current test
    32     TEST_UDEV_VERSION="$2"  # udev version to simulate
    33     eval 'my_which() { echo test_udev ; }'
    34     eval 'my_test() { true ; }'
    35     eval 'my_rm() { case "$2" in "/etc/udev/rules.d/60-vboxdrv.rules") true ;; *) echo "rm: bad file name \"$2\"!"; false ;; esac ; }'
    36     eval 'test_udev() { echo "$TEST_UDEV_VERSION" ; }'
    37     DELETED_UDEV_FILE=""
    38 }
    39 
    40 cleanup_test_input_install_udev() {
    41     # Clean up after unit testing install_udev for a given input
    42     setup_normal_input_install_udev
    43     unset test_udev
    44     DELETED_UDEV_FILE=""
    45 }
     16# This is used for unit testing and will be reset after the file is sourced for
     17# test runs.
     18unset EXTERN
    4619
    4720udev_write_vboxdrv() {
     
    6437install_udev() {
    6538    # install udev rule (disable with INSTALL_NO_UDEV=1 in /etc/default/virtualbox) for distribution packages
     39    # To unit test, set $EXTERN to point to a function simulating external
     40    # commands: test; which; rm.  See the code for usage.
    6641    VBOXDRV_GRP="$1"      # The group owning the vboxdrv device
    6742    VBOXDRV_MODE="$2"     # The access mode for the vboxdrv device
     
    7550    "1") ;;
    7651    *)
    77         if my_test -d /etc/udev/rules.d; then
     52        if $EXTERN test -d /etc/udev/rules.d; then
    7853            udev_call=""
    79             udev_app=`my_which udevadm 2> /dev/null`
     54            udev_app=`$EXTERN which udevadm 2> /dev/null`
    8055            if [ $? -eq 0 ]; then
    8156                udev_call="${udev_app} version 2> /dev/null"
    8257            else
    83                 udev_app=`my_which udevinfo 2> /dev/null`
     58                udev_app=`$EXTERN which udevinfo 2> /dev/null`
    8459                if [ $? -eq 0 ]; then
    8560                    udev_call="${udev_app} -V 2> /dev/null"
     
    11590    esac
    11691    # Remove old udev description file
    117     if my_test -f /etc/udev/rules.d/60-vboxdrv.rules; then
    118         my_rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null
     92    if $EXTERN test -f /etc/udev/rules.d/60-vboxdrv.rules; then
     93        $EXTERN rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null
    11994    fi
    12095}
    12196
    122 setup_normal_input_install_create_usb_node() {
    123     # install_create_usb_node_for_sysfs contain some aliases for unit testing
    124     # purposes.  This function sets up the aliases to point to the real
    125     # commands for "normal" use.
    126     eval 'my_test() { test "$@" ; }'
    127     eval 'my_cat() { cat "$@" ; }'
    128     eval 'my_sh() { sh "$@" ; }'
    129 }
    130 
    131 # Assume we will be calling the function normally, not for unit testing
    132 setup_normal_input_install_create_usb_node
    133 
    134 # Add a unit test here if/when needed following the same pattern as
    135 # setup_test_input_install_udev.
     97# Add a unit test if/when needed following the same pattern as for
     98# install_udev.
    13699
    137100install_create_usb_node_for_sysfs() {
     
    140103    usb_createnode="$2" # Path to the USB device node creation script
    141104    usb_group="$3"      # The group to give ownership of the node to
    142     if my_test -r "${path}/dev"; then
    143         dev="`my_cat "${path}/dev" 2> /dev/null`"
     105    if $EXTERN test -r "${path}/dev"; then
     106        dev="`$EXTERN cat "${path}/dev" 2> /dev/null`"
    144107        major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
    145108        minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
    146         class="`my_cat ${path}/bDeviceClass 2> /dev/null`"
    147         my_sh "${usb_createnode}" "$major" "$minor" "$class" "${usb_group}" \
    148               2>/dev/null
     109        class="`$EXTERN cat ${path}/bDeviceClass 2> /dev/null`"
     110        $EXTERN sh "${usb_createnode}" "$major" "$minor" "$class" \
     111              "${usb_group}" 2>/dev/null
    149112    fi
    150113}
    151114
    152 setup_normal_input_install_device_node_setup() {
    153     # install_device_node_setup contain some aliases for unit testing
    154     # purposes.  This function sets up the aliases to point to the real
    155     # values for "normal" use.
    156     udev_rule_file=/etc/udev/rules.d/10-vboxdrv.rules # Set this to /dev/null
    157                                                       # for unit testing
    158     sysfs_usb_devices="/sys/bus/usb/devices/*"
    159     eval 'do_install_udev() { install_udev "$@"; }'
    160     eval 'do_install_create_usb_node_for_sysfs() { \
    161                           install_create_usb_node_for_sysfs "$@" ; }'
    162 }
    163 
    164 # Assume we will be calling the function normally, not for unit testing
    165 setup_normal_input_install_device_node_setup
    166 
    167 setup_test_input_install_device_node_setup() {
    168     # Set up unit testing environment for the "install_udev" function below.
    169     test_drv_grp="$1"  # The expected vboxdrv group
    170     test_drv_mode="$2" # The expected vboxdrv mode
    171     test_inst_dir="$3" # The expected installation directory
    172     test_usb_grp="$4"  # The expected USB node group
    173     udev_rule_file=/dev/null
    174     sysfs_usb_devices=test_sysfs_path
    175     eval 'do_install_udev() {    test    "$1" = "${test_drv_grp}" \
    176                                       -a "$2" = "${test_drv_mode}" \
    177                                       -a "$3" = "${test_inst_dir}" \
    178                                       -a "$4" = "${test_usb_grp}" \
    179                                       -a "$5" = "${INSTALL_NO_UDEV}" \
    180                               || echo "do_install_udev: bad parameters: $@" >&2 ; }'
    181     eval 'do_install_create_usb_node_for_sysfs() { \
    182                        test    "$1" = "${sysfs_usb_devices}" \
    183                             -a "$2" = "${test_inst_dir}/VBoxCreateUSBNode.sh" \
    184                             -a "$3" = "${test_usb_grp}" \
    185                     || echo "do_install_create_usb_node_for_sysfs: \
    186 bad parameters: $@" >&2 ; }'
    187 }
    188 
    189 cleanup_test_input_install_device_node_setup() {
    190     # Clean up unit testing environment for the "install_udev" function below.
    191     # Nothing to do.
    192     true
    193 }
     115# install_device_node_setup contains some aliases for unit testing purposes.  # Set them to their normal values here.
     116udev_rule_file=/etc/udev/rules.d/10-vboxdrv.rules # Set this to /dev/null
     117                                                  # for unit testing
     118sysfs_usb_devices="/sys/bus/usb/devices/*"
    194119
    195120install_device_node_setup() {
    196121    # Install udev rules and create device nodes for usb access
     122    # To unit test, set $EXTERN to point to a function simulating these
     123    # functions (defined further up in this file): install_udev;
     124    # install_create_usb_node_for_sysfs.  See the code for usage.
    197125    VBOXDRV_GRP="$1"      # The group that should own /dev/vboxdrv
    198126    VBOXDRV_MODE="$2"     # The mode to be used for /dev/vboxdrv
     
    211139        vboxdrv_group=root
    212140    fi
    213     do_install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
    214                     "${usb_group}" "$INSTALL_NO_UDEV" > ${udev_rule_file}
     141    $EXTERN install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" \
     142                         "$INSTALLATION_DIR" "${usb_group}" \
     143                         "$INSTALL_NO_UDEV" > ${udev_rule_file}
    215144    # Build our device tree
    216145    for i in ${sysfs_usb_devices}; do  # This line intentionally without quotes.
    217         do_install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
    218                                              "${usb_group}"
     146        $EXTERN install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
     147                                                  "${usb_group}"
    219148    done
    220149}
  • trunk/src/VBox/Installer/linux/testcase/tstInstallerLinux.sh

    r38385 r39220  
    2222echo "Testing udev rule generation"
    2323
     24extern_test_input_install_udev() {
     25    command="$1"
     26    shift
     27    case "$command" in
     28        "which") my_which "$@";;
     29        "test")  my_test "$@";;
     30        "rm")    my_rm "$@";;
     31        *) echo Unknown command $command >&2; exit 1;;
     32    esac       
     33}
     34
     35setup_test_input_install_udev() {
     36    # Set up unit testing environment for the "install_udev" function below.
     37    TEST_NAME="$1"          # used to identify the current test
     38    TEST_UDEV_VERSION="$2"  # udev version to simulate
     39    EXTERN=extern_test_input_install_udev
     40    eval 'my_which() { echo test_udev ; }'
     41    eval 'my_test() { true ; }'
     42    eval 'my_rm() { case "$2" in "/etc/udev/rules.d/60-vboxdrv.rules") true ;; *) echo "rm: bad file name \"$2\"!"; false ;; esac ; }'
     43    eval 'test_udev() { echo "$TEST_UDEV_VERSION" ; }'
     44    DELETED_UDEV_FILE=""
     45}
     46
    2447setup_test_input_install_udev ".run, udev-59" 59
    2548
     
    4467esac
    4568
    46 cleanup_test_input_install_udev
    47 
    4869setup_test_input_install_udev ".run, udev-55" 55
    4970
     
    6384        ;;
    6485esac
    65 
    66 cleanup_test_input_install_udev
    6786
    6887setup_test_input_install_udev ".run, udev-54" 54
     
    84103esac
    85104
    86 cleanup_test_input_install_udev
     105echo "Testing device node setup"
    87106
    88 echo "Testing device node setup"
     107extern_test_input_install_device_node_setup() {
     108    command="$1"
     109    shift
     110    case "$command" in
     111        "install_udev")
     112            do_install_udev "$@";;
     113        "install_create_usb_node_for_sysfs")
     114            do_install_create_usb_node_for_sysfs "$@";;
     115        *)
     116            echo Unknown command $command >&2; exit 1;;
     117    esac       
     118}
     119
     120setup_test_input_install_device_node_setup() {
     121    # Set up unit testing environment for the "install_udev" function below.
     122    test_drv_grp="$1"  # The expected vboxdrv group
     123    test_drv_mode="$2" # The expected vboxdrv mode
     124    test_inst_dir="$3" # The expected installation directory
     125    test_usb_grp="$4"  # The expected USB node group
     126    udev_rule_file=/dev/null
     127    sysfs_usb_devices=test_sysfs_path
     128    EXTERN=extern_test_input_install_device_node_setup
     129    eval 'do_install_udev() {    test    "$1" = "${test_drv_grp}" \
     130                                      -a "$2" = "${test_drv_mode}" \
     131                                      -a "$3" = "${test_inst_dir}" \
     132                                      -a "$4" = "${test_usb_grp}" \
     133                                      -a "$5" = "${INSTALL_NO_UDEV}" \
     134                              || echo "do_install_udev: bad parameters: $@" >&2 ; }'
     135    eval 'do_install_create_usb_node_for_sysfs() { \
     136                       test    "$1" = "${sysfs_usb_devices}" \
     137                            -a "$2" = "${test_inst_dir}/VBoxCreateUSBNode.sh" \
     138                            -a "$3" = "${test_usb_grp}" \
     139                    || echo "do_install_create_usb_node_for_sysfs: \
     140bad parameters: $@" >&2 ; }'
     141}
    89142
    90143unset INSTALL_NO_GROUP
     
    101154}
    102155
    103 cleanup_test_input_install_device_node_setup
    104 
    105156INSTALL_NO_GROUP=1
    106157unset INSTALL_NO_UDEV
     
    114165    CERRS="`expr "$CERRS" + 1`"
    115166}
    116 
    117 cleanup_test_input_install_device_node_setup
    118167
    119168unset INSTALL_NO_GROUP
     
    130179}
    131180
    132 cleanup_test_input_install_device_node_setup
    133 
    134181echo "Done.  Error count $CERRS."
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette