blob: ece0b80a64f27eb7cdf251292c011984ad93e015 [file] [log] [blame]
Matt Spinler1e71a4d2020-03-04 13:40:22 -06001#include "config.h"
2
3#include "elog_entry.hpp"
4#include "elog_serialize.hpp"
5#include "log_manager.hpp"
6
7#include <filesystem>
8#include <thread>
9
10#include <gtest/gtest.h>
11
12namespace phosphor
13{
14namespace logging
15{
16namespace test
17{
18
19using namespace std::chrono_literals;
20
21// Test that the update timestamp changes when the resolved property changes
22TEST(TestUpdateTS, testChangeResolved)
23{
24 // Setting resolved will serialize, so need this directory.
25 std::filesystem::create_directory(ERRLOG_PERSIST_PATH);
26
27 auto bus = sdbusplus::bus::new_default();
28 phosphor::logging::internal::Manager manager(bus, OBJ_INTERNAL);
29
30 uint32_t id = 99;
31 uint64_t timestamp{100};
32 std::string message{"test error"};
33 std::string fwLevel{"level42"};
34 std::vector<std::string> testData{"additional", "data"};
35 phosphor::logging::AssociationList associations{};
36
37 Entry elog{bus,
38 std::string(OBJ_ENTRY) + '/' + std::to_string(id),
39 id,
40 timestamp,
41 Entry::Level::Informational,
42 std::move(message),
43 std::move(testData),
44 std::move(associations),
45 fwLevel,
46 manager};
47
48 EXPECT_EQ(elog.timestamp(), elog.updateTimestamp());
49
50 std::this_thread::sleep_for(1ms);
51
52 elog.resolved(true);
53 auto updateTS = elog.updateTimestamp();
54 EXPECT_NE(updateTS, elog.timestamp());
55
56 std::this_thread::sleep_for(1ms);
57
58 elog.resolved(false);
59 EXPECT_NE(updateTS, elog.updateTimestamp());
60 updateTS = elog.updateTimestamp();
61
62 std::this_thread::sleep_for(1ms);
63
64 // No change
65 elog.resolved(false);
66 EXPECT_EQ(updateTS, elog.updateTimestamp());
67
68 std::filesystem::remove_all(ERRLOG_PERSIST_PATH);
69}
70
71} // namespace test
72} // namespace logging
73} // namespace phosphor