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

Unified Diff: tests/syscalls/semaphore_tests.cc

Issue 18796006: libpthread: Implement sem_trywait() and sem_getvalue() (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tests/syscalls/semaphore_tests.cc
diff --git a/tests/syscalls/semaphore_tests.cc b/tests/syscalls/semaphore_tests.cc
index baaff40089f3a8b4f0e02851a14f83f80cdecb18..5d0df9b1d138068594a8a9f0cff732ce1c6cd129 100644
--- a/tests/syscalls/semaphore_tests.cc
+++ b/tests/syscalls/semaphore_tests.cc
@@ -251,9 +251,38 @@ int TestSemNormalOperation() {
END_TEST();
}
+int TestSemTryWait() {
+ START_TEST("test sem_trywait() and sem_getvalue()");
+
+ int start_value = 10;
+ sem_t sem;
+ EXPECT(0 == sem_init(&sem, 0, start_value));
+
+ int value = -1;
+ EXPECT(0 == sem_getvalue(&sem, &value));
+ EXPECT(10 == value);
+ // When the semaphore's value is positive, each call to
+ // sem_trywait() should decrement the semaphore's value.
+ for (int i = 1; i <= start_value; i++) {
+ EXPECT(0 == sem_trywait(&sem));
+ EXPECT(0 == sem_getvalue(&sem, &value));
+ EXPECT(start_value - i == value);
+ }
+ // When the semaphore's value is zero, sem_trywait() should fail.
+ EXPECT(-1 == sem_trywait(&sem));
+ EXPECT(EAGAIN == errno);
+ EXPECT(0 == sem_getvalue(&sem, &value));
+ EXPECT(0 == value);
+
+ EXPECT(0 == sem_destroy(&sem));
+
+ END_TEST();
+}
+
int main() {
int fail_count = 0;
fail_count += TestSemNormalOperation();
+ fail_count += TestSemTryWait();
// A semaphore implementation is not required to check for the
// errors that are tested for here. nacl-newlib checks, but glibc
« src/untrusted/pthread/nc_semaphore.c ('K') | « src/untrusted/pthread/nc_semaphore.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698