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 <chrono> 22 #include <filesystem> 23 #include <thread> 24 25 #include <gtest/gtest.h> 26 27 using namespace openpower::pels; 28 namespace fs = std::filesystem; 29 30 TEST(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; 40 std::this_thread::sleep_for(std::chrono::milliseconds(1)); 41 } 42 } 43 44 TEST(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 } 61