github.com/linuxboot/fiano@v1.2.0/pkg/visitors/nvarinvalidate_test.go (about) 1 // Copyright 2019 the LinuxBoot Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package visitors 6 7 import ( 8 "os" 9 "testing" 10 11 "github.com/linuxboot/fiano/pkg/uefi" 12 ) 13 14 func TestNVarInvalidate(t *testing.T) { 15 16 path := "../../integration/roms/nvartest/" 17 18 tmpDir, err := os.MkdirTemp("", "section-test") 19 20 if err != nil { 21 t.Fatalf("could not create temp dir: %v", err) 22 } 23 defer os.RemoveAll(tmpDir) 24 25 var parsedRoot uefi.Firmware 26 // Call ParseDir 27 pd := ParseDir{BasePath: path} 28 if parsedRoot, err = pd.Parse(); err != nil { 29 t.Fatal(err) 30 } 31 // Assemble the tree from the bottom up 32 a := Assemble{} 33 if err = a.Run(parsedRoot); err != nil { 34 t.Fatal(err) 35 } 36 37 // initial count 38 count := &Count{} 39 if err = count.Run(parsedRoot); err != nil { 40 t.Fatal(err) 41 } 42 43 want := 6 44 got := count.FirmwareTypeCount["NVar"] 45 if got != want { 46 t.Fatalf("counted %d NVar, want %d", got, want) 47 } 48 49 // invalidate "Test0" 50 pred, err := FindNVarPredicate("Test0") 51 if err != nil { 52 t.Fatal(err) 53 } 54 inval := &NVarInvalidate{ 55 Predicate: pred, 56 W: os.Stdout, 57 } 58 if err = inval.Run(parsedRoot); err != nil { 59 t.Fatal(err) 60 } 61 62 // Compact (remove links and invalidated NVars) 63 compact := &NVRamCompact{} 64 if err = compact.Run(parsedRoot); err != nil { 65 t.Fatal(err) 66 } 67 68 // count 69 if err = count.Run(parsedRoot); err != nil { 70 t.Fatal(err) 71 } 72 73 want = 4 74 got = count.FirmwareTypeCount["NVar"] 75 if got != want { 76 t.Fatalf("counted %d NVar, want %d", got, want) 77 } 78 79 }