patch 4.0
This commit is contained in:
@ -28,7 +28,8 @@ using namespace hash;
|
||||
|
||||
const int64_t ITEM_NUM = 1024 * 128;
|
||||
|
||||
struct data_t {
|
||||
struct data_t
|
||||
{
|
||||
uint32_t construct_flag;
|
||||
char data[1024];
|
||||
data_t()
|
||||
@ -40,10 +41,11 @@ struct data_t {
|
||||
typedef SimpleAllocer<data_t, 128> allocer_t;
|
||||
|
||||
template <class T>
|
||||
void shuffle(T* array, const int64_t array_size)
|
||||
void shuffle(T *array, const int64_t array_size)
|
||||
{
|
||||
srand(static_cast<int32_t>(time(NULL)));
|
||||
for (int64_t i = 0; i < array_size; i++) {
|
||||
for (int64_t i = 0; i < array_size; i++)
|
||||
{
|
||||
int64_t swap_pos = rand() % array_size;
|
||||
std::swap(array[i], array[swap_pos]);
|
||||
}
|
||||
@ -52,19 +54,22 @@ void shuffle(T* array, const int64_t array_size)
|
||||
TEST(TestSimpleAllocer, allocate)
|
||||
{
|
||||
allocer_t al;
|
||||
data_t* nil = NULL;
|
||||
data_t *nil = NULL;
|
||||
|
||||
data_t* store[ITEM_NUM];
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++) {
|
||||
data_t *store[ITEM_NUM];
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++)
|
||||
{
|
||||
EXPECT_NE(nil, (store[i] = al.alloc()));
|
||||
EXPECT_EQ(0xffffffff, store[i]->construct_flag);
|
||||
}
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++) {
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++)
|
||||
{
|
||||
store[i]->construct_flag = 0x00000000;
|
||||
al.free(store[i]);
|
||||
}
|
||||
for (int64_t i = ITEM_NUM - 1; i >= 0; i--) {
|
||||
data_t* tmp = NULL;
|
||||
for (int64_t i = ITEM_NUM - 1; i >= 0; i--)
|
||||
{
|
||||
data_t *tmp = NULL;
|
||||
EXPECT_NE(nil, (tmp = al.alloc()));
|
||||
EXPECT_EQ(0xffffffff, tmp->construct_flag);
|
||||
}
|
||||
@ -74,22 +79,27 @@ TEST(TestSimpleAllocer, free)
|
||||
{
|
||||
allocer_t al;
|
||||
|
||||
data_t* store[ITEM_NUM];
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++) {
|
||||
data_t *store[ITEM_NUM];
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++)
|
||||
{
|
||||
store[i] = al.alloc();
|
||||
}
|
||||
al.free(NULL);
|
||||
shuffle(store, ITEM_NUM);
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++) {
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++)
|
||||
{
|
||||
al.free(store[i]);
|
||||
}
|
||||
for (int64_t i = ITEM_NUM - 1; i >= 0; i--) {
|
||||
data_t* tmp = NULL;
|
||||
for (int64_t i = ITEM_NUM - 1; i >= 0; i--)
|
||||
{
|
||||
data_t *tmp = NULL;
|
||||
EXPECT_EQ(store[i], (tmp = al.alloc()));
|
||||
}
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++) {
|
||||
for (int64_t i = 0; i < ITEM_NUM; i++)
|
||||
{
|
||||
al.free(store[i]);
|
||||
if (0 == i % 128) {
|
||||
if (0 == i % 128)
|
||||
{
|
||||
al.gc();
|
||||
}
|
||||
}
|
||||
@ -98,8 +108,8 @@ TEST(TestSimpleAllocer, free)
|
||||
TEST(TestSimpleAllocer, DISABLED_overflow)
|
||||
{
|
||||
allocer_t al;
|
||||
data_t* nil = NULL;
|
||||
data_t* data[2];
|
||||
data_t *nil = NULL;
|
||||
data_t *data[2];
|
||||
data_t tmp;
|
||||
|
||||
EXPECT_NE(nil, (data[0] = al.alloc()));
|
||||
@ -119,9 +129,9 @@ TEST(TestSimpleAllocer, DISABLED_overflow)
|
||||
EXPECT_EQ(data[0], data[1]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ObLogger::get_logger().set_log_level("ERROR");
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
testing::InitGoogleTest(&argc,argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user