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-utils.sh
|
---|
19 |
|
---|
20 | CERRS=0
|
---|
21 |
|
---|
22 | echo "Testing udev rule generation"
|
---|
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 |
|
---|
47 | setup_test_input_install_udev ".run, udev-59" 59
|
---|
48 |
|
---|
49 | udev_59_rules=`cat <<'UDEV_END'
|
---|
50 | KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
|
---|
51 | SUBSYSTEM=="usb_device", ACTION=="add", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
|
---|
52 | SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
|
---|
53 | SUBSYSTEM=="usb_device", ACTION=="remove", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh --remove $major $minor"
|
---|
54 | SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="/opt/VirtualBox/VBoxCreateUSBNode.sh --remove $major $minor"
|
---|
55 | UDEV_END`
|
---|
56 |
|
---|
57 | install_udev_output="`install_udev vboxusers 0660 /opt/VirtualBox`"
|
---|
58 | case "$install_udev_output" in
|
---|
59 | "$udev_59_rules") ;;
|
---|
60 | *)
|
---|
61 | echo "Bad output for udev version 59. Expected:"
|
---|
62 | echo "$udev_59_rules"
|
---|
63 | echo "Actual:"
|
---|
64 | echo "$install_udev_output"
|
---|
65 | CERRS="`expr "$CERRS" + 1`"
|
---|
66 | ;;
|
---|
67 | esac
|
---|
68 |
|
---|
69 | setup_test_input_install_udev ".run, udev-55" 55
|
---|
70 |
|
---|
71 | udev_55_rules=`cat <<'UDEV_END'
|
---|
72 | KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
|
---|
73 | UDEV_END`
|
---|
74 |
|
---|
75 | install_udev_output="`install_udev vboxusers 0660 /opt/VirtualBox`"
|
---|
76 | case "$install_udev_output" in
|
---|
77 | "$udev_55_rules") ;;
|
---|
78 | *)
|
---|
79 | echo "Bad output for udev version 55. Expected:"
|
---|
80 | echo "$udev_55_rules"
|
---|
81 | echo "Actual:"
|
---|
82 | echo "$install_udev_output"
|
---|
83 | CERRS="`expr "$CERRS" + 1`"
|
---|
84 | ;;
|
---|
85 | esac
|
---|
86 |
|
---|
87 | setup_test_input_install_udev ".run, udev-54" 54
|
---|
88 |
|
---|
89 | udev_54_rules=`cat <<'UDEV_END'
|
---|
90 | KERNEL="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="root", MODE="0600"
|
---|
91 | UDEV_END`
|
---|
92 |
|
---|
93 | install_udev_output="`install_udev root 0600 /usr/lib/virtualbox`"
|
---|
94 | case "$install_udev_output" in
|
---|
95 | "$udev_54_rules") ;;
|
---|
96 | *)
|
---|
97 | echo "Bad output for udev version 54. Expected:"
|
---|
98 | echo "$udev_54_rules"
|
---|
99 | echo "Actual:"
|
---|
100 | echo "$install_udev_output"
|
---|
101 | CERRS="`expr "$CERRS" + 1`"
|
---|
102 | ;;
|
---|
103 | esac
|
---|
104 |
|
---|
105 | echo "Testing device node setup"
|
---|
106 |
|
---|
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 | }
|
---|
142 |
|
---|
143 | unset INSTALL_NO_GROUP
|
---|
144 | unset INSTALL_NO_UDEV
|
---|
145 | setup_test_input_install_device_node_setup vboxusers 0660 /opt/VirtualBox \
|
---|
146 | vboxusb
|
---|
147 |
|
---|
148 | command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
|
---|
149 | err="`${command} 2>&1`"
|
---|
150 | test -n "${err}" && {
|
---|
151 | echo "${command} failed."
|
---|
152 | echo "Error: ${err}"
|
---|
153 | CERRS="`expr "$CERRS" + 1`"
|
---|
154 | }
|
---|
155 |
|
---|
156 | INSTALL_NO_GROUP=1
|
---|
157 | unset INSTALL_NO_UDEV
|
---|
158 | setup_test_input_install_device_node_setup root 0660 /opt/VirtualBox root
|
---|
159 |
|
---|
160 | command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
|
---|
161 | err="`${command} 2>&1`"
|
---|
162 | test -n "${err}" && {
|
---|
163 | echo "${command} failed."
|
---|
164 | echo "Error: ${err}"
|
---|
165 | CERRS="`expr "$CERRS" + 1`"
|
---|
166 | }
|
---|
167 |
|
---|
168 | unset INSTALL_NO_GROUP
|
---|
169 | INSTALL_NO_UDEV=1
|
---|
170 | setup_test_input_install_device_node_setup vboxusers 0660 /opt/VirtualBox \
|
---|
171 | vboxusb
|
---|
172 |
|
---|
173 | command="install_device_node_setup vboxusers 0660 /opt/VirtualBox vboxusb"
|
---|
174 | err="`${command} 2>&1`"
|
---|
175 | test -n "${err}" && {
|
---|
176 | echo "${command} failed."
|
---|
177 | echo "Error: ${err}"
|
---|
178 | CERRS="`expr "$CERRS" + 1`"
|
---|
179 | }
|
---|
180 |
|
---|
181 | echo "Done. Error count $CERRS."
|
---|