aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rwxr-xr-xscripts/android-armv7-build.sh13
-rwxr-xr-xscripts/android-armv7-cache-info.sh6
-rwxr-xr-xscripts/android-armv7-cpu-info.sh6
-rwxr-xr-xscripts/android-armv7-isa-info.sh6
-rwxr-xr-xscripts/android-armv7-mock.sh41
-rwxr-xr-xscripts/android-armv7-test.sh6
-rwxr-xr-xscripts/android-filesystem-dump.py122
-rw-r--r--scripts/arm-linux-filesystem-dump.py107
-rw-r--r--src/linux/multiline.c1
-rw-r--r--src/linux/smallfile.c1
11 files changed, 315 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6a18ce..1be3bd8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -130,6 +130,9 @@ TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE src)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
TARGET_LINK_LIBRARIES(cpuinfo PUBLIC ${CMAKE_THREAD_LIBS_INIT})
ENDIF()
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ TARGET_COMPILE_DEFINITIONS(cpuinfo PRIVATE -D_GNU_SOURCE)
+ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|arm64)$")
TARGET_LINK_LIBRARIES(cpuinfo INTERFACE "-framework OpenGLES")
TARGET_LINK_LIBRARIES(cpuinfo INTERFACE "-framework Foundation")
@@ -165,6 +168,9 @@ IF(CPUINFO_BUILD_MOCK_TESTS)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
TARGET_LINK_LIBRARIES(cpuinfo_mock PUBLIC ${CMAKE_THREAD_LIBS_INIT})
ENDIF()
+ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ TARGET_COMPILE_DEFINITIONS(cpuinfo_mock PRIVATE -D_GNU_SOURCE)
+ ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv5te|armv7-a)$")
ADD_EXECUTABLE(blu-r1-hd-test test/mock/blu-r1-hd.cc)
diff --git a/scripts/android-armv7-build.sh b/scripts/android-armv7-build.sh
new file mode 100755
index 0000000..094e9eb
--- /dev/null
+++ b/scripts/android-armv7-build.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+set -e
+
+SYSTEMNAME=`uname`
+if [[ "$SYSTEMNAME" == 'Darwin' ]]
+then
+ PROCESSORS=`sysctl -n hw.ncpu`
+else
+ PROCESSORS=`nproc`
+fi
+
+ndk-build APP_ABI=armeabi-v7a -j$PROCESSORS
diff --git a/scripts/android-armv7-cache-info.sh b/scripts/android-armv7-cache-info.sh
new file mode 100755
index 0000000..ab1313e
--- /dev/null
+++ b/scripts/android-armv7-cache-info.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/armeabi-v7a/cache-info /data/local/tmp/cache-info
+adb shell /data/local/tmp/cache-info
diff --git a/scripts/android-armv7-cpu-info.sh b/scripts/android-armv7-cpu-info.sh
new file mode 100755
index 0000000..cd7d885
--- /dev/null
+++ b/scripts/android-armv7-cpu-info.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/armeabi-v7a/cpu-info /data/local/tmp/cpu-info
+adb shell /data/local/tmp/cpu-info
diff --git a/scripts/android-armv7-isa-info.sh b/scripts/android-armv7-isa-info.sh
new file mode 100755
index 0000000..7b0176a
--- /dev/null
+++ b/scripts/android-armv7-isa-info.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/armeabi-v7a/isa-info /data/local/tmp/isa-info
+adb shell /data/local/tmp/isa-info
diff --git a/scripts/android-armv7-mock.sh b/scripts/android-armv7-mock.sh
new file mode 100755
index 0000000..9991b5b
--- /dev/null
+++ b/scripts/android-armv7-mock.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/armeabi-v7a/blu-r1-hd-test /data/local/tmp/blu-r1-hd-test
+adb push libs/armeabi-v7a/moto-e-gen1-test /data/local/tmp/moto-e-gen1-test
+adb push libs/armeabi-v7a/moto-g-gen2-test /data/local/tmp/moto-g-gen2-test
+adb push libs/armeabi-v7a/moto-g-gen3-test /data/local/tmp/moto-g-gen3-test
+adb push libs/armeabi-v7a/nexus4-test /data/local/tmp/nexus4-test
+adb push libs/armeabi-v7a/nexus5x-test /data/local/tmp/nexus5x-test
+adb push libs/armeabi-v7a/nexus6-test /data/local/tmp/nexus6-test
+adb push libs/armeabi-v7a/nexus6p-test /data/local/tmp/nexus6p-test
+adb push libs/armeabi-v7a/nexus9-test /data/local/tmp/nexus9-test
+adb push libs/armeabi-v7a/meizu-pro-6s-test /data/local/tmp/meizu-pro-6s-test
+adb push libs/armeabi-v7a/galaxy-grand-prime-value-edition-test /data/local/tmp/galaxy-grand-prime-value-edition-test
+adb push libs/armeabi-v7a/galaxy-s3-us-test /data/local/tmp/galaxy-s3-us-test
+adb push libs/armeabi-v7a/galaxy-s4-us-test /data/local/tmp/galaxy-s4-us-test
+adb push libs/armeabi-v7a/galaxy-s6-test /data/local/tmp/galaxy-s6-test
+adb push libs/armeabi-v7a/galaxy-s7-us-test /data/local/tmp/galaxy-s7-us-test
+adb push libs/armeabi-v7a/galaxy-s7-global-test /data/local/tmp/galaxy-s7-global-test
+adb push libs/armeabi-v7a/galaxy-s8-us-test /data/local/tmp/galaxy-s8-us-test
+adb push libs/armeabi-v7a/galaxy-s8-global-test /data/local/tmp/galaxy-s8-global-test
+
+# adb shell "/data/local/tmp/blu-r1-hd-test --gtest_color=yes"
+# adb shell "/data/local/tmp/moto-e-gen1-test --gtest_color=yes"
+# adb shell "/data/local/tmp/moto-g-gen2-test --gtest_color=yes"
+# adb shell "/data/local/tmp/moto-g-gen3-test --gtest_color=yes"
+# adb shell "/data/local/tmp/nexus4-test --gtest_color=yes"
+# adb shell "/data/local/tmp/nexus5x-test --gtest_color=yes"
+# adb shell "/data/local/tmp/nexus6-test --gtest_color=yes"
+# adb shell "/data/local/tmp/nexus6p-test --gtest_color=yes"
+# adb shell "/data/local/tmp/nexus9-test --gtest_color=yes"
+# adb shell "/data/local/tmp/meizu-pro-6s-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-grand-prime-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-s3-us-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-s4-us-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-s6-test --gtest_color=yes"
+adb shell "/data/local/tmp/galaxy-s7-us-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-s7-global-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-s8-us-test --gtest_color=yes"
+# adb shell "/data/local/tmp/galaxy-s8-global-test --gtest_color=yes"
diff --git a/scripts/android-armv7-test.sh b/scripts/android-armv7-test.sh
new file mode 100755
index 0000000..21d8f47
--- /dev/null
+++ b/scripts/android-armv7-test.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/armeabi-v7a/init-test /data/local/tmp/init-test
+adb shell /data/local/tmp/init-test --gtest_color=yes
diff --git a/scripts/android-filesystem-dump.py b/scripts/android-filesystem-dump.py
new file mode 100755
index 0000000..52d4fb9
--- /dev/null
+++ b/scripts/android-filesystem-dump.py
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import argparse
+import subprocess
+import tempfile
+
+
+parser = argparse.ArgumentParser(description='Android system files extractor')
+parser.add_argument("-p", "--prefix", metavar="NAME", required=True,
+ help="Prefix for stored files, e.g. galaxy-s7-us")
+
+
+SYSTEM_FILES = [
+ "/proc/cpuinfo",
+ "/system/build.prop",
+ "/sys/devices/system/cpu/kernel_max",
+ "/sys/devices/system/cpu/possible",
+ "/sys/devices/system/cpu/present",
+]
+
+CPU_FILES = [
+ "cpufreq/cpuinfo_max_freq",
+ "cpufreq/cpuinfo_min_freq",
+ "topology/physical_package_id",
+ "topology/core_siblings_list",
+ "topology/core_id",
+ "topology/thread_siblings_list",
+]
+
+CACHE_FILES = [
+ "allocation_policy",
+ "coherency_line_size",
+ "level",
+ "number_of_sets",
+ "shared_cpu_list",
+ "size",
+ "type",
+ "ways_of_associativity",
+ "write_policy",
+]
+
+def c_escape(string):
+ c_string = ""
+ for c in string:
+ if c == "\\":
+ c_string += "\\\\"
+ elif c == "\"":
+ c_string += "\\\""
+ elif c == "\t":
+ c_string += "\\t"
+ elif c == "\n":
+ c_string += "\\n"
+ elif c == "\r":
+ c_string += "\\r"
+ elif ord(c) == 0:
+ c_string += "\\0"
+ elif 32 <= ord(c) < 127:
+ c_string += c
+ else:
+ c_string += "x%02X" % ord(c)
+ return c_string
+
+def adb_pull(device_path, local_path):
+ env = os.environ.copy()
+ env["LC_ALL"] = "C"
+
+ adb = subprocess.Popen(["adb", "pull", device_path, local_path], env=env)
+ adb.communicate()
+ return adb.returncode == 0
+
+
+def dump_device_file(stream, path):
+ temp_fd, temp_path = tempfile.mkstemp()
+ os.close(temp_fd)
+ try:
+ if adb_pull(path, temp_path):
+ with open(temp_path, "rb") as temp_file:
+ content = temp_file.read()
+ stream.write("\t{\n")
+ stream.write("\t\t.path = \"%s\",\n" % path)
+ stream.write("\t\t.size = %d,\n" % len(content))
+ if len(content.splitlines()) > 1:
+ stream.write("\t\t.content =")
+ for line in content.splitlines(True):
+ stream.write("\n\t\t\t\"%s\"" % c_escape(line))
+ stream.write(",\n")
+ else:
+ stream.write("\t\t.content = \"%s\",\n" % c_escape(content))
+ stream.write("\t},\n")
+ return True
+ finally:
+ os.remove(temp_path)
+
+
+def main(args):
+ options = parser.parse_args(args)
+
+ # with open(os.path.join("test", "dmesg", options.prefix + ".log"), "w") as dmesg_log:
+ # dmesg_log.write(device.Shell("dmesg"))
+ with open(os.path.join("test", options.prefix + ".h"), "w") as file_header:
+ file_header.write("struct cpuinfo_mock_file filesystem[] = {\n")
+ for path in SYSTEM_FILES:
+ dump_device_file(file_header, path)
+ for cpu in range(16):
+ for filename in CPU_FILES:
+ path = "/sys/devices/system/cpu/cpu%d/%s" % (cpu, filename)
+ dump_device_file(file_header, path)
+ for index in range(10):
+ for filename in CACHE_FILES:
+ path = "/sys/devices/system/cpu/cpu%d/cache/index%d/%s" % (cpu, index, filename)
+ dump_device_file(file_header, path)
+ file_header.write("\t{ NULL },\n")
+ file_header.write("};\n")
+ adb_pull("/proc/cpuinfo",
+ os.path.join("test", "cpuinfo", options.prefix + ".log"))
+ adb_pull("/system/build.prop",
+ os.path.join("test", "build.prop", options.prefix + ".log"))
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
diff --git a/scripts/arm-linux-filesystem-dump.py b/scripts/arm-linux-filesystem-dump.py
new file mode 100644
index 0000000..feecf4b
--- /dev/null
+++ b/scripts/arm-linux-filesystem-dump.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import argparse
+import shutil
+
+
+parser = argparse.ArgumentParser(description='Android system files extractor')
+parser.add_argument("-p", "--prefix", metavar="NAME", required=True,
+ help="Prefix for stored files, e.g. galaxy-s7-us")
+
+
+SYSTEM_FILES = [
+ "/proc/cpuinfo",
+ "/sys/devices/system/cpu/kernel_max",
+ "/sys/devices/system/cpu/possible",
+ "/sys/devices/system/cpu/present",
+]
+
+CPU_FILES = [
+ "cpufreq/cpuinfo_max_freq",
+ "cpufreq/cpuinfo_min_freq",
+ "topology/physical_package_id",
+ "topology/core_siblings_list",
+ "topology/core_id",
+ "topology/thread_siblings_list",
+]
+
+CACHE_FILES = [
+ "allocation_policy",
+ "coherency_line_size",
+ "level",
+ "number_of_sets",
+ "shared_cpu_list",
+ "size",
+ "type",
+ "ways_of_associativity",
+ "write_policy",
+]
+
+def c_escape(string):
+ c_string = ""
+ for c in string:
+ if c == "\\":
+ c_string += "\\\\"
+ elif c == "\"":
+ c_string += "\\\""
+ elif c == "\t":
+ c_string += "\\t"
+ elif c == "\n":
+ c_string += "\\n"
+ elif c == "\r":
+ c_string += "\\r"
+ elif ord(c) == 0:
+ c_string += "\\0"
+ elif 32 <= ord(c) < 127:
+ c_string += c
+ else:
+ c_string += "x%02X" % ord(c)
+ return c_string
+
+
+def dump_system_file(stream, path):
+ try:
+ with open(path, "rb") as device_file:
+ content = device_file.read()
+ stream.write("\t{\n")
+ stream.write("\t\t.path = \"%s\",\n" % path)
+ stream.write("\t\t.size = %d,\n" % len(content))
+ if len(content.splitlines()) > 1:
+ stream.write("\t\t.content =")
+ for line in content.splitlines(True):
+ stream.write("\n\t\t\t\"%s\"" % c_escape(line))
+ stream.write(",\n")
+ else:
+ stream.write("\t\t.content = \"%s\",\n" % c_escape(content))
+ stream.write("\t},\n")
+ return True
+ except IOError:
+ pass
+
+
+def main(args):
+ options = parser.parse_args(args)
+
+ # with open(os.path.join("test", "dmesg", options.prefix + ".log"), "w") as dmesg_log:
+ # dmesg_log.write(device.Shell("dmesg"))
+ with open(os.path.join("test", options.prefix + ".h"), "w") as file_header:
+ file_header.write("struct cpuinfo_mock_file filesystem[] = {\n")
+ for path in SYSTEM_FILES:
+ dump_system_file(file_header, path)
+ for cpu in range(16):
+ for filename in CPU_FILES:
+ path = "/sys/devices/system/cpu/cpu%d/%s" % (cpu, filename)
+ dump_system_file(file_header, path)
+ for index in range(10):
+ for filename in CACHE_FILES:
+ path = "/sys/devices/system/cpu/cpu%d/cache/index%d/%s" % (cpu, index, filename)
+ dump_system_file(file_header, path)
+ file_header.write("\t{ NULL },\n")
+ file_header.write("};\n")
+ shutil.copy("/proc/cpuinfo",
+ os.path.join("test", "cpuinfo", options.prefix + ".log"))
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
diff --git a/src/linux/multiline.c b/src/linux/multiline.c
index fe3c14b..9a07b6e 100644
--- a/src/linux/multiline.c
+++ b/src/linux/multiline.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <alloca.h>
#include <errno.h>
#include <sys/types.h>
diff --git a/src/linux/smallfile.c b/src/linux/smallfile.c
index eb97b74..977852c 100644
--- a/src/linux/smallfile.c
+++ b/src/linux/smallfile.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <alloca.h>
#include <errno.h>
#include <sys/types.h>