2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
21 // Internal headers are allowed here
23 #include <dali/internal/common/fixed-size-memory-pool.h>
27 void utc_dali_internal_fixedsizememorypool_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_internal_fixedsizememorypool_cleanup(void)
34 test_return_value = TET_PASS;
39 unsigned int gTestObjectConstructed = 0;
40 unsigned int gTestObjectDestructed = 0;
41 unsigned int gTestObjectMethod = 0;
42 unsigned int gTestObjectDataAccess = 0;
53 gTestObjectConstructed++;
58 gTestObjectDestructed++;
71 gTestObjectDataAccess++;
79 int UtcDaliFixedSizeMemoryPoolCreate(void)
81 gTestObjectConstructed = 0;
82 gTestObjectDestructed = 0;
83 gTestObjectMethod = 0;
84 gTestObjectDataAccess = 0;
86 Internal::FixedSizeMemoryPool memoryPool(Internal::TypeSizeWithAlignment<TestObject>::size);
88 TestObject* testObject1 = new(memoryPool.Allocate()) TestObject();
89 DALI_TEST_CHECK(testObject1);
90 DALI_TEST_EQUALS(gTestObjectConstructed, 1U, TEST_LOCATION);
92 testObject1->Method();
93 DALI_TEST_EQUALS(gTestObjectMethod, 1U, TEST_LOCATION);
95 testObject1->DataAccess();
96 DALI_TEST_EQUALS(gTestObjectDataAccess, 1U, TEST_LOCATION);
98 testObject1->~TestObject();
99 memoryPool.Free(testObject1);
100 DALI_TEST_EQUALS(gTestObjectDestructed, 1U, TEST_LOCATION);
105 int UtcDaliFixedSizeMemoryPoolStressTest(void)
107 gTestObjectConstructed = 0;
108 gTestObjectDestructed = 0;
109 gTestObjectMethod = 0;
110 gTestObjectDataAccess = 0;
112 const size_t initialCapacity = 32;
113 const size_t maximumCapacity = 1024;
115 const unsigned int numObjects = 1024 * 1024;
117 Internal::FixedSizeMemoryPool memoryPool(Internal::TypeSizeWithAlignment<TestObject>::size, initialCapacity, maximumCapacity);
119 Dali::Vector<TestObject*> objects;
120 objects.Reserve(numObjects);
122 for(unsigned int i = 0; i < numObjects; ++i)
124 TestObject* testObject = new(memoryPool.Allocate()) TestObject();
125 DALI_TEST_CHECK(testObject);
127 objects.PushBack(testObject);
130 DALI_TEST_EQUALS(gTestObjectConstructed, numObjects, TEST_LOCATION);
132 for(unsigned int i = 0; i < numObjects; ++i)
134 objects[i]->~TestObject();
135 memoryPool.Free(objects[i]);
138 DALI_TEST_EQUALS(gTestObjectDestructed, numObjects, TEST_LOCATION);