From 90f9a493784603c676ae4358582e3c5e810af0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Thu, 18 Jul 2024 16:34:54 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=20=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91add=20dt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/dcmi/dcmi_api_test.go | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/runtime/dcmi/dcmi_api_test.go b/runtime/dcmi/dcmi_api_test.go index 491da1e..963c375 100644 --- a/runtime/dcmi/dcmi_api_test.go +++ b/runtime/dcmi/dcmi_api_test.go @@ -17,8 +17,10 @@ package dcmi import ( "context" + "reflect" "testing" + "github.com/agiledragon/gomonkey/v2" "github.com/opencontainers/runtime-spec/specs-go" "huawei.com/npu-exporter/v5/common-utils/hwlog" ) @@ -107,3 +109,52 @@ func TestCreateVDevice(t *testing.T) { } } + +// TestGetChipName tests the function GetChipName +func TestGetChipName(t *testing.T) { + patchInitialize := gomonkey.ApplyMethod(reflect.TypeOf(&NpuWorker{}), "Initialize", func(f *NpuWorker) error { + return nil + }) + defer patchInitialize.Reset() + patchShutDown := gomonkey.ApplyMethod(reflect.TypeOf(&NpuWorker{}), "ShutDown", func(f *NpuWorker) {}) + defer patchShutDown.Reset() + patch := gomonkey.ApplyFunc(GetCardList, func() (int32, []int32, error) { + return 1, []int32{0}, nil + }) + defer patch.Reset() + patchGetDeviceNumInCard := gomonkey.ApplyFunc(GetDeviceNumInCard, func(cardID int32) (int32, error) { + return 1, nil + }) + defer patchGetDeviceNumInCard.Reset() + patchGetChipInfo := gomonkey.ApplyMethod(reflect.TypeOf(&NpuWorker{}), "GetChipInfo", func(f *NpuWorker, cardID int32, deviceID int32) (*ChipInfo, error) { + return &ChipInfo{ + Name: "a", + Type: "b", + Version: "1", + }, nil + }) + defer patchGetChipInfo.Reset() + tests := []struct { + name string + want string + wantErr bool + }{ + { + name: "GetChipName success 1", + want: "a", + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetChipName() + if (err != nil) != tt.wantErr { + t.Errorf("GetChipName() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetChipName() got = %v, want %v", got, tt.want) + } + }) + } +} -- Gitee From c9c7ba5a72997fc5fbeb4c8cde257d8f12ac35f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Thu, 18 Jul 2024 16:56:43 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=20=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91add=20dt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/dcmi/dcmi_api_test.go | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/runtime/dcmi/dcmi_api_test.go b/runtime/dcmi/dcmi_api_test.go index 963c375..5883d06 100644 --- a/runtime/dcmi/dcmi_api_test.go +++ b/runtime/dcmi/dcmi_api_test.go @@ -158,3 +158,40 @@ func TestGetChipName(t *testing.T) { }) } } + +// TestGetProductType tests the function GetProductType +func TestGetProductType(t *testing.T) { + patch := gomonkey.ApplyFunc(GetCardList, func() (int32, []int32, error) { + return 1, []int32{0}, nil + }) + defer patch.Reset() + patchGetDeviceNumInCard := gomonkey.ApplyFunc(GetDeviceNumInCard, func(cardID int32) (int32, error) { + return 1, nil + }) + defer patchGetDeviceNumInCard.Reset() + tests := []struct { + name string + w WorkerInterface + want string + wantErr bool + }{ + { + name: "GetProductType success case 1", + w: &mockWorker{}, + want: "", + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetProductType(tt.w) + if (err != nil) != tt.wantErr { + t.Errorf("GetProductType() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetProductType() got = %v, want %v", got, tt.want) + } + }) + } +} -- Gitee From 31755e4de397fb507edb2aa699af7b0d2222b69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Thu, 18 Jul 2024 16:59:32 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=20=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91add=20dt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/dcmi/dcmi_api_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/dcmi/dcmi_api_test.go b/runtime/dcmi/dcmi_api_test.go index 5883d06..ca4c611 100644 --- a/runtime/dcmi/dcmi_api_test.go +++ b/runtime/dcmi/dcmi_api_test.go @@ -116,7 +116,9 @@ func TestGetChipName(t *testing.T) { return nil }) defer patchInitialize.Reset() - patchShutDown := gomonkey.ApplyMethod(reflect.TypeOf(&NpuWorker{}), "ShutDown", func(f *NpuWorker) {}) + patchShutDown := gomonkey.ApplyMethod(reflect.TypeOf(&NpuWorker{}), "ShutDown", func(f *NpuWorker) { + return + }) defer patchShutDown.Reset() patch := gomonkey.ApplyFunc(GetCardList, func() (int32, []int32, error) { return 1, []int32{0}, nil -- Gitee From 5a241955d903e34eab2996619e1a3472e083158e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Fri, 19 Jul 2024 09:02:31 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=20=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91add=20dt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/test/dt_go/build.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli/test/dt_go/build.sh b/cli/test/dt_go/build.sh index a61cd5a..044255b 100644 --- a/cli/test/dt_go/build.sh +++ b/cli/test/dt_go/build.sh @@ -24,10 +24,6 @@ export GONOSUMDB="*" function execute_test() { cd ${TOP_DIR} - go mod tidy - go install github.com/axw/gocov/gocov@v1.0.0 - go install github.com/matm/gocov-html@latest - go install gotest.tools/gotestsum@latest if ! (go test -mod=mod -gcflags=all=-l -v -race -coverprofile cov.out ${TOP_DIR}/... >./$file_input); then echo '****** go test cases error! ******' exit 1 -- Gitee From 7fbc75da5604403bb3cadab03b960605507c4794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Fri, 26 Jul 2024 17:07:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=20=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91=E4=BF=AE=E6=94=B9=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install/process/containerd_process_test.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/install/process/containerd_process_test.go b/install/process/containerd_process_test.go index 118d7a7..4ac5c89 100644 --- a/install/process/containerd_process_test.go +++ b/install/process/containerd_process_test.go @@ -73,28 +73,21 @@ func TestIsCgroupV2(t *testing.T) { name string cgroupInfo string want bool - wantErr bool }{ { name: "v2 case 1", cgroupInfo: cgroupV2InfoStr, want: true, - wantErr: false, }, { name: "v1 case 2", cgroupInfo: "", want: false, - wantErr: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := isCgroupV2(tt.cgroupInfo) - if (err != nil) != tt.wantErr { - t.Errorf("isCgroupV2() error = %v, wantErr %v", err, tt.wantErr) - return - } + got := isCgroupV2(tt.cgroupInfo) if got != tt.want { t.Errorf("isCgroupV2() got = %v, want %v", got, tt.want) } -- Gitee From 1fe42a7bddc05554398921501541727b5f2fb6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Fri, 26 Jul 2024 17:17:29 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=20=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91=E4=BF=AE=E6=94=B9=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install/process/containerd_process_test.go | 28 ---------------------- 1 file changed, 28 deletions(-) diff --git a/install/process/containerd_process_test.go b/install/process/containerd_process_test.go index 4ac5c89..6859e47 100644 --- a/install/process/containerd_process_test.go +++ b/install/process/containerd_process_test.go @@ -67,34 +67,6 @@ func initTestLog(t *testing.T) { } } -// TestIsCgroupV2 tests the function isCgroupV2 -func TestIsCgroupV2(t *testing.T) { - tests := []struct { - name string - cgroupInfo string - want bool - }{ - { - name: "v2 case 1", - cgroupInfo: cgroupV2InfoStr, - want: true, - }, - { - name: "v1 case 2", - cgroupInfo: "", - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := isCgroupV2(tt.cgroupInfo) - if got != tt.want { - t.Errorf("isCgroupV2() got = %v, want %v", got, tt.want) - } - }) - } -} - // TestEditContainerdConfig tests the function editContainerdConfig func TestEditContainerdConfig(t *testing.T) { tests := []struct { -- Gitee