Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include <dirent.h> | 11 #include <dirent.h> |
| 12 #include <errno.h> | 12 #include <errno.h> |
| 13 #include <fcntl.h> | 13 #include <fcntl.h> |
| 14 #include <limits.h> | 14 #include <limits.h> |
| 15 #include <sched.h> | 15 #include <sched.h> |
| 16 #include <stdlib.h> | 16 #include <stdlib.h> |
| 17 #include <stdio.h> | 17 #include <stdio.h> |
| 18 #include <string.h> | 18 #include <string.h> |
| 19 #include <unistd.h> | 19 #include <unistd.h> |
| 20 #include <utime.h> | |
| 20 | 21 |
| 21 #include "native_client/src/include/nacl_assert.h" | 22 #include "native_client/src/include/nacl_assert.h" |
| 22 #include "native_client/src/trusted/service_runtime/include/sys/nacl_syscalls.h" | 23 #include "native_client/src/trusted/service_runtime/include/sys/nacl_syscalls.h" |
| 23 #include "native_client/src/trusted/service_runtime/nacl_config.h" | 24 #include "native_client/src/trusted/service_runtime/nacl_config.h" |
| 24 | 25 |
| 25 #define PRINT_HEADER 0 | 26 #define PRINT_HEADER 0 |
| 26 #define TEXT_LINE_SIZE 1024 | 27 #define TEXT_LINE_SIZE 1024 |
| 27 | 28 |
| 28 /* | 29 /* |
| 29 * TODO(sbc): remove this test once these declarations get added to the prebuilt | 30 * TODO(sbc): remove this test once these declarations get added to the |
| 30 * newlib toolchain | 31 * newlib toolchain |
| 31 */ | 32 */ |
| 32 #ifndef __GLIBC__ | 33 #ifndef __GLIBC__ |
| 33 extern "C" int gethostname(char *name, size_t len); | 34 extern "C" { |
| 34 extern "C" int utimes(const char *filename, const struct timeval times[2]); | 35 int gethostname(char *name, size_t len); |
| 35 extern "C" int eaccess(const char *pathname, int mode); | 36 int utimes(const char *filename, const struct timeval times[2]); |
| 37 int utime(const char *filename, const struct utimbuf *times); | |
| 38 int eaccess(const char *pathname, int mode); | |
| 39 } | |
| 36 #endif | 40 #endif |
| 37 | 41 |
| 38 /* | 42 /* |
| 39 * function failed(testname, msg) | 43 * function failed(testname, msg) |
| 40 * print failure message and exit with a return code of -1 | 44 * print failure message and exit with a return code of -1 |
| 41 */ | 45 */ |
| 42 bool failed(const char *testname, const char *msg) { | 46 bool failed(const char *testname, const char *msg) { |
| 43 printf("TEST FAILED: %s: %s\n", testname, msg); | 47 printf("TEST FAILED: %s: %s\n", testname, msg); |
| 44 return false; | 48 return false; |
| 45 } | 49 } |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 if (NONSFI_MODE) | 472 if (NONSFI_MODE) |
| 469 return true; | 473 return true; |
| 470 struct timeval times[2]; | 474 struct timeval times[2]; |
| 471 // utimes() is currently not implemented and should always | 475 // utimes() is currently not implemented and should always |
| 472 // fail with ENOSYS | 476 // fail with ENOSYS |
| 473 ASSERT_EQ(utimes("dummy", times), -1); | 477 ASSERT_EQ(utimes("dummy", times), -1); |
| 474 ASSERT_EQ(errno, ENOSYS); | 478 ASSERT_EQ(errno, ENOSYS); |
| 475 return passed("test_utimes", "all"); | 479 return passed("test_utimes", "all"); |
| 476 } | 480 } |
| 477 | 481 |
| 482 bool test_utime(const char *test_file) { | |
| 483 // TODO(mseaborn): Implement utimes for unsandboxed mode. | |
| 484 if (NONSFI_MODE) | |
| 485 return true; | |
| 486 printf("test_utime"); | |
| 487 struct utimbuf times; | |
| 488 times.actime = 0; | |
| 489 times.modtime = 0; | |
| 490 // utimes() is currently not implemented and should always | |
| 491 // fail with ENOSYS | |
| 492 printf("test_utime 2"); | |
| 493 | |
| 494 ASSERT_EQ(utime("dummy", ×), -1); | |
| 495 ASSERT_EQ(errno, ENOSYS); | |
| 496 return passed("test_utime", "all"); | |
| 497 } | |
| 498 | |
| 478 bool test_truncate(const char *test_file) { | 499 bool test_truncate(const char *test_file) { |
| 479 char temp_file[PATH_MAX]; | 500 char temp_file[PATH_MAX]; |
| 480 snprintf(temp_file, PATH_MAX, "%s.tmp_truncate", test_file); | 501 snprintf(temp_file, PATH_MAX, "%s.tmp_truncate", test_file); |
| 481 | 502 |
| 482 char buffer[100]; | 503 char buffer[100]; |
| 483 char read_buffer[200]; | 504 char read_buffer[200]; |
| 484 struct stat buf; | 505 struct stat buf; |
| 485 for (size_t i = 0; i < sizeof(buffer); i++) | 506 for (size_t i = 0; i < sizeof(buffer); i++) |
| 486 buffer[i] = i; | 507 buffer[i] = i; |
| 487 | 508 |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 ret &= test_symlinks(test_file); | 1090 ret &= test_symlinks(test_file); |
| 1070 ret &= test_chmod(test_file); | 1091 ret &= test_chmod(test_file); |
| 1071 ret &= test_access(test_file); | 1092 ret &= test_access(test_file); |
| 1072 #endif | 1093 #endif |
| 1073 // TODO(sbc): remove this restriction once glibc's truncate calls | 1094 // TODO(sbc): remove this restriction once glibc's truncate calls |
| 1074 // is hooked up to the IRT dev-filename-0.2 interface: | 1095 // is hooked up to the IRT dev-filename-0.2 interface: |
| 1075 // https://code.google.com/p/nativeclient/issues/detail?id=3709 | 1096 // https://code.google.com/p/nativeclient/issues/detail?id=3709 |
| 1076 #if !defined(__GLIBC__) | 1097 #if !defined(__GLIBC__) |
| 1077 ret &= test_truncate(test_file); | 1098 ret &= test_truncate(test_file); |
| 1078 #endif | 1099 #endif |
| 1100 ret &= test_utime(test_file); | |
|
Mark Seaborn
2015/04/07 19:08:43
Nit: Put after test_utimes() to match the definiti
Sam Clegg
2015/04/10 21:18:56
Done.
| |
| 1079 ret &= test_utimes(test_file); | 1101 ret &= test_utimes(test_file); |
| 1080 return ret; | 1102 return ret; |
| 1081 } | 1103 } |
| 1082 | 1104 |
| 1083 /* | 1105 /* |
| 1084 * main entry point. | 1106 * main entry point. |
| 1085 * | 1107 * |
| 1086 * run all tests and call system exit with appropriate value | 1108 * run all tests and call system exit with appropriate value |
| 1087 * 0 - success, all tests passed. | 1109 * 0 - success, all tests passed. |
| 1088 * -1 - one or more tests failed. | 1110 * -1 - one or more tests failed. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1099 passed = testSuite(argv[1]); | 1121 passed = testSuite(argv[1]); |
| 1100 | 1122 |
| 1101 if (passed) { | 1123 if (passed) { |
| 1102 printf("All tests PASSED\n"); | 1124 printf("All tests PASSED\n"); |
| 1103 exit(0); | 1125 exit(0); |
| 1104 } else { | 1126 } else { |
| 1105 printf("One or more tests FAILED\n"); | 1127 printf("One or more tests FAILED\n"); |
| 1106 exit(-1); | 1128 exit(-1); |
| 1107 } | 1129 } |
| 1108 } | 1130 } |
| OLD | NEW |