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

Side by Side Diff: tests/syscalls/syscalls.cc

Issue 24889002: Provides some of the missing POSIX file syscalls Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 2 months 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
« no previous file with comments | « src/untrusted/nacl/syscall_bindings_trampoline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl tests for simple syscalls 8 * NaCl tests for simple syscalls
9 */ 9 */
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 bool test_getcwd() { 98 bool test_getcwd() {
99 return passed("test_getcwd", "all"); 99 return passed("test_getcwd", "all");
100 } 100 }
101 101
102 bool test_unlink(const char *test_file) { 102 bool test_unlink(const char *test_file) {
103 return passed("test_unlink", "all"); 103 return passed("test_unlink", "all");
104 } 104 }
105 105
106 bool test_truncate(const char *test_file) {
107 return passed("test_truncate", "all");
108 }
109
110 bool test_symlink_readlink(const char *test_file) {
111 return passed("test_symlink_readlink", "all");
112 }
113
114 bool test_chmod_access(const char *test_file) {
115 return passed("test_chmod_access", "all");
116 }
117
118 bool test_rename(const char *test_file) {
119 return passed("test_rename", "all");
120 }
121
122 bool test_utimes(const char *test_file) {
123 return passed("test_utimes", "all");
124 }
125
106 #else 126 #else
107 127
108 // Simple test that chdir returns zero for '.'. chdir gets more 128 // Simple test that chdir returns zero for '.'. chdir gets more
109 // significant testing as part of the getcwd test. 129 // significant testing as part of the getcwd test.
110 bool test_chdir() { 130 bool test_chdir() {
111 int rtn = chdir("."); 131 int rtn = chdir(".");
112 ASSERT_EQ_MSG(rtn, 0, "chdir() failed"); 132 ASSERT_EQ_MSG(rtn, 0, "chdir() failed");
113 133
114 return passed("test_chdir", "all"); 134 return passed("test_chdir", "all");
115 } 135 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 224
205 rtn = stat(buffer, &buf); 225 rtn = stat(buffer, &buf);
206 ASSERT_NE_MSG(rtn, 0, "unlink() failed to remove file"); 226 ASSERT_NE_MSG(rtn, 0, "unlink() failed to remove file");
207 227
208 rtn = unlink(buffer); 228 rtn = unlink(buffer);
209 ASSERT_NE_MSG(rtn, 0, "unlink() failed to fail"); 229 ASSERT_NE_MSG(rtn, 0, "unlink() failed to fail");
210 230
211 return passed("test_unlink", "all"); 231 return passed("test_unlink", "all");
212 } 232 }
213 233
234 bool test_truncate(const char *test_file) {
235 char buffer[PATH_MAX];
236 struct stat stbuf;
237 int retval;
238 snprintf(buffer, PATH_MAX, "%s.tmp", test_file);
239 buffer[PATH_MAX - 1] = '\0';
240
241 int fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
242 ASSERT_MSG(fd >= 0, "open() failed");
243
244 retval = close(fd);
245 ASSERT_EQ_MSG(retval, 0, "close() failed");
246
247 retval = truncate(buffer, 4096);
248 ASSERT_EQ_MSG(retval, 0, "truncate() failed");
249
250 retval = stat(buffer, &stbuf);
251 ASSERT_EQ_MSG(retval, 0, "stat() failed");
252
253 ASSERT_EQ(stbuf.st_size, 4096);
254
255 return passed("test_truncate", "all");
256 }
257
258 bool test_symlink_readlink(const char *test_file) {
259 char oldpath[PATH_MAX];
260 char newpath[PATH_MAX];
261 char buffer[PATH_MAX];
262 int retval;
263
264 snprintf(oldpath, PATH_MAX, "%s.tmp", test_file);
265 buffer[PATH_MAX - 1] = '\0';
266
267 int fd = open(oldpath, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
268 ASSERT_MSG(fd >= 0, "open() failed");
269
270 retval = close(fd);
271 ASSERT_EQ_MSG(retval, 0, "close() failed");
272
273 snprintf(newpath, PATH_MAX, "%s_link.tmp", test_file);
274 newpath[PATH_MAX - 1] = '\0';
275
276 retval = symlink(oldpath, newpath);
277 ASSERT_EQ_MSG(retval, 0, "symlink() failed");
278
279 retval = readlink(newpath, buffer, sizeof buffer);
280 ASSERT_EQ_MSG(retval, 0, "readlink() failed");
281 ASSERT_EQ(strcmp(oldpath, buffer), 0);
282
283 return passed("test_symlink_readlink", "all");
284 }
285
286 bool test_chmod_access(const char *test_file) {
287 return passed("test_chmod_access", "all");
288 }
289
290 bool test_rename(const char *test_file) {
291 return passed("test_rename", "all");
292 }
293
294 bool test_utimes(const char *test_file) {
295 return passed("test_utimes", "all");
296 }
297
214 #endif // !TESTS_USE_IRT 298 #endif // !TESTS_USE_IRT
215 299
216 // open() returns the new file descriptor, or -1 if an error occurred 300 // open() returns the new file descriptor, or -1 if an error occurred
217 bool test_open(const char *test_file) { 301 bool test_open(const char *test_file) {
218 int fd; 302 int fd;
219 const char *testname = "test_open"; 303 const char *testname = "test_open";
220 304
221 // file OK, flag OK 305 // file OK, flag OK
222 fd = open(test_file, O_RDONLY); 306 fd = open(test_file, O_RDONLY);
223 if (fd == -1) 307 if (fd == -1)
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 bool ret = true; 613 bool ret = true;
530 // The order of executing these tests matters! 614 // The order of executing these tests matters!
531 ret &= test1(); 615 ret &= test1();
532 ret &= test2(); 616 ret &= test2();
533 ret &= test_open(test_file); 617 ret &= test_open(test_file);
534 ret &= test_close(test_file); 618 ret &= test_close(test_file);
535 ret &= test_read(test_file); 619 ret &= test_read(test_file);
536 ret &= test_write(test_file); 620 ret &= test_write(test_file);
537 ret &= test_lseek(test_file); 621 ret &= test_lseek(test_file);
538 ret &= test_unlink(test_file); 622 ret &= test_unlink(test_file);
623 ret &= test_truncate(test_file);
624 ret &= test_symlink_readlink(test_file);
625 ret &= test_chmod_access(test_file);
626 ret &= test_rename(test_file);
627 ret &= test_utimes(test_file);
539 ret &= test_chdir(); 628 ret &= test_chdir();
540 ret &= test_getcwd(); 629 ret &= test_getcwd();
541 ret &= test_mkdir_rmdir(test_file); 630 ret &= test_mkdir_rmdir(test_file);
542 return ret; 631 return ret;
543 } 632 }
544 633
545 /* 634 /*
546 * main entry point. 635 * main entry point.
547 * 636 *
548 * run all tests and call system exit with appropriate value 637 * run all tests and call system exit with appropriate value
(...skipping 12 matching lines...) Expand all
561 passed = testSuite(argv[1]); 650 passed = testSuite(argv[1]);
562 651
563 if (passed) { 652 if (passed) {
564 printf("All tests PASSED\n"); 653 printf("All tests PASSED\n");
565 exit(0); 654 exit(0);
566 } else { 655 } else {
567 printf("One or more tests FAILED\n"); 656 printf("One or more tests FAILED\n");
568 exit(-1); 657 exit(-1);
569 } 658 }
570 } 659 }
OLDNEW
« no previous file with comments | « src/untrusted/nacl/syscall_bindings_trampoline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698