From 701dfc8c6ebb9f3eecb22fd83522d71b7ca2215a Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Mon, 27 Apr 2020 16:52:29 +0200 Subject: [PATCH] Add a bunch of tests for Vulkan --- Test.hs | 87 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/Test.hs b/Test.hs index 7dbc60f..8a990c8 100755 --- a/Test.hs +++ b/Test.hs @@ -8,11 +8,19 @@ import Data.Text (Text) import Control.Monad.IO.Class (liftIO) import Data.List (find) -currentChannel = "channel:nixos-19.03-small" +-- nixos-19-09 is used so hopefully it will have a different libc than +-- the current `` used in a current nixOS system, so it will trigger the +-- driver failure. +-- Run `./Test.hs --match "/Sanity/"` to ensure that non wrapped +-- binaries fails on NixOS. + +currentChannel = "channel:nixos-19.09-small" -- | Utils function: run a command and returns its output. processOutput p args = Text.strip . Text.pack <$> readProcess (Text.unpack p) (Text.unpack <$> args) "" +-- * OpenGL + -- | Returns the path to the nixGLXXX binary. getNixGLBin version = (<>("/bin/"<>version)) <$> processOutput "nix-build" ["./", "-A", version, "--arg", "pkgs", "import (fetchTarball " <> currentChannel <> ")"] @@ -32,31 +40,72 @@ checkOpenGL_32_64 glxinfo32 glxinfo64 vendorName nixGLName = do Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo64, "-B"]) vendorString `shouldContain` vendorName +-- * Vulkan + +-- | Returns the vendor string associated with a glxinfo wrapped by a nixGL. +getVulkanVendorString io = do + output <- Text.lines <$> io + pure $ Text.unpack <$> find ("driverName"`Text.isInfixOf`) output + +-- | Checks that a nixGL wrapper works with glxinfo 32 & 64 bits. +checkVulkan_32_64 vulkaninfo32 vulkaninfo64 vendorName nixGLName = do + beforeAll (getNixGLBin nixGLName) $ do + it "32 bits" $ \nixGLBin -> do + Just vendorString <- getVulkanVendorString (processOutput nixGLBin [vulkaninfo32]) + vendorString `shouldContain` vendorName + + it "64 bits" $ \nixGLBin -> do + Just vendorString <- getVulkanVendorString (processOutput nixGLBin [vulkaninfo64]) + vendorString `shouldContain` vendorName + + main = do - -- nixos-18-03 is used so hopefully it will have a different libc - -- than the one used in current nixOS system, so it will trigger the - -- driver failure. glxinfo64 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" [currentChannel, "-A", "glxinfo"] glxinfo32 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" [currentChannel, "-A", "pkgsi686Linux.glxinfo"] + vulkaninfo64 <- (<>"/bin/vulkaninfo") <$> processOutput "nix-build" [currentChannel, "-A", "vulkan-tools"] + vulkaninfo32 <- (<>"/bin/vulkaninfo") <$> processOutput "nix-build" [currentChannel, "-A", "pkgsi686Linux.vulkan-tools"] + let checkOpenGL = checkOpenGL_32_64 glxinfo32 glxinfo64 + checkVulkan = checkVulkan_32_64 vulkaninfo32 vulkaninfo64 hspec $ do - describe "Must fail" $ do - it "fails with unwrapped glxinfo64" $ do - vendorString <- getVendorString (processOutput glxinfo64 []) - vendorString `shouldBe` Nothing + -- This category ensure that tests are failing if not run with nixGL + -- This allows testing on nixOS + describe "Sanity" $ do + describe "OpenGL" $ do + it "fails with unwrapped glxinfo64" $ do + vendorString <- getVendorString (processOutput glxinfo64 ["-B"]) + vendorString `shouldBe` Nothing - it "fails with unwrapped glxinfo32" $ do - vendorString <- getVendorString (processOutput glxinfo32 []) - vendorString `shouldBe` Nothing - describe "Mesa" $ do - checkOpenGL "Mesa" "nixGLIntel" - describe "Nvidia - Bumblebee" $ do - checkOpenGL "NVIDIA" "nixGLNvidiaBumblebee" + it "fails with unwrapped glxinfo32" $ do + vendorString <- getVendorString (processOutput glxinfo32 ["-B"]) + vendorString `shouldBe` Nothing + describe "Vulkan" $ do + it "fails with unwrapped vulkaninfo64" $ do + getVulkanVendorString (processOutput vulkaninfo64 []) `shouldThrow` anyIOException - -- TODO: check Nvidia (I don't have this hardware) - describe "Nvidia" $ do - checkOpenGL "NVIDIA" "nixGLNvidia" + it "fails with unwrapped vulkaninfo32" $ do + getVulkanVendorString (processOutput vulkaninfo32 []) `shouldThrow` anyIOException - -- TODO: check vulkan (I don't have vulkan compatible hardware) + describe "NixGL" $ do + describe "Mesa" $ do + describe "OpenGL" $ do + checkOpenGL "Mesa" "nixGLIntel" + describe "Vulkan" $ do + checkVulkan "Mesa" "nixVulkanIntel" + + describe "Nvidia - Bumblebee" $ do + describe "OpenGL" $ do + checkOpenGL "NVIDIA" "nixGLNvidiaBumblebee" + describe "Vulkan" $ do + -- Not tested: I don't have the hardware (@guibou) + checkVulkan "NVIDIA" "nixVulkanNvidiaBumblebee" + + -- TODO: check Nvidia (I don't have this hardware) + describe "Nvidia" $ do + describe "OpenGL" $ do + checkOpenGL "NVIDIA" "nixGLNvidia" + describe "Vulkan" $ do + describe "Nvidia" $ do + checkVulkan "NVIDIA" "nixVulkanNvidia"