]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/align/test/aligned_alloc_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / align / test / aligned_alloc_test.cpp
CommitLineData
7c673cae
FG
1/*
2(c) 2014 Glen Joseph Fernandes
3<glenjofe -at- gmail.com>
4
5Distributed under the Boost Software
6License, Version 1.0.
7http://boost.org/LICENSE_1_0.txt
8*/
9#include <boost/align/aligned_alloc.hpp>
10#include <boost/align/is_aligned.hpp>
11#include <boost/core/lightweight_test.hpp>
12#include <cstring>
13
14void test(std::size_t alignment)
15{
16 {
17 void* p = boost::alignment::aligned_alloc(alignment,
18 alignment);
19 BOOST_TEST(p != 0);
20 BOOST_TEST(boost::alignment::is_aligned(p, alignment));
21 std::memset(p, 0, 1);
22 boost::alignment::aligned_free(p);
23 }
24 {
25 void* p = boost::alignment::aligned_alloc(alignment,
26 alignment + 1);
27 BOOST_TEST(p != 0);
28 BOOST_TEST(boost::alignment::is_aligned(p, alignment));
29 std::memset(p, 0, 1);
30 boost::alignment::aligned_free(p);
31 }
32 if (alignment > 1) {
33 void* p = boost::alignment::aligned_alloc(alignment,
34 alignment - 1);
35 BOOST_TEST(p != 0);
36 BOOST_TEST(boost::alignment::is_aligned(p, alignment));
37 std::memset(p, 0, 1);
38 boost::alignment::aligned_free(p);
39 } else {
40 void* p = boost::alignment::aligned_alloc(alignment, 0);
41 boost::alignment::aligned_free(p);
42 }
43}
44
45int main()
46{
47 test(1);
48 test(2);
49 test(4);
50 test(8);
51 test(16);
52 test(32);
53 test(64);
54 test(128);
55
56 return boost::report_errors();
57}