Mercurial > hg > octave-kai > gnulib-hg
annotate tests/test-times.c @ 17476:6057744acd2c default tip master
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Fri, 16 Aug 2013 06:32:22 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
10736
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* Test of times function. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. |
10736
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
3 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
16 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 /* Written by Simon Josefsson <simon@josefsson.org>, 2008. */ |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
18 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 #include <config.h> |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
20 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
21 #include <sys/times.h> |
12489 | 22 |
23 #include "signature.h" | |
24 SIGNATURE_CHECK (times, clock_t, (struct tms *)); | |
25 | |
10736
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 #include <stdio.h> |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 #include <stdlib.h> |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
28 #include <stdint.h> |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
29 #include <unistd.h> |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
30 #include <math.h> |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 static int |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 doublecmp (const void *p, const void *q) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
34 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
35 double a = *(double *) p; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
36 double b = *(double *) q; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 return a < b; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 } |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
40 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 int |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
42 main (int argc, char *argv[]) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
43 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 struct tms tms; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 clock_t t; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
46 #ifndef _SC_CLK_TCK |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 clock_t clk_tck = CLK_TCK; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
48 #else |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 clock_t clk_tck = sysconf (_SC_CLK_TCK); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
50 #endif |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
51 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
52 t = times (&tms); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
53 if (t == (clock_t) -1) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
54 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
55 perror ("times"); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
56 return EXIT_FAILURE; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
57 } |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
58 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
59 if (argc > 1) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
60 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
61 printf ("clk_tck %ld\n", (long int) clk_tck); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
62 |
14040
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
63 printf ("t %ld\n", (long int) t); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
64 printf ("tms.tms_utime %ldms\n", ((long int) tms.tms_utime * 1000) / clk_tck); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
65 printf ("tms.tms_stime %ldms\n", ((long int) tms.tms_stime * 1000) / clk_tck); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
66 printf ("tms.tms_cutime %ldms\n", ((long int) tms.tms_cutime * 1000) / clk_tck); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
67 printf ("tms.tms_cstime %ldms\n", ((long int) tms.tms_cstime * 1000) / clk_tck); |
10736
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
68 } |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
69 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
70 if (argc > 1) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
71 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
72 size_t size = atoi (argv[1]); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
73 double *base; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
74 size_t i; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
75 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
76 base = malloc (size * sizeof (double)); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
77 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
78 for (i = 0; i < size; i++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10736
diff
changeset
|
79 base[i] = i * i; |
10736
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
80 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
81 qsort (base, size, sizeof (double), doublecmp); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
82 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
83 free (base); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
84 } |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
85 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
86 t = times (&tms); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
87 if (t == (clock_t) -1) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
88 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
89 perror ("times"); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
90 return EXIT_FAILURE; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
91 } |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
92 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
93 if (argc > 1) |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
94 { |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
95 printf ("clk_tck %ld\n", (long int) clk_tck); |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
96 |
14040
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
97 printf ("t %ld\n", (long int) t); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
98 printf ("tms.tms_utime %ldms\n", ((long int) tms.tms_utime * 1000) / clk_tck); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
99 printf ("tms.tms_stime %ldms\n", ((long int) tms.tms_stime * 1000) / clk_tck); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
100 printf ("tms.tms_cutime %ldms\n", ((long int) tms.tms_cutime * 1000) / clk_tck); |
6beda9a0e57a
times test: Avoid gcc warnings on OSF/1.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
101 printf ("tms.tms_cstime %ldms\n", ((long int) tms.tms_cstime * 1000) / clk_tck); |
10736
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
102 } |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
103 |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
104 return 0; |
0a0a6357e314
Add files missing from last commit.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
105 } |