Skip to content

Instantly share code, notes, and snippets.

@tfogal tfogal/gist:9765258
Last active Aug 29, 2015

Embed
What would you like to do?
a new test for libuv which tests large writes.
diff --git a/test/test-fs.c b/test/test-fs.c
index f0ff824..837d251 100644
--- a/test/test-fs.c
+++ b/test/test-fs.c
@@ -732,6 +732,39 @@ TEST_IMPL(fs_file_sync) {
return 0;
}
+TEST_IMPL(fs_large_write) {
+ int r;
+
+ /* Setup. */
+ unlink("large-file");
+
+ loop = uv_default_loop();
+
+ r = uv_fs_open(loop, &open_req1, "large-file", O_WRONLY | O_CREAT,
+ S_IWUSR | S_IRUSR, NULL);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
+ uv_fs_req_cleanup(&open_req1);
+
+ const size_t sz = 1000*1000*1000*sizeof(float);
+ float* largebuf = malloc(sz);
+ r = uv_fs_write(loop, &write_req, open_req1.result, largebuf,
+ sz, -1, NULL);
+ free(largebuf);
+ ASSERT(r >= 0);
+ ASSERT(write_req.result >= 0);
+ ASSERT(write_req.result == sz);
+ uv_fs_req_cleanup(&write_req);
+
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
+ uv_fs_req_cleanup(&close_req);
+
+ unlink("large-file"); /* large file, so clean it up now. */
+ return 0;
+}
+
TEST_IMPL(fs_async_dir) {
int r;
diff --git a/test/test-list.h b/test/test-list.h
index a6e692f..34d8a3e 100644
--- a/test/test-list.h
+++ b/test/test-list.h
@@ -179,6 +179,7 @@ TEST_DECLARE (fs_file_nametoolong)
TEST_DECLARE (fs_file_loop)
TEST_DECLARE (fs_file_async)
TEST_DECLARE (fs_file_sync)
+TEST_DECLARE (fs_large_write)
TEST_DECLARE (fs_async_dir)
TEST_DECLARE (fs_async_sendfile)
TEST_DECLARE (fs_fstat)
@@ -495,6 +496,7 @@ TASK_LIST_START
TEST_ENTRY (fs_file_loop)
TEST_ENTRY (fs_file_async)
TEST_ENTRY (fs_file_sync)
+ TEST_ENTRY (fs_large_write)
TEST_ENTRY (fs_async_dir)
TEST_ENTRY (fs_async_sendfile)
TEST_ENTRY (fs_fstat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.