Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" }"""
}
}