tst-clockid.c 924 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (C) 2017 Sergey Korolev <s.korolev@ndmsystems.com>
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. #include <time.h>
  6. #include <errno.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <pthread.h>
  10. int do_test (void)
  11. {
  12. clockid_t clk;
  13. struct timespec ts;
  14. const int err = pthread_getcpuclockid(pthread_self(), &clk);
  15. if (err != 0) {
  16. errno = err;
  17. perror("pthread_getcpuclockid");
  18. return EXIT_FAILURE;
  19. }
  20. if (clock_gettime(clk, &ts) == -1) {
  21. perror("clock_gettime");
  22. return EXIT_FAILURE;
  23. }
  24. printf("Thread time is %lu.%06lu.\n",
  25. ts.tv_sec,
  26. ts.tv_nsec / 1000);
  27. return EXIT_SUCCESS;
  28. }
  29. #define TEST_FUNCTION do_test ()
  30. #include "../test-skeleton.c"