@@ -16,6 +16,7 @@ package dpdkdrv
1616
1717import (
1818 "flag"
19+ "fmt"
1920 "os"
2021 "path"
2122 "reflect"
@@ -162,15 +163,16 @@ func TestGetPreferredAllocation(t *testing.T) {
162163
163164func TestScan (t * testing.T ) {
164165 tcases := []struct {
165- name string
166- dpdkDriver string
167- dirs []string
168- files map [string ][]byte
169- symlinks map [string ]string
170- kernelVfDrivers []string
171- expectedErr bool
172- maxDevNum int
173- expectedDevNum int
166+ name string
167+ dpdkDriver string
168+ dirs []string
169+ files map [string ][]byte
170+ symlinks map [string ]string
171+ kernelVfDrivers []string
172+ expectedErr bool
173+ maxDevNum int
174+ expectedDevNum int
175+ expectedUnhealthyNum int
174176 }{
175177 {
176178 name : "No error returned for uninitialized device plugin" ,
@@ -519,7 +521,119 @@ func TestScan(t *testing.T) {
519521 maxDevNum : 2 ,
520522 expectedDevNum : 2 ,
521523 },
524+ {
525+ name : "vfio-pci DPDKdriver with no kernel bound driver and where vfdevID is equal to qatDevId (4941) heartbeat status bad" ,
526+ dpdkDriver : "vfio-pci" ,
527+ kernelVfDrivers : []string {"4xxxvf" },
528+ dirs : []string {
529+ "sys/bus/pci/drivers/4xxx" ,
530+ "sys/bus/pci/drivers/vfio-pci" ,
531+ "sys/devices/pci0000:02/0000:02:00.0" ,
532+ "sys/devices/pci0000:02/0000:02:00.0/qat" ,
533+ "sys/kernel/debug/qat_4xxx_0000:02:00.0" ,
534+ "sys/kernel/debug/qat_4xxx_0000:02:00.0/heartbeat" ,
535+ "sys/bus/pci/devices/0000:02:01.0" ,
536+ },
537+ files : map [string ][]byte {
538+ "sys/devices/pci0000:02/0000:02:00.0/device" : []byte ("0x4940" ),
539+ "sys/devices/pci0000:02/0000:02:00.0/qat/state" : []byte ("up" ),
540+ "sys/devices/pci0000:02/0000:02:00.0/qat/cfg_services" : []byte ("sym;asym" ),
541+ "sys/bus/pci/devices/0000:02:01.0/device" : []byte ("0x4941" ),
542+ "sys/kernel/debug/qat_4xxx_0000:02:00.0/heartbeat/status" : []byte ("-1" ),
543+ },
544+ symlinks : map [string ]string {
545+ "sys/bus/pci/devices/0000:02:01.0/iommu_group" : "sys/kernel/iommu_groups/vfiotestfile" ,
546+ "sys/bus/pci/devices/0000:02:01.0/physfn" : "sys/devices/pci0000:02/0000:02:00.0" ,
547+ "sys/bus/pci/drivers/4xxx/0000:02:00.0" : "sys/devices/pci0000:02/0000:02:00.0" ,
548+ "sys/bus/pci/devices/0000:02:00.0" : "sys/devices/pci0000:02/0000:02:00.0" ,
549+ "sys/devices/pci0000:02/0000:02:00.0/virtfn0" : "sys/bus/pci/devices/0000:02:01.0" ,
550+ "sys/devices/pci0000:02/0000:02:00.0/driver" : "sys/bus/pci/drivers/4xxx" ,
551+ },
552+ maxDevNum : 1 ,
553+ expectedDevNum : 1 ,
554+ expectedUnhealthyNum : 1 ,
555+ },
556+ {
557+ name : "vfio-pci DPDKdriver with no kernel bound driver and where vfdevID is equal to qatDevId (4941) heartbeat status good" ,
558+ dpdkDriver : "vfio-pci" ,
559+ kernelVfDrivers : []string {"4xxxvf" },
560+ dirs : []string {
561+ "sys/bus/pci/drivers/4xxx" ,
562+ "sys/bus/pci/drivers/vfio-pci" ,
563+ "sys/devices/pci0000:02/0000:02:00.0" ,
564+ "sys/devices/pci0000:02/0000:02:00.0/qat" ,
565+ "sys/kernel/debug/qat_4xxx_0000:02:00.0" ,
566+ "sys/kernel/debug/qat_4xxx_0000:02:00.0/heartbeat" ,
567+ "sys/bus/pci/devices/0000:02:01.0" ,
568+ },
569+ files : map [string ][]byte {
570+ "sys/devices/pci0000:02/0000:02:00.0/device" : []byte ("0x4940" ),
571+ "sys/devices/pci0000:02/0000:02:00.0/qat/state" : []byte ("up" ),
572+ "sys/devices/pci0000:02/0000:02:00.0/qat/cfg_services" : []byte ("sym;asym" ),
573+ "sys/bus/pci/devices/0000:02:01.0/device" : []byte ("0x4941" ),
574+ "sys/kernel/debug/qat_4xxx_0000:02:00.0/heartbeat/status" : []byte ("0" ),
575+ },
576+ symlinks : map [string ]string {
577+ "sys/bus/pci/devices/0000:02:01.0/iommu_group" : "sys/kernel/iommu_groups/vfiotestfile" ,
578+ "sys/bus/pci/devices/0000:02:01.0/physfn" : "sys/devices/pci0000:02/0000:02:00.0" ,
579+ "sys/bus/pci/drivers/4xxx/0000:02:00.0" : "sys/devices/pci0000:02/0000:02:00.0" ,
580+ "sys/bus/pci/devices/0000:02:00.0" : "sys/devices/pci0000:02/0000:02:00.0" ,
581+ "sys/devices/pci0000:02/0000:02:00.0/virtfn0" : "sys/bus/pci/devices/0000:02:01.0" ,
582+ "sys/devices/pci0000:02/0000:02:00.0/driver" : "sys/bus/pci/drivers/4xxx" ,
583+ },
584+ maxDevNum : 1 ,
585+ expectedDevNum : 1 ,
586+ expectedUnhealthyNum : 0 ,
587+ },
588+ {
589+ name : "vfio-pci DPDKdriver with no kernel bound driver and where vfDevID is equal to qatDevId (37c9) heartbeat status bad" ,
590+ dpdkDriver : "vfio-pci" ,
591+ kernelVfDrivers : []string {"c6xxvf" },
592+ dirs : []string {
593+ "sys/bus/pci/drivers/c6xx" ,
594+ "sys/bus/pci/drivers/vfio-pci" ,
595+ "sys/bus/pci/devices/0000:02:01.0" ,
596+ "sys/bus/pci/devices/0000:02:01.1" ,
597+ "sys/devices/pci0000:02/0000:02:00.0" ,
598+ "sys/kernel/debug/qat_c6xx_0000:02:00.0/heartbeat" ,
599+ },
600+ files : map [string ][]byte {
601+ "sys/bus/pci/devices/0000:02:01.0/device" : []byte ("0x37c9" ),
602+ "sys/bus/pci/devices/0000:02:01.1/device" : []byte ("0x37c9" ),
603+ "sys/kernel/debug/qat_c6xx_0000:02:00.0/heartbeat/status" : []byte ("-1" ),
604+ },
605+ symlinks : map [string ]string {
606+ "sys/bus/pci/devices/0000:02:01.0/iommu_group" : "sys/kernel/iommu_groups/vfiotestfile" ,
607+ "sys/bus/pci/devices/0000:02:01.0/physfn" : "sys/devices/pci0000:02/0000:02:00.0" ,
608+ "sys/bus/pci/devices/0000:02:01.1/iommu_group" : "sys/kernel/iommu_groups/vfiotestfile" ,
609+ "sys/bus/pci/devices/0000:02:01.1/physfn" : "sys/devices/pci0000:02/0000:02:00.0" ,
610+ "sys/bus/pci/drivers/c6xx/0000:02:00.0" : "sys/devices/pci0000:02/0000:02:00.0" ,
611+ "sys/bus/pci/devices/0000:02:00.0" : "sys/devices/pci0000:02/0000:02:00.0" ,
612+ "sys/devices/pci0000:02/0000:02:00.0/virtfn0" : "sys/bus/pci/devices/0000:02:01.0" ,
613+ "sys/devices/pci0000:02/0000:02:00.0/virtfn1" : "sys/bus/pci/devices/0000:02:01.1" ,
614+ "sys/devices/pci0000:02/0000:02:00.0/driver" : "sys/bus/pci/drivers/c6xx" ,
615+ },
616+ maxDevNum : 3 ,
617+ expectedDevNum : 2 ,
618+ expectedUnhealthyNum : 2 ,
619+ },
522620 }
621+
622+ countUnhealthyDevices := func (tree dpapi.DeviceTree ) int {
623+ unhealtyNum := 0
624+
625+ for _ , v := range tree {
626+ for _ , vv := range v {
627+ field := reflect .ValueOf (vv ).FieldByName ("state" )
628+ if fmt .Sprintf ("%+v" , field ) == pluginapi .Unhealthy {
629+ unhealtyNum = unhealtyNum + 1
630+ }
631+ }
632+ }
633+
634+ return unhealtyNum
635+ }
636+
523637 for _ , tt := range tcases {
524638 t .Run (tt .name , func (t * testing.T ) {
525639 tmpdir , err := os .MkdirTemp ("/tmp/" , "qatplugin-TestScanPrivate-*" )
@@ -560,6 +674,10 @@ func TestScan(t *testing.T) {
560674 t .Errorf ("expected %d, but got %d devices" , tt .expectedDevNum , devNum )
561675 }
562676
677+ if unhealtyNum := countUnhealthyDevices (fN .tree ); unhealtyNum != tt .expectedUnhealthyNum {
678+ t .Errorf ("expected %d, but got %d unhealthy devices" , tt .expectedUnhealthyNum , unhealtyNum )
679+ }
680+
563681 if err = os .RemoveAll (tmpdir ); err != nil {
564682 t .Fatal (err )
565683 }
0 commit comments