diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml new file mode 100644 index 0000000..e8b591c --- /dev/null +++ b/.github/workflows/golang.yml @@ -0,0 +1,45 @@ +name: Golang + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ '1.21.3' ] + + steps: + - name: checkout furios-smi + uses: actions/checkout@v4 + with: + repository: furiosa-ai/furiosa-smi + token: ${{ secrets.TOKEN_FOR_CLONE_ANOTHER_REPO}} + path: furiosa-smi + - name: install furiosa-smi + run: | + cd furiosa-smi + rustup component add clippy rustfmt + cargo build + make install + - uses: actions/checkout@v4 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Display Go version + run: go version + - name: build + run: make build + - name: test + run: make test + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.59.1 + - name: lint + run: make lint diff --git a/Makefile b/Makefile index 1b32d07..1eecf63 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,37 @@ define build_examples_function done endef +.PHONY: all +all: build fmt lint vet test tidy vendor test + +.PHONY: build +build: + CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) go build ./... + +.PHONY: fmt +fmt: + go fmt ./... + +.PHONY: lint +lint: + CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) golangci-lint run + +.PHONY: vet +vet: + CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) go vet -v ./... + +.PHONY: test +test: + CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) go test ./... + +.PHONY: tidy +tidy: + go mod tidy + +.PHONY: vendor +vendor: + go mod vendor + .PHONY: example example: $(call build_examples_function,./example) diff --git a/go.mod b/go.mod index e9b5ef1..1f0bfb0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/furiosa-ai/furiosa-smi-go -go 1.22 +go 1.21.3 require ( github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 diff --git a/pkg/smi/device_error_test.go b/pkg/smi/device_error_test.go new file mode 100644 index 0000000..e0ad3ac --- /dev/null +++ b/pkg/smi/device_error_test.go @@ -0,0 +1,80 @@ +package smi + +import ( + "reflect" + "testing" + + "github.com/furiosa-ai/furiosa-smi-go/pkg/smi/binding" +) + +func testDeviceErrorInfo(arch Arch, t *testing.T, expected DeviceErrorInfo) { + mockdevice := GetStaticMockDevice(arch, 0) + + device_error_info, err := mockdevice.DeviceErrorInfo() + + if err != nil { + t.Errorf("Failed to get Device Error Info") + } + + if !reflect.DeepEqual(expected.AxiPostErrorCount(), device_error_info.AxiPostErrorCount()) { + t.Errorf("expected AxiPostErrorCount %v but got %v", expected.AxiPostErrorCount(), device_error_info.AxiPostErrorCount()) + } + + if !reflect.DeepEqual(expected.AxiFetchErrorCount(), device_error_info.AxiFetchErrorCount()) { + t.Errorf("expected AxiFetchErrorCount %v but got %v", expected.AxiFetchErrorCount(), device_error_info.AxiFetchErrorCount()) + } + + if !reflect.DeepEqual(expected.AxiDiscardErrorCount(), device_error_info.AxiDiscardErrorCount()) { + t.Errorf("expected AxiDiscardErrorCount %v but got %v", expected.AxiDiscardErrorCount(), device_error_info.AxiDiscardErrorCount()) + } + + if !reflect.DeepEqual(expected.AxiDoorbellErrorCount(), device_error_info.AxiDoorbellErrorCount()) { + t.Errorf("expected AxiDoorbellErrorCount %v but got %v", expected.AxiDoorbellErrorCount(), device_error_info.AxiDoorbellErrorCount()) + } + + if !reflect.DeepEqual(expected.PciePostErrorCount(), device_error_info.PciePostErrorCount()) { + t.Errorf("expected PciePostErrorCount %v but got %v", expected.PciePostErrorCount(), device_error_info.PciePostErrorCount()) + } + + if !reflect.DeepEqual(expected.PcieFetchErrorCount(), device_error_info.PcieFetchErrorCount()) { + t.Errorf("expected PcieFetchErrorCount %v but got %v", expected.PcieFetchErrorCount(), device_error_info.PcieFetchErrorCount()) + } + + if !reflect.DeepEqual(expected.PcieDiscardErrorCount(), device_error_info.PcieDiscardErrorCount()) { + t.Errorf("expected PcieDiscardErrorCount %v but got %v", expected.PcieDiscardErrorCount(), device_error_info.PcieDiscardErrorCount()) + } + + if !reflect.DeepEqual(expected.PcieDoorbellErrorCount(), device_error_info.PcieDoorbellErrorCount()) { + t.Errorf("expected PcieDoorbellErrorCount %v but got %v", expected.PcieDoorbellErrorCount(), device_error_info.PcieDoorbellErrorCount()) + } +} + +func TestWarboyDeviceErrorInfo(t *testing.T) { + expected := newDeviceErrorInfo(binding.FuriosaSmiDeviceErrorInfo{ + AxiPostErrorCount: 0, + AxiFetchErrorCount: 0, + AxiDiscardErrorCount: 0, + AxiDoorbellErrorCount: 0, + PciePostErrorCount: 0, + PcieFetchErrorCount: 0, + PcieDiscardErrorCount: 0, + PcieDoorbellErrorCount: 0, + DeviceErrorCount: 0}) + + testDeviceErrorInfo(ArchWarboy, t, expected) +} + +func TestRngdDeviceErrorInfo(t *testing.T) { + expected := newDeviceErrorInfo(binding.FuriosaSmiDeviceErrorInfo{ + AxiPostErrorCount: 0, + AxiFetchErrorCount: 0, + AxiDiscardErrorCount: 0, + AxiDoorbellErrorCount: 0, + PciePostErrorCount: 0, + PcieFetchErrorCount: 0, + PcieDiscardErrorCount: 0, + PcieDoorbellErrorCount: 0, + DeviceErrorCount: 0}) + + testDeviceErrorInfo(ArchRngd, t, expected) +} diff --git a/pkg/smi/device_file_test.go b/pkg/smi/device_file_test.go new file mode 100644 index 0000000..b566eb6 --- /dev/null +++ b/pkg/smi/device_file_test.go @@ -0,0 +1,87 @@ +package smi + +import ( + "reflect" + "testing" + + "github.com/furiosa-ai/furiosa-smi-go/pkg/smi/binding" +) + +func testDeviceFiles(arch Arch, t *testing.T, expected []DeviceFile) { + mockdevice := GetStaticMockDevice(arch, 0) + + device_files, err := mockdevice.DeviceFiles() + + if err != nil { + t.Errorf("Failed to get Device Files") + } + + if len(expected) != len(device_files) { + t.Errorf("expected device files num %d but got %d", len(expected), len(device_files)) + } + + for i := 0; i < len(expected); i++ { + if !reflect.DeepEqual(expected[i].Cores(), device_files[i].Cores()) { + t.Errorf("expected cores %v but got %v", expected[i].Cores(), device_files[i].Cores()) + } + + if !reflect.DeepEqual(expected[i].Path(), device_files[i].Path()) { + t.Errorf("expected path %s but got %s", expected[i].Path(), device_files[i].Path()) + } + } + +} + +func stringTo256ByteArray(str string) [256]byte { + var arr [256]byte + copy(arr[:], str) + return arr +} + +func TestWarboyDeviceFiles(t *testing.T) { + expected := []DeviceFile{ + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 0, CoreEnd: 0, Path: stringTo256ByteArray("/dev/npu0pe0")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 1, CoreEnd: 1, Path: stringTo256ByteArray("/dev/npu0pe1")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 0, CoreEnd: 1, Path: stringTo256ByteArray("/dev/npu0pe0-1")}), + } + + testDeviceFiles(ArchWarboy, t, expected) +} + +func TestRngdDeviceFiles(t *testing.T) { + expected := []DeviceFile{ + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 0, CoreEnd: 0, Path: stringTo256ByteArray("/dev/rngd/npu0pe0")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 1, CoreEnd: 1, Path: stringTo256ByteArray("/dev/rngd/npu0pe1")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 0, CoreEnd: 1, Path: stringTo256ByteArray("/dev/rngd/npu0pe0-1")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 2, CoreEnd: 2, Path: stringTo256ByteArray("/dev/rngd/npu0pe2")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 3, CoreEnd: 3, Path: stringTo256ByteArray("/dev/rngd/npu0pe3")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 2, CoreEnd: 3, Path: stringTo256ByteArray("/dev/rngd/npu0pe2-3")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 0, CoreEnd: 3, Path: stringTo256ByteArray("/dev/rngd/npu0pe0-3")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 4, CoreEnd: 4, Path: stringTo256ByteArray("/dev/rngd/npu0pe4")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 5, CoreEnd: 5, Path: stringTo256ByteArray("/dev/rngd/npu0pe5")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 4, CoreEnd: 5, Path: stringTo256ByteArray("/dev/rngd/npu0pe4-5")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 6, CoreEnd: 6, Path: stringTo256ByteArray("/dev/rngd/npu0pe6")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 7, CoreEnd: 7, Path: stringTo256ByteArray("/dev/rngd/npu0pe7")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 6, CoreEnd: 7, Path: stringTo256ByteArray("/dev/rngd/npu0pe6-7")}), + newDeviceFile(binding.FuriosaSmiDeviceFile{ + CoreStart: 4, CoreEnd: 7, Path: stringTo256ByteArray("/dev/rngd/npu0pe4-7")}), + } + + testDeviceFiles(ArchRngd, t, expected) +} diff --git a/pkg/smi/device_info_test.go b/pkg/smi/device_info_test.go new file mode 100644 index 0000000..ba9fcc2 --- /dev/null +++ b/pkg/smi/device_info_test.go @@ -0,0 +1,152 @@ +package smi + +import ( + "reflect" + "testing" + + "github.com/furiosa-ai/furiosa-smi-go/pkg/smi/binding" +) + +func testDeviceInfo(arch Arch, t *testing.T, expected DeviceInfo) { + mockdevice := GetStaticMockDevice(arch, 0) + + device_info, err := mockdevice.DeviceInfo() + + if err != nil { + t.Errorf("Failed to get Device Information") + } + + if !reflect.DeepEqual(expected.Arch(), device_info.Arch()) { + t.Errorf("expected architecture %s but got %s", expected.Arch().ToString(), device_info.Arch().ToString()) + } + + if !reflect.DeepEqual(expected.CoreNum(), device_info.CoreNum()) { + t.Errorf("expected corenum %d but got %d", expected.CoreNum(), device_info.CoreNum()) + } + + if !reflect.DeepEqual(expected.NumaNode(), device_info.NumaNode()) { + t.Errorf("expected numanode %d but got %d", expected.NumaNode(), device_info.NumaNode()) + } + + if !reflect.DeepEqual(expected.Name(), device_info.Name()) { + t.Errorf("expected name %s but got %s", expected.Name(), device_info.Name()) + } + + if !reflect.DeepEqual(expected.Serial(), device_info.Serial()) { + t.Errorf("expected serial %s but got %s", expected.Serial(), device_info.Serial()) + } + + if !reflect.DeepEqual(expected.UUID(), device_info.UUID()) { + t.Errorf("expected uuid %s but got %s", expected.UUID(), device_info.UUID()) + } + + if !reflect.DeepEqual(expected.BDF(), device_info.BDF()) { + t.Errorf("expected bdf %s but got %s", expected.BDF(), device_info.BDF()) + } + + if !reflect.DeepEqual(expected.Major(), device_info.Major()) { + t.Errorf("expected major %d but got %d", expected.Major(), device_info.Major()) + } + + if !reflect.DeepEqual(expected.Minor(), device_info.Minor()) { + t.Errorf("expected minor %d but got %d", expected.Minor(), device_info.Minor()) + } + + if !reflect.DeepEqual(expected.FirmwareVersion().Arch(), device_info.FirmwareVersion().Arch()) { + t.Errorf("expected firmware arch %s but got %s", expected.FirmwareVersion().Arch().ToString(), device_info.FirmwareVersion().Arch().ToString()) + } + + if !reflect.DeepEqual(expected.FirmwareVersion().Major(), device_info.FirmwareVersion().Major()) { + t.Errorf("expected firmware major %d but got %d", expected.FirmwareVersion().Major(), device_info.FirmwareVersion().Major()) + } + + if !reflect.DeepEqual(expected.FirmwareVersion().Minor(), device_info.FirmwareVersion().Minor()) { + t.Errorf("expected firmware minor %d but got %d", expected.FirmwareVersion().Minor(), device_info.FirmwareVersion().Minor()) + } + + if !reflect.DeepEqual(expected.FirmwareVersion().Patch(), device_info.FirmwareVersion().Patch()) { + t.Errorf("expected firmware patch %d but got %d", expected.FirmwareVersion().Patch(), device_info.FirmwareVersion().Patch()) + } + + if !reflect.DeepEqual(expected.FirmwareVersion().Metadata(), device_info.FirmwareVersion().Metadata()) { + t.Errorf("expected firmware metadata %s but got %s", expected.FirmwareVersion().Metadata(), device_info.FirmwareVersion().Metadata()) + } + + if !reflect.DeepEqual(expected.DriverVersion().Arch(), device_info.DriverVersion().Arch()) { + t.Errorf("expected driver arch %s but got %s", expected.DriverVersion().Arch().ToString(), device_info.DriverVersion().Arch().ToString()) + } + + if !reflect.DeepEqual(expected.DriverVersion().Major(), device_info.DriverVersion().Major()) { + t.Errorf("expected driver major %d but got %d", expected.DriverVersion().Major(), device_info.DriverVersion().Major()) + } + + if !reflect.DeepEqual(expected.DriverVersion().Minor(), device_info.DriverVersion().Minor()) { + t.Errorf("expected driver minor %d but got %d", expected.DriverVersion().Minor(), device_info.DriverVersion().Minor()) + } + + if !reflect.DeepEqual(expected.DriverVersion().Patch(), device_info.DriverVersion().Patch()) { + t.Errorf("expected driver patch %d but got %d", expected.DriverVersion().Patch(), device_info.DriverVersion().Patch()) + } + + if !reflect.DeepEqual(expected.DriverVersion().Metadata(), device_info.DriverVersion().Metadata()) { + t.Errorf("expected driver metadata %s but got %s", expected.DriverVersion().Metadata(), device_info.DriverVersion().Metadata()) + } +} + +func stringTo96ByteArray(str string) [96]byte { + var arr [96]byte + copy(arr[:], str) + return arr +} + +func TestWarboyDeviceInfo(t *testing.T) { + expected := newDeviceInfo(binding.FuriosaSmiDeviceInfo{ + Arch: binding.FuriosaSmiArchWarboy, + CoreNum: 2, + NumaNode: 0, + Name: stringTo96ByteArray("/dev/npu0"), + Serial: stringTo96ByteArray("TEST0236FH505KRE0"), + Uuid: stringTo96ByteArray("A76AAD68-6855-40B1-9E86-D080852D1C80"), + Bdf: stringTo96ByteArray("0000:27:00.0"), + Major: 234, + Minor: 0, + FirmwareVersion: binding.FuriosaSmiVersion{ + Arch: binding.FuriosaSmiArchWarboy, + Major: 1, + Minor: 6, + Patch: 0, + Metadata: stringTo96ByteArray("c1bebfd")}, + DriverVersion: binding.FuriosaSmiVersion{ + Arch: binding.FuriosaSmiArchWarboy, + Major: 1, + Minor: 9, + Patch: 2, + Metadata: stringTo96ByteArray("3def9c2")}}) + testDeviceInfo(ArchWarboy, t, expected) +} + +func TestRngdDeviceInfo(t *testing.T) { + expected := newDeviceInfo(binding.FuriosaSmiDeviceInfo{ + Arch: binding.FuriosaSmiArchRngd, + CoreNum: 8, + NumaNode: 0, + Name: stringTo96ByteArray("/dev/rngd/npu0"), + Serial: stringTo96ByteArray("TEST0236FH505KRE0"), + Uuid: stringTo96ByteArray("A76AAD68-6855-40B1-9E86-D080852D1C80"), + Bdf: stringTo96ByteArray("0000:27:00.0"), + Major: 234, + Minor: 0, + FirmwareVersion: binding.FuriosaSmiVersion{ + Arch: binding.FuriosaSmiArchRngd, + Major: 1, + Minor: 6, + Patch: 0, + Metadata: stringTo96ByteArray("c1bebfd")}, + DriverVersion: binding.FuriosaSmiVersion{ + Arch: binding.FuriosaSmiArchRngd, + Major: 1, + Minor: 9, + Patch: 2, + Metadata: stringTo96ByteArray("3def9c2")}}) + testDeviceInfo(ArchRngd, t, expected) +} diff --git a/pkg/smi/device_test.go b/pkg/smi/device_test.go new file mode 100644 index 0000000..f5dc0cf --- /dev/null +++ b/pkg/smi/device_test.go @@ -0,0 +1,101 @@ +package smi + +import ( + "reflect" + "testing" +) + +func testCoreStatus(arch Arch, t *testing.T, expected map[uint32]CoreStatus) { + mockdevice := GetStaticMockDevice(arch, 0) + + core_status, err := mockdevice.CoreStatus() + + if err != nil { + t.Errorf("Failed to get core status") + } + + if !reflect.DeepEqual(expected, core_status) { + t.Errorf("expected core status %v but got %v", expected, core_status) + } +} + +func TestWarboyCoreStatus(t *testing.T) { + expected := make(map[uint32]CoreStatus) + + for i := 0; i < 2; i++ { + expected[uint32(i)] = CoreStatusAvailable + } + + testCoreStatus(ArchWarboy, t, expected) +} + +func TestRngdCoreStatus(t *testing.T) { + expected := make(map[uint32]CoreStatus) + + for i := 0; i < 8; i++ { + expected[uint32(i)] = CoreStatusAvailable + } + + testCoreStatus(ArchRngd, t, expected) +} + +func testLiveness(arch Arch, t *testing.T, expected bool) { + mockdevice := GetStaticMockDevice(arch, 0) + + liveness, err := mockdevice.Liveness() + + if err != nil { + t.Errorf("Failed to get liveness") + } + + if !reflect.DeepEqual(expected, liveness) { + t.Errorf("expected liveness %v but got %v", expected, liveness) + } +} + +func TestWarboyLiveness(t *testing.T) { + expected := true + + testLiveness(ArchWarboy, t, expected) +} + +func TestRngdLiveness(t *testing.T) { + expected := true + + testLiveness(ArchRngd, t, expected) +} + +func testGetDeviceToDeviceLinkType(devices []Device, t *testing.T, expectedMap map[int]map[int]LinkType) { + + for i, device0 := range devices { + for j, device1 := range devices { + linktype, err := device0.GetDeviceToDeviceLinkType(device1) + + if err != nil { + t.Errorf("Failed to get linktype") + } + + idx0, idx1 := i, j + if i > j { + idx0, idx1 = j, i + } + + expected := expectedMap[idx0][idx1] + if !reflect.DeepEqual(expected, linktype) { + t.Errorf("expected linktype between npu%d, npu%d is %v but got %v", i, j, expected, linktype) + } + } + } +} + +func TestWarboyGetDeviceToDeviceLinkType(t *testing.T) { + devices := GetStaticMockDevices(ArchRngd) + + testGetDeviceToDeviceLinkType(devices, t, linkTypeHintMap) +} + +func TestRngdGetDeviceToDeviceLinkType(t *testing.T) { + devices := GetStaticMockDevices(ArchRngd) + + testGetDeviceToDeviceLinkType(devices, t, linkTypeHintMap) +} diff --git a/pkg/smi/mock_common.go b/pkg/smi/mock_common.go index 81b8a62..5d83c6b 100644 --- a/pkg/smi/mock_common.go +++ b/pkg/smi/mock_common.go @@ -186,11 +186,11 @@ type staticMockDeviceTemperature struct{} var _ DeviceTemperature = new(staticMockDeviceTemperature) func (m *staticMockDeviceTemperature) SocPeak() float64 { - return 0 + return 20 } func (m *staticMockDeviceTemperature) Ambient() float64 { - return 0 + return 10 } func newStaticMockVersionInfo(arch Arch, major, minor, patch uint32, metadata string) VersionInfo { diff --git a/pkg/smi/mock_rngd.go b/pkg/smi/mock_rngd.go index aaff0bc..ed8833c 100644 --- a/pkg/smi/mock_rngd.go +++ b/pkg/smi/mock_rngd.go @@ -26,51 +26,51 @@ func (m *staticRngdMockDevice) DeviceFiles() ([]DeviceFile, error) { path: fmt.Sprintf("/dev/rngd/npu%dpe1", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{0, 1}, path: fmt.Sprintf("/dev/rngd/npu%dpe0-1", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{0}, + cores: []uint32{2}, path: fmt.Sprintf("/dev/rngd/npu%dpe2", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{3}, path: fmt.Sprintf("/dev/rngd/npu%dpe3", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{2, 3}, path: fmt.Sprintf("/dev/rngd/npu%dpe2-3", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{0, 1, 2, 3}, path: fmt.Sprintf("/dev/rngd/npu%dpe0-3", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{0}, + cores: []uint32{4}, path: fmt.Sprintf("/dev/rngd/npu%dpe4", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{5}, path: fmt.Sprintf("/dev/rngd/npu%dpe5", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{4, 5}, path: fmt.Sprintf("/dev/rngd/npu%dpe4-5", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{0}, + cores: []uint32{6}, path: fmt.Sprintf("/dev/rngd/npu%dpe6", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{7}, path: fmt.Sprintf("/dev/rngd/npu%dpe7", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{6, 7}, path: fmt.Sprintf("/dev/rngd/npu%dpe6-7", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{4, 5, 6, 7}, path: fmt.Sprintf("/dev/rngd/npu%dpe4-7", m.nodeIdx), }, }, nil diff --git a/pkg/smi/mock_warboy.go b/pkg/smi/mock_warboy.go index 51116c8..a4bd14a 100644 --- a/pkg/smi/mock_warboy.go +++ b/pkg/smi/mock_warboy.go @@ -19,10 +19,6 @@ func (m *staticWarboyMockDevice) DeviceInfo() (DeviceInfo, error) { func (m *staticWarboyMockDevice) DeviceFiles() ([]DeviceFile, error) { return []DeviceFile{ - &staticMockDeviceFile{ - cores: []uint32{0}, - path: fmt.Sprintf("/dev/npu%d", m.nodeIdx), - }, &staticMockDeviceFile{ cores: []uint32{0}, path: fmt.Sprintf("/dev/npu%dpe0", m.nodeIdx), @@ -32,7 +28,7 @@ func (m *staticWarboyMockDevice) DeviceFiles() ([]DeviceFile, error) { path: fmt.Sprintf("/dev/npu%dpe1", m.nodeIdx), }, &staticMockDeviceFile{ - cores: []uint32{1}, + cores: []uint32{0, 1}, path: fmt.Sprintf("/dev/npu%dpe0-1", m.nodeIdx), }, }, nil diff --git a/pkg/smi/performance_test.go b/pkg/smi/performance_test.go new file mode 100644 index 0000000..10ab453 --- /dev/null +++ b/pkg/smi/performance_test.go @@ -0,0 +1,79 @@ +package smi + +import ( + "reflect" + "testing" + + "github.com/furiosa-ai/furiosa-smi-go/pkg/smi/binding" +) + +func testDeviceTemperature(arch Arch, t *testing.T, expected deviceTemperature) { + mockdevice := GetStaticMockDevice(arch, 0) + + temperature, err := mockdevice.DeviceTemperature() + if err != nil { + t.Errorf("Failed to get Device Temperature") + } + + if !reflect.DeepEqual(expected.SocPeak(), temperature.SocPeak()) { + t.Errorf("expected SocPeak %f but got %f", expected.SocPeak(), temperature.SocPeak()) + } + if !reflect.DeepEqual(expected.Ambient(), temperature.Ambient()) { + t.Errorf("expected Ambient %f but got %f", expected.Ambient(), temperature.Ambient()) + } +} + +func TestWarboyDeviceTemperature(t *testing.T) { + expected := deviceTemperature{binding.FuriosaSmiDeviceTemperature{SocPeak: 20.0, Ambient: 10.0}} + + testDeviceTemperature(ArchWarboy, t, expected) +} + +func TestRngdDeviceTemperature(t *testing.T) { + expected := deviceTemperature{binding.FuriosaSmiDeviceTemperature{SocPeak: 20.0, Ambient: 10.0}} + + testDeviceTemperature(ArchRngd, t, expected) +} + +func testPowerConsumption(arch Arch, t *testing.T, expected float64) { + mockdevice := GetStaticMockDevice(arch, 0) + + power, err := mockdevice.PowerConsumption() + if err != nil { + t.Errorf("Failed to get Power Consumption") + } + + if !reflect.DeepEqual(expected, power) { + t.Errorf("expected power consumption %f but got %f", expected, power) + } +} + +func TestWarboyPowerConsumption(t *testing.T) { + expected := 100.0 + + testPowerConsumption(ArchWarboy, t, expected) +} + +func TestRngdPowerConsumption(t *testing.T) { + expected := 100.0 + + testPowerConsumption(ArchRngd, t, expected) +} + +func testDeviceUtilization(arch Arch, t *testing.T) { + mockdevice := GetStaticMockDevice(arch, 0) + + _, err := mockdevice.DeviceUtilization() // Currenlty, not to check the value. + + if err != nil { + t.Errorf("Failed to get Device Utilization") + } +} + +func TestWarboyDeviceUtilization(t *testing.T) { + testDeviceUtilization(ArchWarboy, t) +} + +func TestRngdDeviceUtilization(t *testing.T) { + testDeviceUtilization(ArchRngd, t) +}