Build bionic unit tests for musl

Modify bionic unit tests that are built for glibc so that they also
build against musl.  They don't all pass though:

With glibc:
 2 SLOW TESTS
 4 TIMEOUT TESTS
313 FAILED TESTS
  YOU HAVE 2 DISABLED TESTS

With musl:
11 SLOW TESTS
11 TIMEOUT TESTS
363 FAILED TESTS
  YOU HAVE 2 DISABLED TESTS

Bug: 190084016
Test: m bionic-unit-tests-glibc with musl
Test: atest bionic-unit-tests-static
Test: atest --host bionic-unit-tests-glibc with glibc
Change-Id: I79b6eab04fed3cc4392450df5eef2579412edfe1
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 1a00460..3686ffb 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -844,6 +844,8 @@
     ASSERT_EQ(pshared_value_array[i], pshared);
   }
 
+#if !defined(MUSL)
+  // musl doesn't have pthread_rwlockattr_setkind_np
   int kind_array[] = {PTHREAD_RWLOCK_PREFER_READER_NP,
                       PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP};
   for (size_t i = 0; i < sizeof(kind_array) / sizeof(kind_array[0]); ++i) {
@@ -852,6 +854,7 @@
     ASSERT_EQ(0, pthread_rwlockattr_getkind_np(&attr, &kind));
     ASSERT_EQ(kind_array[i], kind);
   }
+#endif
 
   ASSERT_EQ(0, pthread_rwlockattr_destroy(&attr));
 }
@@ -1235,6 +1238,8 @@
 #endif  // __BIONIC__
 }
 
+#if !defined(MUSL)
+// musl doesn't have pthread_rwlockattr_setkind_np
 class RwlockKindTestHelper {
  private:
   struct ThreadArg {
@@ -1302,8 +1307,10 @@
     delete arg;
   }
 };
+#endif
 
 TEST(pthread, pthread_rwlock_kind_PTHREAD_RWLOCK_PREFER_READER_NP) {
+#if !defined(MUSL)
   RwlockKindTestHelper helper(PTHREAD_RWLOCK_PREFER_READER_NP);
   ASSERT_EQ(0, pthread_rwlock_rdlock(&helper.lock));
 
@@ -1319,9 +1326,13 @@
 
   ASSERT_EQ(0, pthread_rwlock_unlock(&helper.lock));
   ASSERT_EQ(0, pthread_join(writer_thread, nullptr));
+#else
+  GTEST_SKIP() << "musl doesn't have pthread_rwlockattr_setkind_np";
+#endif
 }
 
 TEST(pthread, pthread_rwlock_kind_PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) {
+#if !defined(MUSL)
   RwlockKindTestHelper helper(PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
   ASSERT_EQ(0, pthread_rwlock_rdlock(&helper.lock));
 
@@ -1338,6 +1349,9 @@
   ASSERT_EQ(0, pthread_rwlock_unlock(&helper.lock));
   ASSERT_EQ(0, pthread_join(writer_thread, nullptr));
   ASSERT_EQ(0, pthread_join(reader_thread, nullptr));
+#else
+  GTEST_SKIP() << "musl doesn't have pthread_rwlockattr_setkind_np";
+#endif
 }
 
 static int g_once_fn_call_count = 0;
@@ -2152,6 +2166,9 @@
   ASSERT_EQ(0, memcmp(&lock_normal, &m1.lock, sizeof(pthread_mutex_t)));
   pthread_mutex_destroy(&lock_normal);
 
+#if !defined(MUSL)
+  // musl doesn't support PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP or
+  // PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP.
   pthread_mutex_t lock_errorcheck = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
   PthreadMutex m2(PTHREAD_MUTEX_ERRORCHECK);
   ASSERT_EQ(0, memcmp(&lock_errorcheck, &m2.lock, sizeof(pthread_mutex_t)));
@@ -2161,6 +2178,7 @@
   PthreadMutex m3(PTHREAD_MUTEX_RECURSIVE);
   ASSERT_EQ(0, memcmp(&lock_recursive, &m3.lock, sizeof(pthread_mutex_t)));
   ASSERT_EQ(0, pthread_mutex_destroy(&lock_recursive));
+#endif
 }
 
 class MutexWakeupHelper {