Skip to content

Commit

Permalink
feat(stats): Add detsys-stats program for getting stats of test run
Browse files Browse the repository at this point in the history
```
> detsys-stats check --testId [the-testid-to-test] --file [file-describing-properties-to-test]
```

This will output a report for the test, with information how many runs had each
property.

The file should follow the following format:
```
[NAME OF REPORT]

[NAME OF 1 PROPERTY]
[LTL-FORMULA FOR THAT PROPERTY]

[NAME OF 2 PROPERTY]
[LTL-FORMULA FOR THAT PROPERTY]

...

[NAME OF n PROPERTY]
[LTL-FORMULA FOR THAT PROPERTY]
```
  • Loading branch information
symbiont-daniel-gustafsson committed Aug 3, 2021
1 parent 8a07b4e commit 03c4a49
Show file tree
Hide file tree
Showing 15 changed files with 3,194 additions and 1 deletion.
5 changes: 4 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let
ldfi = callPackage ./src/ldfi/default.nix {};
ltl = callPackage ./src/ltl/default.nix {};
scheduler = callPackage ./src/scheduler/default.nix {};
stats = callPackage ./src/stats/default.nix {};
in

stdenv.mkDerivation {
Expand Down Expand Up @@ -53,7 +54,8 @@ stdenv.mkDerivation {
++ lib.optional (nix-build-all || nix-build-generator) [ generator ]
++ lib.optional (nix-build-all || nix-build-ldfi) [ ldfi ]
++ lib.optional (nix-build-all || nix-build-ltl) [ ltl ]
++ lib.optional (nix-build-all || nix-build-scheduler) [ scheduler ];
++ lib.optional (nix-build-all || nix-build-scheduler) [ scheduler ]
++ [ stats ];

installPhase = ''
mkdir -p $out/bin
Expand Down Expand Up @@ -119,6 +121,7 @@ stdenv.mkDerivation {
install -D $bazelBin/ltl/ltl $out/bin/detsys-ltl
''
}
install -D ${stats.out}/bin/detsys-stats $out/bin
${if nix-build-scheduler || nix-build-all then ''
install -D ${scheduler.out}/bin/detsys-scheduler $out/bin
'' else ''
Expand Down
25 changes: 25 additions & 0 deletions src/stats/.stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
steps:
- imports:
align: none
list_align: with_module_name
pad_module_names: false
long_list_align: new_line_multiline
empty_list_align: inherit
list_padding: 7 # length "import "
separate_lists: false
space_surround: false
- language_pragmas:
style: vertical
align: false
remove_redundant: true
- simple_align:
cases: false
top_level_patterns: false
records: false
- trailing_whitespace: {}

# You need to put any language extensions that's enabled for the entire project
# here.
language_extensions: []

columns: 72
5 changes: 5 additions & 0 deletions src/stats/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
3 changes: 3 additions & 0 deletions src/stats/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Copyright (c) 2021 Symbiont Inc.

All rights reserved.
3 changes: 3 additions & 0 deletions src/stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Statistics for a detsys run

> detsys-stats check --testId XXX --file
56 changes: 56 additions & 0 deletions src/stats/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}

module Main where

import qualified Description
import Options.Generic
import qualified Stats

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

-- When building with Bazel we generate a module containing the git commit hash
-- at compile-time.
#ifdef __BAZEL_BUILD__
import GitHash
-- When building with cabal we expect the git commit hash to be passed in via
-- CPP flags, i.e. `--ghc-option=-D__GIT_HASH__=\"X\"`.
#elif defined __GIT_HASH__
gitHash :: String
gitHash = __GIT_HASH__
#else
gitHash :: String
gitHash = "unknown"
#endif

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

-- shold we use some other type for FilePath that isn't just alias = [Char]
data Config
= Check
{ testId :: Int <?> "Which TestId to get stats for",
file :: FilePath <?> "File that contains the description of the stats"
}
| Version
deriving (Generic)

instance ParseRecord Config

main :: IO ()
main = do
(cfg, help) <- getWithHelp "Stats"
case cfg of
Version -> putStrLn gitHash
Check {..} -> do
input <- readFile $ unHelpful file
case Description.parse input of
Nothing -> do
putStrLn "Can't parse <file>"
Just desc -> do
(result, nrRuns) <- Stats.gatherInformation (unHelpful testId) desc
putStrLn $ Description.pprint nrRuns result
15 changes: 15 additions & 0 deletions src/stats/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
packages: .

with-compiler: ghc-8.10.4

reject-unconstrained-dependencies: all

constraints: QuickCheck +old-random

package stats
ghc-options:
-Wall
-O2

allow-older: *
allow-newer: *
Loading

0 comments on commit 03c4a49

Please sign in to comment.