This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,52 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module System.CGroup.TypesSpec ( | ||
spec, | ||
) where | ||
|
||
-- This test won't work on Windows (mingw32), because paths starting with `/` are invalid | ||
#ifndef mingw32_HOST_OS | ||
import Path | ||
import Path.IO (getCurrentDir, resolveFile) | ||
import System.CGroup.Types | ||
import System.Info (os) | ||
import Test.Hspec (Spec, describe, it, runIO, shouldBe) | ||
|
||
-- This test won't work on Windows, because paths starting with `/` are invalid | ||
spec :: Spec | ||
spec = do | ||
spec = exceptOnWindows $ do | ||
currentDir <- runIO getCurrentDir | ||
|
||
describe "resolveGroupController" $ do | ||
it "should work on a real world example" $ do | ||
cgroup <- resolveFile currentDir "test/System/CGroup/testdata/realworld/cgroup" | ||
mountinfo <- resolveFile currentDir "test/System/CGroup/testdata/realworld/mountinfo" | ||
expected <- parseAbsDir "/sys/fs/cgroup/cpu" | ||
|
||
controller <- resolveCGroupController' cgroup mountinfo "cpu" | ||
controller `shouldBe` Controller $(mkAbsDir "/sys/fs/cgroup/cpu") | ||
controller `shouldBe` Controller expected | ||
|
||
it "should resolve a direct mount root" $ do | ||
cgroup <- resolveFile currentDir "test/System/CGroup/testdata/direct/cgroup" | ||
mountinfo <- resolveFile currentDir "test/System/CGroup/testdata/direct/mountinfo" | ||
expected <- parseAbsDir "/sys/fs/cgroup/cpu" | ||
|
||
controller <- resolveCGroupController' cgroup mountinfo "cpu" | ||
controller `shouldBe` Controller $(mkAbsDir "/sys/fs/cgroup/cpu") | ||
controller `shouldBe` Controller expected | ||
|
||
it "should resolve subdirectories of a mount root" $ do | ||
cgroup <- resolveFile currentDir "test/System/CGroup/testdata/indirect/cgroup" | ||
mountinfo <- resolveFile currentDir "test/System/CGroup/testdata/indirect/mountinfo" | ||
expected <- parseAbsDir "/sys/fs/cgroup/cpu/subdir" | ||
|
||
controller <- resolveCGroupController' cgroup mountinfo "cpu" | ||
controller `shouldBe` Controller $(mkAbsDir "/sys/fs/cgroup/cpu/subdir") | ||
controller `shouldBe` Controller expected | ||
|
||
it "should work for cgroups v2" $ do | ||
cgroup <- resolveFile currentDir "test/System/CGroup/testdata/cgroupsv2/cgroup" | ||
mountinfo <- resolveFile currentDir "test/System/CGroup/testdata/cgroupsv2/mountinfo" | ||
expected <- parseAbsDir "/sys/fs/cgroup/cpu" | ||
|
||
controller <- resolveCGroupController' cgroup mountinfo "cpu" | ||
controller `shouldBe` Controller $(mkAbsDir "/sys/fs/cgroup/cpu") | ||
#else | ||
import Test.Hspec (Spec) | ||
controller `shouldBe` Controller expected | ||
|
||
-- Windows: do nothing | ||
spec :: Spec | ||
spec = pure () | ||
#endif | ||
exceptOnWindows :: Applicative m => m () -> m () | ||
exceptOnWindows act | ||
| os == "mingw32" = pure () | ||
| otherwise = act |