Skip to content

Commit

Permalink
Merge 8912de8 into 86f3c31
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 committed Jun 3, 2019
2 parents 86f3c31 + 8912de8 commit dde6800
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/scala/grading/ExampleGraderScala.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dinocpu

/** Example definition of graded test, runs a few tests from lab 1
*
*/
object examplegrader {
def main(args: Array[String]): Unit = {

//each test set appears as one test on gradescope, contains at least one InstTests
val sets = List[GradedTestSet](
new GradedTestSet("Single Cycle Add",List[CPUTestCase](InstTests.nameMap("add1")),10,true,"single-cycle"),
new GradedTestSet("R-type single cycle",InstTests.rtype,10,true,"single-cycle"),
new GradedTestSet("R-type multicycle",InstTests.rtypeMultiCycle,10,true,"single-cycle")
)
//json string to gradescope
var json: String = s"""{ "tests":["""
var results = new scala.collection.mutable.ArrayBuffer[String]()
//runs each test in each set and appends result to json string
for(set <- sets){
val result = set.runTests()
results += result.toJsonStr()
}
json += results.mkString(",")
//for now just print result
json += "]}"
print(json)
}
}
51 changes: 51 additions & 0 deletions src/test/scala/grading/GradedTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dinocpu

/** Defines a set of tests to run for grading, to appear as one test on gradescope
*
*/
class GradedTestSet(setName: String, tests: List[CPUTestCase], maxScore: Double, partialCredit: Boolean, cpu:String, branchPredictor:String = "") {
var testToRun: List[CPUTestCase] = tests
var totalScore: Double = maxScore
var pc: Boolean = partialCredit
var name: String = setName
var cpuType: String = cpu
var bp: String = branchPredictor

/** runs all the tests defined in the set and computes the resulting score
*
* @return a GradedTestResult containing the output of the test
*/
def runTests(): GradedTestResult ={
val result = new GradedTestResult(this)
for (test <- testToRun) {
if(CPUTesterDriver(test, cpuType, bp)){
result.score += totalScore / testToRun.length
result.output += s"Passed ${test.binary}${test.extraName}\\n"
} else {
result.output += s"Failed ${test.binary}${test.extraName} \\n"
}
}
result.score = (result.score * 100).round / 100.0

if(result.score != totalScore && !pc)
result.score = 0
return result
}
}

/** Wraps the result of a graded test, to have a field requires for gradescope
* @param tests corresponding graded test of this result
*/
class GradedTestResult(tests: GradedTestSet) {
var score: Double = 0.0
var name: String = tests.name
var max_score: Double = tests.totalScore
var output: String = ""

/** returns JSON formated string containing result of test
*
*/
def toJsonStr(): String = {
return f"""{ "score": $score, "max_score": $max_score, "name": "$name", "output": "$output" }"""
}
}

0 comments on commit dde6800

Please sign in to comment.