Skip to content

Commit

Permalink
feat: add amd-suite
Browse files Browse the repository at this point in the history
amd-suite runs AMD specific tests for:
* AMD PSB
* AMD SME
* AMD SEV
* AMD SEV-SNP

Signed-off-by: Christian Walter <[email protected]>
  • Loading branch information
walterchris committed Jan 26, 2025
1 parent b24692f commit 06230b7
Show file tree
Hide file tree
Showing 4 changed files with 826 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/core/amd-suite/TESTPLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Id | Group | Test | Implemented | Reference | Notes
13 | PSB | Platform Model ID is not zero | :x: | - | Should be non-zero
14 | PSB | Read BIOS Key Revision is not zero | :x: | - | Should be non zero
15 | PSB | AMD Key is disabled | :x: | - | If the AMD key is not disabled, the system will still boot AMD signed firmware
16 | PSB | Secure Debug is disabled | :x: | - | -
16 | PSB | Secure Debug is disabled | :x: | - | Should be disabled
17 | PSB | Keys are fused | :x: | - | Test checks if the customer keys have been fused by reading `Customer Key Lock` from the `PSB_STATUS` register.
18 | PSB | PSB Policy Hash | :x: | - | Check the PSB Policy Hash
18 | PSB | PSB Policy Hash | :x: | - | Check the PSB Policy Hash and print it.
19 | PSB | Revocation Status | :x: | - | Check the Revokation Status
20 | SME | SME Support | :x: | - | Test checks `0x8000001f`
21 | SME | SME Enabled | :x: | - | Test checks `MSR_AMD64_SYSCFG`
Expand Down
118 changes: 118 additions & 0 deletions cmd/core/amd-suite/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package main

import (
"fmt"
"sort"

"github.com/9elements/converged-security-suite/v2/pkg/test"
"github.com/9elements/converged-security-suite/v2/pkg/tools"
"github.com/9elements/go-linux-lowlevel-hw/pkg/hwapi"
log "github.com/sirupsen/logrus"

a "github.com/logrusorgru/aurora"
)

type context struct {
logpath string
}

var cli struct {
ExecTests execTestsCmd `cmd:"" help:"Executes tests given by test set" short:"e"`

Version versionCmd `cmd:"" help:"Prints the version of the program"`
Debug bool `help:"Enable debug mode."`
}

type versionCmd struct{}

type execTestsCmd struct {
Set string `required:"" short:"s" default:"all" help:"Select a subset, or all test that should be run"`
}

func (v *versionCmd) Run(ctx *context) error {
tools.ShowVersion(programName, gittag, gitcommit)
return nil
}

func (e *execTestsCmd) Run(ctx *context) error {
switch e.Set {
case "general":
return nil
case "psb":
return nil
case "sev":
return nil
case "sevsnp":
return nil
case "all":
fmt.Println("Default is all tests")
preset := &test.PreSet{}
run("AMD", getTests(), preset)
default:
return fmt.Errorf("Unknown test set: %s", e.Set)
}

return nil
}

func getTests() []*test.Test {
var tests []*test.Test
for i := range test.TestsAMD {
tests = append(tests, test.TestsAMD[i])
}

return tests
}

func run(testGroup string, tests []*test.Test, preset *test.PreSet) bool {
result := false

hwAPI := hwapi.GetAPI()

log.Infof("%s tests (%d tests)", a.Bold(a.Gray(20-1, testGroup).BgGray(4-1)), len(tests))
log.Info("--------------------------------------------------")
for idx := range tests {
if len(testnos) > 0 {
// SearchInt returns an index where to "insert" idx
i := sort.SearchInts(testnos, idx)
if i >= len(testnos) {
continue
}
// still here? i must be within testnos.
if testnos[i] != idx {
continue
}
}

_ = tests[idx].Run(hwAPI, preset)
}

for index := range tests {
var s string

if tests[index].Status == test.NotImplemented {
continue
}
if tests[index].Result == test.ResultNotRun {
continue
}
s += fmt.Sprintf("%02d - ", index)
s += fmt.Sprintf("%-40s: ", a.Bold(tests[index].Name))

if tests[index].Result == test.ResultPass {
s += fmt.Sprintf("%-20s", a.Bold(a.Green(tests[index].Result)))
} else {
s += fmt.Sprintf("%-20s", a.Bold(a.Red(tests[index].Result)))
result = false
}
if tests[index].ErrorText != "" {
s += fmt.Sprintf(" (%s)", tests[index].ErrorText)
} else if len(tests[index].ErrorText) == 0 && tests[index].Result == test.ResultFail {
s += fmt.Sprintf(" (No error text given)")
}
log.Infof("%s", s)

}

return result
}
33 changes: 33 additions & 0 deletions cmd/core/amd-suite/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"github.com/9elements/converged-security-suite/v2/pkg/log"
"github.com/alecthomas/kong"
fianoLog "github.com/linuxboot/fiano/pkg/log"
)

const (
programName = "amd-suite"
programDesc = "AMD PSB, SME, SEV and SEV-SNP Test Suite"
)

var (
gitcommit string
gittag string
testnos []int
)

func main() {
ctx := kong.Parse(&cli,
kong.Name(programName),
kong.Description(programDesc),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
Summary: true,
}))

fianoLog.DefaultLogger = log.FianoLogger{}
err := ctx.Run(&context{})
ctx.FatalIfErrorf(err)
}
Loading

0 comments on commit 06230b7

Please sign in to comment.