summaryrefslogtreecommitdiff
path: root/test/redfish-core/include/journal_read_state.cpp
blob: 4d4f90da0da3c1228d312e319e0790976603c287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include "utils/journal_read_state.hpp"

#include "utils/journal_utils.hpp"

#include <optional>
#include <string>

#include <gtest/gtest.h>

namespace redfish
{

namespace
{

// The journald filesystem format is documented here:
// https://systemd.io/JOURNAL_FILE_FORMAT/

TEST(JournalReadState, TestDataFile)
{
    std::string journalFile(TEST_DATA_DIR "/vacuum.journal");
    std::optional<JournalReadState> state =
        JournalReadState::openFile(journalFile);
    ASSERT_TRUE(state);
    if (!state)
    {
        return;
    }
    ASSERT_EQ(state->next(), 1);

    // Note, this is technically opaque, so if it changes in the future
    EXPECT_EQ(state->getCursor(),
              "s=bf184a6f61fc4619886c6a7c63681ec8;"
              "i=120f;"
              "b=6b5b037894684e1fb93498a9469c8f79;"
              "m=788287f6;t=63649492fb873;"
              "x=d7680905cd14f13b");
    EXPECT_EQ(state->getRealtimeUsec(), 1748538248640627);
    EXPECT_EQ(
        state->getData("MESSAGE"),
        "Runtime Journal (/run/log/journal/95ea7c5055094ceb88078b3efa71d2d0) is 8M, max 64M, 56M free.");
    EXPECT_EQ(getJournalMetadataInt(*state, "PRIORITY"), 6);

    ASSERT_EQ(state->next(), 1);
    EXPECT_EQ(state->getCursor(),
              "s=bf184a6f61fc4619886c6a7c63681ec8;"
              "i=1210;b=6b5b037894684e1fb93498a9469c8f79;"
              "m=7882f714;t=63649493027a3;"
              "x=fbf01ac34e1fade");
    EXPECT_EQ(state->getRealtimeUsec(), 1748538248669091);
    EXPECT_EQ(state->getData("MESSAGE"),
              "Received client request to rotate journal, rotating.");
    EXPECT_EQ(getJournalMetadataInt(*state, "PRIORITY"), 6);
}
} // namespace
} // namespace redfish