blob: bbcd5f12499d10dce090174474f0fa34f32a22b0 [file] [log] [blame]
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +09301#pragma once
2
Andrew Jeffery2abbce72023-10-18 10:17:35 +10303#include "common/instance_id.hpp"
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +09304
5static constexpr uintmax_t pldmMaxInstanceIds = 32;
6
7class TestInstanceIdDb : public pldm::InstanceIdDb
8{
9 public:
10 TestInstanceIdDb() : TestInstanceIdDb(createDb()) {}
11
12 ~TestInstanceIdDb()
13 {
14 std::filesystem::remove(dbPath);
15 };
16
17 private:
18 static std::filesystem::path createDb()
19 {
20 static const char dbTmpl[] = "/tmp/db.XXXXXX";
21 char dbName[sizeof(dbTmpl)] = {};
22
23 ::strncpy(dbName, dbTmpl, sizeof(dbName));
24 ::close(::mkstemp(dbName));
25
26 std::filesystem::path dbPath(dbName);
27 std::filesystem::resize_file(
28 dbPath, static_cast<uintmax_t>(PLDM_MAX_TIDS) * pldmMaxInstanceIds);
29
30 return dbPath;
31 };
32
33 TestInstanceIdDb(std::filesystem::path dbPath) :
34 InstanceIdDb(dbPath), dbPath(dbPath)
35 {}
36
37 std::filesystem::path dbPath;
38};