]> git.proxmox.com Git - systemd.git/blame - src/test/test-boot-timestamps.c
Merge tag 'upstream/229'
[systemd.git] / src / test / test-boot-timestamps.c
CommitLineData
14228c0d
MB
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
db2df898 21#include "acpi-fpdt.h"
14228c0d
MB
22#include "boot-timestamps.h"
23#include "efivars.h"
db2df898
MP
24#include "log.h"
25#include "util.h"
14228c0d
MB
26
27static 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) {
37 if (r != -ENOENT)
f47781d8 38 log_error_errno(r, "Failed to read ACPI FPDT: %m");
14228c0d
MB
39 return r;
40 }
41
42 log_info("ACPI FPDT: loader start=%s exit=%s duration=%s",
43 format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
44 format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
45 format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
46
47 return 0;
48}
49
50static int test_efi_loader(void) {
51 usec_t loader_start;
52 usec_t loader_exit;
53 char ts_start[FORMAT_TIMESPAN_MAX];
54 char ts_exit[FORMAT_TIMESPAN_MAX];
55 char ts_span[FORMAT_TIMESPAN_MAX];
56 int r;
57
58 r = efi_loader_get_boot_usec(&loader_start, &loader_exit);
59 if (r < 0) {
60 if (r != -ENOENT)
f47781d8 61 log_error_errno(r, "Failed to read EFI loader data: %m");
14228c0d
MB
62 return r;
63 }
64
65 log_info("EFI Loader: start=%s exit=%s duration=%s",
66 format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
67 format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
68 format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
69
70 return 0;
71}
72
73int main(int argc, char* argv[]) {
74 char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)];
75 int r;
76 dual_timestamp fw, l, k;
77
78 test_acpi_fpdt();
79 test_efi_loader();
80
81 dual_timestamp_from_monotonic(&k, 0);
82
83 r = boot_timestamps(NULL, &fw, &l);
84 if (r < 0) {
f47781d8 85 log_error_errno(r, "Failed to read variables: %m");
14228c0d
MB
86 return 1;
87 }
88
89 log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0));
90 log_info("Loader began %s before kernel.", format_timespan(s, sizeof(s), l.monotonic, 0));
91 log_info("Firmware began %s.", format_timestamp(s, sizeof(s), fw.realtime));
92 log_info("Loader began %s.", format_timestamp(s, sizeof(s), l.realtime));
93 log_info("Kernel began %s.", format_timestamp(s, sizeof(s), k.realtime));
94
95 return 0;
96}