Changeset 39220 in vbox
- Timestamp:
- Nov 7, 2011 11:07:39 PM (13 years ago)
- Location:
- trunk/src/VBox/Installer/linux
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/installer-utils.sh
r38385 r39220 14 14 # 15 15 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. 18 unset EXTERN 46 19 47 20 udev_write_vboxdrv() { … … 64 37 install_udev() { 65 38 # 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. 66 41 VBOXDRV_GRP="$1" # The group owning the vboxdrv device 67 42 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device … … 75 50 "1") ;; 76 51 *) 77 if my_test -d /etc/udev/rules.d; then52 if $EXTERN test -d /etc/udev/rules.d; then 78 53 udev_call="" 79 udev_app=` my_which udevadm 2> /dev/null`54 udev_app=`$EXTERN which udevadm 2> /dev/null` 80 55 if [ $? -eq 0 ]; then 81 56 udev_call="${udev_app} version 2> /dev/null" 82 57 else 83 udev_app=` my_which udevinfo 2> /dev/null`58 udev_app=`$EXTERN which udevinfo 2> /dev/null` 84 59 if [ $? -eq 0 ]; then 85 60 udev_call="${udev_app} -V 2> /dev/null" … … 115 90 esac 116 91 # Remove old udev description file 117 if my_test -f /etc/udev/rules.d/60-vboxdrv.rules; then118 my_rm -f /etc/udev/rules.d/60-vboxdrv.rules 2> /dev/null92 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 119 94 fi 120 95 } 121 96 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. 136 99 137 100 install_create_usb_node_for_sysfs() { … … 140 103 usb_createnode="$2" # Path to the USB device node creation script 141 104 usb_group="$3" # The group to give ownership of the node to 142 if my_test -r "${path}/dev"; then143 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`" 144 107 major="`expr "$dev" : '\(.*\):' 2> /dev/null`" 145 108 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/null109 class="`$EXTERN cat ${path}/bDeviceClass 2> /dev/null`" 110 $EXTERN sh "${usb_createnode}" "$major" "$minor" "$class" \ 111 "${usb_group}" 2>/dev/null 149 112 fi 150 113 } 151 114 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. 116 udev_rule_file=/etc/udev/rules.d/10-vboxdrv.rules # Set this to /dev/null 117 # for unit testing 118 sysfs_usb_devices="/sys/bus/usb/devices/*" 194 119 195 120 install_device_node_setup() { 196 121 # 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. 197 125 VBOXDRV_GRP="$1" # The group that should own /dev/vboxdrv 198 126 VBOXDRV_MODE="$2" # The mode to be used for /dev/vboxdrv … … 211 139 vboxdrv_group=root 212 140 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} 215 144 # Build our device tree 216 145 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}" 219 148 done 220 149 } -
trunk/src/VBox/Installer/linux/testcase/tstInstallerLinux.sh
r38385 r39220 22 22 echo "Testing udev rule generation" 23 23 24 extern_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 35 setup_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 24 47 setup_test_input_install_udev ".run, udev-59" 59 25 48 … … 44 67 esac 45 68 46 cleanup_test_input_install_udev47 48 69 setup_test_input_install_udev ".run, udev-55" 55 49 70 … … 63 84 ;; 64 85 esac 65 66 cleanup_test_input_install_udev67 86 68 87 setup_test_input_install_udev ".run, udev-54" 54 … … 84 103 esac 85 104 86 cleanup_test_input_install_udev 105 echo "Testing device node setup" 87 106 88 echo "Testing device node setup" 107 extern_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 120 setup_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: \ 140 bad parameters: $@" >&2 ; }' 141 } 89 142 90 143 unset INSTALL_NO_GROUP … … 101 154 } 102 155 103 cleanup_test_input_install_device_node_setup104 105 156 INSTALL_NO_GROUP=1 106 157 unset INSTALL_NO_UDEV … … 114 165 CERRS="`expr "$CERRS" + 1`" 115 166 } 116 117 cleanup_test_input_install_device_node_setup118 167 119 168 unset INSTALL_NO_GROUP … … 130 179 } 131 180 132 cleanup_test_input_install_device_node_setup133 134 181 echo "Done. Error count $CERRS."
Note:
See TracChangeset
for help on using the changeset viewer.