Skip to content

Commit f77ebb7

Browse files
committed
Fixed oslat & cyclictest HT specific tests
The BZ 2094046 test cases for oslat and cyclictest were negative tests expecting to fail on HT-enabled systems, but they passed unexpectedly on HT-disabled systems because the tools executed successfully. Changes: - Add hyperthreading detection in its test execution path - Skip BZ 2094046 tests when HT is disabled to prevent false passes Signed-Off-by: Sargun Narula <[email protected]>
1 parent b5d66f8 commit f77ebb7

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

test/e2e/performanceprofile/functests/5_latency_testing/latency_testing.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package __latency_testing
22

33
import (
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+
222255
func 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})

test/e2e/performanceprofile/functests/utils/nodes/nodes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ func GetSMTLevel(ctx context.Context, cpuID int, node *corev1.Node) int {
274274
return cpus.Size()
275275
}
276276

277+
// IsHyperthreadingEnabled checks if hyperthreading (SMT) is enabled on the node
278+
// Returns true if SMT level > 1, false otherwise
279+
func IsHyperthreadingEnabled(ctx context.Context, cpuID int, node *corev1.Node) bool {
280+
smtLevel := GetSMTLevel(ctx, cpuID, node)
281+
return smtLevel > 1
282+
}
283+
277284
// GetNumaNodes returns the number of numa nodes and the associated cpus as list on the node
278285
func GetNumaNodes(ctx context.Context, node *corev1.Node) (map[int][]int, error) {
279286
lscpuCmd := []string{"lscpu", "-e=node,core,cpu", "-J"}

0 commit comments

Comments
 (0)