blob: 6979e56e3b7e61799c05ee5772fcf1ef5fa977c5 [file] [log] [blame]
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +09301#pragma once
2
3#include "instance_id.hpp"
4
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};