Merge "Add #defines for some key enums."
diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp
index e6c6570..86a7c35 100644
--- a/benchmarks/string_benchmark.cpp
+++ b/benchmarks/string_benchmark.cpp
@@ -173,3 +173,33 @@
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
BENCHMARK(BM_string_strcat_half_copy_half_seek)->AT_COMMON_SIZES;
+
+static void BM_string_strcpy(benchmark::State& state) {
+ const size_t nbytes = state.range(0);
+ std::vector<char> src(nbytes, 'x');
+ std::vector<char> dst(nbytes);
+ src[nbytes - 1] = '\0';
+
+ while (state.KeepRunning()) {
+ strcpy(dst.data(), src.data());
+ }
+
+ state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
+}
+BENCHMARK(BM_string_strcpy)->AT_COMMON_SIZES;
+
+static void BM_string_strcmp(benchmark::State& state) {
+ const size_t nbytes = state.range(0);
+ std::vector<char> s1(nbytes, 'x');
+ std::vector<char> s2(nbytes, 'x');
+ s1[nbytes - 1] = '\0';
+ s2[nbytes - 1] = '\0';
+
+ volatile int c __attribute__((unused));
+ while (state.KeepRunning()) {
+ c = strcmp(s1.data(), s2.data());
+ }
+
+ state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
+}
+BENCHMARK(BM_string_strcmp)->AT_COMMON_SIZES;
diff --git a/libc/arch-arm/include/machine/cpu-features.h b/libc/arch-arm/include/machine/cpu-features.h
index fc8c80d..a46149b 100644
--- a/libc/arch-arm/include/machine/cpu-features.h
+++ b/libc/arch-arm/include/machine/cpu-features.h
@@ -28,6 +28,9 @@
#ifndef _ARM_MACHINE_CPU_FEATURES_H
#define _ARM_MACHINE_CPU_FEATURES_H
+// cpu-features.h is deprecated, so warn if it is included //
+#warning cpu-features.h is deprecated
+
/* __ARM_ARCH__ is a number corresponding to the ARM revision
* we're going to support. Our toolchain doesn't define __ARM_ARCH__
* so try to guess it.
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index a7b9d52..ddd78b0 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -100,16 +100,6 @@
}
}
-TEST(malloc, posix_memalign_non_power2) {
- void* ptr;
- ASSERT_EQ(EINVAL, posix_memalign(&ptr, 17, 1024));
-}
-
-TEST(malloc, posix_memalign_overflow) {
- void* ptr;
- ASSERT_NE(0, posix_memalign(&ptr, 16, SIZE_MAX));
-}
-
TEST(malloc, memalign_realloc) {
// Memalign and then realloc the pointer a couple of times.
for (size_t alignment = 1; alignment <= 4096; alignment <<= 1) {
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index fc17cde..4c4c102 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -138,15 +138,48 @@
EXPECT_EQ(795539493, mrand48());
}
-TEST(stdlib, posix_memalign) {
- void* p;
+TEST(stdlib, posix_memalign_sweep) {
+ void* ptr;
- ASSERT_EQ(0, posix_memalign(&p, 512, 128));
- ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(p) % 512);
- free(p);
+ // These should all fail.
+ for (size_t align = 0; align < sizeof(long); align++) {
+ ASSERT_EQ(EINVAL, posix_memalign(&ptr, align, 256))
+ << "Unexpected value at align " << align;
+ }
- // Can't align to a non-power of 2.
- ASSERT_EQ(EINVAL, posix_memalign(&p, 81, 128));
+ // Verify powers of 2 up to 2048 allocate, and verify that all other
+ // alignment values between the powers of 2 fail.
+ size_t last_align = sizeof(long);
+ for (size_t align = sizeof(long); align <= 2048; align <<= 1) {
+ // Try all of the non power of 2 values from the last until this value.
+ for (size_t fail_align = last_align + 1; fail_align < align; fail_align++) {
+ ASSERT_EQ(EINVAL, posix_memalign(&ptr, fail_align, 256))
+ << "Unexpected success at align " << fail_align;
+ }
+ ASSERT_EQ(0, posix_memalign(&ptr, align, 256))
+ << "Unexpected failure at align " << align;
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & (align - 1))
+ << "Did not return a valid aligned ptr " << ptr << " expected alignment " << align;
+ free(ptr);
+ last_align = align;
+ }
+}
+
+TEST(stdlib, posix_memalign_various_sizes) {
+ std::vector<size_t> sizes{1, 4, 8, 256, 1024, 65000, 128000, 256000, 1000000};
+ for (auto size : sizes) {
+ void* ptr;
+ ASSERT_EQ(0, posix_memalign(&ptr, 16, 1))
+ << "posix_memalign failed at size " << size;
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & 0xf)
+ << "Pointer not aligned at size " << size << " ptr " << ptr;
+ free(ptr);
+ }
+}
+
+TEST(stdlib, posix_memalign_overflow) {
+ void* ptr;
+ ASSERT_NE(0, posix_memalign(&ptr, 16, SIZE_MAX));
}
TEST(stdlib, realpath__NULL_filename) {