2023-02-13 15:04:30 +00:00
|
|
|
/**
|
|
|
|
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
package nvcdi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2024-05-21 11:23:42 +00:00
|
|
|
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
|
2023-02-13 15:04:30 +00:00
|
|
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResolveMode(t *testing.T) {
|
|
|
|
logger, _ := testlog.NewNullLogger()
|
|
|
|
|
|
|
|
testCases := []struct {
|
2023-05-23 13:59:08 +00:00
|
|
|
mode string
|
|
|
|
isTegra bool
|
2023-02-13 15:04:30 +00:00
|
|
|
hasDXCore bool
|
2023-05-23 13:59:08 +00:00
|
|
|
hasNVML bool
|
2023-02-13 15:04:30 +00:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
mode: "auto",
|
|
|
|
hasDXCore: true,
|
|
|
|
expected: "wsl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "auto",
|
|
|
|
hasDXCore: false,
|
2023-05-23 13:59:08 +00:00
|
|
|
isTegra: true,
|
|
|
|
hasNVML: false,
|
|
|
|
expected: "csv",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "auto",
|
|
|
|
hasDXCore: false,
|
|
|
|
isTegra: false,
|
|
|
|
hasNVML: false,
|
|
|
|
expected: "nvml",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "auto",
|
|
|
|
hasDXCore: false,
|
|
|
|
isTegra: true,
|
|
|
|
hasNVML: true,
|
|
|
|
expected: "nvml",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "auto",
|
|
|
|
hasDXCore: false,
|
|
|
|
isTegra: false,
|
2023-02-13 15:04:30 +00:00
|
|
|
expected: "nvml",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "nvml",
|
|
|
|
hasDXCore: true,
|
2023-05-23 13:59:08 +00:00
|
|
|
isTegra: true,
|
2023-02-13 15:04:30 +00:00
|
|
|
expected: "nvml",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "wsl",
|
|
|
|
hasDXCore: false,
|
|
|
|
expected: "wsl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "not-auto",
|
|
|
|
hasDXCore: true,
|
|
|
|
expected: "not-auto",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
|
|
|
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
|
|
|
|
l := nvcdilib{
|
2024-05-21 11:23:42 +00:00
|
|
|
logger: logger,
|
|
|
|
mode: tc.mode,
|
|
|
|
infolib: infoMock{
|
|
|
|
PropertyExtractor: &info.PropertyExtractorMock{
|
|
|
|
HasDXCoreFunc: func() (bool, string) { return tc.hasDXCore, "" },
|
|
|
|
HasNvmlFunc: func() (bool, string) { return tc.hasNVML, "" },
|
|
|
|
HasTegraFilesFunc: func() (bool, string) { return tc.isTegra, "" },
|
|
|
|
},
|
|
|
|
},
|
2023-02-13 15:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, tc.expected, l.resolveMode())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:59:08 +00:00
|
|
|
type infoMock struct {
|
2024-05-21 11:23:42 +00:00
|
|
|
info.PropertyExtractor
|
2023-05-23 13:59:08 +00:00
|
|
|
}
|
2023-02-13 15:04:30 +00:00
|
|
|
|
2024-05-21 11:23:42 +00:00
|
|
|
func (i infoMock) ResolvePlatform() info.Platform {
|
|
|
|
return "not-implemented"
|
2023-02-13 15:04:30 +00:00
|
|
|
}
|