@@ -16,6 +16,8 @@ package qat
1616
1717import (
1818 "context"
19+ "fmt"
20+ "os"
1921 "path/filepath"
2022 "strconv"
2123 "time"
@@ -38,6 +40,8 @@ const (
3840 qatPluginKustomizationYaml = "deployments/qat_plugin/overlays/e2e/kustomization.yaml"
3941 cryptoTestYaml = "deployments/qat_dpdk_app/crypto-perf/crypto-perf-dpdk-pod-requesting-qat-cy.yaml"
4042 compressTestYaml = "deployments/qat_dpdk_app/compress-perf/compress-perf-dpdk-pod-requesting-qat-dc.yaml"
43+ autoResetPattern = "/sys/bus/pci/drivers/*/*/qat/auto-reset"
44+ injectErrorPattern = "/sys/kernel/debug/qat_*/heartbeat/inject_error"
4145)
4246
4347const (
@@ -137,6 +141,27 @@ func describeQatDpdkPlugin() {
137141 ginkgo .When ("there is no app to run [App:noapp]" , func () {
138142 ginkgo .It ("does nothing" , func () {})
139143 })
144+
145+ ginkgo .It ("checks auto-reset functionality [Functionality: auto-reset]" , func (ctx context.Context ) {
146+ ginkgo .By ("checking if heartbeat status is read correctly" )
147+ if err := setQatAutoReset ("off" ); err != nil {
148+ framework .Failf ("unable to set auto reset in this system: %v" , err )
149+ }
150+ if err := injectError (); err != nil {
151+ framework .Failf ("unable to test error injection in this system: %v" , err )
152+ }
153+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 100 * time .Second , utils .WaitForZeroResource ); err != nil {
154+ framework .Failf ("unable to wait for nodes to have zero resource: %v" , err )
155+ }
156+
157+ ginkgo .By ("checking if auto-reset works to solve injected errors" )
158+ if err := setQatAutoReset ("on" ); err != nil {
159+ framework .Failf ("unable to set auto reset in this system: %v" , err )
160+ }
161+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 100 * time .Second , utils .WaitForPositiveResource ); err != nil {
162+ framework .Failf ("unable to wait for nodes to have positive allocatable resource: %v" , err )
163+ }
164+ })
140165 })
141166
142167 ginkgo .Context ("When QAT resources are available with compress (dc) services enabled [Resource:dc]" , func () {
@@ -164,6 +189,27 @@ func describeQatDpdkPlugin() {
164189 ginkgo .When ("there is no app to run [App:noapp]" , func () {
165190 ginkgo .It ("does nothing" , func () {})
166191 })
192+
193+ ginkgo .It ("checks auto-reset functionality [Functionality: auto-reset]" , func (ctx context.Context ) {
194+ ginkgo .By ("checking if heartbeat status is read correctly" )
195+ if err := setQatAutoReset ("off" ); err != nil {
196+ framework .Failf ("unable to set auto reset in this system: %v" , err )
197+ }
198+ if err := injectError (); err != nil {
199+ framework .Failf ("unable to test error injection in this system: %v" , err )
200+ }
201+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 100 * time .Second , utils .WaitForZeroResource ); err != nil {
202+ framework .Failf ("unable to wait for nodes to have zero resource: %v" , err )
203+ }
204+
205+ ginkgo .By ("checking if auto-reset works to solve injected errors" )
206+ if err := setQatAutoReset ("on" ); err != nil {
207+ framework .Failf ("unable to set auto reset in this system: %v" , err )
208+ }
209+ if err := utils .WaitForNodesWithResource (ctx , f .ClientSet , resourceName , 100 * time .Second , utils .WaitForPositiveResource ); err != nil {
210+ framework .Failf ("unable to wait for nodes to have positive allocatable resource: %v" , err )
211+ }
212+ })
167213 })
168214}
169215
@@ -199,3 +245,38 @@ func runCpaSampleCode(ctx context.Context, f *framework.Framework, runTests int,
199245 err = e2epod .WaitForPodSuccessInNamespaceTimeout (ctx , f .ClientSet , pod .ObjectMeta .Name , f .Namespace .Name , 300 * time .Second )
200246 gomega .Expect (err ).To (gomega .BeNil (), utils .GetPodLogs (ctx , f , pod .ObjectMeta .Name , pod .Spec .Containers [0 ].Name ))
201247}
248+
249+ func setQatAutoReset (cfgVal string ) error {
250+ matches , err := filepath .Glob (autoResetPattern )
251+ if err != nil {
252+ return err
253+ }
254+
255+ for _ , filePath := range matches {
256+ err = os .WriteFile (filePath , []byte (cfgVal ), 0600 )
257+ if err != nil {
258+ return err
259+ }
260+ }
261+ return nil
262+ }
263+
264+ func injectError () error {
265+ matches , err := filepath .Glob (injectErrorPattern )
266+ if err != nil {
267+ return err
268+ }
269+
270+ for _ , filePath := range matches {
271+ file , err := os .OpenFile (filePath , os .O_WRONLY | os .O_TRUNC , 0600 )
272+ if err != nil {
273+ return err
274+ }
275+ defer file .Close ()
276+
277+ os .Stdout = file
278+ fmt .Println ("1" )
279+ }
280+
281+ return nil
282+ }
0 commit comments