Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/gridtools/sid/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ namespace gridtools {
template <class LazyT>
friend auto allocate(allocator &self, LazyT, size_t size) {
using type = typename LazyT::type;
auto ptr = self.m_impl(sizeof(type) * size);
self.m_buffers.push_back(self.m_impl(sizeof(type) * size));
return simple_ptr_holder(reinterpret_cast<type *>(self.m_buffers.back().get()));
}
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/sid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
gridtools_add_unit_test(test_sid_allocator SOURCES test_sid_allocator.cpp)
gridtools_add_unit_test(test_sid_as_const SOURCES test_sid_as_const.cpp)
gridtools_add_unit_test(test_sid_block SOURCES test_sid_block.cpp)
gridtools_add_unit_test(test_sid_composite SOURCES test_sid_composite.cpp)
Expand Down
37 changes: 37 additions & 0 deletions tests/unit_tests/sid/test_sid_allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* GridTools
*
* Copyright (c) 2014-2023, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <gridtools/sid/allocator.hpp>

#include <cstddef>
#include <memory>

#include <gtest/gtest.h>

#include <gridtools/meta.hpp>

namespace gridtools {
namespace {

TEST(allocator, allocates_once_per_request) {
int count = 0;
auto alloc = sid::allocator([&count](size_t size) {
++count;
return std::make_unique<char[]>(size);
});

allocate(alloc, meta::lazy::id<double>{}, 3);
EXPECT_EQ(1, count);

allocate(alloc, meta::lazy::id<double>{}, 3);
EXPECT_EQ(2, count);
}
} // namespace
} // namespace gridtools
Loading