Merge "linker: add the L3 cache auxv constants." into main
diff --git a/libc/NOTICE b/libc/NOTICE
index ef64e0c..d464e1d 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -942,6 +942,35 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 1982, 1986, 1988, 1993
+   The Regents of the University of California.  All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 1982, 1986, 1993
    The Regents of the University of California.  All rights reserved.
 
diff --git a/libc/include/syslog.h b/libc/include/syslog.h
index 90ea76e..1e2fcc4 100644
--- a/libc/include/syslog.h
+++ b/libc/include/syslog.h
@@ -25,6 +25,34 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 
 #pragma once
 
@@ -129,6 +157,60 @@
  */
 #define LOG_PERROR 0x20
 
+#if defined(SYSLOG_NAMES)
+/** A mapping from name to value, used by `facilitynames` and `prioritynames`. */
+typedef struct _code {
+  char* c_name;
+  int c_val;
+} CODE;
+/* A bogus facility value for "mark". */
+#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0)
+/** A table mapping facility names to values. */
+static const CODE facilitynames[] = {
+  { "auth", LOG_AUTH, },
+  { "authpriv", LOG_AUTHPRIV, },
+  { "cron", LOG_CRON, },
+  { "daemon", LOG_DAEMON, },
+  { "ftp", LOG_FTP, },
+  { "kern", LOG_KERN, },
+  { "lpr", LOG_LPR, },
+  { "mail", LOG_MAIL, },
+  { "mark", INTERNAL_MARK, },
+  { "news", LOG_NEWS, },
+  { "security", LOG_AUTH, },
+  { "syslog", LOG_SYSLOG, },
+  { "user", LOG_USER, },
+  { "uucp", LOG_UUCP, },
+  { "local0", LOG_LOCAL0, },
+  { "local1", LOG_LOCAL1, },
+  { "local2", LOG_LOCAL2, },
+  { "local3", LOG_LOCAL3, },
+  { "local4", LOG_LOCAL4, },
+  { "local5", LOG_LOCAL5, },
+  { "local6", LOG_LOCAL6, },
+  { "local7", LOG_LOCAL7, },
+  { NULL, -1, },
+};
+/* A bogus priority value for "none". */
+#define INTERNAL_NOPRI 8
+/** A table mapping priority names to values. */
+static const CODE prioritynames[] = {
+  { "alert", LOG_ALERT, },
+  { "crit", LOG_CRIT, },
+  { "debug", LOG_DEBUG, },
+  { "emerg", LOG_EMERG, },
+  { "err", LOG_ERR, },
+  { "error", LOG_ERR, },
+  { "info", LOG_INFO, },
+  { "none", INTERNAL_NOPRI, },
+  { "notice", LOG_NOTICE, },
+  { "panic", LOG_EMERG, },
+  { "warn", LOG_WARNING, },
+  { "warning", LOG_WARNING, },
+  { NULL, -1, },
+};
+#endif
+
 /**
  * [closelog(3)](http://man7.org/linux/man-pages/man3/closelog.3.html) does
  * nothing on Android.
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 97ae709..0ad0fd5 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -849,7 +849,7 @@
  *   load_bias   -> load bias
  *   prop        -> GnuPropertySection or nullptr
  * Return:
- *   0 on error, -1 on failure (error code in errno).
+ *   0 on success, -1 on failure (error code in errno).
  */
 int phdr_table_protect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                                 ElfW(Addr) load_bias, const GnuPropertySection* prop __unused) {
@@ -876,7 +876,7 @@
  *   phdr_count  -> number of entries in tables
  *   load_bias   -> load bias
  * Return:
- *   0 on error, -1 on failure (error code in errno).
+ *   0 on success, -1 on failure (error code in errno).
  */
 int phdr_table_unprotect_segments(const ElfW(Phdr)* phdr_table,
                                   size_t phdr_count, ElfW(Addr) load_bias) {
@@ -939,7 +939,7 @@
  *   phdr_count  -> number of entries in tables
  *   load_bias   -> load bias
  * Return:
- *   0 on error, -1 on failure (error code in errno).
+ *   0 on success, -1 on failure (error code in errno).
  */
 int phdr_table_protect_gnu_relro(const ElfW(Phdr)* phdr_table,
                                  size_t phdr_count, ElfW(Addr) load_bias) {
@@ -957,7 +957,7 @@
  *   fd          -> writable file descriptor to use
  *   file_offset -> pointer to offset into file descriptor to use/update
  * Return:
- *   0 on error, -1 on failure (error code in errno).
+ *   0 on success, -1 on failure (error code in errno).
  */
 int phdr_table_serialize_gnu_relro(const ElfW(Phdr)* phdr_table,
                                    size_t phdr_count,
@@ -1005,7 +1005,7 @@
  *   fd          -> readable file descriptor to use
  *   file_offset -> pointer to offset into file descriptor to use/update
  * Return:
- *   0 on error, -1 on failure (error code in errno).
+ *   0 on success, -1 on failure (error code in errno).
  */
 int phdr_table_map_gnu_relro(const ElfW(Phdr)* phdr_table,
                              size_t phdr_count,
@@ -1102,7 +1102,7 @@
  *   arm_exidx       -> address of table in memory (null on failure).
  *   arm_exidx_count -> number of items in table (0 on failure).
  * Return:
- *   0 on error, -1 on failure (_no_ error code in errno)
+ *   0 on success, -1 on failure (_no_ error code in errno)
  */
 int phdr_table_get_arm_exidx(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                              ElfW(Addr) load_bias,
diff --git a/tests/bionic_allocator_test.cpp b/tests/bionic_allocator_test.cpp
index fdcf868..d543d26 100644
--- a/tests/bionic_allocator_test.cpp
+++ b/tests/bionic_allocator_test.cpp
@@ -238,23 +238,27 @@
 TEST(bionic_allocator, test_memalign_large) {
   BionicAllocator allocator;
   void* ptr;
+  size_t alignment;
 
-  // a large object with alignment < PAGE_SIZE
-  ptr = allocator.memalign(0x100, 0x2000);
+  // a large object with alignment < kPageSize
+  alignment = kPageSize >> 1;
+  ptr = allocator.memalign(alignment, 0x2000);
   ASSERT_TRUE(ptr != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % 0x100);
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % alignment);
   allocator.free(ptr);
 
-  // a large object with alignment == PAGE_SIZE
-  ptr = allocator.memalign(0x1000, 0x2000);
+  // a large object with alignment == kPageSize
+  alignment = kPageSize;
+  ptr = allocator.memalign(alignment, 0x2000);
   ASSERT_TRUE(ptr != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % 0x1000);
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % alignment);
   allocator.free(ptr);
 
-  // A large object with alignment > PAGE_SIZE is only guaranteed to have page
+  // A large object with alignment > kPageSize is only guaranteed to have page
   // alignment.
-  ptr = allocator.memalign(0x2000, 0x4000);
+  alignment = kPageSize << 1;
+  ptr = allocator.memalign(alignment, 0x4000);
   ASSERT_TRUE(ptr != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % 0x1000);
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % kPageSize);
   allocator.free(ptr);
 }
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 3c2dcf2..d078e50 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -85,6 +85,7 @@
   }
 
   void* handle_;
+  const size_t kPageSize = getpagesize();
 };
 
 TEST_F(DlExtTest, ExtInfoNull) {
@@ -159,12 +160,12 @@
   ASSERT_STREQ("dlopen failed: file offset for the library \"libname_placeholder\" is not page-aligned: 17", dlerror());
 
   // Test an address above 2^44, for http://b/18178121 .
-  extinfo.library_fd_offset = (5LL<<48) + PAGE_SIZE;
+  extinfo.library_fd_offset = (5LL << 48) + kPageSize;
   handle_ = android_dlopen_ext("libname_placeholder", RTLD_NOW, &extinfo);
   ASSERT_TRUE(handle_ == nullptr);
   ASSERT_SUBSTR("dlopen failed: file offset for the library \"libname_placeholder\" >= file size", dlerror());
 
-  extinfo.library_fd_offset = 0LL - PAGE_SIZE;
+  extinfo.library_fd_offset = 0LL - kPageSize;
   handle_ = android_dlopen_ext("libname_placeholder", RTLD_NOW, &extinfo);
   ASSERT_TRUE(handle_ == nullptr);
   ASSERT_SUBSTR("dlopen failed: file offset for the library \"libname_placeholder\" is negative", dlerror());
@@ -340,17 +341,17 @@
   dlclose(handle_);
   handle_ = nullptr;
 
-  void* new_start = mmap(start, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* new_start = mmap(start, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(start, new_start) << "dlclose unmapped reserved space";
 }
 
 TEST_F(DlExtTest, ReservedTooSmall) {
-  void* start = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* start = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_TRUE(start != MAP_FAILED);
   android_dlextinfo extinfo;
   extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
   extinfo.reserved_addr = start;
-  extinfo.reserved_size = PAGE_SIZE;
+  extinfo.reserved_size = kPageSize;
   handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
   EXPECT_EQ(nullptr, handle_);
 }
@@ -389,12 +390,12 @@
 }
 
 TEST_F(DlExtTest, ReservedRecursiveTooSmall) {
-  void* start = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* start = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_TRUE(start != MAP_FAILED);
   android_dlextinfo extinfo;
   extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS | ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE;
   extinfo.reserved_addr = start;
-  extinfo.reserved_size = PAGE_SIZE;
+  extinfo.reserved_size = kPageSize;
   handle_ = android_dlopen_ext(kLibNameRecursive, RTLD_NOW, &extinfo);
   EXPECT_EQ(nullptr, handle_);
 }
@@ -417,19 +418,18 @@
 }
 
 TEST_F(DlExtTest, ReservedHintTooSmall) {
-  void* start = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* start = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_TRUE(start != MAP_FAILED);
   android_dlextinfo extinfo;
   extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS_HINT;
   extinfo.reserved_addr = start;
-  extinfo.reserved_size = PAGE_SIZE;
+  extinfo.reserved_size = kPageSize;
   handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
   ASSERT_DL_NOTNULL(handle_);
   fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
   ASSERT_DL_NOTNULL(f);
   EXPECT_TRUE(reinterpret_cast<void*>(f) < start ||
-              (reinterpret_cast<void*>(f) >=
-               reinterpret_cast<char*>(start) + PAGE_SIZE));
+              (reinterpret_cast<void*>(f) >= reinterpret_cast<char*>(start) + kPageSize));
   EXPECT_EQ(4, f());
 }
 
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 67f1973..5b3eaf8 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -824,6 +824,8 @@
 }
 
 TEST(dlfcn, dlclose_unload) {
+  const size_t kPageSize = getpagesize();
+
   void* handle = dlopen("libtest_simple.so", RTLD_NOW);
   ASSERT_TRUE(handle != nullptr) << dlerror();
   uint32_t* taxicab_number = static_cast<uint32_t*>(dlsym(handle, "dlopen_testlib_taxicab_number"));
@@ -833,8 +835,8 @@
   // Making sure that the library has been unmapped as part of library unload
   // process. Note that mprotect somewhat counter-intuitively returns ENOMEM in
   // this case.
-  uintptr_t page_start = reinterpret_cast<uintptr_t>(taxicab_number) & ~(PAGE_SIZE - 1);
-  ASSERT_TRUE(mprotect(reinterpret_cast<void*>(page_start), PAGE_SIZE, PROT_NONE) != 0);
+  uintptr_t page_start = reinterpret_cast<uintptr_t>(taxicab_number) & ~(kPageSize - 1);
+  ASSERT_TRUE(mprotect(reinterpret_cast<void*>(page_start), kPageSize, PROT_NONE) != 0);
   ASSERT_ERRNO(ENOMEM);
 }
 
