Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / test-gettimebasefreq.c
blobe1b305ac9af5d77d6ebe42b89f6e5cf49094a9f8
1 /* Check __ppc_get_timebase_freq() for architecture changes
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* Test if __ppc_get_timebase_freq() works and is different from zero. A read
20 failure might indicate a Linux Kernel change.
21 This test also use the frequency to compute the real elapsed time. */
23 #include <inttypes.h>
24 #include <stdio.h>
25 #include <stdint.h>
27 #include <sys/platform/ppc.h>
29 /* Maximum value of the Time Base Register: 2^60 - 1. */
30 #define MAX_TB 0xFFFFFFFFFFFFFFF
32 static int
33 do_test (void)
35 uint64_t t1, t2, f, diff;
37 t1 = __ppc_get_timebase ();
38 printf ("t1 = %"PRIu64"\n", t1);
40 f = __ppc_get_timebase_freq ();
41 printf ("Time Base frequency = %"PRIu64" Hz\n", f);
43 if (f == 0) {
44 printf ("Fail: The time base frequency can't be zero.\n");
45 return 1;
48 t2 = __ppc_get_timebase ();
49 printf ("t2 = %"PRIu64"\n", t2);
51 if (t2 > t1) {
52 diff = t2 - t1;
53 } else {
54 diff = (MAX_TB - t2) + t1;
57 printf ("Elapsed time = %1.2f usecs\n", (double) diff * 1000000 / f );
59 return 0;
62 #define TEST_FUNCTION do_test ()
63 #include "../test-skeleton.c"