Skip to content

Instantly share code, notes, and snippets.

@tfogal
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfogal/9765258 to your computer and use it in GitHub Desktop.
Save tfogal/9765258 to your computer and use it in GitHub Desktop.
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