| 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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 ret &= test_chmod(test_file); | 1157 ret &= test_chmod(test_file); |
| 1137 ret &= test_access(test_file); | 1158 ret &= test_access(test_file); |
| 1138 #endif | 1159 #endif |
| 1139 // TODO(sbc): remove this restriction once glibc's truncate calls | 1160 // TODO(sbc): remove this restriction once glibc's truncate calls |
| 1140 // is hooked up to the IRT dev-filename-0.2 interface: | 1161 // is hooked up to the IRT dev-filename-0.2 interface: |
| 1141 // https://code.google.com/p/nativeclient/issues/detail?id=3709 | 1162 // https://code.google.com/p/nativeclient/issues/detail?id=3709 |
| 1142 #if !defined(__GLIBC__) | 1163 #if !defined(__GLIBC__) |
| 1143 ret &= test_truncate(test_file); | 1164 ret &= test_truncate(test_file); |
| 1144 #endif | 1165 #endif |
| 1145 ret &= test_utimes(test_file); | 1166 ret &= test_utimes(test_file); |
| 1167 ret &= test_utime(test_file); |
| 1146 return ret; | 1168 return ret; |
| 1147 } | 1169 } |
| 1148 | 1170 |
| 1149 /* | 1171 /* |
| 1150 * main entry point. | 1172 * main entry point. |
| 1151 * | 1173 * |
| 1152 * run all tests and call system exit with appropriate value | 1174 * run all tests and call system exit with appropriate value |
| 1153 * 0 - success, all tests passed. | 1175 * 0 - success, all tests passed. |
| 1154 * -1 - one or more tests failed. | 1176 * -1 - one or more tests failed. |
| 1155 */ | 1177 */ |
| 1156 | 1178 |
| 1157 int main(const int argc, const char *argv[]) { | 1179 int main(const int argc, const char *argv[]) { |
| 1158 bool passed; | 1180 bool passed; |
| 1159 | 1181 |
| 1160 if (argc != 2) { | 1182 if (argc != 2) { |
| 1161 printf("Please specify the test file name\n"); | 1183 printf("Please specify the test file name\n"); |
| 1162 exit(-1); | 1184 exit(-1); |
| 1163 } | 1185 } |
| 1164 // run the full test suite | 1186 // run the full test suite |
| 1165 passed = testSuite(argv[1]); | 1187 passed = testSuite(argv[1]); |
| 1166 | 1188 |
| 1167 if (passed) { | 1189 if (passed) { |
| 1168 printf("All tests PASSED\n"); | 1190 printf("All tests PASSED\n"); |
| 1169 exit(0); | 1191 exit(0); |
| 1170 } else { | 1192 } else { |
| 1171 printf("One or more tests FAILED\n"); | 1193 printf("One or more tests FAILED\n"); |
| 1172 exit(-1); | 1194 exit(-1); |
| 1173 } | 1195 } |
| 1174 } | 1196 } |
| OLD | NEW |