test: Add unit tests for simple array alignment
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include "util/types.hpp"
|
||||
#include "util/pair.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
struct some_struct
|
||||
{
|
||||
u64 v{};
|
||||
@@ -14,7 +16,7 @@ struct some_struct
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Utils, Pair)
|
||||
TEST(Pair, General)
|
||||
{
|
||||
some_struct s{};
|
||||
s.v = 1234;
|
||||
@@ -44,3 +46,4 @@ TEST(Utils, Pair)
|
||||
EXPECT_EQ(p3.first, 666);
|
||||
EXPECT_EQ(p3.second, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,4 +267,40 @@ namespace rsx
|
||||
EXPECT_EQ(std::memcmp(arr[i].second.s, "Hello World", sizeof(arr[i].second.s)), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SimpleArray, DataAlignment_SmallVector)
|
||||
{
|
||||
struct alignas(16) some_struct {
|
||||
char data[16];
|
||||
};
|
||||
|
||||
rsx::simple_array<some_struct> arr(2);
|
||||
const auto data_ptr = reinterpret_cast<uintptr_t>(arr.data());
|
||||
|
||||
EXPECT_EQ(data_ptr & 15, 0);
|
||||
}
|
||||
|
||||
TEST(SimpleArray, DataAlignment_HeapAlloc)
|
||||
{
|
||||
struct alignas(16) some_struct {
|
||||
char data[16];
|
||||
};
|
||||
|
||||
rsx::simple_array<some_struct> arr(128);
|
||||
const auto data_ptr = reinterpret_cast<uintptr_t>(arr.data());
|
||||
|
||||
EXPECT_EQ(data_ptr & 15, 0);
|
||||
}
|
||||
|
||||
TEST(SimpleArray, DataAlignment_Overrides)
|
||||
{
|
||||
rsx::simple_array<std::byte, 16> arr(4);
|
||||
rsx::simple_array<std::byte, 128> arr2(4);
|
||||
|
||||
const auto data_ptr1 = reinterpret_cast<uintptr_t>(arr.data());
|
||||
const auto data_ptr2 = reinterpret_cast<uintptr_t>(arr2.data());
|
||||
|
||||
EXPECT_EQ(data_ptr1 & 15, 0);
|
||||
EXPECT_EQ(data_ptr2 & 127, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "util/tuple.hpp"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
struct some_struct
|
||||
{
|
||||
u64 v{};
|
||||
@@ -13,7 +15,7 @@ struct some_struct
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Utils, Tuple)
|
||||
TEST(Tuple, General)
|
||||
{
|
||||
some_struct s{};
|
||||
s.v = 1234;
|
||||
@@ -112,3 +114,4 @@ TEST(Utils, Tuple)
|
||||
EXPECT_EQ(ta.get<0>(), 2);
|
||||
EXPECT_EQ(ta.get<1>(), s);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user