1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Oracle VM VirtualBox
|
---|
4 | # VirtualBox linux installation script unit test
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2007-2011 Oracle Corporation
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 |
|
---|
18 | #include installer-common.sh
|
---|
19 |
|
---|
20 | CERRS=0
|
---|
21 |
|
---|
22 | echo "Testing udev rule generation"
|
---|
23 |
|
---|
24 | check_udev_rule_generation() {
|
---|
25 | OUTPUT="$2"
|
---|
26 | EXPECTED="$4"
|
---|
27 | VERSION="$6"
|
---|
28 | case "$OUTPUT" in
|
---|
29 | "$EXPECTED") ;;
|
---|
30 | *)
|
---|
31 | echo "Bad output for udev version $VERSION. Expected:"
|
---|
32 | echo "$EXPECTED"
|
---|
33 | echo "Actual:"
|
---|
34 | echo "$OUTPUT"
|
---|
35 | CERRS="`expr "$CERRS" + 1`"
|
---|
36 | ;;
|
---|
37 | esac
|
---|
38 | }
|
---|
39 |
|
---|
40 | udev_59_rules=`cat <<'UDEV_END'
|
---|
41 | KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
|
---|
42 | KERNEL=="vboxnetctl", NAME="vboxnetctl", OWNER="root", GROUP="vboxusers", MODE="0660"
|
---|
43 | SUBSYSTEM=="usb_device", ACTION=="add", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
|
---|
44 | SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
|
---|
45 | SUBSYSTEM=="usb_device", ACTION=="remove", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh --remove $major $minor"
|
---|
46 | SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh --remove $major $minor"
|
---|
47 | UDEV_END`
|
---|
48 |
|
---|
49 | install_udev_output="`generate_udev_rule vboxusers 0660 /opt/VirtualBox "" "" "udevinfo, version 059"`"
|
---|
50 | check_udev_rule_generation OUTPUT "$install_udev_output" \
|
---|
51 | EXPECTED "$udev_59_rules" \
|
---|
52 | VERSION 59
|
---|
53 |
|
---|
54 | udev_55_rules=`cat <<'UDEV_END'
|
---|
55 | KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
|
---|
56 | KERNEL=="vboxnetctl", NAME="vboxnetctl", OWNER="root", GROUP="vboxusers", MODE="0660"
|
---|
57 | UDEV_END`
|
---|
58 |
|
---|
59 | install_udev_output="`generate_udev_rule vboxusers 0660 /opt/VirtualBox "" "" "v 0055"`"
|
---|
60 | check_udev_rule_generation OUTPUT "$install_udev_output" \
|
---|
61 | EXPECTED "$udev_55_rules" \
|
---|
62 | VERSION 55
|
---|
63 |
|
---|
64 | udev_54_rules=`cat <<'UDEV_END'
|
---|
65 | KERNEL="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="root", MODE="0600"
|
---|
66 | KERNEL="vboxnetctl", NAME="vboxnetctl", OWNER="root", GROUP="root", MODE="0600"
|
---|
67 | UDEV_END`
|
---|
68 |
|
---|
69 | install_udev_output="`generate_udev_rule root 0600 /usr/lib/virtualbox "" "" 54`"
|
---|
70 | check_udev_rule_generation OUTPUT "$install_udev_output" \
|
---|
71 | EXPECTED "$udev_54_rules" \
|
---|
72 | VERSION 54
|
---|
73 |
|
---|
74 | echo "Testing device node setup"
|
---|
75 |
|
---|
76 | extern_test_input_install_device_node_setup() {
|
---|
77 | command="$1"
|
---|
78 | shift
|
---|
79 | case "$command" in
|
---|
80 | "install_udev")
|
---|
81 | do_install_udev "$@";;
|
---|
82 | "install_create_usb_node_for_sysfs")
|
---|
83 | do_install_create_usb_node_for_sysfs "$@";;
|
---|
84 | *)
|
---|
85 | echo Unknown command $command >&2; exit 1;;
|
---|
86 | esac
|
---|
87 | }
|
---|
88 |
|
---|
89 | setup_test_input_install_device_node_setup() {
|
---|
90 | # Set up unit testing environment for the "install_udev" function below.
|
---|
91 | test_drv_grp="$1" # The expected vboxdrv group
|
---|
92 | test_drv_mode="$2" # The expected vboxdrv mode
|
---|
93 | test_inst_dir="$3" # The expected installation directory
|
---|
94 | test_usb_grp="$4" # The expected USB node group
|
---|
95 | udev_rule_file=/dev/null
|
---|
96 | sysfs_usb_devices=test_sysfs_path
|
---|
97 | EXTERN=extern_test_input_install_device_node_setup
|
---|
98 | eval 'do_install_udev() { test "$1" = "${test_drv_grp}" \
|
---|
99 | -a "$2" = "${test_drv_mode}" \
|
---|
100 | -a "$3" = "${test_inst_dir}" \
|
---|
101 | -a "$4" = "${test_usb_grp}" \
|
---|
102 | -a "$5" = "${INSTALL_NO_UDEV}" \
|
---|
103 | || echo "do_install_udev: bad parameters: $@" >&2 ; }'
|
---|
104 | eval 'do_install_create_usb_node_for_sysfs() { \
|
---|
105 | test "$1" = "${sysfs_usb_devices}" \
|
---|
106 | -a "$2" = "${test_inst_dir}/VBoxCreateUSBNode.sh" \
|
---|
107 | -a "$3" = "${test_usb_grp}" \
|
---|
108 | || echo "do_install_create_usb_node_for_sysfs: \
|
---|
109 | bad parameters: $@" >&2 ; }'
|
---|
110 | }
|
---|
111 |
|
---|
112 | unset INSTALL_NO_GROUP
|
---|
113 | unset INSTALL_NO_UDEV
|
---|
114 | setup_test_input_install_device_node_setup vboxusers 0660 /opt/VirtualBox \
|
---|
115 | vboxusb
|
---|
116 |
|
---|
117 | command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
|
---|
118 | err="`${command} 2>&1`"
|
---|
119 | test -n "${err}" && {
|
---|
120 | echo "${command} failed."
|
---|
121 | echo "Error: ${err}"
|
---|
122 | CERRS="`expr "$CERRS" + 1`"
|
---|
123 | }
|
---|
124 |
|
---|
125 | INSTALL_NO_GROUP=1
|
---|
126 | unset INSTALL_NO_UDEV
|
---|
127 | setup_test_input_install_device_node_setup root 0660 /opt/VirtualBox root
|
---|
128 |
|
---|
129 | command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
|
---|
130 | err="`${command} 2>&1`"
|
---|
131 | test -n "${err}" && {
|
---|
132 | echo "${command} failed."
|
---|
133 | echo "Error: ${err}"
|
---|
134 | CERRS="`expr "$CERRS" + 1`"
|
---|
135 | }
|
---|
136 |
|
---|
137 | unset INSTALL_NO_GROUP
|
---|
138 | INSTALL_NO_UDEV=1
|
---|
139 | setup_test_input_install_device_node_setup vboxusers 0660 /opt/VirtualBox \
|
---|
140 | vboxusb
|
---|
141 |
|
---|
142 | command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
|
---|
143 | err="`${command} 2>&1`"
|
---|
144 | test -n "${err}" && {
|
---|
145 | echo "${command} failed."
|
---|
146 | echo "Error: ${err}"
|
---|
147 | CERRS="`expr "$CERRS" + 1`"
|
---|
148 | }
|
---|
149 |
|
---|
150 | echo "Done. Error count $CERRS."
|
---|