diff options
Diffstat (limited to 'startop')
-rw-r--r-- | startop/iorap/stress/Android.bp | 33 | ||||
-rw-r--r-- | startop/iorap/stress/main_memory.cc | 126 | ||||
-rw-r--r-- | startop/iorap/tests/src/com/google/android/startop/iorap/IIorapIntegrationTest.kt | 5 | ||||
-rw-r--r-- | startop/view_compiler/dex_layout_compiler.cc | 4 | ||||
-rw-r--r-- | startop/view_compiler/util.cc | 4 |
5 files changed, 168 insertions, 4 deletions
diff --git a/startop/iorap/stress/Android.bp b/startop/iorap/stress/Android.bp new file mode 100644 index 000000000000..f9f251bdd889 --- /dev/null +++ b/startop/iorap/stress/Android.bp @@ -0,0 +1,33 @@ +// +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +cc_binary { + name: "iorap.stress.memory", + srcs: ["main_memory.cc"], + + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + "-Wno-unused-parameter" + ], + + shared_libs: [ + "libbase" + ], + + host_supported: true, +} diff --git a/startop/iorap/stress/main_memory.cc b/startop/iorap/stress/main_memory.cc new file mode 100644 index 000000000000..1f268619e4d9 --- /dev/null +++ b/startop/iorap/stress/main_memory.cc @@ -0,0 +1,126 @@ +// +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include <chrono> +#include <fstream> +#include <iostream> +#include <random> +#include <string> + +#include <string.h> +#include <stdlib.h> +#include <sys/mman.h> + +#include <android-base/parseint.h> + +static constexpr size_t kBytesPerMb = 1048576; +const size_t kMemoryAllocationSize = 2 * 1024 * kBytesPerMb; + +#define USE_MLOCKALL 0 + +std::string GetProcessStatus(const char* key) { + // Build search pattern of key and separator. + std::string pattern(key); + pattern.push_back(':'); + + // Search for status lines starting with pattern. + std::ifstream fs("/proc/self/status"); + std::string line; + while (std::getline(fs, line)) { + if (strncmp(pattern.c_str(), line.c_str(), pattern.size()) == 0) { + // Skip whitespace in matching line (if any). + size_t pos = line.find_first_not_of(" \t", pattern.size()); + if (pos == std::string::npos) { + break; + } + return std::string(line, pos); + } + } + return "<unknown>"; +} + +int main(int argc, char** argv) { + size_t allocationSize = 0; + if (argc >= 2) { + if (!android::base::ParseUint(argv[1], /*out*/&allocationSize)) { + std::cerr << "Failed to parse the allocation size (must be 0,MAX_SIZE_T)" << std::endl; + return 1; + } + } else { + allocationSize = kMemoryAllocationSize; + } + + void* mem = malloc(allocationSize); + if (mem == nullptr) { + std::cerr << "Malloc failed" << std::endl; + return 1; + } + + volatile int* imem = static_cast<int *>(mem); // don't optimize out memory usage + + size_t imemCount = allocationSize / sizeof(int); + + std::cout << "Allocated " << allocationSize << " bytes" << std::endl; + + auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); + std::mt19937 mt_rand(seed); + + size_t randPrintCount = 10; + + // Write random numbers: + // * Ensures each page is resident + // * Avoids zeroed out pages (zRAM) + // * Avoids same-page merging + for (size_t i = 0; i < imemCount; ++i) { + imem[i] = mt_rand(); + + if (i < randPrintCount) { + std::cout << "Generated random value: " << imem[i] << std::endl; + } + } + +#if USE_MLOCKALL + /* + * Lock all pages from the address space of this process. + */ + if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) { + std::cerr << "Mlockall failed" << std::endl; + return 1; + } +#else + // Use mlock because of the predictable VmLck size. + // Using mlockall tends to bring in anywhere from 2-2.5GB depending on the device. + if (mlock(mem, allocationSize) != 0) { + std::cerr << "Mlock failed" << std::endl; + return 1; + } +#endif + + // Validate memory is actually resident and locked with: + // $> cat /proc/$(pidof iorap.stress.memory)/status | grep VmLck + std::cout << "Locked memory (VmLck) = " << GetProcessStatus("VmLck") << std::endl; + + std::cout << "Press any key to terminate" << std::endl; + int any_input; + std::cin >> any_input; + + std::cout << "Terminating..." << std::endl; + + munlockall(); + free(mem); + + return 0; +} diff --git a/startop/iorap/tests/src/com/google/android/startop/iorap/IIorapIntegrationTest.kt b/startop/iorap/tests/src/com/google/android/startop/iorap/IIorapIntegrationTest.kt index 460add897f2f..18c249136d05 100644 --- a/startop/iorap/tests/src/com/google/android/startop/iorap/IIorapIntegrationTest.kt +++ b/startop/iorap/tests/src/com/google/android/startop/iorap/IIorapIntegrationTest.kt @@ -16,6 +16,7 @@ package com.google.android.startop.iorap import android.net.Uri import android.os.ServiceManager +import androidx.test.filters.FlakyTest import androidx.test.filters.MediumTest import org.junit.Test import org.mockito.Mockito.argThat @@ -26,6 +27,7 @@ import org.mockito.Mockito.timeout // @Ignore("Test is disabled until iorapd is added to init and there's selinux policies for it") @MediumTest +@FlakyTest(bugId = 149098310) // Failing on cuttlefish with SecurityException. class IIorapIntegrationTest { /** * @throws ServiceManager.ServiceNotFoundException if iorapd service could not be found @@ -55,6 +57,9 @@ class IIorapIntegrationTest { private fun testAnyMethod(func: (RequestId) -> Unit) { val taskListener = spy(DummyTaskListener())!! + // FIXME: b/149098310 + return + try { iorapService.setTaskListener(taskListener) // Note: Binder guarantees total order for oneway messages sent to the same binder diff --git a/startop/view_compiler/dex_layout_compiler.cc b/startop/view_compiler/dex_layout_compiler.cc index cb820f8f20fb..bddb8aa6716a 100644 --- a/startop/view_compiler/dex_layout_compiler.cc +++ b/startop/view_compiler/dex_layout_compiler.cc @@ -118,7 +118,7 @@ namespace { std::string ResolveName(const std::string& name) { if (name == "View") return "android.view.View"; if (name == "ViewGroup") return "android.view.ViewGroup"; - if (name.find(".") == std::string::npos) { + if (name.find('.') == std::string::npos) { return StringPrintf("android.widget.%s", name.c_str()); } return name; @@ -205,4 +205,4 @@ void DexViewBuilder::PopViewStack() { view_stack_.pop_back(); } -} // namespace startop
\ No newline at end of file +} // namespace startop diff --git a/startop/view_compiler/util.cc b/startop/view_compiler/util.cc index a0637e6da32f..c34d7b059cfc 100644 --- a/startop/view_compiler/util.cc +++ b/startop/view_compiler/util.cc @@ -23,13 +23,13 @@ namespace util { // TODO: see if we can borrow this from somewhere else, like aapt2. string FindLayoutNameFromFilename(const string& filename) { - size_t start = filename.rfind("/"); + size_t start = filename.rfind('/'); if (start == string::npos) { start = 0; } else { start++; // advance past '/' character } - size_t end = filename.find(".", start); + size_t end = filename.find('.', start); return filename.substr(start, end - start); } |