Electroneum
Loading...
Searching...
No Matches
aligned.cpp File Reference
#include "gtest/gtest.h"
#include "common/aligned.h"
Include dependency graph for aligned.cpp:

Go to the source code of this file.

Functions

 TEST (aligned, large_null)
 TEST (aligned, free_null)
 TEST (aligned, zero)
 TEST (aligned, aligned1)
 TEST (aligned, aligned4096)
 TEST (aligned, aligned8)
 TEST (aligned, realloc_null)
 TEST (aligned, realloc_diff_align)
 TEST (aligned, realloc_same)
 TEST (aligned, realloc_larger)
 TEST (aligned, realloc_zero)
 TEST (aligned, contents_larger)
 TEST (aligned, contents_same)
 TEST (aligned, contents_smaller)
 TEST (aligned, alignment)

Function Documentation

◆ TEST() [1/15]

TEST ( aligned ,
aligned1  )

Definition at line 36 of file aligned.cpp.

36{ void *ptr = aligned_malloc(1, 1); ASSERT_TRUE(ptr); aligned_free(ptr); }
void * aligned_malloc(size_t bytes, size_t align)
void aligned_free(void *ptr)
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
Here is the call graph for this function:

◆ TEST() [2/15]

TEST ( aligned ,
aligned4096  )

Definition at line 37 of file aligned.cpp.

37{ void *ptr = aligned_malloc(1, 4096); ASSERT_TRUE(ptr && ((uintptr_t)ptr & 4095) == 0); aligned_free(ptr); }
_W64 unsigned int uintptr_t
Definition stdint.h:165
Here is the call graph for this function:

◆ TEST() [3/15]

TEST ( aligned ,
aligned8  )

Definition at line 38 of file aligned.cpp.

38{ void *ptr = aligned_malloc(1, 8); ASSERT_TRUE(ptr && ((uintptr_t)ptr & 7) == 0); aligned_free(ptr); }
Here is the call graph for this function:

◆ TEST() [4/15]

TEST ( aligned ,
alignment  )

Definition at line 87 of file aligned.cpp.

88{
89 static const size_t good_alignments[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192};
90 for (size_t a = 0; a <= 8192; ++a)
91 {
92 bool good = false;
93 for (const auto t: good_alignments) if (a == t) good = true;
94 void *ptr = aligned_malloc(1, a);
95 if (good)
96 {
97 ASSERT_TRUE(ptr != NULL);
98 aligned_free(ptr);
99 }
100 else
101 {
102 ASSERT_TRUE(ptr == NULL);
103 }
104 }
105
106 ASSERT_TRUE(aligned_malloc(1, ~0) == NULL);
107}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
Here is the call graph for this function:

◆ TEST() [5/15]

TEST ( aligned ,
contents_larger  )

Definition at line 45 of file aligned.cpp.

46{
47 unsigned char *ptr = (unsigned char*)aligned_malloc(50, 256);
48 ASSERT_TRUE(ptr);
49 for (int n = 0; n < 50; ++n)
50 ptr[n] = n;
51 unsigned char *ptr2 = (unsigned char*)aligned_realloc(ptr, 51, 256);
52 for (int n = 0; n < 50; ++n)
53 {
54 ASSERT_TRUE(ptr2[n] == n);
55 }
56 aligned_free(ptr2);
57}
void * aligned_realloc(void *ptr, size_t bytes, size_t align)
Here is the call graph for this function:

◆ TEST() [6/15]

TEST ( aligned ,
contents_same  )

Definition at line 59 of file aligned.cpp.

60{
61 unsigned char *ptr = (unsigned char*)aligned_malloc(50, 256);
62 ASSERT_TRUE(ptr);
63 for (int n = 0; n < 50; ++n)
64 ptr[n] = n;
65 unsigned char *ptr2 = (unsigned char*)aligned_realloc(ptr, 50, 256);
66 for (int n = 0; n < 50; ++n)
67 {
68 ASSERT_TRUE(ptr2[n] == n);
69 }
70 aligned_free(ptr2);
71}
Here is the call graph for this function:

◆ TEST() [7/15]

TEST ( aligned ,
contents_smaller  )

Definition at line 73 of file aligned.cpp.

74{
75 unsigned char *ptr = (unsigned char*)aligned_malloc(50, 256);
76 ASSERT_TRUE(ptr);
77 for (int n = 0; n < 50; ++n)
78 ptr[n] = n;
79 unsigned char *ptr2 = (unsigned char*)aligned_realloc(ptr, 49, 256);
80 for (int n = 0; n < 49; ++n)
81 {
82 ASSERT_TRUE(ptr2[n] == n);
83 }
84 aligned_free(ptr2);
85}
Here is the call graph for this function:

◆ TEST() [8/15]

TEST ( aligned ,
free_null  )

Definition at line 34 of file aligned.cpp.

34{ aligned_free(NULL); }
Here is the call graph for this function:

◆ TEST() [9/15]

TEST ( aligned ,
large_null  )

Definition at line 33 of file aligned.cpp.

33{ ASSERT_TRUE(aligned_malloc((size_t)-1, 1) == NULL); }
Here is the call graph for this function:

◆ TEST() [10/15]

TEST ( aligned ,
realloc_diff_align  )

Definition at line 40 of file aligned.cpp.

40{ void *ptr = aligned_malloc(1, 4096); ASSERT_TRUE(!aligned_realloc(ptr, 1, 2048)); aligned_free(ptr); }
Here is the call graph for this function:

◆ TEST() [11/15]

TEST ( aligned ,
realloc_larger  )

Definition at line 42 of file aligned.cpp.

42{ void *ptr = aligned_malloc(1, 4096), *ptr2 = aligned_realloc(ptr, 2, 4096); ASSERT_TRUE(ptr != ptr2); aligned_free(ptr2); }
Here is the call graph for this function:

◆ TEST() [12/15]

TEST ( aligned ,
realloc_null  )

Definition at line 39 of file aligned.cpp.

39{ void *ptr = aligned_realloc(NULL, 1, 4096); ASSERT_TRUE(ptr && ((uintptr_t)ptr & 4095) == 0); aligned_free(ptr); }
Here is the call graph for this function:

◆ TEST() [13/15]

TEST ( aligned ,
realloc_same  )

Definition at line 41 of file aligned.cpp.

41{ void *ptr = aligned_malloc(1, 4096), *ptr2 = aligned_realloc(ptr, 1, 4096); ASSERT_TRUE(ptr == ptr2); aligned_free(ptr2); }
Here is the call graph for this function:

◆ TEST() [14/15]

TEST ( aligned ,
realloc_zero  )

Definition at line 43 of file aligned.cpp.

43{ void *ptr = aligned_malloc(1, 4096), *ptr2 = aligned_realloc(ptr, 0, 4096); ASSERT_TRUE(ptr && !ptr2); }
Here is the call graph for this function:

◆ TEST() [15/15]

TEST ( aligned ,
zero  )

Definition at line 35 of file aligned.cpp.

35{ void *ptr = aligned_malloc(0, 1); ASSERT_TRUE(ptr); aligned_free(ptr); }
Here is the call graph for this function: