@@ -48,12 +48,6 @@ constexpr std::uint8_t kDeleteEntryFailed = 0x1;
4848constexpr std::uint8_t kExistEntryNotExist = 0x0 ;
4949constexpr std::uint8_t kExistEntryExist = 0x1 ;
5050
51- std::filesystem::path StoreRoot (const FakeBackendConfig& config)
52- {
53- if (!config.storePath .empty ()) { return config.storePath ; }
54- return " ./asu-fake-backend-store" ;
55- }
56-
5751std::uint64_t ReadU64 (std::uint32_t low, std::uint32_t high)
5852{
5953 return static_cast <std::uint64_t >(low) | (static_cast <std::uint64_t >(high) << 32 );
@@ -89,17 +83,18 @@ std::string KeyFileName(const std::string& key)
8983 return stream.str ();
9084}
9185
92- std::filesystem::path AsuRoot (const FakeBackendConfig & config, AsuId asuId)
86+ std::filesystem::path AsuRoot (const FakeTransProviderConfig & config, AsuId asuId)
9387{
94- return StoreRoot (config) / (" asu-" + std::to_string (asuId));
88+ return std::filesystem::path (config. storePath ) / (" asu-" + std::to_string (asuId));
9589}
9690
97- std::filesystem::path KeyPath (const FakeBackendConfig& config, AsuId asuId, const std::string& key)
91+ std::filesystem::path KeyPath (const FakeTransProviderConfig& config, AsuId asuId,
92+ const std::string& key)
9893{
9994 return AsuRoot (config, asuId) / KeyFileName (key);
10095}
10196
102- bool StoreBytes (const FakeBackendConfig & config, AsuId asuId, const std::string& key,
97+ bool StoreBytes (const FakeTransProviderConfig & config, AsuId asuId, const std::string& key,
10398 std::uint64_t addr, std::uint32_t length)
10499{
105100 std::vector<char > buffer (length);
@@ -124,7 +119,7 @@ bool StoreBytes(const FakeBackendConfig& config, AsuId asuId, const std::string&
124119 return output.good ();
125120}
126121
127- bool LoadBytes (const FakeBackendConfig & config, AsuId asuId, const std::string& key,
122+ bool LoadBytes (const FakeTransProviderConfig & config, AsuId asuId, const std::string& key,
128123 std::uint64_t addr, std::uint32_t length)
129124{
130125 std::ifstream input (KeyPath (config, asuId, key), std::ios::binary);
@@ -151,14 +146,14 @@ bool LoadBytes(const FakeBackendConfig& config, AsuId asuId, const std::string&
151146 return true ;
152147}
153148
154- bool DeleteKey (const FakeBackendConfig & config, AsuId asuId, const std::string& key)
149+ bool DeleteKey (const FakeTransProviderConfig & config, AsuId asuId, const std::string& key)
155150{
156151 std::error_code errorCode;
157152 std::filesystem::remove (KeyPath (config, asuId, key), errorCode);
158153 return !errorCode;
159154}
160155
161- bool ExistsKey (const FakeBackendConfig & config, AsuId asuId, const std::string& key)
156+ bool ExistsKey (const FakeTransProviderConfig & config, AsuId asuId, const std::string& key)
162157{
163158 std::error_code errorCode;
164159 return std::filesystem::exists (KeyPath (config, asuId, key), errorCode);
@@ -223,7 +218,7 @@ std::vector<std::string> ReadKeyEntries(const std::uint32_t* request, std::uint1
223218 return keys;
224219}
225220
226- Status CompleteBatchStore (const FakeBackendConfig & config, AsuId asuId,
221+ Status CompleteBatchStore (const FakeTransProviderConfig & config, AsuId asuId,
227222 const std::uint32_t * request)
228223{
229224 const auto cid = static_cast <std::uint16_t >(RequestCid (request));
@@ -248,7 +243,7 @@ Status CompleteBatchStore(const FakeBackendConfig& config, AsuId asuId,
248243 return Status::OK ();
249244}
250245
251- Status CompleteBatchRetrieve (const FakeBackendConfig & config, AsuId asuId,
246+ Status CompleteBatchRetrieve (const FakeTransProviderConfig & config, AsuId asuId,
252247 const std::uint32_t * request)
253248{
254249 const auto cid = static_cast <std::uint16_t >(RequestCid (request));
@@ -273,7 +268,8 @@ Status CompleteBatchRetrieve(const FakeBackendConfig& config, AsuId asuId,
273268 return Status::OK ();
274269}
275270
276- Status CompleteDelete (const FakeBackendConfig& config, AsuId asuId, const std::uint32_t * request)
271+ Status CompleteDelete (const FakeTransProviderConfig& config, AsuId asuId,
272+ const std::uint32_t * request)
277273{
278274 const auto cid = static_cast <std::uint16_t >(RequestCid (request));
279275 const auto responseBufferAddr = ReadU64 (request[3 ], request[4 ]);
@@ -294,7 +290,8 @@ Status CompleteDelete(const FakeBackendConfig& config, AsuId asuId, const std::u
294290 return Status::OK ();
295291}
296292
297- Status CompleteExist (const FakeBackendConfig& config, AsuId asuId, const std::uint32_t * request)
293+ Status CompleteExist (const FakeTransProviderConfig& config, AsuId asuId,
294+ const std::uint32_t * request)
298295{
299296 const auto cid = static_cast <std::uint16_t >(RequestCid (request));
300297 const auto responseBufferAddr = ReadU64 (request[3 ], request[4 ]);
@@ -319,7 +316,7 @@ Status CompleteExist(const FakeBackendConfig& config, AsuId asuId, const std::ui
319316 return Status::OK ();
320317}
321318
322- Status CompleteFakeBackendRequest (FakeBackendConfig config, const void * sendBuffer,
319+ Status CompleteFakeBackendRequest (const FakeTransProviderConfig& config, const void * sendBuffer,
323320 std::uint64_t len)
324321{
325322 if (config.latencyMs > 0 ) {
@@ -350,12 +347,14 @@ Status CompleteFakeBackendRequest(FakeBackendConfig config, const void* sendBuff
350347
351348} // namespace
352349
353- FakeBackendConfig MakeFakeBackendConfig (const TransportConfig& config)
350+ FakeTransProviderConfig MakeFakeTransProviderConfig (const TransportConfig& config)
354351{
355- FakeBackendConfig fakeConfig;
352+ FakeTransProviderConfig fakeConfig;
356353 fakeConfig.deviceId = config.endpoints .empty () ? 0 : config.endpoints .front ().deviceId ;
357354 auto pathIter = config.attrs .find (" fake_backend.path" );
358- if (pathIter != config.attrs .end ()) { fakeConfig.storePath = pathIter->second ; }
355+ if (pathIter != config.attrs .end () && !pathIter->second .empty ()) {
356+ fakeConfig.storePath = pathIter->second ;
357+ }
359358 auto latencyIter = config.attrs .find (" fake_backend.latency_ms" );
360359 if (latencyIter != config.attrs .end ()) {
361360 fakeConfig.latencyMs = static_cast <std::uint64_t >(std::stoull (latencyIter->second ));
@@ -364,14 +363,10 @@ FakeBackendConfig MakeFakeBackendConfig(const TransportConfig& config)
364363 if (deviceIter != config.attrs .end ()) {
365364 fakeConfig.deviceId = static_cast <std::int32_t >(std::stol (deviceIter->second ));
366365 }
367- if (fakeConfig.storePath .empty ()) { fakeConfig.storePath = " ./asu-fake-backend-store" ; }
368366 return fakeConfig;
369367}
370368
371- FakeTransProvider::FakeTransProvider (FakeBackendConfig config) : config_(std::move(config))
372- {
373- if (config_.storePath .empty ()) { config_.storePath = " ./asu-fake-backend-store" ; }
374- }
369+ FakeTransProvider::FakeTransProvider (FakeTransProviderConfig config) : config_(std::move(config)) {}
375370
376371Status FakeTransProvider::SetUpAclRuntime ()
377372{
0 commit comments