github.hscsec.cn/u-root/u-root@v7.0.0+incompatible/pkg/kmodule/kmodule_linux_test.go (about)

     1  // Copyright 2019 the u-root 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 kmodule
     6  
     7  import (
     8  	"bytes"
     9  	"path"
    10  	"testing"
    11  )
    12  
    13  var procModsMock = `hid_generic 16384 0 - Live 0x0000000000000000
    14  usbhid 49152 0 - Live 0x0000000000000000
    15  ccm 20480 6 - Live 0x0000000000000000
    16  `
    17  
    18  func TestGenLoadedMods(t *testing.T) {
    19  	m := depMap{
    20  		"/lib/modules/6.6.6-generic/kernel/drivers/hid/hid-generic.ko":   &dependency{},
    21  		"/lib/modules/6.6.6-generic/kernel/drivers/hid/usbhid/usbhid.ko": &dependency{},
    22  		"/lib/modules/6.6.6-generic/kernel/crypto/ccm.ko":                &dependency{},
    23  	}
    24  	br := bytes.NewBufferString(procModsMock)
    25  	err := genLoadedMods(br, m)
    26  	if err != nil {
    27  		t.Fatalf("fail to genLoadedMods: %v\n", err)
    28  	}
    29  	for mod, d := range m {
    30  		if d.state != loaded {
    31  			t.Fatalf("mod %q should have been loaded", path.Base(mod))
    32  		}
    33  	}
    34  }