Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test ci #4

Merged
merged 9 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/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" ]
bg-furiosa marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.21.3' ]
bg-furiosa marked this conversation as resolved.
Show resolved Hide resolved

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
hoony9x-furiosa-ai marked this conversation as resolved.
Show resolved Hide resolved
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
hoony9x-furiosa-ai marked this conversation as resolved.
Show resolved Hide resolved
- name: build and test
run: make all
Copy link
Collaborator

@bg-furiosa bg-furiosa Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 golang.yml을 참고해서 build, test, lint를 별도의 step으로 분리 부탁드립니다.
문제 발생시 디버깅을 쉽게 하기 위함입니다, 필요에 따라 Makefile도 업데이트 부탁드립니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

781e7f4 에서 수정하였습니다.

31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
Loading