blob: 7167dd7b3e931dc9efb3e75c9d2df6b6ff9ec368 [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinlerdf13bdb2019-07-10 16:54:13 -050016#include "extensions/openpower-pels/log_id.hpp"
17#include "extensions/openpower-pels/paths.hpp"
18
19#include <arpa/inet.h>
20
Andrew Geissler620ef382020-06-16 14:52:14 -050021#include <chrono>
Matt Spinlerdf13bdb2019-07-10 16:54:13 -050022#include <filesystem>
Andrew Geissler620ef382020-06-16 14:52:14 -050023#include <thread>
Matt Spinlerdf13bdb2019-07-10 16:54:13 -050024
25#include <gtest/gtest.h>
26
27using namespace openpower::pels;
28namespace fs = std::filesystem;
29
30TEST(LogIdTest, TimeBasedIDTest)
31{
32 uint32_t lastID = 0;
33 for (int i = 0; i < 10; i++)
34 {
35 auto id = detail::getTimeBasedLogID();
36
37 EXPECT_EQ(id & 0xFF000000, 0x50000000);
38 EXPECT_NE(id, lastID);
39 lastID = id;
Andrew Geissler620ef382020-06-16 14:52:14 -050040 std::this_thread::sleep_for(std::chrono::milliseconds(1));
Matt Spinlerdf13bdb2019-07-10 16:54:13 -050041 }
42}
43
44TEST(LogIdTest, IDTest)
45{
46 EXPECT_EQ(generatePELID(), 0x50000001);
47 EXPECT_EQ(generatePELID(), 0x50000002);
48 EXPECT_EQ(generatePELID(), 0x50000003);
49 EXPECT_EQ(generatePELID(), 0x50000004);
50 EXPECT_EQ(generatePELID(), 0x50000005);
51 EXPECT_EQ(generatePELID(), 0x50000006);
52
53 auto backingFile = getPELIDFile();
54 fs::remove(backingFile);
55 EXPECT_EQ(generatePELID(), 0x50000001);
56 EXPECT_EQ(generatePELID(), 0x50000002);
57 EXPECT_EQ(generatePELID(), 0x50000003);
58
59 fs::remove_all(fs::path{backingFile}.parent_path());
60}