]>
Commit | Line | Data |
---|---|---|
c51d84dc KS |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2013 Lennart Poettering | |
5 | Copyright 2013 Kay Sievers | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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/>. | |
19 | ***/ | |
20 | ||
cf0fbc49 | 21 | #include "acpi-fpdt.h" |
c51d84dc KS |
22 | #include "boot-timestamps.h" |
23 | #include "efivars.h" | |
cf0fbc49 TA |
24 | #include "log.h" |
25 | #include "util.h" | |
c51d84dc KS |
26 | |
27 | static int test_acpi_fpdt(void) { | |
28 | usec_t loader_start; | |
29 | usec_t loader_exit; | |
30 | char ts_start[FORMAT_TIMESPAN_MAX]; | |
31 | char ts_exit[FORMAT_TIMESPAN_MAX]; | |
32 | char ts_span[FORMAT_TIMESPAN_MAX]; | |
33 | int r; | |
34 | ||
35 | r = acpi_get_boot_usec(&loader_start, &loader_exit); | |
36 | if (r < 0) { | |
67a47c60 | 37 | bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES) || r == -ENODATA; |
a4bfedec ZJS |
38 | |
39 | log_full_errno(ok ? LOG_DEBUG : LOG_ERR, | |
40 | r, "Failed to read ACPI FPDT: %m"); | |
41 | return ok ? 0 : r; | |
c51d84dc KS |
42 | } |
43 | ||
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)); | |
a4bfedec | 48 | return 1; |
c51d84dc KS |
49 | } |
50 | ||
51 | static int test_efi_loader(void) { | |
52 | usec_t loader_start; | |
53 | usec_t loader_exit; | |
54 | char ts_start[FORMAT_TIMESPAN_MAX]; | |
55 | char ts_exit[FORMAT_TIMESPAN_MAX]; | |
56 | char ts_span[FORMAT_TIMESPAN_MAX]; | |
57 | int r; | |
58 | ||
59 | r = efi_loader_get_boot_usec(&loader_start, &loader_exit); | |
60 | if (r < 0) { | |
a4bfedec ZJS |
61 | bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); |
62 | ||
63 | log_full_errno(ok ? LOG_DEBUG : LOG_ERR, | |
64 | r, "Failed to read EFI loader data: %m"); | |
65 | return ok ? 0 : r; | |
c51d84dc KS |
66 | } |
67 | ||
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)); | |
a4bfedec | 72 | return 1; |
c51d84dc KS |
73 | } |
74 | ||
a4bfedec | 75 | static int test_boot_timestamps(void) { |
c51d84dc KS |
76 | char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)]; |
77 | int r; | |
78 | dual_timestamp fw, l, k; | |
79 | ||
c51d84dc KS |
80 | dual_timestamp_from_monotonic(&k, 0); |
81 | ||
82 | r = boot_timestamps(NULL, &fw, &l); | |
83 | if (r < 0) { | |
a4bfedec ZJS |
84 | bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); |
85 | ||
86 | log_full_errno(ok ? LOG_DEBUG : LOG_ERR, | |
87 | r, "Failed to read variables: %m"); | |
88 | return ok ? 0 : r; | |
c51d84dc KS |
89 | } |
90 | ||
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)); | |
a4bfedec ZJS |
96 | return 1; |
97 | } | |
98 | ||
99 | int main(int argc, char* argv[]) { | |
100 | int p, q, r; | |
101 | ||
102 | log_set_max_level(LOG_DEBUG); | |
103 | log_parse_environment(); | |
104 | ||
105 | p = test_acpi_fpdt(); | |
106 | assert(p >= 0); | |
107 | q = test_efi_loader(); | |
108 | assert(q >= 0); | |
109 | r = test_boot_timestamps(); | |
110 | assert(r >= 0); | |
c51d84dc | 111 | |
a4bfedec | 112 | return (p > 0 || q > 0 || r >> 0) ? EXIT_SUCCESS : EXIT_TEST_SKIP; |
c51d84dc | 113 | } |