diff --git a/test/e2e/performanceprofile/functests/4_latency/latency.go b/test/e2e/performanceprofile/functests/4_latency/latency.go index 49f4514f2..35b7ff3af 100644 --- a/test/e2e/performanceprofile/functests/4_latency/latency.go +++ b/test/e2e/performanceprofile/functests/4_latency/latency.go @@ -43,6 +43,8 @@ const ( defaultTestRuntime = "300" defaultMaxLatency = -1 defaultTestCpus = -1 + defaultTestMemory = "1Gi" + dynamicMemory = "dynamic" minCpuAmountForOslat = 2 ) @@ -51,13 +53,14 @@ var ( latencyTestRuntime = defaultTestRuntime maximumLatency = defaultMaxLatency latencyTestCpus = defaultTestCpus + latencyTestMemory = defaultTestMemory ) // LATENCY_TEST_DELAY delay the run of the binary, can be useful to give time to the CPU manager reconcile loop // to update the default CPU pool // LATENCY_TEST_RUNTIME: the amount of time in seconds that the latency test should run // LATENCY_TEST_CPUS: the amount of CPUs the pod which run the latency test should request - +// LATENCY_TEST_MEMORY: the amount of memory the pod which run the latency test should request var _ = Describe("[performance] Latency Test", Ordered, func() { var workerRTNode *corev1.Node var profile *performancev2.PerformanceProfile @@ -278,6 +281,29 @@ func getLatencyTestCpus() (int, error) { return defaultTestCpus, nil } +func getLatencyTestMemory(cpus int) (string, error) { + if val, ok := os.LookupEnv("LATENCY_TEST_MEMORY"); ok { + if val == dynamicMemory { + // Defensive check: fall back to default memory if the cpus was not normalized + if cpus == defaultTestCpus { + return defaultTestMemory, nil + } + // 32Mi per requested CPU should be reasonable for the test; if needed more, it can + // be overridden by explicitly setting the environment variable + memoryFactor := 32 + memory := memoryFactor * cpus + return fmt.Sprintf("%dMi", memory), nil + } + + _, err := resource.ParseQuantity(val) + if err != nil { + return val, fmt.Errorf("the environment variable LATENCY_TEST_MEMORY has incorrect value %q, it must be a valid quantity: %w", val, err) + } + return val, nil + } + return defaultTestMemory, nil +} + // getMaximumLatency should look for one of the following environment variables: // OSLAT_MAXIMUM_LATENCY: the expected maximum latency for all buckets in us // CYCLICTEST_MAXIMUM_LATENCY: the expected maximum latency for all buckets in us @@ -325,6 +351,10 @@ func getLatencyTestPod(profile *performancev2.PerformanceProfile, node *corev1.N latencyTestCpus = cpus.Size() - 1 } + var err error + latencyTestMemory, err = getLatencyTestMemory(latencyTestCpus) + Expect(err).ToNot(HaveOccurred()) + latencyTestRunnerArgs := []string{ "-logtostderr=false", "-alsologtostderr=true", @@ -361,7 +391,7 @@ func getLatencyTestPod(profile *performancev2.PerformanceProfile, node *corev1.N Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse(strconv.Itoa(latencyTestCpus)), - corev1.ResourceMemory: resource.MustParse("1Gi"), + corev1.ResourceMemory: resource.MustParse(latencyTestMemory), }, }, SecurityContext: &corev1.SecurityContext{