From 1f44bcf643d54d5ba881a546905f65a2a48fbc7d Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Fri, 20 Sep 2024 06:49:52 +0300 Subject: [PATCH 1/2] pkg/visitors: use testing.TempDir and embed test file Signed-off-by: Siarhiej Siemianczuk --- integration/files.go | 10 +++++++++ pkg/visitors/extract_test.go | 39 +++++------------------------------ pkg/visitors/validate_test.go | 3 ++- 3 files changed, 17 insertions(+), 35 deletions(-) create mode 100644 integration/files.go diff --git a/integration/files.go b/integration/files.go new file mode 100644 index 00000000..114de1e1 --- /dev/null +++ b/integration/files.go @@ -0,0 +1,10 @@ +// Copyright 2024 the LinuxBoot Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package utk_test + +import _ "embed" + +//go:embed roms/ovmfSECFV.fv +var OVMFSecFV []byte diff --git a/pkg/visitors/extract_test.go b/pkg/visitors/extract_test.go index db3ffb41..80c57392 100644 --- a/pkg/visitors/extract_test.go +++ b/pkg/visitors/extract_test.go @@ -5,26 +5,12 @@ package visitors import ( - "os" "testing" - "github.com/linuxboot/fiano/pkg/log" + utk_test "github.com/linuxboot/fiano/integration" "github.com/linuxboot/fiano/pkg/uefi" ) -var ( - // FV examples - sampleFV []byte // Sample FV from OVMF -) - -func init() { - var err error - sampleFV, err = os.ReadFile("../../integration/roms/ovmfSECFV.fv") - if err != nil { - log.Fatalf("%v", err) - } -} - var ( // File headers // Hardcoded checksums for testing :( @@ -93,12 +79,7 @@ func TestExtractAssembleFile(t *testing.T) { uefi.Attributes.ErasePolarity = 0xFF for _, test := range tests { t.Run(test.name, func(t *testing.T) { - tmpDir, err := os.MkdirTemp("", "section-test") - - if err != nil { - t.Fatalf("could not create temp dir: %v", err) - } - defer os.RemoveAll(tmpDir) + tmpDir := t.TempDir() f, err := uefi.NewFile(test.origBuf) if err != nil { @@ -133,18 +114,13 @@ func TestExtractAssembleFV(t *testing.T) { origBuf []byte newBuf []byte }{ - {"sampleFV", sampleFV, sampleFV}, + {"sampleFV", utk_test.OVMFSecFV, utk_test.OVMFSecFV}, } // Set erasepolarity to FF uefi.Attributes.ErasePolarity = 0xFF for _, test := range tests { t.Run(test.name, func(t *testing.T) { - tmpDir, err := os.MkdirTemp("", "section-test") - - if err != nil { - t.Fatalf("could not create temp dir: %v", err) - } - defer os.RemoveAll(tmpDir) + tmpDir := t.TempDir() fv, err := uefi.NewFirmwareVolume(test.origBuf, 0, false) if err != nil { @@ -188,12 +164,7 @@ func TestExtractAssembleSection(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - tmpDir, err := os.MkdirTemp("", "section-test") - - if err != nil { - t.Fatalf("could not create temp dir: %v", err) - } - defer os.RemoveAll(tmpDir) + tmpDir := t.TempDir() s, err := uefi.NewSection(test.buf, test.fileOrder) if err != nil { diff --git a/pkg/visitors/validate_test.go b/pkg/visitors/validate_test.go index 06589595..2447ad2c 100644 --- a/pkg/visitors/validate_test.go +++ b/pkg/visitors/validate_test.go @@ -7,6 +7,7 @@ package visitors import ( "testing" + utk_test "github.com/linuxboot/fiano/integration" "github.com/linuxboot/fiano/pkg/uefi" ) @@ -16,7 +17,7 @@ func TestValidateFV(t *testing.T) { buf []byte msgs []string }{ - {"sampleFV", sampleFV, nil}, + {"sampleFV", utk_test.OVMFSecFV, nil}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { From 1f8e946681249dbd1456e1997034297269bb53d4 Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Fri, 20 Sep 2024 07:12:39 +0300 Subject: [PATCH 2/2] circleci: update go version and gofmt Signed-off-by: Siarhiej Siemianczuk --- .circleci/config.yml | 10 +++++----- pkg/uefi/fuzz_test.go | 2 +- pkg/uefi/section.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 70c7dd8a..8f58da2e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ workflows: jobs: clean-code: docker: - - image: cimg/go:1.17 + - image: cimg/go:1.22 steps: - checkout - run: @@ -38,7 +38,7 @@ jobs: command: test -z "$(gofmt -s -l cmds pkg)" test: docker: - - image: cimg/go:1.17 + - image: cimg/go:1.22 steps: - checkout - run: @@ -51,7 +51,7 @@ jobs: resource_class: medium race: docker: - - image: cimg/go:1.17 + - image: cimg/go:1.22 steps: - checkout - run: @@ -59,7 +59,7 @@ jobs: command: go test -race ./... coverage: docker: - - image: cimg/go:1.17 + - image: cimg/go:1.22 steps: - checkout - run: @@ -80,7 +80,7 @@ jobs: command: bash <(curl -s https://codecov.io/bash) check_licenses: docker: - - image: cimg/go:1.17 + - image: cimg/go:1.22 steps: - checkout - run: diff --git a/pkg/uefi/fuzz_test.go b/pkg/uefi/fuzz_test.go index 29e8d810..2ddb8fab 100644 --- a/pkg/uefi/fuzz_test.go +++ b/pkg/uefi/fuzz_test.go @@ -19,7 +19,7 @@ import ( "github.com/ulikunitz/xz" ) -//no-op writer to minimize logging overhead +// no-op writer to minimize logging overhead type nopWriter struct{} func (n *nopWriter) Write(_ []byte) (int, error) { return 0, nil } diff --git a/pkg/uefi/section.go b/pkg/uefi/section.go index ba4cba9a..e981bab6 100644 --- a/pkg/uefi/section.go +++ b/pkg/uefi/section.go @@ -343,7 +343,7 @@ func (s *Section) GenSecHeader() error { return nil } -//ErrOversizeHdr is the error returned by NewSection when the header is oversize. +// ErrOversizeHdr is the error returned by NewSection when the header is oversize. type ErrOversizeHdr struct { hdrsiz uintptr bufsiz int