 // RUN: %target-run-simple-swift %t
 // REQUIRES: executable_test
 
-// Android Bionic does not provide a working implementation of
-// <semaphore.h>.
-// XFAIL: OS=linux-androideabi
-
 import StdlibUnittest
-#if os(Linux)
+#if os(Linux) || os(Android)
   import Glibc
 #else
   import Darwin

}

// Failed semaphore creation.
POSIXTests.test("sem_open fail") {
  let sem = sem_open(semaphoreName, 0)
  expectEqual(SEM_FAILED, sem)
  expectEqual(ENOENT, errno)
}

// Successful semaphore creation.
POSIXTests.test("sem_open success") {
  let sem = sem_open(semaphoreName, O_CREAT, 0o777, 1)
  expectNotEqual(SEM_FAILED, sem)

  // Lock for reading...
  var flck = flock()
  flck.l_type = Int16(F_RDLCK)
  #if os(Android)
  // In Android l_len is __kernel_off_t which is not the same size as off_t in
  // 64 bits.
  flck.l_len = __kernel_off_t(data.utf8.count)
  #else
  flck.l_len = off_t(data.utf8.count)
  #endif
  rc = fcntl(fd, F_SETLK, &flck)
  expectEqual(0, rc)

