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

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: Remove NULL checks 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
« no previous file with comments | « src/untrusted/pthread/nc_semaphore.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/syscalls/semaphore_tests.cc
diff --git a/tests/syscalls/semaphore_tests.cc b/tests/syscalls/semaphore_tests.cc
index 86fb41646bf76506fa45a8af624df0570dc701a8..3022bf30b09cca1b58f41c19c7eb856d81c28f44 100644
--- a/tests/syscalls/semaphore_tests.cc
+++ b/tests/syscalls/semaphore_tests.cc
@@ -163,10 +163,39 @@ 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 += TestSemInitErrors();
fail_count += TestSemPostErrors();
fail_count += TestSemNormalOperation();
+ fail_count += TestSemTryWait();
std::exit(fail_count);
}
« no previous file with comments | « src/untrusted/pthread/nc_semaphore.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698