@@ -16,6 +16,7 @@ package dpdkdrv
16
16
17
17
import (
18
18
"flag"
19
+ "fmt"
19
20
"os"
20
21
"path"
21
22
"reflect"
@@ -162,15 +163,16 @@ func TestGetPreferredAllocation(t *testing.T) {
162
163
163
164
func TestScan (t * testing.T ) {
164
165
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
174
176
}{
175
177
{
176
178
name : "No error returned for uninitialized device plugin" ,
@@ -519,7 +521,119 @@ func TestScan(t *testing.T) {
519
521
maxDevNum : 2 ,
520
522
expectedDevNum : 2 ,
521
523
},
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
+ },
522
620
}
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
+
523
637
for _ , tt := range tcases {
524
638
t .Run (tt .name , func (t * testing.T ) {
525
639
tmpdir , err := os .MkdirTemp ("/tmp/" , "qatplugin-TestScanPrivate-*" )
@@ -560,6 +674,10 @@ func TestScan(t *testing.T) {
560
674
t .Errorf ("expected %d, but got %d devices" , tt .expectedDevNum , devNum )
561
675
}
562
676
677
+ if unhealtyNum := countUnhealthyDevices (fN .tree ); unhealtyNum != tt .expectedUnhealthyNum {
678
+ t .Errorf ("expected %d, but got %d unhealthy devices" , tt .expectedUnhealthyNum , unhealtyNum )
679
+ }
680
+
563
681
if err = os .RemoveAll (tmpdir ); err != nil {
564
682
t .Fatal (err )
565
683
}
0 commit comments