* sysdeps/unix/sysv/linux/tst-getcpu.c: New file.
[glibc/pb-stable.git] / sysdeps / unix / sysv / linux / tst-getcpu.c
blob78c4a6919e96e7896048169207bf2a862924987b
1 #include <errno.h>
2 #include <stdio.h>
3 #include <sched.h>
6 static int
7 do_test (void)
9 cpu_set_t cs;
10 if (sched_getaffinity (getpid (), sizeof (cs), &cs) != 0)
12 printf ("getaffinity failed: %m\n");
13 return 1;
16 int result = 0;
17 int cpu = 0;
18 while (CPU_COUNT (&cs) != 0)
20 if (CPU_ISSET (cpu, &cs))
22 cpu_set_t cs2;
23 CPU_ZERO (&cs2);
24 CPU_SET (cpu, &cs2);
25 if (sched_setaffinity (getpid (), sizeof (cs2), &cs2) != 0)
27 printf ("setaffinity(%d) failed: %m\n", cpu);
28 result = 1;
30 else
32 int cpu2 = sched_getcpu ();
33 if (cpu2 == -1 && errno == ENOSYS)
35 puts ("getcpu syscall not implemented");
36 return 0;
38 if (cpu2 != cpu)
40 printf ("getcpu results %d not possible\n", cpu2);
41 result = 1;
44 CPU_CLR (cpu, &cs);
46 ++cpu;
49 return result;
52 #define TEST_FUNCTION do_test ()
53 #include <test-skeleton.c>