Skip to content

Commit 50c452e

Browse files
authored
Merge pull request #7 from onera/6-adapt-readme-and-purge-tests
6 adapt readme and purge tests
2 parents 4e99b32 + 95da618 commit 50c452e

21 files changed

+372
-258
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ To use the standalone JAR with the GUI run:
6060
```
6161
Note that by default the standalone JAR path is `target/scala-2.13/dalculator-assembly-X.Y.jar` (where X.Y is the version number).
6262

63+
### Run tests using SBT
64+
65+
You can perform the tests executing the examples in `src/test/resources`.
66+
Each example contains
67+
- a set of command files used to specify a set of analysis
68+
- the sequences generated by the Cecilia Workshop tool and used by the Dalculator to perform the DAL allocation
69+
- some user constraints specifying costs, independence and DAL allocations constraints
70+
- (FAZER example only) the results of the automatic FMEA from the Cecilia tool to perform a Probable Failure Qualitative Analysis (PFQA)
71+
72+
All the tests will produce result files in `analysis` directory and are launched using the following command:
73+
```shell
74+
sbt test
75+
```
76+
6377
### Installing the WBO Pseudo-Boolean solver (optional)
6478
The tool wbo1.4b-fixed can be obtained by contacting its author, Vasco Manquinho from INESC-ID in Portugal.
6579
The binary of the solver must be placed in the `src/resources` folder.

src/main/scala/dalculator/DalculatorCore.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import dalculator.cli.DalculatorParameters
2121
import dalculator.model._
2222
import dalculator.solver.{SolveBudget, SolveDal, SolveIndep}
2323
import dalculator.translator.ModelParser
24+
import dalculator.utils.Configuration
2425

2526
/** The entry point of the dalculator. */
2627
object DalculatorCore {
2728

2829
/** Runs an analysis according to the given parameters. */
29-
def apply(params: DalculatorParameters): Unit = {
30+
def apply(params: DalculatorParameters)(implicit conf:Configuration): Unit = {
3031
this.clear()
3132
if (!(params.seqFiles.nonEmpty &&
3233
params.nSevs.length == params.seqFiles.length &&

src/main/scala/dalculator/cli/CLI.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package dalculator.cli
1919

2020
import dalculator.DalculatorCore
2121
import dalculator.translator.ModelParser
22+
import dalculator.utils.Configuration
2223

2324
object CLI {
2425

@@ -42,7 +43,7 @@ object CLI {
4243
} else {
4344
ModelParser.loadParamsFile(opt, params)
4445
// run specified commands
45-
DalculatorCore(params)
46+
DalculatorCore(params)(Configuration.default)
4647
}
4748
}
4849
}

src/main/scala/dalculator/gui/DalculatorGuiWithListener.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import theory.pb.solver._
3030
import dalculator.cli._
3131
import dalculator.model.DalLevel._
3232
import dalculator.model._
33+
import dalculator.utils.Configuration
3334

3435
import scala.language.postfixOps
3536

@@ -194,7 +195,7 @@ class DalculatorGuiWithListener extends DalculatorGui with ActionListener {
194195
def doInBackground(): Unit = {
195196
frame.analysisThread = Some(this)
196197
println("analysis is running")
197-
dalculator.DalculatorCore(params)
198+
dalculator.DalculatorCore(params)(Configuration.default)
198199
}
199200

200201
override def done(): Unit = {

src/main/scala/dalculator/model/FailureMode.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package dalculator.model
1919

2020
import dalculator.cli.DefaultParameters
21-
import dalculator.utils.{Stringpool, UniqueString}
21+
import dalculator.utils.{Configuration, Stringpool, UniqueString}
2222

2323
/** Represents the failure mode 'name' of function 'function'. */
2424
class FailureMode(val name: UniqueString, val function: Item) {
@@ -99,11 +99,13 @@ object FailureMode extends Iterable[FailureMode] {
9999
}
100100

101101
/** Simplified constructor, decomposes the given string to find 'func'.'name' */
102-
def apply(name: String): FailureMode = {
102+
def apply(name: String)(implicit conf:Configuration): FailureMode = {
103103
val s = name.split('.')
104104
if (s.length <= 1) {
105-
println("[WARNING] FailureMode error: could not identify failure mode in function identifier because it is too short to be decomposed:" + name)
106-
println(s"[WARNING] Assuming failure mode is implicit and $name is the name of the item or a common cause failure")
105+
if(conf.printWarning) {
106+
println("[WARNING] FailureMode error: could not identify failure mode in function identifier because it is too short to be decomposed:" + name)
107+
println(s"[WARNING] Assuming failure mode is implicit and $name is the name of the item or a common cause failure")
108+
}
107109
FailureMode("",Item(name))
108110
} else {
109111
// call normal constructor

src/main/scala/dalculator/translator/ModelParser.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package dalculator.translator
1919

2020
import dalculator.cli.DalculatorParameters
2121
import dalculator.model._
22+
import dalculator.utils.Configuration
2223
import theory.pb.solver.{OpbSolver, Sat4jBoth, Sat4jCP, Sat4jRes}
2324

2425
import java.io.{FileNotFoundException, FileReader}
@@ -45,10 +46,10 @@ object ModelParser extends RegexParsers {
4546
def qident: Parser[String] = "'" ~> ident <~ "'"
4647

4748
/** Rule for a minmal cut set (a list of quoted identifiers). */
48-
def cut: Parser[FailureModeList] = ("{" ~> repsep(qident, ",") <~ "}") ^^ (l => FailureModeList(l.map(f => FailureMode(f))))
49+
def cut(implicit conf:Configuration): Parser[FailureModeList] = ("{" ~> repsep(qident, ",") <~ "}") ^^ (l => FailureModeList(l.map(f => FailureMode(f))))
4950

5051
/** Rule for lists of minimal cut sets */
51-
def cuts: Parser[List[FailureModeList]] = rep(cut)
52+
def cuts(implicit conf:Configuration): Parser[List[FailureModeList]] = rep(cut)
5253

5354
/** Rule for minimal cut sets header, contains name. */
5455
def fcname: Parser[String] = "products(MCS(" ~> qident <~ "))" ~ "="
@@ -63,7 +64,7 @@ object ModelParser extends RegexParsers {
6364
* @param xSev the given xSev value is assigned to the parsed FC
6465
* @param refDal the given refDal is assigned to the parsed FC
6566
* */
66-
def fc(model: Model, nSev: Int, xSev: BigDecimal, refDal: DalLevel): Parser[Model] = opt(comment) ~> fcname ~ cuts <~ "end" ~ opt(comment) ^^ {
67+
def fc(model: Model, nSev: Int, xSev: BigDecimal, refDal: DalLevel)(implicit conf:Configuration): Parser[Model] = opt(comment) ~> fcname ~ cuts <~ "end" ~ opt(comment) ^^ {
6768
case name ~ cuts =>
6869
model.add(FailureCondition(name, nSev, xSev, cuts, refDal))
6970
model
@@ -76,7 +77,7 @@ object ModelParser extends RegexParsers {
7677
* @param xSev the given xSev value is assigned to the parsed FC
7778
* @param refDal the given refDal is assigned to the parsed FC
7879
*/
79-
def loadFC(filename: String, model: Model, nSev: Int, xSev: BigDecimal, refDal: DalLevel): Unit = {
80+
def loadFC(filename: String, model: Model, nSev: Int, xSev: BigDecimal, refDal: DalLevel)(implicit conf:Configuration): Unit = {
8081
val reader = try {
8182
new FileReader(filename)
8283
} catch {
@@ -310,24 +311,24 @@ object ModelParser extends RegexParsers {
310311
}
311312

312313
/** Rule for user defined lambda bounds declaration */
313-
def lambdaBounds: Parser[UserDefinedConstraint] = ("LambdaBounds(" ~> qident ~ "," ~ decimal ~ "," ~ decimal <~ ")") ^^ {
314+
def lambdaBounds(implicit conf:Configuration): Parser[UserDefinedConstraint] = ("LambdaBounds(" ~> qident ~ "," ~ decimal ~ "," ~ decimal <~ ")") ^^ {
314315
case fm ~ _ ~ l ~ _ ~ u =>
315316
LambdaBoundsCstr(FailureMode(fm), l, u)
316317
}
317318

318319
/** Rule for user defined latent failure mode declarations */
319-
def latent: Parser[UserDefinedConstraint] = ("Latent(" ~> qident <~ ")") ^^ (fm => LatentCstr(FailureMode(fm)))
320+
def latent(implicit conf:Configuration): Parser[UserDefinedConstraint] = ("Latent(" ~> qident <~ ")") ^^ (fm => LatentCstr(FailureMode(fm)))
320321

321322
/** Rule for user defined latent failure mode declarations with special interval checks */
322-
def latentItv: Parser[UserDefinedConstraint] = ("Latent(" ~> qident ~ "," ~ repsep(integer, ",") <~ ")") ^^ {
323+
def latentItv(implicit conf:Configuration): Parser[UserDefinedConstraint] = ("Latent(" ~> qident ~ "," ~ repsep(integer, ",") <~ ")") ^^ {
323324
case fm ~ _ ~ itvs => LatentCstr(FailureMode(fm), Some(itvs))
324325
}
325326

326327
/** Disjunction of user defined constraints */
327-
def usrDefCtr: Parser[UserDefinedConstraint] = alloc | coloc | indep | notindep | noneIndep | dalBound | aircraftData | lambdaBounds | latent | latentItv | optimisation | dalRule | maxCost | minCost | DalCost | dalBoundqIdent
328+
def usrDefCtr(implicit conf:Configuration): Parser[UserDefinedConstraint] = alloc | coloc | indep | notindep | noneIndep | dalBound | aircraftData | lambdaBounds | latent | latentItv | optimisation | dalRule | maxCost | minCost | DalCost | dalBoundqIdent
328329

329330
/** Rule for user defined constraints file */
330-
def usrDefCtrs(c: UserDefinedConstraints): Parser[UserDefinedConstraints] = opt(rep(usrDefCtr | comment)) ^^ {
331+
def usrDefCtrs(c: UserDefinedConstraints)(implicit conf:Configuration): Parser[UserDefinedConstraints] = opt(rep(usrDefCtr | comment)) ^^ {
331332
constraints => {
332333
if (constraints.isDefined)
333334
constraints.get collect {case cst:UserDefinedConstraint => cst} foreach c.add
@@ -336,7 +337,7 @@ object ModelParser extends RegexParsers {
336337
}
337338

338339
/** Loads the given user defined constraints file. */
339-
def loadUDef(filename: String, c: UserDefinedConstraints): Unit = {
340+
def loadUDef(filename: String, c: UserDefinedConstraints)(implicit conf:Configuration): Unit = {
340341
val reader = try {
341342
val reader = new FileReader(filename)
342343
reader
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2023. ONERA
3+
* This file is part of Dalculator
4+
*
5+
* Dalculator is free software ;
6+
* you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation ;
8+
* either version 2 of the License, or (at your option) any later version.
9+
*
10+
* PML Analyzer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ;
11+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License along with this program ;
15+
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16+
*/
17+
18+
package dalculator.utils
19+
20+
case class Configuration(
21+
printWarning:Boolean
22+
)
23+
24+
object Configuration {
25+
val default: Configuration = Configuration(true)
26+
}

src/main/scala/preprocessor/composer/DALComposer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import dalculator.cli.DalculatorParameters
2121
import dalculator.model.DalLevel._
2222
import dalculator.model._
2323
import dalculator.solver.SolveDal
24+
import dalculator.utils.Configuration
2425
import preprocessor.analysis.AnalysisTypes.{DALAnalysis, FHA, MCSAnalysis, UDEFFile}
2526
import preprocessor.ast._
2627
import preprocessor.transformers.Parser
@@ -34,7 +35,7 @@ trait DALComposer[Pre] extends Composer[Pre] {
3435

3536
trait DALComposerInstances {
3637

37-
implicit def UDEFFileToDALComposer(implicit parser: Parser.Aux[UDEFFile, Map[Item, DalLevel]]): DALComposer[UDEFFile] = new DALComposer[UDEFFile] {
38+
implicit def UDEFFileToDALComposer(implicit parser: Parser.Aux[UDEFFile, Map[Item, DalLevel]], conf:Configuration): DALComposer[UDEFFile] = new DALComposer[UDEFFile] {
3839

3940
def apply(pre: UDEFFile): DALAnalysis = DALAnalysis(parser.parse(pre))
4041
}

src/main/scala/preprocessor/composer/MCSComposer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package preprocessor.composer
1919

2020
import dalculator.model.FailureMode
21+
import dalculator.utils.Configuration
2122
import preprocessor.analysis.AnalysisTypes._
2223
import preprocessor.ast.ASTImplicits._
2324
import preprocessor.ast.FC
@@ -40,7 +41,7 @@ trait MCSComposerInstances {
4041
.value
4142
}
4243

43-
implicit def OCASFileToMCSComposer(implicit parser: Parser.Aux[OCASFile,Option[(FC,List[List[FailureMode]])]]): MCSComposer[List[OCASFile]] = new MCSComposer[List[OCASFile]] {
44+
implicit def OCASFileToMCSComposer(implicit parser: Parser.Aux[OCASFile,Option[(FC,List[List[FailureMode]])]], conf:Configuration): MCSComposer[List[OCASFile]] = new MCSComposer[List[OCASFile]] {
4445

4546
def apply(files: List[OCASFile]): MCSAnalysis = MCSAnalysis(files.flatMap(parse).toMap)
4647

src/main/scala/preprocessor/composer/MSSComposer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package preprocessor.composer
1919

2020
import dalculator.model.FailureMode
21+
import dalculator.utils.Configuration
2122
import preprocessor.analysis.AnalysisTypes._
2223
import preprocessor.ast.ASTImplicits._
2324
import preprocessor.ast.FC
@@ -33,7 +34,7 @@ trait MSSComposer[Pre] extends Composer [Pre]{
3334

3435
trait MSSComposerInstances {
3536

36-
implicit def FileToMSSComposer(implicit parser:Parser.Aux[OCASFile,Option[(FC,List[MS])]]): MSSComposer[List[OCASFile]] = new MSSComposer[List[OCASFile]] {
37+
implicit def FileToMSSComposer(implicit parser:Parser.Aux[OCASFile,Option[(FC,List[MS])]], conf:Configuration): MSSComposer[List[OCASFile]] = new MSSComposer[List[OCASFile]] {
3738

3839
def apply(files: List[OCASFile]): MSSAnalysis = MSSAnalysis(files.flatMap(parse).toMap)
3940

0 commit comments

Comments
 (0)