diff --git a/tests/libs/stack_tagging_helper.cpp b/tests/libs/stack_tagging_helper.cpp
index d29844d..7396dd0 100644
--- a/tests/libs/stack_tagging_helper.cpp
+++ b/tests/libs/stack_tagging_helper.cpp
@@ -240,14 +240,14 @@
 }
 
 void test_longjmp_sigaltstack() {
-  constexpr size_t kAltStackSize = kStackAllocationSize + PAGE_SIZE * 16;
+  const size_t kAltStackSize = kStackAllocationSize + getpagesize() * 16;
   SigAltStackScoped sigAltStackScoped(kAltStackSize);
   SigActionScoped sigActionScoped(
       SIGUSR1, [](int, siginfo_t*, void*) { check_longjmp_restores_tags(); });
   raise(SIGUSR1);
 
   // same for a secondary thread
-  std::thread t([]() {
+  std::thread t([&]() {
     SigAltStackScoped sigAltStackScoped(kAltStackSize);
     raise(SIGUSR1);
   });
diff --git a/tests/sys_mman_test.cpp b/tests/sys_mman_test.cpp
index e785ff4..df13e07 100644
--- a/tests/sys_mman_test.cpp
+++ b/tests/sys_mman_test.cpp
@@ -25,6 +25,8 @@
 
 #include "utils.h"
 
+static const size_t kPageSize = getpagesize();
+
 TEST(sys_mman, mmap_std) {
   void* map = mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   ASSERT_NE(MAP_FAILED, map);
@@ -233,42 +235,42 @@
 }
 
 TEST(sys_mman, mremap_PTRDIFF_MAX) {
-  void* map = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* map = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(MAP_FAILED, map);
 
-  ASSERT_EQ(MAP_FAILED, mremap(map, PAGE_SIZE, kHuge, MREMAP_MAYMOVE));
+  ASSERT_EQ(MAP_FAILED, mremap(map, kPageSize, kHuge, MREMAP_MAYMOVE));
 
-  ASSERT_EQ(0, munmap(map, PAGE_SIZE));
+  ASSERT_EQ(0, munmap(map, kPageSize));
 }
 
 TEST(sys_mman, mmap_bug_27265969) {
-  char* base = reinterpret_cast<char*>(mmap(nullptr, PAGE_SIZE * 2, PROT_EXEC | PROT_READ,
-                                            MAP_ANONYMOUS | MAP_PRIVATE, -1, 0));
+  char* base = reinterpret_cast<char*>(
+      mmap(nullptr, kPageSize * 2, PROT_EXEC | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0));
   // Some kernels had bugs that would cause segfaults here...
-  __builtin___clear_cache(base, base + (PAGE_SIZE * 2));
+  __builtin___clear_cache(base, base + (kPageSize * 2));
 }
 
 TEST(sys_mman, mlock) {
-  void* map = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* map = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(MAP_FAILED, map);
 
   // Not really anything we can assert about this.
-  mlock(map, PAGE_SIZE);
+  mlock(map, kPageSize);
 
-  ASSERT_EQ(0, munmap(map, PAGE_SIZE));
+  ASSERT_EQ(0, munmap(map, kPageSize));
 }
 
 TEST(sys_mman, mlock2) {
 #if defined(__GLIBC__)
   GTEST_SKIP() << "needs glibc 2.27";
 #else
-  void* map = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  void* map = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(MAP_FAILED, map);
 
   // Not really anything we can assert about this.
-  mlock2(map, PAGE_SIZE, MLOCK_ONFAULT);
+  mlock2(map, kPageSize, MLOCK_ONFAULT);
 
-  ASSERT_EQ(0, munmap(map, PAGE_SIZE));
+  ASSERT_EQ(0, munmap(map, kPageSize));
 #endif
 }
 
diff --git a/tests/syslog_test.cpp b/tests/syslog_test.cpp
index 3ec3337..623d8a3 100644
--- a/tests/syslog_test.cpp
+++ b/tests/syslog_test.cpp
@@ -26,6 +26,9 @@
  * SUCH DAMAGE.
  */
 
+#include <stddef.h>  // glibc's <syslog.h> breaks without this; musl seems fine.
+
+#define SYSLOG_NAMES
 #include <syslog.h>
 
 #include <errno.h>
@@ -72,3 +75,34 @@
       },
       0, "bar: x{1023}\n");
 }
