Skip to content

Commit

Permalink
add test ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jongchanpark-furiosa committed Aug 16, 2024
1 parent 53cf3ae commit 4cefdd3
Show file tree
Hide file tree
Showing 11 changed files with 640 additions and 29 deletions.
41 changes: 41 additions & 0 deletions .github/workflow/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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@v4
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
run: go version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.0
- name: build and test
run: make all
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ define build_examples_function
done
endef

.PHONY: check
check: fmt lint vet test tidy vendor

.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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions pkg/smi/device_error_test.go
Original file line number Diff line number Diff line change
@@ -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) {
device := GetStaticMockDevice(arch, 0)

device_error_info, err := device.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: 1,
AxiFetchErrorCount: 2,
AxiDiscardErrorCount: 3,
AxiDoorbellErrorCount: 4,
PciePostErrorCount: 5,
PcieFetchErrorCount: 6,
PcieDiscardErrorCount: 7,
PcieDoorbellErrorCount: 8,
DeviceErrorCount: 9})

testDeviceErrorInfo(ArchWarboy, t, expected)
}

func TestRngdDeviceErrorInfo(t *testing.T) {
expected := newDeviceErrorInfo(binding.FuriosaSmiDeviceErrorInfo{
AxiPostErrorCount: 1,
AxiFetchErrorCount: 2,
AxiDiscardErrorCount: 3,
AxiDoorbellErrorCount: 4,
PciePostErrorCount: 5,
PcieFetchErrorCount: 6,
PcieDiscardErrorCount: 7,
PcieDoorbellErrorCount: 8,
DeviceErrorCount: 9})

testDeviceErrorInfo(ArchRngd, t, expected)
}
87 changes: 87 additions & 0 deletions pkg/smi/device_file_test.go
Original file line number Diff line number Diff line change
@@ -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) {
device := GetStaticMockDevice(arch, 0)

device_files, err := device.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)
}
Loading

0 comments on commit 4cefdd3

Please sign in to comment.