Skip to content

Commit

Permalink
feat(chipsec): adapt chipsec teststep
Browse files Browse the repository at this point in the history
Signed-off-by: llogen <[email protected]>
  • Loading branch information
llogen committed Aug 19, 2024
1 parent b89329a commit b0e7c0e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 47 deletions.
3 changes: 1 addition & 2 deletions plugins/teststeps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ The "ChipSec" teststep allows you to run different chipsec modules on your DUT.
password: PASSWORD # optional, type: string
identity_file: IDENTITY_FILE # optional, type: string
parameter:
tool_path: TOOL_PATH # optional, type: string
modules: [MODULE1, MODULE2] # optional, type: []string
nix_os: NIXOS_FLAG # optional, type: boolean, default: false (tool_path is not required if set)
pch: PCH_6XXP # optional, type: string
options:
timeout: TIMEOUT # optional, type: duration, default: 1m
```
Expand Down
2 changes: 0 additions & 2 deletions plugins/teststeps/chipsec/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ func (ts TestStep) writeTestStep(builders ...*strings.Builder) {
builder.WriteString("\n")

builder.WriteString(" Parameter:\n")
builder.WriteString(fmt.Sprintf(" ToolPath: %s\n", ts.ToolPath))
builder.WriteString(fmt.Sprintf(" NixOS: %t\n", ts.NixOS))
builder.WriteString(fmt.Sprintf(" Platform: %s\n", platform))
builder.WriteString(fmt.Sprintf(" PCH: %s\n", pch))

Expand Down
6 changes: 0 additions & 6 deletions plugins/teststeps/chipsec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ const (

type parameters struct {
Modules []string `json:"modules"`
ToolPath string `json:"tool_path"`
Platform string `json:"platform,omitempty"`
PCH string `json:"pch,omitempty"`
NixOS bool `json:"nix_os"`
}

// Name is the name used to look this plugin up.
Expand Down Expand Up @@ -80,10 +78,6 @@ func (ts *TestStep) validateAndPopulate(stepParams test.TestStepParameters) erro
return fmt.Errorf("missing or empty 'modules' parameter")
}

if ts.ToolPath == "" && !ts.NixOS {
return fmt.Errorf("missing or empty 'tool_path' parameter")
}

return nil
}

Expand Down
59 changes: 22 additions & 37 deletions plugins/teststeps/chipsec/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"path/filepath"
"strings"

"github.com/linuxboot/contest/pkg/event/testevent"
Expand Down Expand Up @@ -60,7 +59,7 @@ func (r *TargetRunner) Run(ctx xcontext.Context, target *target.Target) error {
return emitStderr(ctx, outputBuf.String(), target, r.ev, err)
}

if err := r.ts.runModule(ctx, &outputBuf, target, transportProto); err != nil {
if err := r.ts.runModule(ctx, &outputBuf, transportProto); err != nil {
outputBuf.WriteString(fmt.Sprintf("%v", err))

return emitStderr(ctx, outputBuf.String(), target, r.ev, err)
Expand All @@ -69,7 +68,9 @@ func (r *TargetRunner) Run(ctx xcontext.Context, target *target.Target) error {
return emitStdout(ctx, outputBuf.String(), target, r.ev)
}

func (ts *TestStep) runModule(ctx xcontext.Context, outputBuf *strings.Builder, target *target.Target,
func (ts *TestStep) runModule(
ctx xcontext.Context,
outputBuf *strings.Builder,
transp transport.Transport,
) error {
var (
Expand All @@ -92,37 +93,18 @@ func (ts *TestStep) runModule(ctx xcontext.Context, outputBuf *strings.Builder,
optionalArgs = append(optionalArgs, "--pch", ts.PCH)
}

switch ts.NixOS {
case false:
args := []string{
cmd,
filepath.Join(ts.ToolPath, bin),
"-m",
module,
jsonFlag,
filepath.Join(ts.ToolPath, outputFile),
}

args = append(args, optionalArgs...)

proc, err = transp.NewProcess(ctx, privileged, args, "")
if err != nil {
return fmt.Errorf("Failed to create proc: %w", err)
}
case true:
args := []string{
"-m",
module,
jsonFlag,
filepath.Join(ts.ToolPath, outputFile),
}

args = append(args, optionalArgs...)

proc, err = transp.NewProcess(ctx, nixOSBin, args, "")
if err != nil {
return fmt.Errorf("Failed to create proc: %w", err)
}
args := []string{
"-m",
module,
jsonFlag,
outputFile,
}

args = append(args, optionalArgs...)

proc, err = transp.NewProcess(ctx, nixOSBin, args, "")
if err != nil {
return fmt.Errorf("Failed to create proc: %w", err)
}

writeCommand(proc.String(), outputBuf)
Expand Down Expand Up @@ -191,12 +173,15 @@ func readBuffer(r io.Reader) ([]byte, error) {
return buf.Bytes(), nil
}

func (ts *TestStep) parseOutput(ctx xcontext.Context, outputBuf *strings.Builder,
transport transport.Transport, module string,
func (ts *TestStep) parseOutput(
ctx xcontext.Context,
outputBuf *strings.Builder,
transport transport.Transport,
module string,
) error {
args := []string{
"cat",
filepath.Join(ts.ToolPath, outputFile),
outputFile,
}

proc, err := transport.NewProcess(ctx, privileged, args, "")
Expand Down

0 comments on commit b0e7c0e

Please sign in to comment.