Skip to content

Commit

Permalink
Updated to make the testcase generator and test cases work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels authored and Niels committed Dec 7, 2021
1 parent 78c90bd commit 33550a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 72 deletions.
72 changes: 23 additions & 49 deletions RULES/hdl/questa.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func CompileSrcs(ctx core.Context, rule Simulation,
// generated output
ctx.AddBuildStep(core.BuildStep{
Out: log,
Ins: deps,
Ins: append(deps, src),
Cmd: cmd,
Descr: fmt.Sprintf("%s: %s", tool, path.Base(src.String())),
Descr: fmt.Sprintf("%s: %s", tool, src.Relative()),
})

// Add the log file to the dependencies of the next files
Expand Down Expand Up @@ -223,35 +223,9 @@ func Optimize(ctx core.Context, rule Simulation, deps []core.Path) {
rules[log_file.String()] = true
}

// CreateLib creates a Questa simulation library named after the rule with the
// suffix "Lib" added. It also adds the base name where source code will be
// compiled to the global list of created rules after it has added the
// build step for the library.
func CreateLib(ctx core.Context, rule Simulation) {
path := rule.Path()

// Skip if we already know this rule
if rules[path.String()] {
return
}

// Add the rule to run 'vlib'
ctx.AddBuildStep(core.BuildStep{
Out: path.WithSuffix("Lib"),
Cmd: fmt.Sprintf("vlib %s", rule.Lib()),
Descr: fmt.Sprintf("vlib: %s", rule.Lib()),
})

// Remember that we created this rule
rules[path.String()] = true
}

// Build will compile and optimize the source and IPs associated with the given
// BuildQuesta will compile and optimize the source and IPs associated with the given
// rule.
func BuildQuesta(ctx core.Context, rule Simulation) {
// Create the library
CreateLib(ctx, rule)

// Compile the code
deps := Compile(ctx, rule)

Expand Down Expand Up @@ -315,21 +289,20 @@ func SimulateQuesta(rule Simulation, args []string, gui bool) string {

// Create a testcase generation command if necessary
if rule.TestCaseGenerator != nil {
// Default, simply call script
cmd_preamble = fmt.Sprintf("%s . ; ", rule.TestCaseGenerator.String())

// If directory of testcases available, pick the first one
if rule.TestCasesDir != nil {
items, err := os.ReadDir(rule.TestCasesDir.String())
if err != nil {
log.Fatal(err)
}

if len(items) == 0 {
log.Fatal("TestCasesDir empty!")
if items, err := os.ReadDir(rule.TestCasesDir.String()); err == nil {
if len(items) == 0 {
log.Fatal(fmt.Sprintf("TestCasesDir directory '%s' empty!", rule.TestCasesDir.String()))
}

// Create path to testcase
testcase := rule.TestCasesDir.Absolute() + "/" + items[0].Name()
cmd_preamble = fmt.Sprintf(" { echo Testcase %s; } && { %s %s . ; } ", testcase, rule.TestCaseGenerator.String(), testcase)
}

// Create path to testcase
testcase_file := rule.TestCasesDir.WithSuffix("/" + items[0].Name())
cmd_preamble = fmt.Sprintf("%s %s . ; ", rule.TestCaseGenerator.String(), testcase_file.String())
} else {
cmd_preamble = fmt.Sprintf("%s . ; ", rule.TestCaseGenerator.String())
}
}

Expand All @@ -351,16 +324,17 @@ func SimulateQuesta(rule Simulation, args []string, gui bool) string {
} else {
log.Fatal("-verbosity expects an argument of 'low', 'medium', 'high' or 'none'!")
}
} else if strings.HasPrefix(arg, "-testcase=") {
} else if strings.HasPrefix(arg, "-testcase=") && rule.TestCaseGenerator != nil {
var testcase string
if _, err := fmt.Sscanf(arg, "-testcase=%s", &testcase); err == nil {
// Create path to testcase
testcase_file := rule.TestCasesDir.WithSuffix("/" + testcase)

// Do we have a test generation script?
if rule.TestCaseGenerator != nil {
cmd_preamble = fmt.Sprintf("%s %s .;", rule.TestCaseGenerator.String(), testcase_file.String())
// Do we have a directory for testcases?
if rule.TestCasesDir != nil {
// Create path to testcase
testcase = rule.TestCasesDir.Absolute() + "/" + testcase
}

// Create commands
cmd_preamble = fmt.Sprintf(" { echo Testcase %s; } && { %s %s . ; } ", testcase, rule.TestCaseGenerator.String(), testcase)
}
} else if strings.HasPrefix(arg, "+") {
// All '+' arguments go directly to the simulator
Expand Down
31 changes: 8 additions & 23 deletions RULES/hdl/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Simulator = core.StringFlag{
Name: "hdl-simulator",
Description: "HDL simulator to use when generating simulation targets",
DefaultFn: func() string {
return "xsim"
return "questa"
},
AllowedValues: []string{"xsim", "questa"},
}.Register()
Expand Down Expand Up @@ -90,6 +90,7 @@ func (rule Simulation) Test(args []string) string {
}

func (rule Simulation) Description() string {
// Print the rule name as its needed for parameter selection
description := " Name: " + rule.Name + " "
first := true
for param, _ := range(rule.Params) {
Expand All @@ -102,31 +103,15 @@ func (rule Simulation) Description() string {

if rule.TestCaseGenerator != nil && rule.TestCasesDir != nil {
description = description + "TestCases: "

// Loop through all defined testcases in directory
items, err := os.ReadDir(rule.TestCasesDir.String())
if err != nil {
if items, err := os.ReadDir(rule.TestCasesDir.String()); err == nil {
for _, item := range items {
description = description + item.Name() + " "
}
} else {
log.Fatal(err)
}

for _, item := range items {
// Handle one level of subdirectories
if item.IsDir() {
subitems, err := os.ReadDir(item.Name())
if err != nil {
log.Fatal(err)
}

for _, subitem := range subitems {
if !subitem.IsDir() {
// handle file there
description = description + item.Name() + "/" + subitem.Name() + " "
}
}
} else {
// handle file there
description = description + item.Name() + " "
}
}
}

return description
Expand Down

0 comments on commit 33550a7

Please sign in to comment.