[lxc-devel] [lxd/master] Device GPU tests

tomponline on Github lxc-bot at linuxcontainers.org
Mon Aug 19 13:41:11 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 360 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190819/85f6b5e0/attachment.bin>
-------------- next part --------------
From 18e893168eca7721d06d49987f40b88cb867909b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 19 Aug 2019 14:39:36 +0100
Subject: [PATCH 1/2] device/utils/unix: Fix double device name encoding in
 file name

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/device/device_utils_unix.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/device/device_utils_unix.go b/lxd/device/device_utils_unix.go
index d97c6f3984..de2cf57644 100644
--- a/lxd/device/device_utils_unix.go
+++ b/lxd/device/device_utils_unix.go
@@ -325,7 +325,7 @@ func unixDeviceSetup(s *state.State, devicesPath string, typePrefix string, devi
 	}
 
 	// Create the device on the host.
-	ourPrefix := unixDeviceEncode(unixDeviceJoinPath(typePrefix, deviceName))
+	ourPrefix := unixDeviceJoinPath(typePrefix, deviceName)
 	d, err := UnixDeviceCreate(s, nil, devicesPath, ourPrefix, m, defaultMode)
 	if err != nil {
 		return err

From 7e37085284794e665e1ccd69cfac9c9a630ac63c Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 19 Aug 2019 14:39:56 +0100
Subject: [PATCH 2/2] test: Adds GPU tests

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 test/main.sh                         |  3 +-
 test/suites/container_devices_gpu.sh | 88 ++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 test/suites/container_devices_gpu.sh

diff --git a/test/main.sh b/test/main.sh
index 53cbc6a94c..a207dcb28f 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -198,6 +198,8 @@ run_test test_container_devices_nic_ipvlan "container devices - nic - ipvlan"
 run_test test_container_devices_nic_sriov "container devices - nic - sriov"
 run_test test_container_devices_ib_physical "container devices - infiniband - physical"
 run_test test_container_devices_ib_sriov "container devices - infiniband - sriov"
+run_test test_container_devices_proxy "container devices - proxy"
+run_test test_container_devices_gpu "container devices - gpu"
 run_test test_security "security features"
 run_test test_security_protection "container protection"
 run_test test_image_expiry "image expiry"
@@ -240,7 +242,6 @@ run_test test_kernel_limits "kernel limits"
 run_test test_macaroon_auth "macaroon authentication"
 run_test test_console "console"
 run_test test_query "query"
-run_test test_container_devices_proxy "container devices - proxy"
 run_test test_storage_local_volume_handling "storage local volume handling"
 run_test test_backup_import "backup import"
 run_test test_backup_export "backup export"
diff --git a/test/suites/container_devices_gpu.sh b/test/suites/container_devices_gpu.sh
new file mode 100644
index 0000000000..1adf78d66a
--- /dev/null
+++ b/test/suites/container_devices_gpu.sh
@@ -0,0 +1,88 @@
+test_container_devices_gpu() {
+  ensure_import_testimage
+  ensure_has_localhost_remote "${LXD_ADDR}"
+
+  if [ ! -c /dev/dri/card0 ]; then
+    echo "==> SKIP: No /dev/dri/card0 device found"
+    return
+  fi
+
+  ctName="ct$$"
+  lxc launch testimage "${ctName}"
+
+  # Check adding all cards creates the correct device mounts and cleans up on removal.
+  startMountCount=$(lxc exec "${ctName}" -- mount | wc -l)
+  startDevCount=$(find "${LXD_DIR}"/devices/"${ctName}" -type c | wc -l)
+  lxc config device add "${ctName}" gpu-all gpu mode=0600
+  lxc exec "${ctName}" -- mount | grep "tmpfs on /dev/dri/card0 type tmpfs"
+  lxc exec "${ctName}" -- stat -c '%a' /dev/dri/card0 | grep 600
+  stat -c '%a' "${LXD_DIR}"/devices/"${ctName}"/unix.gpu--all.dev-dri-card0 | grep 600
+  lxc config device remove "${ctName}" gpu-all
+  endMountCount=$(lxc exec "${ctName}" -- mount | wc -l)
+  endDevCount=$(find "${LXD_DIR}"/devices/"${ctName}" -type c | wc -l)
+
+  if [ "$startMountCount" != "$endMountCount" ]; then
+    echo "leftover container mounts detected"
+    false
+  fi
+
+  if [ "$startDevCount" != "$endDevCount" ]; then
+    echo "leftover host devices detected"
+    false
+  fi
+
+  # Check adding non-existant card fails.
+  ! lxc config device add "${ctName}" gpu-missing gpu id=9999
+
+  # Check default create mode is 0660.
+  lxc config device add "${ctName}" gpu-default gpu id=0
+  lxc exec "${ctName}" -- stat -c '%a' /dev/dri/card0 | grep 660
+  lxc config device remove "${ctName}" gpu-default
+
+  # Check Nvidia devices if card0 is an Nvidia GPU.
+  card0Minor=$(stat -c %T /dev/dri/card0)
+  if [ ! -c /dev/nvidia"${card0Minor}"  ]; then
+    echo "==> SKIP: /dev/dri/card0 is not Nvidia card, skipping Nvidia tests"
+    lxc delete -f "${ctName}"
+    return
+  fi
+
+  # Check the Nvidia specific devices are mounted correctly.
+  lxc config device add "${ctName}" gpu-nvidia gpu id=0 mode=0600
+  lxc exec "${ctName}" -- mount | grep "tmpfs on /dev/dri/card0 type tmpfs"
+
+  lxc exec "${ctName}" -- mount | grep /dev/nvidia0
+  stat -c '%a' "${LXD_DIR}"/devices/"${ctName}"/unix.gpu--nvidia.dev-dri-card0 | grep 600
+
+  lxc exec "${ctName}" -- mount | grep /dev/nvidia-modeset
+  stat -c '%a' "${LXD_DIR}"/devices/"${ctName}"/unix.gpu--nvidia.dev-nvidia--modeset | grep 600
+
+  lxc exec "${ctName}" -- mount | grep /dev/nvidia-uvm
+  stat -c '%a' "${LXD_DIR}"/devices/"${ctName}"/unix.gpu--nvidia.dev-nvidia--uvm | grep 600
+
+  lxc exec "${ctName}" -- mount | grep /dev/nvidia-uvm-tools
+  stat -c '%a' "${LXD_DIR}"/devices/"${ctName}"/unix.gpu--nvidia.dev-nvidia--uvm--tools | grep 600
+
+  lxc exec "${ctName}" -- mount | grep /dev/nvidiactl
+  stat -c '%a' "${LXD_DIR}"/devices/"${ctName}"/unix.gpu--nvidia.dev-nvidiactl | grep 600
+
+  lxc config device remove "${ctName}" gpu-nvidia
+
+  # Check support for nvidia runtime (requires libnvidia-container-tools be installed).
+  if [ ! -f /usr/bin/nvidia-container-cli ]; then
+    echo "==> SKIP: /usr/bin/nvidia-container-cli not available (please install libnvidia-container-tools)"
+    lxc delete -f "${ctName}"
+    return
+  fi
+
+  lxc stop -f "${ctName}"
+  lxc config set "${ctName}" nvidia.runtime true
+  lxc start "${ctName}"
+  nvidiaMountCount=$(lxc exec "${ctName}" -- mount | grep nvidia | wc -l)
+  if [ "$nvidiaMountCount" != "16" ]; then
+    echo "nvidia runtime mounts invalid"
+    false
+  fi
+
+  lxc delete -f "${ctName}"
+}


More information about the lxc-devel mailing list