Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc

Issue 73083005: [NaCl SDK] Enable linux host build for nacl_io and nacl_io_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <pthread.h> 7 #include <pthread.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 int garbage[buffer_size]; 110 int garbage[buffer_size];
111 111
112 MountMem* mount = (MountMem*)kp_.RootMount(); 112 MountMem* mount = (MountMem*)kp_.RootMount();
113 ScopedMountNode root; 113 ScopedMountNode root;
114 114
115 ASSERT_EQ(0, mount->Open(Path("/"), O_RDONLY, &root)); 115 ASSERT_EQ(0, mount->Open(Path("/"), O_RDONLY, &root));
116 ASSERT_EQ(0, root->ChildCount()); 116 ASSERT_EQ(0, root->ChildCount());
117 117
118 for (int file_num = 0; file_num < 4096; file_num++) { 118 for (int file_num = 0; file_num < 4096; file_num++) {
119 sprintf(filename, "/foo%i.tmp", file_num++); 119 sprintf(filename, "/foo%i.tmp", file_num++);
120 FILE* f = fopen(filename, "w"); 120 int fd = ki_open(filename, O_WRONLY | O_CREAT);
121 ASSERT_NE((FILE*)NULL, f); 121 ASSERT_GT(fd, -1);
122 ASSERT_EQ(1, root->ChildCount()); 122 ASSERT_EQ(1, root->ChildCount());
123 ASSERT_EQ(buffer_size, fwrite(garbage, 1, buffer_size, f)); 123 ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size));
124 fclose(f); 124 ki_close(fd);
125 ASSERT_EQ(0, remove(filename)); 125 ASSERT_EQ(0, ki_remove(filename));
126 } 126 }
127 ASSERT_EQ(0, root->ChildCount()); 127 ASSERT_EQ(0, root->ChildCount());
128 } 128 }
129 129
130 static bool g_handler_called = false; 130 static bool g_handler_called = false;
131 static void sighandler(int) { 131 static void sighandler(int) {
132 g_handler_called = true; 132 g_handler_called = true;
133 } 133 }
134 134
135 TEST_F(KernelProxyTest, Sigaction) { 135 TEST_F(KernelProxyTest, Sigaction) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 len = ki_read(fd2, text, sizeof(text)); 351 len = ki_read(fd2, text, sizeof(text));
352 if (len > 0) 352 if (len > 0)
353 text[len] = 0; 353 text[len] = 0;
354 EXPECT_EQ(10, len); 354 EXPECT_EQ(10, len);
355 EXPECT_STREQ("HELLOWORLD", text); 355 EXPECT_STREQ("HELLOWORLD", text);
356 } 356 }
357 357
358 TEST_F(KernelProxyTest, MemMountLseek) { 358 TEST_F(KernelProxyTest, MemMountLseek) {
359 int fd = ki_open("/foo", O_CREAT | O_RDWR); 359 int fd = ki_open("/foo", O_CREAT | O_RDWR);
360 ASSERT_GT(fd, -1); 360 ASSERT_GT(fd, -1);
361 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); 361 ASSERT_EQ(9, ki_write(fd, "Some text", 9));
362 362
363 EXPECT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); 363 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR));
364 EXPECT_EQ(9, ki_lseek(fd, 0, SEEK_END)); 364 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_END));
365 EXPECT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); 365 ASSERT_EQ(-1, ki_lseek(fd, -1, SEEK_SET));
366 EXPECT_EQ(EINVAL, errno); 366 ASSERT_EQ(EINVAL, errno);
367 367
368 // Seek past end of file. 368 // Seek past end of file.
369 EXPECT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); 369 ASSERT_EQ(13, ki_lseek(fd, 13, SEEK_SET));
370 char buffer[4]; 370 char buffer[4];
371 memset(&buffer[0], 0xfe, 4); 371 memset(&buffer[0], 0xfe, 4);
372 EXPECT_EQ(9, ki_lseek(fd, -4, SEEK_END)); 372 ASSERT_EQ(9, ki_lseek(fd, -4, SEEK_END));
373 EXPECT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); 373 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR));
374 EXPECT_EQ(4, ki_read(fd, &buffer[0], 4)); 374 ASSERT_EQ(4, ki_read(fd, &buffer[0], 4));
375 EXPECT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); 375 ASSERT_EQ(0, memcmp("\0\0\0\0", buffer, 4));
376 } 376 }
377 377
378 TEST_F(KernelProxyTest, CloseTwice) { 378 TEST_F(KernelProxyTest, CloseTwice) {
379 int fd = ki_open("/foo", O_CREAT | O_RDWR); 379 int fd = ki_open("/foo", O_CREAT | O_RDWR);
380 ASSERT_GT(fd, -1); 380 ASSERT_GT(fd, -1);
381 381
382 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); 382 EXPECT_EQ(9, ki_write(fd, "Some text", 9));
383 383
384 int fd2 = ki_dup(fd); 384 int fd2 = ki_dup(fd);
385 ASSERT_GT(fd2, -1); 385 ASSERT_GT(fd2, -1);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 680
681 int fd = ki_open("/dummy", O_RDONLY); 681 int fd = ki_open("/dummy", O_RDONLY);
682 EXPECT_NE(0, fd); 682 EXPECT_NE(0, fd);
683 683
684 char buf[20]; 684 char buf[20];
685 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); 685 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20));
686 // The Mount should be able to return whatever error it wants and have it 686 // The Mount should be able to return whatever error it wants and have it
687 // propagate through. 687 // propagate through.
688 EXPECT_EQ(1234, errno); 688 EXPECT_EQ(1234, errno);
689 } 689 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_test/example.dsc ('k') | native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698