Skip to content

Commit

Permalink
prototype(ldfi v2): add basic project structure including testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Feb 10, 2021
1 parent 33dbd29 commit d2bd105
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/ldfi2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Copyright (c) 2021 Symbiont Inc.

All rights reserved.
6 changes: 6 additions & 0 deletions src/ldfi2/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Ldfi

main :: IO ()
main = print (ldfi exTraces)
13 changes: 13 additions & 0 deletions src/ldfi2/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
packages: .

with-compiler: ghc-8.10.3

-- reject-unconstrained-dependencies: all

constraints:

package ldfi
ghc-options: -Wall

allow-older: *
allow-newer: *
60 changes: 44 additions & 16 deletions src/ldfi2/ldfi.cabal
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
cabal-version: >=1.10
-- Initial package description 'ldfi.cabal' generated by 'cabal init'.
-- For further documentation, see http://haskell.org/cabal/users-guide/

name: ldfi
version: 0.0.0
-- synopsis:
-- description:
-- bug-reports:
-- license:
synopsis: Lineage-driven fault injection
description: See README at <https://github.com/symbiont-io/detsys-testkit/tree/main/src/ldfi#readme>
bug-reports: https://github.com/symbiont-io/detsys-testkit/issues
license: AllRightsReserved
license-file: LICENSE
author: Stevan Andjelkovic
maintainer: stevana@users.noreply.github.com
-- copyright:
-- category:
maintainer: symbiont-stevan-andjelkovic@users.noreply.github.com
copyright: Copyright (c) 2021 Symbiont Inc
category: Testing, Distributed Systems
build-type: Simple
extra-source-files: CHANGELOG.md
tested-with: GHC ==8.10.3

library
hs-source-dirs: src/
exposed-modules: Ldfi
-- GHC boot libraries
-- (https://gitlab.haskell.org/ghc/ghc/-/blob/master/packages)
build-depends:
base >=4.14 && <4.15
, containers
default-language: Haskell2010

test-suite test
type: exitcode-stdio-1.0
hs-source-dirs: test/
main-is: Driver.hs
build-depends:
base
, containers
, HUnit
, ldfi
, tasty
, tasty-hunit
other-modules:
LdfiTest
ghc-options: -threaded -rtsopts -with-rtsopts=-N -fno-ignore-asserts
default-language: Haskell2010

executable ldfi
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.13 && <4.14
-- hs-source-dirs:
default-language: Haskell2010
hs-source-dirs: app
main-is: Main.hs
build-depends:
base
, ldfi
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/symbiont-io/detsys-testkit
50 changes: 28 additions & 22 deletions src/ldfi2/Main.hs → src/ldfi2/src/Ldfi.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Main where
module Ldfi where

import Data.Set (Set)
import qualified Data.Set as Set
Expand All @@ -17,9 +17,8 @@ type Trace = [Event]

exTraces :: [Trace]
exTraces =
[ [Event "A" "B", Event "A" "C", Event "A" "D"]
, [Event "A" "B", Event "A" "R", Event "R" "S1", Event "R" "S2", Event "A" "D"]
, [Event "A" "B", Event "A" "C", Event "A" "T1", Event "A" "T2"]
[ [Event "A" "B", Event "A" "C"]
, [Event "A" "B", Event "A" "R", Event "R" "S1", Event "R" "S2"]
]

nodes :: Trace -> Set Node
Expand All @@ -43,19 +42,27 @@ data Formula
deriving (Eq, Show)

simplify :: Formula -> Formula
simplify (TT :&& r) = simplify r
simplify (And xs :&& y) = And (map simplify xs ++ [simplify y])
simplify (x :&& And ys) = And (simplify x : map simplify ys)
simplify (FF :|| r) = simplify r
simplify (l :|| r) = simplify l :|| simplify r
simplify (And fs) = case filter (/= TT) . (>>= expandAnd) $ map simplify fs of
[] -> TT
[f] -> f
fs' -> And fs'
where
expandAnd (And xs) = xs
expandAnd (l :&& r) = [l, r]
expandAnd f = [f]
simplify (TT :&& r) = simplify r
simplify (l :&& r) = simplify l :&& simplify r
simplify (FF :|| r) = simplify r
simplify (l :|| r) = simplify l :|| simplify r
simplify (And []) = TT
simplify (And [f]) = f
simplify (And fs) = And (map simplify fs)

-- simplify (TT :&& r) = simplify r
-- simplify (And xs :&& y) = And (map simplify xs ++ [simplify y])
-- simplify (x :&& And ys) = And (simplify x : map simplify ys)
-- simplify (FF :|| r) = simplify r
-- simplify (l :|| r) = simplify l :|| simplify r
-- simplify (And fs) = case filter (/= TT) . (>>= expandAnd) $ map simplify fs of
-- [] -> TT
-- [f] -> f
-- fs' -> And fs'
-- where
-- expandAnd (And xs) = xs
-- expandAnd (l :&& r) = [l, r]
-- expandAnd f = [f]
simplify f = f

fixpoint :: Formula -> Formula
Expand All @@ -68,8 +75,8 @@ intersections = foldl1 Set.intersection
vars :: Set String -> Formula
vars = And . map Var . Set.toList

ldfi :: [Trace] -> Formula
ldfi ts =
ldfi' :: [Trace] -> Formula
ldfi' ts =
let
ns = map nodes ts
is = intersections ns
Expand All @@ -82,6 +89,5 @@ ldfi ts =
, j <- drop len ns
]


main :: IO ()
main = print (fixpoint (ldfi exTraces))
ldfi :: [Trace] -> Formula
ldfi = fixpoint . ldfi'
1 change: 1 addition & 0 deletions src/ldfi2/test/Driver.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF tasty-discover #-}
13 changes: 13 additions & 0 deletions src/ldfi2/test/LdfiTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module LdfiTest where

import Test.HUnit

import Ldfi

------------------------------------------------------------------------

unit_cache :: Assertion
unit_cache =
assertEqual ""
(ldfi exTraces)
(And [Var "A",Var "B"] :&& (Var "C" :|| And [Var "R",Var "S1",Var "S2"]))

0 comments on commit d2bd105

Please sign in to comment.