summaryrefslogtreecommitdiff
path: root/gtest
diff options
context:
space:
mode:
author“pengxuanzheng” <[email protected]>2021-09-24 10:44:30 +0800
committerpengxuanzheng <[email protected]>2021-09-24 15:43:47 +0800
commitf9bce9d590407cea1ab9764f7c10342ffb4eb795 (patch)
tree2de3b0d69d0f61c2b3a80067cd472ce5bad8c5ad /gtest
parent9250031fac8f5c5eec8c17498923315ea8a38a23 (diff)
🦄 refactor(TSG-7851): 重构fd,使用内存地址作为fdv2.0.5
Diffstat (limited to 'gtest')
-rw-r--r--gtest/CheckHosClient.cpp1
-rw-r--r--gtest/common/gtest_hos_common.h2
-rw-r--r--gtest/file/test.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test0.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test1.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test2.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test3.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test4.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test5.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test6.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test7.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test8.filebin0 -> 10485760 bytes
-rw-r--r--gtest/file/test9.filebin0 -> 10485760 bytes
-rw-r--r--gtest/gtest_hos_close_fd.cpp12
-rw-r--r--gtest/gtest_hos_open_fd.cpp14
-rw-r--r--gtest/gtest_hos_write.cpp115
16 files changed, 63 insertions, 81 deletions
diff --git a/gtest/CheckHosClient.cpp b/gtest/CheckHosClient.cpp
index 75787eed..b9f64d1d 100644
--- a/gtest/CheckHosClient.cpp
+++ b/gtest/CheckHosClient.cpp
@@ -98,7 +98,6 @@ void CheckStructGHosFdContext(hos_fd_context_t *actual, hos_fd_context_t *expect
EXPECT_EQ(actual->cache_count, expect->cache_count);
EXPECT_EQ(actual->cache_rest, expect->cache_rest);
EXPECT_EQ(actual->callback, expect->callback);
- EXPECT_EQ(actual->fd, expect->fd);
EXPECT_EQ(actual->fd_status, expect->fd_status);
EXPECT_EQ(actual->mode, expect->mode);
EXPECT_STREQ(actual->object, expect->object);
diff --git a/gtest/common/gtest_hos_common.h b/gtest/common/gtest_hos_common.h
index b0e2c751..e97957e7 100644
--- a/gtest/common/gtest_hos_common.h
+++ b/gtest/common/gtest_hos_common.h
@@ -61,7 +61,5 @@ typedef struct hos_fd_context_s hos_fd_context_t;
extern struct hos_instance_s g_hos_instance;
extern hos_client_handle_t g_hos_handle;//一个进程只允许有一个g_hos_handle
-extern hos_fd_context_t **g_fd_context;
-extern size_t (*g_fd_info)[65536]; //fd 实际从3开始, fd[thread_id][0]记录register的fd,fd[thread_id][1]记录inject的fd
#endif \ No newline at end of file
diff --git a/gtest/file/test.file b/gtest/file/test.file
new file mode 100644
index 00000000..37b8932e
--- /dev/null
+++ b/gtest/file/test.file
Binary files differ
diff --git a/gtest/file/test0.file b/gtest/file/test0.file
new file mode 100644
index 00000000..6c5d4031
--- /dev/null
+++ b/gtest/file/test0.file
Binary files differ
diff --git a/gtest/file/test1.file b/gtest/file/test1.file
new file mode 100644
index 00000000..6edfa831
--- /dev/null
+++ b/gtest/file/test1.file
Binary files differ
diff --git a/gtest/file/test2.file b/gtest/file/test2.file
new file mode 100644
index 00000000..1557d590
--- /dev/null
+++ b/gtest/file/test2.file
Binary files differ
diff --git a/gtest/file/test3.file b/gtest/file/test3.file
new file mode 100644
index 00000000..394b1e1c
--- /dev/null
+++ b/gtest/file/test3.file
Binary files differ
diff --git a/gtest/file/test4.file b/gtest/file/test4.file
new file mode 100644
index 00000000..84e72051
--- /dev/null
+++ b/gtest/file/test4.file
Binary files differ
diff --git a/gtest/file/test5.file b/gtest/file/test5.file
new file mode 100644
index 00000000..98d38209
--- /dev/null
+++ b/gtest/file/test5.file
Binary files differ
diff --git a/gtest/file/test6.file b/gtest/file/test6.file
new file mode 100644
index 00000000..85a49e19
--- /dev/null
+++ b/gtest/file/test6.file
Binary files differ
diff --git a/gtest/file/test7.file b/gtest/file/test7.file
new file mode 100644
index 00000000..d772f2a6
--- /dev/null
+++ b/gtest/file/test7.file
Binary files differ
diff --git a/gtest/file/test8.file b/gtest/file/test8.file
new file mode 100644
index 00000000..c2c5ab83
--- /dev/null
+++ b/gtest/file/test8.file
Binary files differ
diff --git a/gtest/file/test9.file b/gtest/file/test9.file
new file mode 100644
index 00000000..a38d3b4e
--- /dev/null
+++ b/gtest/file/test9.file
Binary files differ
diff --git a/gtest/gtest_hos_close_fd.cpp b/gtest/gtest_hos_close_fd.cpp
index dbedf6a6..0311440a 100644
--- a/gtest/gtest_hos_close_fd.cpp
+++ b/gtest/gtest_hos_close_fd.cpp
@@ -57,7 +57,6 @@ static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL;
- fd_info->fd = 1;
fd_info->fd_status = HOS_FD_REGISTER;
fd_info->mode = BUFF_MODE | APPEND_MODE;
fd_info->position = 0;
@@ -79,11 +78,10 @@ TEST(hos_close_fd, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0);
- EXPECT_EQ(fd, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -107,7 +105,6 @@ TEST(hos_close_fd, normal)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_close_fd, paramer_error)
@@ -128,7 +125,6 @@ TEST(hos_close_fd, paramer_error)
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- CheckStructGHosFdContext(g_fd_context[0], NULL);
int ret = hos_close_fd(fd, thread_num + 1);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
@@ -152,7 +148,6 @@ TEST(hos_close_fd, paramer_error)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_close_fd, not_init_instance)
@@ -161,6 +156,7 @@ TEST(hos_close_fd, not_init_instance)
EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT);
}
+#if 0
TEST(hos_close_fd, fd_not_exits)
{
hos_instance_s expect_hos_instance;
@@ -196,5 +192,5 @@ TEST(hos_close_fd, fd_not_exits)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
-} \ No newline at end of file
+}
+#endif \ No newline at end of file
diff --git a/gtest/gtest_hos_open_fd.cpp b/gtest/gtest_hos_open_fd.cpp
index 121cdcef..4fe22d13 100644
--- a/gtest/gtest_hos_open_fd.cpp
+++ b/gtest/gtest_hos_open_fd.cpp
@@ -57,7 +57,6 @@ static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL;
- fd_info->fd = 1;
fd_info->fd_status = HOS_FD_REGISTER;
fd_info->mode = BUFF_MODE | APPEND_MODE;
fd_info->position = 0;
@@ -78,30 +77,26 @@ TEST(hos_open_fd, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0);
- EXPECT_EQ(fd, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]);
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
size_t fd1 = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 1);
- EXPECT_EQ(fd1, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]);
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
int ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[0], NULL);
ret = hos_close_fd(fd1, 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[1], NULL);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -120,7 +115,6 @@ TEST(hos_open_fd, normal)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_open_fd, paramer_error)
@@ -138,7 +132,6 @@ TEST(hos_open_fd, paramer_error)
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- CheckStructGHosFdContext(g_fd_context[0], NULL);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -157,7 +150,6 @@ TEST(hos_open_fd, paramer_error)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_open_fd, over_threadnums)
@@ -175,7 +167,6 @@ TEST(hos_open_fd, over_threadnums)
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- CheckStructGHosFdContext(g_fd_context[2], NULL);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -194,7 +185,6 @@ TEST(hos_open_fd, over_threadnums)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_open_fd, not_init_instance)
diff --git a/gtest/gtest_hos_write.cpp b/gtest/gtest_hos_write.cpp
index e08445a3..c84b1016 100644
--- a/gtest/gtest_hos_write.cpp
+++ b/gtest/gtest_hos_write.cpp
@@ -59,7 +59,6 @@ static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL;
- fd_info->fd = 1;
fd_info->fd_status = HOS_FD_REGISTER;
fd_info->mode = BUFF_MODE | APPEND_MODE;
fd_info->position = 0;
@@ -119,14 +118,13 @@ TEST(hos_write, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0);
- EXPECT_EQ(fd, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]);
expect_fd_info[0].callback = (void *)hos_write_buff_cb;
expect_fd_info[0].object = (char *)"object_buff";
expect_fd_info[0].userdata = (void *)"object_buff";
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -137,17 +135,15 @@ TEST(hos_write, normal)
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1);
- EXPECT_EQ(fd1, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]);
expect_fd_info[1].callback = (void *)hos_write_append_cb;
expect_fd_info[1].object = (char *)"object_append";
expect_fd_info[1].userdata = (void *)"object_append";
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -158,8 +154,8 @@ TEST(hos_write, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -170,8 +166,8 @@ TEST(hos_write, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd, 0);
@@ -205,7 +201,6 @@ TEST(hos_write, normal)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_write, bucket_not_exits)
@@ -224,7 +219,6 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0);
- EXPECT_EQ(fd, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]);
@@ -232,7 +226,7 @@ TEST(hos_write, bucket_not_exits)
expect_fd_info[0].userdata = (void *)"object_buff";
expect_fd_info[0].bucket = (char *)"bucket_not_exits";
expect_fd_info[0].object = (char *)"object_buff";
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -243,7 +237,6 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd1 = hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1);
- EXPECT_EQ(fd1, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]);
@@ -251,7 +244,7 @@ TEST(hos_write, bucket_not_exits)
expect_fd_info[1].userdata = (void *)"object_append";
expect_fd_info[1].bucket = (char *)"bucket_not_exits";
expect_fd_info[1].object = (char *)"object_append";
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -262,8 +255,8 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -274,8 +267,8 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -308,7 +301,6 @@ TEST(hos_write, bucket_not_exits)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_write, sync_mode)
@@ -328,12 +320,11 @@ TEST(hos_write, sync_mode)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0);
- EXPECT_EQ(fd, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]);
expect_fd_info[0].object = (char *)"object_buff";
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -342,15 +333,13 @@ TEST(hos_write, sync_mode)
data_info->cache[0] += strlen(HOS_BUFF);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1);
- EXPECT_EQ(fd1, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]);
expect_fd_info[1].object = (char *)"object_append";
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -361,8 +350,8 @@ TEST(hos_write, sync_mode)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -373,8 +362,8 @@ TEST(hos_write, sync_mode)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -407,7 +396,6 @@ TEST(hos_write, sync_mode)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_write, sync_mode_bucket_not_exits)
@@ -427,13 +415,12 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0);
- EXPECT_EQ(fd, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]);
expect_fd_info[0].object = (char *)"object_buff";
expect_fd_info[0].bucket = (char *)HOS_CONF;
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -443,16 +430,14 @@ TEST(hos_write, sync_mode_bucket_not_exits)
data_info->cache[0] += strlen(HOS_BUFF);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
size_t fd1 = hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1);
- EXPECT_EQ(fd1, 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]);
expect_fd_info[1].object = (char *)"object_append";
expect_fd_info[1].bucket = (char *)HOS_CONF;
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -463,8 +448,8 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -475,8 +460,8 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
- CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -509,7 +494,6 @@ TEST(hos_write, sync_mode_bucket_not_exits)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_write, paramer_error)
@@ -525,20 +509,18 @@ TEST(hos_write, paramer_error)
gtest_hos_handle_init(&expect_hos_handle, thread_num);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- int fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0);
- EXPECT_EQ(fd, 1);
+ long fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
expect_fd_info.object = (char *)"object_buff";
expect_fd_info.callback = (void *)hos_callback;
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_write(fd, NULL, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -557,9 +539,9 @@ TEST(hos_write, paramer_error)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
+#if 0
TEST(hos_write, fd_not_find)
{
hos_instance_s expect_hos_instance;
@@ -577,7 +559,6 @@ TEST(hos_write, fd_not_find)
EXPECT_EQ(ret, HOS_HASH_NOT_FIND);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- CheckStructGHosFdContext(g_fd_context[0], NULL);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -596,8 +577,8 @@ TEST(hos_write, fd_not_find)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
+#endif
TEST(hos_write, over_threadnums)
{
@@ -612,19 +593,17 @@ TEST(hos_write, over_threadnums)
gtest_hos_handle_init(&expect_hos_handle, thread_num);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- int fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0);
- EXPECT_EQ(fd, 1);
+ long fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
expect_fd_info.object = (char *)"object";
- CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 6);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
@@ -643,7 +622,6 @@ TEST(hos_write, over_threadnums)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}
TEST(hos_write, not_init_instance)
@@ -652,6 +630,22 @@ TEST(hos_write, not_init_instance)
EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT);
}
+static void read_file(char *path, char **content, int *len)
+{
+ FILE *fp;
+ fp = fopen(path, "rb");
+
+ fseek(fp, 0L, SEEK_END);
+ size_t flen = ftell(fp);
+ *content = (char *)malloc(flen + 1);
+ fseek(fp, 0L, SEEK_SET);
+ fread(*content, flen, 1, fp);
+
+ (*content)[flen] = 0;
+ *len = flen;
+ fclose(fp);
+}
+
static void *hos_function(void *ptr)
{
#define HOS_FD_NUMS_LOCAL 20
@@ -659,7 +653,7 @@ static void *hos_function(void *ptr)
size_t thread_id = reinterpret_cast<size_t>(ptr);
hos_instance hos_instance = NULL;
int i = 0;
- int fd[HOS_FD_NUMS_LOCAL] = {0};
+ long fd[HOS_FD_NUMS_LOCAL] = {0};
char object[HOS_FD_NUMS_LOCAL][1024];
int ret = 0;
hos_instance_s expect_hos_instance;
@@ -692,12 +686,18 @@ static void *hos_function(void *ptr)
gtest_hos_fd_init(&expect_fd_info[thread_id][i]);
expect_fd_info[thread_id][i].object = object[i];
expect_fd_info[thread_id][i].callback = (void *)hos_callback;
- CheckStructGHosFdContext(g_fd_context[thread_id], &expect_fd_info[thread_id][i]);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd[i], &expect_fd_info[thread_id][i]);
}
for (i = 0; i < HOS_FD_NUMS_LOCAL; i++)
{
- ret = hos_write(fd[i], HOS_BUFF, strlen(HOS_BUFF), i);
+ char *content = NULL;
+ char path[256];
+ int len = 0;
+ snprintf(path, 256, "../file/test%d.file", i%10);
+ read_file(path, &content, &len);
+ ret = hos_write(fd[i], content, len, i);
+ free(content);
EXPECT_EQ(ret, HOS_CLIENT_OK);
data_info->cache[i] = strlen(HOS_BUFF);
data_info->rx_bytes[i] = strlen(HOS_BUFF);
@@ -706,8 +706,8 @@ static void *hos_function(void *ptr)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[thread_id][i].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[thread_id][i].cache_count--;
- CheckStructGHosFdContext(&g_fd_context[thread_id][i], &expect_fd_info[thread_id][i]);
- EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
+ CheckStructGHosFdContext((hos_fd_context_t *)fd[i], &expect_fd_info[thread_id][i]);
+ EXPECT_TRUE(((hos_fd_context_t *)fd[i])->cache != NULL);
}
for (i = 0; i < HOS_FD_NUMS_LOCAL; i++)
@@ -737,7 +737,6 @@ static void *hos_function(void *ptr)
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
- EXPECT_EQ((void *)g_fd_context, (void *)NULL);
pthread_exit(NULL);
#undef HOS_FD_NUMS_LOCAL