Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / test-gettimebasefreq.c
blob779ea49c8e008f7f400bec1118653c4354ce18da
1 /* Check __ppc_get_timebase_freq() for architecture changes
2 Copyright (C) 2012-2013 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>
26 #include <sys/platform/ppc.h>
28 /* Maximum value of the Time Base Register: 2^60 - 1. */
29 #define MAX_TB 0xFFFFFFFFFFFFFFF
31 static int
32 do_test (void)
34 uint64_t t1, t2, f, diff;
36 t1 = __ppc_get_timebase ();
37 printf ("t1 = %"PRIu64"\n", t1);
39 f = __ppc_get_timebase_freq ();
40 printf ("Time Base frequency = %"PRIu64" Hz\n", f);
42 if (f == 0) {
43 printf ("Fail: The time base frequency can't be zero.");
44 return 1;
47 t2 = __ppc_get_timebase ();
48 printf ("t2 = %"PRIu64"\n", t2);
50 if (t2 > t1) {
51 diff = t2 - t1;
52 } else {
53 diff = (MAX_TB - t2) + t1;
56 printf ("Elapsed time = %1.2f usecs\n", (double) diff * 1000000 / f );
58 return 0;
61 #define TEST_FUNCTION do_test ()
62 #include "../test-skeleton.c"