Skip to content

Commit

Permalink
config: proper unit tests, fix exotic gpu systems prim
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Nov 3, 2023
1 parent 5f564e7 commit b034aee
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
9 changes: 4 additions & 5 deletions config/cardpick.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ func (b *Binary) pickCard() error {
idx = i
}

// Check if the system actually has PRIME offload and there's no ambiguity with the GPUs.
if prime {
vk := b.Dxvk || b.Renderer == "Vulkan"

if n != 2 && (!vk && n != 1) {
return ErrOpenGLBlind
if n <= 1 {
return nil
}

if n != 2 {
return nil
if n > 2 && !vk {
return ErrOpenGLBlind
}

if !sysinfo.Cards[0].Embedded {
Expand Down
73 changes: 52 additions & 21 deletions config/cardpick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

func TestCard(t *testing.T) {
sysinfo.Cards = []sysinfo.Card{}
b := Binary{
ForcedGpu: "meow",
Env: Environment{},
}
sysinfo.Cards = []sysinfo.Card{}

if err := b.pickCard(); !errors.Is(err, strconv.ErrSyntax) {
t.Fatal("expected to not handle string gpu")
Expand All @@ -29,7 +29,7 @@ func TestCard(t *testing.T) {
}
}

func TestPRIMECard(t *testing.T) {
func TestIntegratedCard(t *testing.T) {
b := Binary{
ForcedGpu: "integrated",
Env: Environment{},
Expand All @@ -39,45 +39,76 @@ func TestPRIMECard(t *testing.T) {
Driver: "i915",
Embedded: true,
},
{
Driver: "nvidia",
Embedded: false,
},
}

if err := b.pickCard(); err != nil {
t.Fatal(err)
}

if _, ok := b.Env["DRI_PRIME"]; ok {
t.Fatal("expected no change")
}

sysinfo.Cards = append(sysinfo.Cards, sysinfo.Card{
Driver: "nvidia",
Embedded: false,
})

if err := b.pickCard(); err != nil {
t.Fatal(err)
}

if v := b.Env["DRI_PRIME"]; v != "0" {
t.Fatal("expected change in prime index")
t.Fatal("expected change in integrated prime index")
}

if v := b.Env["__GLX_VENDOR_LIBRARY_NAME"]; v != "mesa" {
t.Fatal("expected glx vendor to be mesa")
}
}

func TestDiscreteCard(t *testing.T) {
b := Binary{
ForcedGpu: "prime-discrete",
Env: Environment{},
}
sysinfo.Cards = []sysinfo.Card{
{
Driver: "i915",
Embedded: true,
},
{
Driver: "nvidia",
Embedded: false,
},
}

b.ForcedGpu = "prime-discrete"
delete(b.Env, "DRI_PRIME")
delete(b.Env, "__GLX_VENDOR_LIBRARY_NAME")
if err := b.pickCard(); err != nil {
t.Fatal(err)
}

if v := b.Env["DRI_PRIME"]; v != "1" {
t.Fatal("expected change in descrete index")
t.Fatal("expected change in discrete prime index")
}

if v := b.Env["__GLX_VENDOR_LIBRARY_NAME"]; v != "nvidia" {
t.Fatal("expected glx vendor to be nvidia")
}
}
}

func TestVulkanCard(t *testing.T) {
b := Binary{
ForcedGpu: "prime-discrete",
Renderer: "OpenGL",
Env: Environment{},
}
sysinfo.Cards = []sysinfo.Card{
{
Driver: "i915",
Embedded: true,
},
{
Driver: "nvidia",
Embedded: false,
},
{
Driver: "radeon",
Embedded: false,
},
}

if err := b.pickCard(); !errors.Is(err, ErrOpenGLBlind) {
t.Fatal("expected handle opengl skill issue")
}
}

0 comments on commit b034aee

Please sign in to comment.