+
+static int by_name(const CODE* array, const char* name) {
+  for (auto c = array; c->c_name != nullptr; c++) {
+    if (!strcmp(c->c_name, name)) return c->c_val;
+  }
+  return -1;
+}
+
+static const char* by_value(const CODE* array, int value) {
+  for (auto c = array; c->c_name != nullptr; c++) {
+    if (c->c_val == value) return c->c_name;
+  }
+  return nullptr;
+}
+
+TEST(syslog, facilitynames) {
+  ASSERT_STREQ("auth", by_value(facilitynames, LOG_AUTH));
+  ASSERT_STREQ("local7", by_value(facilitynames, LOG_LOCAL7));
+  ASSERT_EQ(LOG_AUTH, by_name(facilitynames, "auth"));
+  ASSERT_EQ(LOG_LOCAL7, by_name(facilitynames, "local7"));
+}
+
+TEST(syslog, prioritynames) {
+  ASSERT_STREQ("alert", by_value(prioritynames, LOG_ALERT));
+  ASSERT_STREQ("err", by_value(prioritynames, LOG_ERR));
+  ASSERT_STREQ("warn", by_value(prioritynames, LOG_WARNING));
+  ASSERT_EQ(LOG_ALERT, by_name(prioritynames, "alert"));
+  ASSERT_EQ(LOG_ERR, by_name(prioritynames, "err"));
+  ASSERT_EQ(LOG_WARNING, by_name(prioritynames, "warn"));
+  ASSERT_EQ(LOG_WARNING, by_name(prioritynames, "warning"));
+}