1+ /*
2+ * Copyright (c) Facebook, Inc. and its affiliates.
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+
17+ // Copyright 2022-present Facebook. All Rights Reserved.
18+
19+ #include < algorithm>
20+
21+ #include < gmock/gmock.h>
22+ #include < gtest/gtest.h>
23+
24+ #include " cachelib/cachebench/util/CacheConfig.h"
25+
26+ namespace facebook {
27+ namespace cachelib {
28+ namespace cachebench {
29+
30+ TEST (MemoryTierConfigTest, MemBind_SingleNumaNode) {
31+ const std::string configString =
32+ " {"
33+ " \" ratio\" : 1,"
34+ " \" memBindNodes\" : 1"
35+ " }" ;
36+
37+ const std::vector<size_t > expectedNumaNodes = {1 };
38+
39+ auto configJson = folly::parseJson (folly::json::stripComments (configString));
40+
41+ MemoryTierConfig memoryTierConfig (configJson);
42+ MemoryTierCacheConfig tierCacheConfig = memoryTierConfig.getMemoryTierCacheConfig ();
43+
44+ auto parsedNumaNodes = tierCacheConfig.getMemBind ();
45+ ASSERT_TRUE (std::equal (expectedNumaNodes.begin (), expectedNumaNodes.end (), parsedNumaNodes.begin ()));
46+ }
47+
48+ TEST (MemoryTierConfigTest, MemBind_RangeNumaNodes) {
49+ const std::string configString =
50+ " {"
51+ " \" ratio\" : 1,"
52+ " \" memBindNodes\" : \" 0-2\" "
53+ " }" ;
54+
55+ const std::vector<size_t > expectedNumaNodes = {0 , 1 , 2 };
56+
57+ auto configJson = folly::parseJson (folly::json::stripComments (configString));
58+
59+ MemoryTierConfig memoryTierConfig (configJson);
60+ MemoryTierCacheConfig tierCacheConfig = memoryTierConfig.getMemoryTierCacheConfig ();
61+
62+ auto parsedNumaNodes = tierCacheConfig.getMemBind ();
63+ ASSERT_TRUE (std::equal (expectedNumaNodes.begin (), expectedNumaNodes.end (), parsedNumaNodes.begin ()));
64+ }
65+
66+ TEST (MemoryTierConfigTest, MemBind_SingleAndRangeNumaNodes) {
67+ const std::string configString =
68+ " {"
69+ " \" ratio\" : 1,"
70+ " \" memBindNodes\" : \" 0,2-5\" "
71+ " }" ;
72+
73+ const std::vector<size_t > expectedNumaNodes = {0 , 2 , 3 , 4 , 5 };
74+
75+ auto configJson = folly::parseJson (folly::json::stripComments (configString));
76+
77+ MemoryTierConfig memoryTierConfig (configJson);
78+ MemoryTierCacheConfig tierCacheConfig = memoryTierConfig.getMemoryTierCacheConfig ();
79+
80+ auto parsedNumaNodes = tierCacheConfig.getMemBind ();
81+ ASSERT_TRUE (std::equal (expectedNumaNodes.begin (), expectedNumaNodes.end (), parsedNumaNodes.begin ()));
82+ }
83+
84+ } // namespace facebook
85+ } // namespace cachelib
86+ } // namespace cachebench
0 commit comments