summaryrefslogtreecommitdiff
path: root/tests/kernel.config/scrape_mmap_addr.cpp
diff options
context:
space:
mode:
authordcashman <dcashman@google.com>2016-03-07 10:32:05 -0800
committerdcashman <dcashman@google.com>2016-03-09 16:39:14 -0800
commitd661642651a6689c76d3f575b4b5dbf04e6b75bd (patch)
treef52dde11935ced3208c4071e5b9af0fbc8e961a7 /tests/kernel.config/scrape_mmap_addr.cpp
parent0a34d462046a77c7649a40226b06c2232a547635 (diff)
downloadextras-d661642651a6689c76d3f575b4b5dbf04e6b75bd.tar.gz
Migrate aslr test to gtest.
Create tests which test the values of mmap_rnd_bits, and mmap_rnd_compat_bits, if applicable, and verify that the address space is randomized as expected given the provided values. Also add a pair of tests to CTS that enforce that the observed entropy is at least as high as a designated value. That value will start as our default value, which also corresponds to the maximum value of some configurations. Packaging of executables along with a nativetest suite is not supported, so add a dummy nativetest suite, scrape_mmap_addr, which ensure that the executables are present along with the given tests at predictable locations. Bug: 26512380 Change-Id: Ib1202984f9b98c503b8d3bc2c2248a9d06940845
Diffstat (limited to 'tests/kernel.config/scrape_mmap_addr.cpp')
-rw-r--r--tests/kernel.config/scrape_mmap_addr.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/kernel.config/scrape_mmap_addr.cpp b/tests/kernel.config/scrape_mmap_addr.cpp
new file mode 100644
index 00000000..be5995f1
--- /dev/null
+++ b/tests/kernel.config/scrape_mmap_addr.cpp
@@ -0,0 +1,32 @@
+#include <errno.h>
+#include <fstream>
+#include <iostream>
+#include <regex>
+#include <string>
+#include <string.h>
+
+int main(int argc, char * argv[]) {
+ if (argc != 2) {
+ std::cerr << "usage: " << argv[0] << ": libname\n";
+ return -1;
+ }
+ std::regex reg(std::string("^([a-f0-9]+)\\-[0-9a-f]+\\s+.+\\s+(\\d+)\\s+.+\\s+\\d+\\s+") + std::string(argv[1]) + std::string("\\s*$"));
+
+ /* open /proc/self/maps */
+ std::string ln;
+ std::ifstream m_file("/proc/self/maps");
+ if (!m_file) {
+ std::cerr << "Unable to open /proc/self/maps " << strerror(errno) << "\n";
+ return -1;
+ }
+ while (getline(m_file, ln)) {
+ std::smatch sm;
+ if (std::regex_match (ln,sm, reg)) {
+ if (std::stoi(sm[2]) == 0) {
+ std::cout << sm[1];
+ return 0;
+ }
+ }
+ }
+ return -1;
+}