Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package __latency_testing

import (
"bytes"
"context"
"fmt"
"math"
"os"
Expand All @@ -12,7 +13,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
testlog "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/log"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodes"
)

// TODO get commonly used variables from one shared file that defines constants
Expand Down Expand Up @@ -264,6 +267,15 @@ func getNegativeTests(toolToTest string) []latencyTest {
latencyFailureMsg = hwlatdetectFail
}

// BZ 2094046: need SMT active on pool to add the HT-specific test. One node is enough (pool shares same config).
var htEnabled bool
if toolToTest == oslat || toolToTest == cyclictest {
workerNodes, err := nodes.GetByLabels(testutils.NodeSelectorLabels)
if err == nil && len(workerNodes) > 0 {
htEnabled, _ = nodes.IsSMTActive(context.Background(), &workerNodes[0])
}
}

testSet = append(testSet, latencyTest{testDelay: "0", testRuntime: "5", testMaxLatency: "1", outputMsgs: []string{latencyFailureMsg, fail}, toolToTest: toolToTest})
testSet = append(testSet, latencyTest{testRuntime: fmt.Sprint(math.MaxInt32 + 1), outputMsgs: []string{invalidNumberRuntime, fail}, toolToTest: toolToTest})
testSet = append(testSet, latencyTest{testRuntime: "-1", testMaxLatency: "1", outputMsgs: []string{invalidNumberRuntime, fail}, toolToTest: toolToTest})
Expand All @@ -283,15 +295,17 @@ func getNegativeTests(toolToTest string) []latencyTest {
testSet = append(testSet, latencyTest{testRuntime: "2", oslatMaxLatency: "&", outputMsgs: []string{incorrectOslatMaxLatency, fail}, toolToTest: toolToTest})
testSet = append(testSet, latencyTest{testRuntime: "2", oslatMaxLatency: fmt.Sprint(math.MaxInt32 + 1), outputMsgs: []string{invalidNumberOslatMaxLatency, fail}, toolToTest: toolToTest})
testSet = append(testSet, latencyTest{testRuntime: "2", oslatMaxLatency: "-3", outputMsgs: []string{invalidNumberOslatMaxLatency, fail}, toolToTest: toolToTest})
// Covers the scenario of BZ 2094046
testSet = append(testSet, latencyTest{testRuntime: "2", testCpus: "2", outputMsgs: []string{unexpectedError, fail}, toolToTest: toolToTest})
if htEnabled {
testSet = append(testSet, latencyTest{testRuntime: "2", testCpus: "2", oslatMaxLatency: untunedLatencyThreshold, outputMsgs: []string{unexpectedError, fail}, toolToTest: toolToTest})
}
}
if toolToTest == cyclictest {
testSet = append(testSet, latencyTest{testRuntime: "2", cyclictestMaxLatency: "&", outputMsgs: []string{incorrectCyclictestMaxLatency, fail}, toolToTest: toolToTest})
testSet = append(testSet, latencyTest{testRuntime: "2", cyclictestMaxLatency: fmt.Sprint(math.MaxInt32 + 1), outputMsgs: []string{invalidNumberCyclictestMaxLatency, fail}, toolToTest: toolToTest})
testSet = append(testSet, latencyTest{testRuntime: "2", cyclictestMaxLatency: "-3", outputMsgs: []string{invalidNumberCyclictestMaxLatency, fail}, toolToTest: toolToTest})
// Covers the scenario of BZ 2094046
testSet = append(testSet, latencyTest{testRuntime: "2", testCpus: "2", outputMsgs: []string{unexpectedError, fail}, toolToTest: toolToTest})
if htEnabled {
testSet = append(testSet, latencyTest{testRuntime: "2", testCpus: "2", cyclictestMaxLatency: untunedLatencyThreshold, outputMsgs: []string{unexpectedError, fail}, toolToTest: toolToTest})
}
}
if toolToTest == hwlatdetect {
testSet = append(testSet, latencyTest{testRuntime: "2", hwlatdetectMaxLatency: "&", outputMsgs: []string{incorrectHwlatdetectMaxLatency, fail}, toolToTest: toolToTest})
Expand Down
21 changes: 21 additions & 0 deletions test/e2e/performanceprofile/functests/utils/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (

const (
sysDevicesOnlineCPUs = "/sys/devices/system/cpu/online"
sysDevicesSMTActive = "/sys/devices/system/cpu/smt/active"
cgroupRoot = "/rootfs/sys/fs/cgroup"
)

Expand Down Expand Up @@ -278,6 +279,26 @@ func GetSMTLevel(ctx context.Context, cpuID int, node *corev1.Node) (int, error)
return cpus.Size(), nil
}

// IsSMTActive returns whether SMT is active on the node.
// It reads /sys/devices/system/cpu/smt/active: 1 = active, 0 = not active (disabled in BIOS or by OS).
// Use this when only enabled/disabled is needed; use GetSMTLevel when the actual thread count is needed.
func IsSMTActive(ctx context.Context, node *corev1.Node) (bool, error) {
cmd := []string{"cat", sysDevicesSMTActive}
out, err := ExecCommand(ctx, node, cmd)
if err != nil {
return false, err
}
s := strings.TrimSpace(testutils.ToString(out))
switch s {
case "1":
return true, nil
case "0":
return false, nil
default:
return false, fmt.Errorf("unexpected %s value: %q", sysDevicesSMTActive, s)
}
}
Comment on lines +291 to +300
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the future: use strconv.ParseBool


// GetNumaNodes returns the number of numa nodes and the associated cpus as list on the node
func GetNumaNodes(ctx context.Context, node *corev1.Node) (map[int][]int, error) {
lscpuCmd := []string{"lscpu", "-e=node,core,cpu", "-J"}
Expand Down