DesignSpaceExplorationParserSpec.scala 2.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//
// Copyright (C) 2017 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco.  If not, see <http://www.gnu.org/licenses/>.
//
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package de.tu_darmstadt.cs.esa.tapasco.parser
import  org.scalacheck._
import  org.scalatest._
import  org.scalatest.prop.Checkers
import  fastparse.all._

class DesignSpaceExplorationParserSpec extends FlatSpec with Matchers with Checkers {
  import org.scalacheck.Prop._
  import DesignSpaceExplorationParser._, DesignSpaceExplorationParserSpec._
  implicit val cfg = PropertyCheckConfiguration(minSize = 50000, sizeRange = 1000)

  "All valid DSE jobs" should "be parsed correctly" in
    check(forAllNoShrink(dseGen) { d =>
      Common.checkParsed(P( dse ~ End ).parse(d))
    })
}

private object DesignSpaceExplorationParserSpec {
  import BasicParserSpec._, CommonArgParsersSpec._, GlobalOptionsSpec.pathGen

  val dimensionGen: Gen[String] = Gen.oneOf(
    anyCase("area"),
    anyCase("utilization"),
    anyCase("util"),
    anyCase("freq"),
    anyCase("frequency"),
    anyCase("alts"),
    anyCase("alternatives")
  )

  val dimensionsGen: Gen[String] = for {
    n <- Gen.choose(1, 5)
    s <- join(0 until n map (_ => dimensionGen), sepStringGen)
  } yield s

  val heuristicGen: Gen[String] = join(Seq(
    genLongOption("heuristic"),
    Gen.oneOf(anyCase("throughput"), quoted(anyCase("job throughput")))
  ))

  val batchSizeGen: Gen[String] = join(Seq(
    genLongOption("batchSize"),
    Gen.posNum[Int] map (_.toString)
  ))

  val basePath: Gen[String] = join(Seq(
    genLongOption("basePath"),
    pathGen map (_.toString)
  ))

  val optionGen: Gen[String] = Gen.oneOf(
    heuristicGen,
    batchSizeGen,
    basePath,
    architecturesGen,
74
75
76
    platformsGen,
    debugModeGen,
    deleteProjectsGen
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  )

  val optionsGen: Gen[String] = for {
    n <- Gen.choose(0, 10)
    o <- join(0 until n map (_ => optionGen))
  } yield o

  val dseGen: Gen[String] = join(Seq(
    anyCase("explore"),
    compositionGen,
    Gen.option(join(Seq("@", freqGen))) map (_ getOrElse ""),
    "in",
    dimensionsGen,
    optionsGen
  ))
}