Browse Source

nptl: add new testcase for pthread_getcpuclockid()

Waldemar Brodkorb 7 years ago
parent
commit
115d20fe89
2 changed files with 40 additions and 3 deletions
  1. 3 3
      test/nptl/Makefile.in
  2. 37 0
      test/nptl/tst-clockid.c

+ 3 - 3
test/nptl/Makefile.in

@@ -48,8 +48,8 @@ TESTS := tst-align tst-align2 tst-atfork1 tst-attr1 tst-attr2 tst-attr3	\
 	tst-signal5 tst-signal6 tst-spin1 tst-spin2 tst-spin3		\
 	tst-stack1 tst-stack2 tst-stdio1 tst-stdio2 tst-sysconf		\
 	tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tsd1 tst-tsd2	\
-	tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 tst-cond-deadlock \
-	tst-align3 tst-cancel4 tst-cancel5 tst-cancel18 tst-cancel23 \
+	tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 tst-cond-deadlock 	\
+	tst-align3 tst-cancel4 tst-cancel5 tst-cancel18 tst-cancel23	\
 	tst-cancel25 tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx6 \
 	tst-cancelx7 tst-cancelx8 tst-cancelx9 tst-cancelx10 tst-cancelx11 \
 	tst-cancelx12 tst-cancelx13 tst-cancelx14 tst-cancelx15 tst-cancelx16 \
@@ -60,7 +60,7 @@ TESTS := tst-align tst-align2 tst-atfork1 tst-attr1 tst-attr2 tst-attr3	\
 	tst-basic7 tst-signal7 tst-vfork1x tst-vfork2x tst-sem10 tst-sem11 \
 	tst-sem12 tst-initializers1-c89 tst-initializers1-c99 \
 	tst-initializers1-gnu89 tst-initializers1-gnu99 \
-	tst-atfork2
+	tst-atfork2 tst-clockid
 
 #
 # These are for the RT library and POSIX timers.

+ 37 - 0
test/nptl/tst-clockid.c

@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 Sergey Korolev <s.korolev@ndmsystems.com>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <time.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+int do_test (void)
+{
+    clockid_t clk;
+    struct timespec ts;
+    const int err = pthread_getcpuclockid(pthread_self(), &clk);
+
+    if (err != 0) {
+        errno = err;
+        perror("pthread_getcpuclockid");
+        return EXIT_FAILURE;
+    }
+
+    if (clock_gettime(clk, &ts) == -1) {
+        perror("clock_gettime");
+        return EXIT_FAILURE;
+    }                                                                                                                                      
+
+    printf("Thread time is %lu.%06lu.\n",
+           ts.tv_sec,
+           ts.tv_nsec / 1000);
+
+    return EXIT_SUCCESS;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"