Skip to content

Commit

Permalink
tests: add (another) allocator test
Browse files Browse the repository at this point in the history
Test that realloc() shrinking a block doesn't do an extra allocation.
  • Loading branch information
avikivity committed Aug 23, 2015
1 parent ebc46f1 commit 3484074
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def debug_flag(compiler):
'tests/timertest',
'tests/tcp_test',
'tests/futures_test',
'tests/alloc_test',
'tests/foreign_ptr_test',
'tests/smp_test',
'tests/thread_test',
Expand Down Expand Up @@ -295,6 +296,7 @@ def have_xen():
'tests/tcp_test': ['tests/tcp_test.cc'] + core + libnet,
'tests/timertest': ['tests/timertest.cc'] + core,
'tests/futures_test': ['tests/futures_test.cc'] + core + boost_test_lib,
'tests/alloc_test': ['tests/alloc_test.cc'] + core + boost_test_lib,
'tests/foreign_ptr_test': ['tests/foreign_ptr_test.cc'] + core + boost_test_lib,
'tests/semaphore_test': ['tests/semaphore_test.cc'] + core + boost_test_lib,
'tests/smp_test': ['tests/smp_test.cc'] + core,
Expand Down
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import re

boost_tests = [
'alloc_test',
'futures_test',
'thread_test',
'memcached/test_ascii_parser',
Expand Down
37 changes: 37 additions & 0 deletions tests/alloc_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is open source software, licensed to you under the terms
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. You may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/

#include "tests/test-utils.hh"
#include "core/memory.hh"


SEASTAR_TEST_CASE(alloc_almost_all_and_realloc_it_with_a_smaller_size) {
#ifndef DEFAULT_ALLOCATOR
auto all = memory::stats().total_memory();
auto obj = malloc(all - (10 << 20));
BOOST_REQUIRE(obj != nullptr);
auto obj2 = realloc(obj, all - (11 << 20));
BOOST_REQUIRE(obj == obj2);
free(obj2);
#endif
return make_ready_future<>();
}

0 comments on commit 3484074

Please sign in to comment.