2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / tst-getcpu.c
blobbf3cb57dd88e41ff18a025b628f26fd604234511
1 #include <errno.h>
2 #include <stdio.h>
3 #include <sched.h>
4 #include <unistd.h>
7 static int
8 do_test (void)
10 cpu_set_t cs;
11 if (sched_getaffinity (getpid (), sizeof (cs), &cs) != 0)
13 printf ("getaffinity failed: %m\n");
14 return 1;
17 int result = 0;
18 int cpu = 0;
19 while (CPU_COUNT (&cs) != 0)
21 if (CPU_ISSET (cpu, &cs))
23 cpu_set_t cs2;
24 CPU_ZERO (&cs2);
25 CPU_SET (cpu, &cs2);
26 if (sched_setaffinity (getpid (), sizeof (cs2), &cs2) != 0)
28 printf ("setaffinity(%d) failed: %m\n", cpu);
29 result = 1;
31 else
33 int cpu2 = sched_getcpu ();
34 if (cpu2 == -1 && errno == ENOSYS)
36 puts ("getcpu syscall not implemented");
37 return 0;
39 if (cpu2 != cpu)
41 printf ("getcpu results %d not possible\n", cpu2);
42 result = 1;
45 CPU_CLR (cpu, &cs);
47 ++cpu;
50 return result;
53 #define TEST_FUNCTION do_test ()
54 #include <test-skeleton.c>