1/* Support code for timespec checks.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <support/timespec.h>
20#include <stdio.h>
21#include <stdint.h>
22
23void
24test_timespec_before_impl (const char *file, int line,
25 const struct timespec left,
26 const struct timespec right)
27{
28 if (left.tv_sec > right.tv_sec
29 || (left.tv_sec == right.tv_sec
30 && left.tv_nsec > right.tv_nsec)) {
31 support_record_failure ();
32 const struct timespec diff = timespec_sub (left, right);
33 printf ("%s:%d: %jd.%09jds not before %jd.%09jds "
34 "(difference %jd.%09jds)\n",
35 file, line,
36 (intmax_t) left.tv_sec, (intmax_t) left.tv_nsec,
37 (intmax_t) right.tv_sec, (intmax_t) right.tv_nsec,
38 (intmax_t) diff.tv_sec, (intmax_t) diff.tv_nsec);
39 }
40}
41
42void
43test_timespec_equal_or_after_impl (const char *file, int line,
44 const struct timespec left,
45 const struct timespec right)
46{
47 if (left.tv_sec < right.tv_sec
48 || (left.tv_sec == right.tv_sec
49 && left.tv_nsec < right.tv_nsec)) {
50 support_record_failure ();
51 const struct timespec diff = timespec_sub (right, left);
52 printf ("%s:%d: %jd.%09jds not after %jd.%09jds "
53 "(difference %jd.%09jds)\n",
54 file, line,
55 (intmax_t) left.tv_sec, (intmax_t) left.tv_nsec,
56 (intmax_t) right.tv_sec, (intmax_t) right.tv_nsec,
57 (intmax_t) diff.tv_sec, (intmax_t) diff.tv_nsec);
58 }
59}
60