@@ -2,6 +2,7 @@ package __latency_testing
22
33import (
44 "bytes"
5+ "context"
56 "fmt"
67 "math"
78 "os"
@@ -12,7 +13,12 @@ import (
1213 . "github.com/onsi/ginkgo/v2"
1314 . "github.com/onsi/gomega"
1415 "github.com/onsi/gomega/format"
16+ "k8s.io/utils/cpuset"
17+
18+ testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
1519 testlog "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/log"
20+ "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodes"
21+ "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profiles"
1622)
1723
1824// TODO get commonly used variables from one shared file that defines constants
@@ -219,6 +225,33 @@ func clearEnv() {
219225 os .Unsetenv (latencyTestCpus )
220226}
221227
228+ // checkHyperthreading determines if the BZ 2094046 test should run based on HT status.
229+ // Returns true if the test should run (HT enabled), false if it should be skipped (HT disabled).
230+ func checkHyperthreading () (bool , error ) {
231+ profile , err := profiles .GetByNodeLabels (testutils .NodeSelectorLabels )
232+ if err != nil {
233+ return false , fmt .Errorf ("get performance profile: %w" , err )
234+ }
235+
236+ workerNodes , err := nodes .GetByLabels (testutils .NodeSelectorLabels )
237+ if err != nil {
238+ return false , fmt .Errorf ("get worker nodes: %w" , err )
239+ }
240+ workerNode := & workerNodes [0 ]
241+
242+ ctx := context .Background ()
243+ set , err := cpuset .Parse (string (* profile .Spec .CPU .Isolated ))
244+ if err != nil || set .Size () == 0 {
245+ return false , fmt .Errorf ("failed to parse isolated CPUs from profile" )
246+ }
247+ cpuID := set .List ()[0 ]
248+
249+ isHTEnabled := nodes .IsHyperthreadingEnabled (ctx , cpuID , workerNode )
250+ testlog .Infof ("Hyperthreading status on node %s (CPU %d): %t" , workerNode .Name , cpuID , isHTEnabled )
251+
252+ return isHTEnabled , nil
253+ }
254+
222255func getValidValuesTests (toolToTest string ) []latencyTest {
223256 var testSet []latencyTest
224257
@@ -283,15 +316,21 @@ func getNegativeTests(toolToTest string) []latencyTest {
283316 testSet = append (testSet , latencyTest {testRuntime : "2" , oslatMaxLatency : "&" , outputMsgs : []string {incorrectOslatMaxLatency , fail }, toolToTest : toolToTest })
284317 testSet = append (testSet , latencyTest {testRuntime : "2" , oslatMaxLatency : fmt .Sprint (math .MaxInt32 + 1 ), outputMsgs : []string {invalidNumberOslatMaxLatency , fail }, toolToTest : toolToTest })
285318 testSet = append (testSet , latencyTest {testRuntime : "2" , oslatMaxLatency : "-3" , outputMsgs : []string {invalidNumberOslatMaxLatency , fail }, toolToTest : toolToTest })
286- // Covers the scenario of BZ 2094046
287- testSet = append (testSet , latencyTest {testRuntime : "2" , testCpus : "2" , outputMsgs : []string {unexpectedError , fail }, toolToTest : toolToTest })
319+ // BZ 2094046: only add this test if HT is enabled
320+ htEnabled , htErr := checkHyperthreading ()
321+ if htErr == nil && htEnabled {
322+ testSet = append (testSet , latencyTest {testRuntime : "2" , testCpus : "2" , oslatMaxLatency : untunedLatencyThreshold , outputMsgs : []string {unexpectedError , fail }, toolToTest : toolToTest })
323+ }
288324 }
289325 if toolToTest == cyclictest {
290326 testSet = append (testSet , latencyTest {testRuntime : "2" , cyclictestMaxLatency : "&" , outputMsgs : []string {incorrectCyclictestMaxLatency , fail }, toolToTest : toolToTest })
291327 testSet = append (testSet , latencyTest {testRuntime : "2" , cyclictestMaxLatency : fmt .Sprint (math .MaxInt32 + 1 ), outputMsgs : []string {invalidNumberCyclictestMaxLatency , fail }, toolToTest : toolToTest })
292328 testSet = append (testSet , latencyTest {testRuntime : "2" , cyclictestMaxLatency : "-3" , outputMsgs : []string {invalidNumberCyclictestMaxLatency , fail }, toolToTest : toolToTest })
293- // Covers the scenario of BZ 2094046
294- testSet = append (testSet , latencyTest {testRuntime : "2" , testCpus : "2" , outputMsgs : []string {unexpectedError , fail }, toolToTest : toolToTest })
329+ // BZ 2094046: only add this test if HT is enabled
330+ htEnabled , htErr := checkHyperthreading ()
331+ if htErr == nil && htEnabled {
332+ testSet = append (testSet , latencyTest {testRuntime : "2" , testCpus : "2" , cyclictestMaxLatency : untunedLatencyThreshold , outputMsgs : []string {unexpectedError , fail }, toolToTest : toolToTest })
333+ }
295334 }
296335 if toolToTest == hwlatdetect {
297336 testSet = append (testSet , latencyTest {testRuntime : "2" , hwlatdetectMaxLatency : "&" , outputMsgs : []string {incorrectHwlatdetectMaxLatency , fail }, toolToTest : toolToTest })
0 commit comments