sched.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #define _GNU_SOURCE
  2. #include <errno.h>
  3. #include <sched.h>
  4. #include <stdio.h>
  5. #include <sys/resource.h>
  6. #include <sys/time.h>
  7. /* This test checks that our dummy implementations work correctly. None of the
  8. * below syscalls are actually propagated to the host OS or change anything.\
  9. * NOTE: This test works correctly only on Graphene (not on Linux). */
  10. int main(int argc, char** argv) {
  11. /* setters */
  12. struct sched_param param = {.sched_priority = 50};
  13. if (sched_setscheduler(0, SCHED_RR, &param) == -1) {
  14. perror("Error setting scheduler\n");
  15. return 1;
  16. }
  17. if (sched_setparam(0, &param) == -1) {
  18. perror("Error setting param\n");
  19. return 1;
  20. }
  21. if (setpriority(PRIO_PROCESS, 0, 10) == -1) {
  22. perror("Error setting priority\n");
  23. return 1;
  24. }
  25. cpu_set_t my_set;
  26. CPU_ZERO(&my_set);
  27. if (sched_setaffinity(0, sizeof(cpu_set_t), &my_set) == -1) {
  28. perror("Error setting affinity\n");
  29. return 1;
  30. }
  31. /* getters */
  32. if (sched_getscheduler(0) != SCHED_OTHER) {
  33. perror("Error getting scheduler\n");
  34. return 2;
  35. }
  36. if (sched_getparam(0, &param) == -1 || param.sched_priority != 0) {
  37. perror("Error getting param\n");
  38. return 2;
  39. }
  40. if (getpriority(PRIO_PROCESS, 0) != 0) {
  41. perror("Error getting priority\n");
  42. return 2;
  43. }
  44. if (sched_getaffinity(0, sizeof(cpu_set_t), &my_set) == -1) {
  45. perror("Error getting affinity\n");
  46. return 2;
  47. }
  48. if (sched_get_priority_max(SCHED_FIFO) != 99) {
  49. perror("Error getting max priority of SCHED_FIFO\n");
  50. return 2;
  51. }
  52. if (sched_get_priority_min(SCHED_FIFO) != 1) {
  53. perror("Error getting min priority of SCHED_FIFO\n");
  54. return 2;
  55. }
  56. struct timespec interval = {0};
  57. if (sched_rr_get_interval(0, &interval) == -1 || interval.tv_sec != 0 ||
  58. interval.tv_nsec != 100000000) {
  59. perror("Error getting interval of SCHED_RR\n");
  60. return 2;
  61. }
  62. puts("Test completed successfully");
  63. return 0;
  64. }