From f37d2d754a2e8bd5649d31c6d3ddcc344fac02c1 Mon Sep 17 00:00:00 2001 From: Eric Kramer Date: Wed, 19 Oct 2016 18:49:16 -0500 Subject: [PATCH 1/2] Test commit --- ek6798-TestAllocator.c++ | 245 +++++++++++++++++++++++++++++++++++++++ ek6798-TestAllocator.out | 96 +++++++++++++++ 2 files changed, 341 insertions(+) create mode 100644 ek6798-TestAllocator.c++ create mode 100644 ek6798-TestAllocator.out diff --git a/ek6798-TestAllocator.c++ b/ek6798-TestAllocator.c++ new file mode 100644 index 0000000..ce741c1 --- /dev/null +++ b/ek6798-TestAllocator.c++ @@ -0,0 +1,245 @@ +// ------------------------------------- +// projects/allocator/TestAllocator1.c++ +// Copyright (C) 2015 +// Glenn P. Downing +// ------------------------------------- + +// -------- +// includes +// -------- + +#include // count +#include // allocator + +#include "gtest/gtest.h" + +#include "Allocator.h" + +// -------------- +// TestAllocator1 +// -------------- + +template +struct TestAllocator1 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer;}; + +typedef testing::Types< + std::allocator, + std::allocator, + my_allocator, + my_allocator> + my_types_1; + +TYPED_TEST_CASE(TestAllocator1, my_types_1); + +TYPED_TEST(TestAllocator1, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s);} +} + +TYPED_TEST(TestAllocator1, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 10; + const value_type v = 2; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p;}} + catch (...) { + while (b != p) { + --p; + x.destroy(p);} + x.deallocate(b, s); + throw;} + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e);} + x.deallocate(b, s);} + } + +// -------------- +// TestAllocator2 +// -------------- + +TEST(TestAllocator2, const_index) { + const my_allocator x; + ASSERT_EQ(x[0], 0);} + +TEST(TestAllocator2, index) { + my_allocator x; + ASSERT_EQ(x[0], 0);} + +// -------------- +// TestAllocator3 +// -------------- + +template +struct TestAllocator3 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer;}; + +typedef testing::Types< + my_allocator, + my_allocator> + my_types_2; + +TYPED_TEST_CASE(TestAllocator3, my_types_2); + +TYPED_TEST(TestAllocator3, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 2; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s);}} + +TYPED_TEST(TestAllocator3, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 10; + const value_type v = 2; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p;}} + catch (...) { + while (b != p) { + --p; + x.destroy(p);} + x.deallocate(b, s); + throw;} + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e);} + x.deallocate(b, s);}} + +// -------------- +// TestAllocator4 +// -------------- +TEST(TestAllocator4, const_index) { + const my_allocator x; + ASSERT_EQ(x[0], 0); +} + +TEST(TestAllocator4, const_index2) { + const my_allocator x; + ASSERT_EQ(x[0], 0); +} + +// -------------- +// TestAllocator5 +// -------------- +template +struct TestAllocator5 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer;}; + +typedef testing::Types< + my_allocator, + my_allocator> + my_types_3; + +TYPED_TEST_CASE(TestAllocator5, my_types_3); + +TYPED_TEST(TestAllocator5, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 42; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s);}} + +TYPED_TEST(TestAllocator5, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 21; + const value_type v = 42; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p;}} + catch (...) { + while (b != p) { + --p; + x.destroy(p);} + x.deallocate(b, s); + throw;} + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e);} + x.deallocate(b, s);}} diff --git a/ek6798-TestAllocator.out b/ek6798-TestAllocator.out new file mode 100644 index 0000000..4ab48b7 --- /dev/null +++ b/ek6798-TestAllocator.out @@ -0,0 +1,96 @@ +==20362== Memcheck, a memory error detector +==20362== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. +==20362== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info +==20362== Command: ./TestAllocator +==20362== +Running main() from gtest_main.cc +[==========] Running 20 tests from 10 test cases. +[----------] Global test environment set-up. +[----------] 2 tests from TestAllocator1/0, where TypeParam = std::allocator +[ RUN ] TestAllocator1/0.test_1 +[ OK ] TestAllocator1/0.test_1 (10 ms) +[ RUN ] TestAllocator1/0.test_10 +[ OK ] TestAllocator1/0.test_10 (4 ms) +[----------] 2 tests from TestAllocator1/0 (21 ms total) + +[----------] 2 tests from TestAllocator1/1, where TypeParam = std::allocator +[ RUN ] TestAllocator1/1.test_1 +[ OK ] TestAllocator1/1.test_1 (5 ms) +[ RUN ] TestAllocator1/1.test_10 +[ OK ] TestAllocator1/1.test_10 (3 ms) +[----------] 2 tests from TestAllocator1/1 (8 ms total) + +[----------] 2 tests from TestAllocator1/2, where TypeParam = my_allocator +[ RUN ] TestAllocator1/2.test_1 +[ OK ] TestAllocator1/2.test_1 (7 ms) +[ RUN ] TestAllocator1/2.test_10 +[ OK ] TestAllocator1/2.test_10 (3 ms) +[----------] 2 tests from TestAllocator1/2 (10 ms total) + +[----------] 2 tests from TestAllocator1/3, where TypeParam = my_allocator +[ RUN ] TestAllocator1/3.test_1 +[ OK ] TestAllocator1/3.test_1 (7 ms) +[ RUN ] TestAllocator1/3.test_10 +[ OK ] TestAllocator1/3.test_10 (3 ms) +[----------] 2 tests from TestAllocator1/3 (10 ms total) + +[----------] 2 tests from TestAllocator2 +[ RUN ] TestAllocator2.const_index +[ OK ] TestAllocator2.const_index (2 ms) +[ RUN ] TestAllocator2.index +[ OK ] TestAllocator2.index (2 ms) +[----------] 2 tests from TestAllocator2 (4 ms total) + +[----------] 2 tests from TestAllocator3/0, where TypeParam = my_allocator +[ RUN ] TestAllocator3/0.test_1 +[ OK ] TestAllocator3/0.test_1 (3 ms) +[ RUN ] TestAllocator3/0.test_10 +[ OK ] TestAllocator3/0.test_10 (3 ms) +[----------] 2 tests from TestAllocator3/0 (6 ms total) + +[----------] 2 tests from TestAllocator3/1, where TypeParam = my_allocator +[ RUN ] TestAllocator3/1.test_1 +[ OK ] TestAllocator3/1.test_1 (3 ms) +[ RUN ] TestAllocator3/1.test_10 +[ OK ] TestAllocator3/1.test_10 (3 ms) +[----------] 2 tests from TestAllocator3/1 (6 ms total) + +[----------] 2 tests from TestAllocator4 +[ RUN ] TestAllocator4.const_index +[ OK ] TestAllocator4.const_index (3 ms) +[ RUN ] TestAllocator4.const_index2 +[ OK ] TestAllocator4.const_index2 (4 ms) +[----------] 2 tests from TestAllocator4 (7 ms total) + +[----------] 2 tests from TestAllocator5/0, where TypeParam = my_allocator +[ RUN ] TestAllocator5/0.test_1 +[ OK ] TestAllocator5/0.test_1 (6 ms) +[ RUN ] TestAllocator5/0.test_10 +[ OK ] TestAllocator5/0.test_10 (2 ms) +[----------] 2 tests from TestAllocator5/0 (10 ms total) + +[----------] 2 tests from TestAllocator5/1, where TypeParam = my_allocator +[ RUN ] TestAllocator5/1.test_1 +[ OK ] TestAllocator5/1.test_1 (7 ms) +[ RUN ] TestAllocator5/1.test_10 +[ OK ] TestAllocator5/1.test_10 (3 ms) +[----------] 2 tests from TestAllocator5/1 (10 ms total) + +[----------] Global test environment tear-down +[==========] 20 tests from 10 test cases ran. (118 ms total) +[ PASSED ] 20 tests. +==20362== +==20362== HEAP SUMMARY: +==20362== in use at exit: 0 bytes in 0 blocks +==20362== total heap usage: 922 allocs, 922 frees, 124,914 bytes allocated +==20362== +==20362== All heap blocks were freed -- no leaks are possible +==20362== +==20362== For counts of detected and suppressed errors, rerun with: -v +==20362== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +File 'TestAllocator.c++' +Lines executed:83.78% of 111 +Branches executed:66.91% of 556 +Taken at least once:36.33% of 556 +Calls executed:52.94% of 527 +Creating 'TestAllocator.c++.gcov' From f8fda0ff806264485b996af22c8c897927468929 Mon Sep 17 00:00:00 2001 From: Eric Kramer Date: Wed, 19 Oct 2016 19:36:36 -0500 Subject: [PATCH 2/2] Updated tests --- ek6798-TestAllocator.c++ | 132 +++++++++++++++++++++++++++++++++++++++ ek6798-TestAllocator.out | 84 ++++++++++++++++--------- 2 files changed, 188 insertions(+), 28 deletions(-) diff --git a/ek6798-TestAllocator.c++ b/ek6798-TestAllocator.c++ index ce741c1..f1521eb 100644 --- a/ek6798-TestAllocator.c++ +++ b/ek6798-TestAllocator.c++ @@ -243,3 +243,135 @@ TYPED_TEST(TestAllocator5, test_10) { --e; x.destroy(e);} x.deallocate(b, s);}} + +// -------------- +// TestAllocator6 +// -------------- +template +struct TestAllocator6 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer;}; + +typedef testing::Types< + my_allocator, + my_allocator> + my_types_4; + +TYPED_TEST_CASE(TestAllocator6, my_types_4); + +TYPED_TEST(TestAllocator6, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 42; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s);}} + +TYPED_TEST(TestAllocator6, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 6; + const value_type v = 42; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p;}} + catch (...) { + while (b != p) { + --p; + x.destroy(p);} + x.deallocate(b, s); + throw;} + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e);} + x.deallocate(b, s);}} + +// -------------- +// TestAllocator7 +// -------------- +template +struct TestAllocator7 : testing::Test { + // -------- + // typedefs + // -------- + + typedef A allocator_type; + typedef typename A::value_type value_type; + typedef typename A::size_type size_type; + typedef typename A::pointer pointer;}; + +typedef testing::Types< + my_allocator, + my_allocator> + my_types_5; + +TYPED_TEST_CASE(TestAllocator7, my_types_5); + +TYPED_TEST(TestAllocator7, test_1) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 1; + const value_type v = 42; + const pointer p = x.allocate(s); + if (p != nullptr) { + x.construct(p, v); + ASSERT_EQ(v, *p); + x.destroy(p); + x.deallocate(p, s);}} + +TYPED_TEST(TestAllocator7, test_10) { + typedef typename TestFixture::allocator_type allocator_type; + typedef typename TestFixture::value_type value_type; + typedef typename TestFixture::size_type size_type; + typedef typename TestFixture::pointer pointer; + + allocator_type x; + const size_type s = 500; + const value_type v = 42; + const pointer b = x.allocate(s); + if (b != nullptr) { + pointer e = b + s; + pointer p = b; + try { + while (p != e) { + x.construct(p, v); + ++p;}} + catch (...) { + while (b != p) { + --p; + x.destroy(p);} + x.deallocate(b, s); + throw;} + ASSERT_EQ(s, std::count(b, e, v)); + while (b != e) { + --e; + x.destroy(e);} + x.deallocate(b, s);}} diff --git a/ek6798-TestAllocator.out b/ek6798-TestAllocator.out index 4ab48b7..7971034 100644 --- a/ek6798-TestAllocator.out +++ b/ek6798-TestAllocator.out @@ -1,23 +1,23 @@ -==20362== Memcheck, a memory error detector -==20362== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. -==20362== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info -==20362== Command: ./TestAllocator -==20362== +==23527== Memcheck, a memory error detector +==23527== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. +==23527== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info +==23527== Command: ./TestAllocator +==23527== Running main() from gtest_main.cc -[==========] Running 20 tests from 10 test cases. +[==========] Running 28 tests from 14 test cases. [----------] Global test environment set-up. [----------] 2 tests from TestAllocator1/0, where TypeParam = std::allocator [ RUN ] TestAllocator1/0.test_1 -[ OK ] TestAllocator1/0.test_1 (10 ms) +[ OK ] TestAllocator1/0.test_1 (9 ms) [ RUN ] TestAllocator1/0.test_10 [ OK ] TestAllocator1/0.test_10 (4 ms) [----------] 2 tests from TestAllocator1/0 (21 ms total) [----------] 2 tests from TestAllocator1/1, where TypeParam = std::allocator [ RUN ] TestAllocator1/1.test_1 -[ OK ] TestAllocator1/1.test_1 (5 ms) +[ OK ] TestAllocator1/1.test_1 (4 ms) [ RUN ] TestAllocator1/1.test_10 -[ OK ] TestAllocator1/1.test_10 (3 ms) +[ OK ] TestAllocator1/1.test_10 (4 ms) [----------] 2 tests from TestAllocator1/1 (8 ms total) [----------] 2 tests from TestAllocator1/2, where TypeParam = my_allocator @@ -59,15 +59,15 @@ Running main() from gtest_main.cc [ RUN ] TestAllocator4.const_index [ OK ] TestAllocator4.const_index (3 ms) [ RUN ] TestAllocator4.const_index2 -[ OK ] TestAllocator4.const_index2 (4 ms) +[ OK ] TestAllocator4.const_index2 (3 ms) [----------] 2 tests from TestAllocator4 (7 ms total) [----------] 2 tests from TestAllocator5/0, where TypeParam = my_allocator [ RUN ] TestAllocator5/0.test_1 -[ OK ] TestAllocator5/0.test_1 (6 ms) +[ OK ] TestAllocator5/0.test_1 (7 ms) [ RUN ] TestAllocator5/0.test_10 -[ OK ] TestAllocator5/0.test_10 (2 ms) -[----------] 2 tests from TestAllocator5/0 (10 ms total) +[ OK ] TestAllocator5/0.test_10 (3 ms) +[----------] 2 tests from TestAllocator5/0 (11 ms total) [----------] 2 tests from TestAllocator5/1, where TypeParam = my_allocator [ RUN ] TestAllocator5/1.test_1 @@ -76,21 +76,49 @@ Running main() from gtest_main.cc [ OK ] TestAllocator5/1.test_10 (3 ms) [----------] 2 tests from TestAllocator5/1 (10 ms total) +[----------] 2 tests from TestAllocator6/0, where TypeParam = my_allocator +[ RUN ] TestAllocator6/0.test_1 +[ OK ] TestAllocator6/0.test_1 (7 ms) +[ RUN ] TestAllocator6/0.test_10 +[ OK ] TestAllocator6/0.test_10 (3 ms) +[----------] 2 tests from TestAllocator6/0 (10 ms total) + +[----------] 2 tests from TestAllocator6/1, where TypeParam = my_allocator +[ RUN ] TestAllocator6/1.test_1 +[ OK ] TestAllocator6/1.test_1 (6 ms) +[ RUN ] TestAllocator6/1.test_10 +[ OK ] TestAllocator6/1.test_10 (1 ms) +[----------] 2 tests from TestAllocator6/1 (8 ms total) + +[----------] 2 tests from TestAllocator7/0, where TypeParam = my_allocator +[ RUN ] TestAllocator7/0.test_1 +[ OK ] TestAllocator7/0.test_1 (7 ms) +[ RUN ] TestAllocator7/0.test_10 +[ OK ] TestAllocator7/0.test_10 (2 ms) +[----------] 2 tests from TestAllocator7/0 (9 ms total) + +[----------] 2 tests from TestAllocator7/1, where TypeParam = my_allocator +[ RUN ] TestAllocator7/1.test_1 +[ OK ] TestAllocator7/1.test_1 (7 ms) +[ RUN ] TestAllocator7/1.test_10 +[ OK ] TestAllocator7/1.test_10 (1 ms) +[----------] 2 tests from TestAllocator7/1 (8 ms total) + [----------] Global test environment tear-down -[==========] 20 tests from 10 test cases ran. (118 ms total) -[ PASSED ] 20 tests. -==20362== -==20362== HEAP SUMMARY: -==20362== in use at exit: 0 bytes in 0 blocks -==20362== total heap usage: 922 allocs, 922 frees, 124,914 bytes allocated -==20362== -==20362== All heap blocks were freed -- no leaks are possible -==20362== -==20362== For counts of detected and suppressed errors, rerun with: -v -==20362== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +[==========] 28 tests from 14 test cases ran. (154 ms total) +[ PASSED ] 28 tests. +==23527== +==23527== HEAP SUMMARY: +==23527== in use at exit: 0 bytes in 0 blocks +==23527== total heap usage: 1,234 allocs, 1,234 frees, 160,736 bytes allocated +==23527== +==23527== All heap blocks were freed -- no leaks are possible +==23527== +==23527== For counts of detected and suppressed errors, rerun with: -v +==23527== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) File 'TestAllocator.c++' -Lines executed:83.78% of 111 -Branches executed:66.91% of 556 -Taken at least once:36.33% of 556 -Calls executed:52.94% of 527 +Lines executed:78.53% of 177 +Branches executed:61.35% of 828 +Taken at least once:32.85% of 828 +Calls executed:49.27% of 751 Creating 'TestAllocator.c++.gcov'