From d05a776200b0395bc87c2eccbda785ab4ec7c2fd Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Mon, 27 Apr 2020 10:12:44 +0200 Subject: [PATCH] Tests: - Add failure test (to test on nixos, we ensure that it fails with another libc implementation). --- Test.hs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Test.hs b/Test.hs index 7871ccb..7dbc60f 100755 --- a/Test.hs +++ b/Test.hs @@ -8,36 +8,48 @@ import Data.Text (Text) import Control.Monad.IO.Class (liftIO) import Data.List (find) +currentChannel = "channel:nixos-19.03-small" + -- | Utils function: run a command and returns its output. processOutput p args = Text.strip . Text.pack <$> readProcess (Text.unpack p) (Text.unpack <$> args) "" -- | Returns the path to the nixGLXXX binary. -nixGLBin version = (<>("/bin/"<>version)) <$> processOutput "nix-build" ["./", "-A", version] +getNixGLBin version = (<>("/bin/"<>version)) <$> processOutput "nix-build" ["./", "-A", version, "--arg", "pkgs", "import (fetchTarball " <> currentChannel <> ")"] -- | Returns the vendor string associated with a glxinfo wrapped by a nixGL. -getVendorString nixGL glxinfo = do - output <- Text.lines <$> processOutput nixGL [glxinfo] +getVendorString io = do + output <- Text.lines <$> io pure $ Text.unpack <$> find ("OpenGL version string"`Text.isPrefixOf`) output -- | Checks that a nixGL wrapper works with glxinfo 32 & 64 bits. checkOpenGL_32_64 glxinfo32 glxinfo64 vendorName nixGLName = do - nixGLBin <- runIO $ (<>("/bin/"<>nixGLName)) <$> processOutput "nix-build" ["./", "-A", nixGLName] + beforeAll (getNixGLBin nixGLName) $ do + it "32 bits" $ \nixGLBin -> do + Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo32, "-B"]) + vendorString `shouldContain` vendorName - it "32 bits" $ do - Just vendorString <- getVendorString nixGLBin glxinfo32 - vendorString `shouldContain` vendorName - - it "64 bits" $ do - Just vendorString <- getVendorString nixGLBin glxinfo64 - vendorString `shouldContain` vendorName + it "64 bits" $ \nixGLBin -> do + Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo64, "-B"]) + vendorString `shouldContain` vendorName main = do - glxinfo64 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" ["", "-A", "glxinfo"] - glxinfo32 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" ["", "-A", "pkgsi686Linux.glxinfo"] + -- 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"] let checkOpenGL = checkOpenGL_32_64 glxinfo32 glxinfo64 hspec $ do + describe "Must fail" $ do + it "fails with unwrapped glxinfo64" $ do + vendorString <- getVendorString (processOutput glxinfo64 []) + 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