diff mbox series

[v2,2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled

Message ID 20250221115750.631990-3-sinadin.shan@oracle.com
State New
Headers show
Series selftests: sched: Add default target support for sched | expand

Commit Message

Sinadin Shan Feb. 21, 2025, 11:57 a.m. UTC
For kernels with CONFIG_SCHED_CORE=n, the sched selftest cs_prctl_test
fails with "Not a core sched system" error. Change this to gracefully
skip the test for systems with core scheduling disabled. Exiting early
would also ensure failures reported in obtaining cookie are valid
failures and not due to the config.

Skip cs_prctl_test for systems with CONFIG_SCHED_CORE=n

Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com>
---
 tools/testing/selftests/sched/cs_prctl_test.c | 29 ++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

Comments

Chris Hyser Feb. 24, 2025, 11:02 p.m. UTC | #1
>From: Sinadin Shan <sinadin.shan@oracle.com>
>Sent: Monday, February 24, 2025 7:10 AM
>To: Shrikanth Hegde; shuah@kernel.org
>Cc: linux-kselftest@vger.kernel.org; linux-kernel@vger.kernel.org; Chris Hyser
>Subject: Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
>
>On 24-02-2025 01:49 pm, Shrikanth Hegde wrote:
...
>> If the self-tests are to be used in development flow, these checks may
>> not be sufficient.
>
>Right, this particular case was overlooked. To handle this, the test
>could take a path to the custom config as an argument. I shall work on
>getting this fixed.

I was thinking something along the lines of just calling the prctl. 

If you call it and SCHED_CORE is not configured, you will get an EINVAL. Unfortunately,
passing other bad values in the other prctl args will also give an EINVAL, but if you call it with a
non-existent PID (say max_pid + 1) it will generate an ESRCH if the code is present.

So something like (and I'd look up the maxpid on the actual system):

int check_core_sched()
{
        ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 32769, PIDTYPE_PID,                                                                                                                                                         
                         (unsigned long)&cookie);                                                                                                                                                                            

        printf("ret = %d\n", ret);                                                                                                                                                                             
        perror("Error:\n");     
}

-chrish
diff mbox series

Patch

diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/selftests/sched/cs_prctl_test.c
index 52d97fae4dbd8..60fd657b56c84 100644
--- a/tools/testing/selftests/sched/cs_prctl_test.c
+++ b/tools/testing/selftests/sched/cs_prctl_test.c
@@ -23,6 +23,7 @@ 
 #include <sys/eventfd.h>
 #include <sys/wait.h>
 #include <sys/types.h>
+#include <sys/utsname.h>
 #include <sched.h>
 #include <sys/prctl.h>
 #include <unistd.h>
@@ -109,6 +110,30 @@  static void handle_usage(int rc, char *msg)
 	exit(rc);
 }
 
+static void check_core_sched_support(void)
+{
+	char config[128] = "/proc/config.gz";
+	char cmd[128];
+	struct utsname kernel;
+
+	printf("## Checking for CONFIG_SCHED_CORE support\n");
+
+	if (access(config, F_OK) != 0)
+		if (uname(&kernel) == 0)
+			snprintf(config, sizeof(config), "/boot/config-%s", kernel.release);
+
+	if (access(config, F_OK) != 0) {
+		printf("Cannot find kernel config in /proc or /boot\n");
+		exit(EXIT_FAILURE);
+	}
+
+	snprintf(cmd, sizeof(cmd), "zgrep CONFIG_SCHED_CORE=[ym] %s", config);
+	if (system(cmd)) {
+		printf("Core scheduling not enabled in kernel, hence skipping tests\n");
+		exit(4);
+	}
+}
+
 static unsigned long get_cs_cookie(int pid)
 {
 	unsigned long long cookie;
@@ -117,7 +142,7 @@  static unsigned long get_cs_cookie(int pid)
 	ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID,
 		    (unsigned long)&cookie);
 	if (ret) {
-		printf("Not a core sched system\n");
+		printf("Failed to get cookie\n");
 		return -1UL;
 	}
 
@@ -270,6 +295,8 @@  int main(int argc, char *argv[])
 	if (keypress)
 		delay = -1;
 
+	check_core_sched_support();
+
 	srand(time(NULL));
 
 	/* put into separate process group */