1 /**
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  */
16 #include "extensions/openpower-pels/log_id.hpp"
17 #include "extensions/openpower-pels/paths.hpp"
18 
19 #include <arpa/inet.h>
20 
21 #include <filesystem>
22 
23 #include <gtest/gtest.h>
24 
25 using namespace openpower::pels;
26 namespace fs = std::filesystem;
27 
28 TEST(LogIdTest, TimeBasedIDTest)
29 {
30     uint32_t lastID = 0;
31     for (int i = 0; i < 10; i++)
32     {
33         auto id = detail::getTimeBasedLogID();
34 
35         EXPECT_EQ(id & 0xFF000000, 0x50000000);
36         EXPECT_NE(id, lastID);
37         lastID = id;
38     }
39 }
40 
41 TEST(LogIdTest, IDTest)
42 {
43     EXPECT_EQ(generatePELID(), 0x50000001);
44     EXPECT_EQ(generatePELID(), 0x50000002);
45     EXPECT_EQ(generatePELID(), 0x50000003);
46     EXPECT_EQ(generatePELID(), 0x50000004);
47     EXPECT_EQ(generatePELID(), 0x50000005);
48     EXPECT_EQ(generatePELID(), 0x50000006);
49 
50     auto backingFile = getPELIDFile();
51     fs::remove(backingFile);
52     EXPECT_EQ(generatePELID(), 0x50000001);
53     EXPECT_EQ(generatePELID(), 0x50000002);
54     EXPECT_EQ(generatePELID(), 0x50000003);
55 
56     fs::remove_all(fs::path{backingFile}.parent_path());
57 }
58