@@ -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,37 @@ 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+ smtLevel , err := nodes .GetSMTLevel (ctx , cpuID , workerNode )
250+ if err != nil {
251+ return false , fmt .Errorf ("failed to get SMT level for CPU %d on node %s: %w" , cpuID , workerNode .Name , err )
252+ }
253+ isHTEnabled := smtLevel > 1
254+ testlog .Infof ("Hyperthreading status on node %s (CPU %d): %t" , workerNode .Name , cpuID , isHTEnabled )
255+
256+ return isHTEnabled , nil
257+ }
258+
222259func getValidValuesTests (toolToTest string ) []latencyTest {
223260 var testSet []latencyTest
224261
@@ -283,15 +320,21 @@ func getNegativeTests(toolToTest string) []latencyTest {
283320 testSet = append (testSet , latencyTest {testRuntime : "2" , oslatMaxLatency : "&" , outputMsgs : []string {incorrectOslatMaxLatency , fail }, toolToTest : toolToTest })
284321 testSet = append (testSet , latencyTest {testRuntime : "2" , oslatMaxLatency : fmt .Sprint (math .MaxInt32 + 1 ), outputMsgs : []string {invalidNumberOslatMaxLatency , fail }, toolToTest : toolToTest })
285322 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 })
323+ // BZ 2094046: only add this test if HT is enabled
324+ htEnabled , htErr := checkHyperthreading ()
325+ if htErr == nil && htEnabled {
326+ testSet = append (testSet , latencyTest {testRuntime : "2" , testCpus : "2" , oslatMaxLatency : untunedLatencyThreshold , outputMsgs : []string {unexpectedError , fail }, toolToTest : toolToTest })
327+ }
288328 }
289329 if toolToTest == cyclictest {
290330 testSet = append (testSet , latencyTest {testRuntime : "2" , cyclictestMaxLatency : "&" , outputMsgs : []string {incorrectCyclictestMaxLatency , fail }, toolToTest : toolToTest })
291331 testSet = append (testSet , latencyTest {testRuntime : "2" , cyclictestMaxLatency : fmt .Sprint (math .MaxInt32 + 1 ), outputMsgs : []string {invalidNumberCyclictestMaxLatency , fail }, toolToTest : toolToTest })
292332 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 })
333+ // BZ 2094046: only add this test if HT is enabled
334+ htEnabled , htErr := checkHyperthreading ()
335+ if htErr == nil && htEnabled {
336+ testSet = append (testSet , latencyTest {testRuntime : "2" , testCpus : "2" , cyclictestMaxLatency : untunedLatencyThreshold , outputMsgs : []string {unexpectedError , fail }, toolToTest : toolToTest })
337+ }
295338 }
296339 if toolToTest == hwlatdetect {
297340 testSet = append (testSet , latencyTest {testRuntime : "2" , hwlatdetectMaxLatency : "&" , outputMsgs : []string {incorrectHwlatdetectMaxLatency , fail }, toolToTest : toolToTest })
0 commit comments