Index: tests/syscalls/semaphore_tests.cc |
diff --git a/tests/syscalls/semaphore_tests.cc b/tests/syscalls/semaphore_tests.cc |
index baaff40089f3a8b4f0e02851a14f83f80cdecb18..86fb41646bf76506fa45a8af624df0570dc701a8 100644 |
--- a/tests/syscalls/semaphore_tests.cc |
+++ b/tests/syscalls/semaphore_tests.cc |
@@ -54,33 +54,14 @@ int TestSemInitErrors() { |
std::numeric_limits<unsigned int>::max())); |
EXPECT(EINVAL == errno); |
- // NaCl semaphores do not currently support the pshared option, so this should |
- // fail with an ENOSYS error. If pshared gets added, we should begin testing |
- // it for proper successful behavior. |
+#if !defined(__GLIBC__) |
+ // nacl-newlib's semaphores do not currently support the pshared |
+ // option, so this should fail with an ENOSYS error. If pshared |
+ // gets added, we should begin testing it for proper successful |
+ // behavior. |
EXPECT(-1 == sem_init(&my_semaphore, 1, 0)); |
EXPECT(ENOSYS == errno); |
- |
- END_TEST(); |
-} |
- |
-// Test simple usages of sem_destroy and return the number of failed checks. |
-// |
-// According to the man page on Linux: |
-// =================================== |
-// RETURN VALUE |
-// |
-// sem_destroy() returns 0 on success; on error, -1 is returned, and |
-// errno is set to indicate the error. |
-// ERRORS |
-// |
-// EINVAL sem is not a valid semaphore. |
-// =================================== |
-int TestSemDestroy() { |
- START_TEST("sem_destroy"); |
- |
- // Try sem_destroy with a null pointer. |
- EXPECT(-1 == sem_destroy(NULL)); |
- EXPECT(EINVAL == errno); |
+#endif |
END_TEST(); |
} |
@@ -103,10 +84,6 @@ int TestSemDestroy() { |
int TestSemPostErrors() { |
START_TEST("sem_post error conditions"); |
- // Test an invalid semaphore: try a null pointer. |
- EXPECT(-1 == sem_post(NULL)); |
- EXPECT(EINVAL == errno); |
- |
// Initialize a semaphore with the max value, and try to post to it. |
sem_t my_semaphore; |
EXPECT(0 == sem_init(&my_semaphore, 0, SEM_VALUE_MAX)); |
@@ -139,71 +116,6 @@ void* PostThreadFunc(void* poster_thread_arg) { |
return NULL; |
} |
-// TODO(dmichael): Add this code and appropriate tests back if/when signal |
-// support is added. |
-// The following is intended to be used to test that calls which may be |
-// interrupted by a signal (e.g., sem_wait) will stop and report failure |
-// properly. However, NaCl does not currently support signals. |
-// |
-// The real type of the void* argument to SignalThreadFunc. See |
-// SignalThreadFunc for more information. |
-// struct SignalThreadArg { |
-// // The signal to send. |
-// int signal; |
-// // The amount of time to sleep before sending the signal (in microseconds). |
-// unsigned int sleep_microseconds; |
-// }; |
-// |
-// Sleep for sleep_microseconds, then raise the given signal. signal_thread_arg |
-// must be of type SignalThreadArg. Returns NULL. |
-// void* SignalThreadFunc(void* signal_thread_arg) { |
-// SignalThreadArg* sta = static_cast<SignalThreadArg*>(signal_thread_arg); |
-// usleep(sta->sleep_microseconds); |
-// raise(sta->signal); // This currently results in link error; signals |
-// // are currently unsupported by NaCl. |
-// return NULL; |
-// } |
- |
-// Test error conditions of sem_wait and return the number of failed checks. |
-// |
-// According to the man page on Linux: |
-// =================================== |
-// RETURN VALUE |
-// All of these functions return 0 on success; on error, the value of the |
-// semaphore is left unchanged, -1 is returned, and errno is set to indi‐ |
-// cate the error. |
-// |
-// ERRORS |
-// EINTR The call was interrupted by a signal handler; see signal(7). |
-// |
-// EINVAL sem is not a valid semaphore. |
-// =================================== |
-int TestSemWaitErrors() { |
- START_TEST("sem_wait error conditions"); |
- |
- // Try a null pointer. |
- EXPECT(-1 == sem_wait(NULL)); |
- EXPECT(EINVAL == errno); |
- |
- // TODO(dmichael): Uncomment this test (and supporting code above) if/when |
- // NaCl support for signals is added. |
- // Now really initialize one with the a value of 1, wait on it until a signal. |
- // EXPECT(0 == sem_init(&my_semaphore[1], 0, SEM_VALUE_MAX)); |
- // // Spawn a thread to signal us so we'll get an EINTR error. |
- // SignalThreadArg sta = { SIGINT, /* signal */ |
- // 2000000u /* sleep_microseconds */ }; |
- |
- // pthread_t sig_thread; |
- // |
- // EXPECT(0 == pthread_create(&sig_thread, 0, &SignalThreadFunc, &sta)); |
- // EXPECT(-1 == sem_wait(&my_semaphore[1])); |
- // EXPECT(EINTR == errno); |
- // void* dummy_return; |
- // EXPECT(0 == pthread_join(sig_thread, &dummy_return)); |
- |
- END_TEST(); |
-} |
- |
int TestSemNormalOperation() { |
START_TEST("semaphore normal operation"); |
@@ -253,17 +165,8 @@ int TestSemNormalOperation() { |
int main() { |
int fail_count = 0; |
- fail_count += TestSemNormalOperation(); |
- |
- // A semaphore implementation is not required to check for the |
- // errors that are tested for here. nacl-newlib checks, but glibc |
- // does not. |
-#ifndef __GLIBC__ |
fail_count += TestSemInitErrors(); |
- fail_count += TestSemDestroy(); |
fail_count += TestSemPostErrors(); |
- fail_count += TestSemWaitErrors(); |
-#endif |
- |
+ fail_count += TestSemNormalOperation(); |
std::exit(fail_count); |
} |