]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-boot-timestamps.c
2 This file is part of systemd.
4 Copyright 2013 Lennart Poettering
5 Copyright 2013 Kay Sievers
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include "acpi-fpdt.h"
22 #include "boot-timestamps.h"
27 static int test_acpi_fpdt(void) {
30 char ts_start
[FORMAT_TIMESPAN_MAX
];
31 char ts_exit
[FORMAT_TIMESPAN_MAX
];
32 char ts_span
[FORMAT_TIMESPAN_MAX
];
35 r
= acpi_get_boot_usec(&loader_start
, &loader_exit
);
37 bool ok
= r
== -ENOENT
|| (getuid() != 0 && r
== -EACCES
) || r
== -ENODATA
;
39 log_full_errno(ok
? LOG_DEBUG
: LOG_ERR
,
40 r
, "Failed to read ACPI FPDT: %m");
44 log_info("ACPI FPDT: loader start=%s exit=%s duration=%s",
45 format_timespan(ts_start
, sizeof(ts_start
), loader_start
, USEC_PER_MSEC
),
46 format_timespan(ts_exit
, sizeof(ts_exit
), loader_exit
, USEC_PER_MSEC
),
47 format_timespan(ts_span
, sizeof(ts_span
), loader_exit
- loader_start
, USEC_PER_MSEC
));
51 static int test_efi_loader(void) {
54 char ts_start
[FORMAT_TIMESPAN_MAX
];
55 char ts_exit
[FORMAT_TIMESPAN_MAX
];
56 char ts_span
[FORMAT_TIMESPAN_MAX
];
59 r
= efi_loader_get_boot_usec(&loader_start
, &loader_exit
);
61 bool ok
= r
== -ENOENT
|| (getuid() != 0 && r
== -EACCES
);
63 log_full_errno(ok
? LOG_DEBUG
: LOG_ERR
,
64 r
, "Failed to read EFI loader data: %m");
68 log_info("EFI Loader: start=%s exit=%s duration=%s",
69 format_timespan(ts_start
, sizeof(ts_start
), loader_start
, USEC_PER_MSEC
),
70 format_timespan(ts_exit
, sizeof(ts_exit
), loader_exit
, USEC_PER_MSEC
),
71 format_timespan(ts_span
, sizeof(ts_span
), loader_exit
- loader_start
, USEC_PER_MSEC
));
75 static int test_boot_timestamps(void) {
76 char s
[MAX(FORMAT_TIMESPAN_MAX
, FORMAT_TIMESTAMP_MAX
)];
78 dual_timestamp fw
, l
, k
;
80 dual_timestamp_from_monotonic(&k
, 0);
82 r
= boot_timestamps(NULL
, &fw
, &l
);
84 bool ok
= r
== -ENOENT
|| (getuid() != 0 && r
== -EACCES
);
86 log_full_errno(ok
? LOG_DEBUG
: LOG_ERR
,
87 r
, "Failed to read variables: %m");
91 log_info("Firmware began %s before kernel.", format_timespan(s
, sizeof(s
), fw
.monotonic
, 0));
92 log_info("Loader began %s before kernel.", format_timespan(s
, sizeof(s
), l
.monotonic
, 0));
93 log_info("Firmware began %s.", format_timestamp(s
, sizeof(s
), fw
.realtime
));
94 log_info("Loader began %s.", format_timestamp(s
, sizeof(s
), l
.realtime
));
95 log_info("Kernel began %s.", format_timestamp(s
, sizeof(s
), k
.realtime
));
99 int main(int argc
, char* argv
[]) {
102 log_set_max_level(LOG_DEBUG
);
103 log_parse_environment();
105 p
= test_acpi_fpdt();
107 q
= test_efi_loader();
109 r
= test_boot_timestamps();
112 return (p
> 0 || q
> 0 || r
>> 0) ? EXIT_SUCCESS
: EXIT_TEST_SKIP
;