summaryrefslogtreecommitdiffstats
path: root/memtrack/1.0
diff options
context:
space:
mode:
authorConnor O'Brien <connoro@google.com>2017-03-06 18:02:19 -0800
committerConnor O'Brien <connoro@google.com>2017-03-07 12:16:00 -0800
commit7d39766157d9403a02ed37950cd639bc2c7d2529 (patch)
tree52df272b6cb3313224dfc05629adab47ad58d169 /memtrack/1.0
parent287adc9897e7bb10c80d2bca68630b0691630194 (diff)
downloadplatform_hardware_interfaces-7d39766157d9403a02ed37950cd639bc2c7d2529.tar.gz
platform_hardware_interfaces-7d39766157d9403a02ed37950cd639bc2c7d2529.tar.bz2
platform_hardware_interfaces-7d39766157d9403a02ed37950cd639bc2c7d2529.zip
memtrack: eliminate dependency on surfaceflinger in VTS test
VTS tests need to be able to run without the framework or native servers. Call getMemory() on the test process instead of on surfaceflinger to facilitate this. Bug: 35945712 Test: Test passes on marlin and bullhead. Change-Id: Ie847da708a95360ed5f2b444973e45b091e912a0 Signed-off-by: Connor O'Brien <connoro@google.com>
Diffstat (limited to 'memtrack/1.0')
-rw-r--r--memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp57
1 files changed, 12 insertions, 45 deletions
diff --git a/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp b/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp
index 1113f425a8..4c569ce414 100644
--- a/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp
+++ b/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp
@@ -16,6 +16,8 @@
#define LOG_TAG "memtrack_hidl_hal_test"
#include <android-base/logging.h>
+#include <android-base/unique_fd.h>
+
#include <android/hardware/memtrack/1.0/IMemtrack.h>
#include <VtsHalHidlTargetBaseTest.h>
@@ -31,6 +33,7 @@ using ::android::hardware::memtrack::V1_0::MemtrackStatus;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::sp;
+using ::android::base::unique_fd;
using std::vector;
using std::count_if;
@@ -66,42 +69,6 @@ bool validStatus(MemtrackStatus s) {
return std::find(statusVec.begin(), statusVec.end(), s) != statusVec.end();
}
-/* Returns a pid found in /proc for which the string read from
- * /proc/[pid]/cmdline matches cmd, or -1 if no such pid exists.
- */
-pid_t getPidFromCmd(const char cmd[], uint32_t len) {
- const char procs[] = "/proc/";
- DIR *dir = opendir(procs);
- if (!dir) {
- return -1;
- }
-
- struct dirent *proc;
- while ((proc = readdir(dir)) != NULL) {
- if (!isdigit(proc->d_name[0])) {
- continue;
- }
- char line[len];
- char fname[PATH_MAX];
- snprintf(fname, PATH_MAX, "/proc/%s/cmdline", proc->d_name);
-
- FILE *file = fopen(fname, "r");
- if (!file) {
- continue;
- }
- char *str = fgets(line, len, file);
- fclose(file);
- if (!str || strcmp(str, cmd)) {
- continue;
- } else {
- closedir(dir);
- return atoi(proc->d_name);
- }
- }
- closedir(dir);
- return -1;
-}
-
auto generate_cb(MemtrackStatus *s, hidl_vec<MemtrackRecord> *v) {
return [=](MemtrackStatus status, hidl_vec<MemtrackRecord> vec) {
*s = status;
@@ -135,15 +102,15 @@ TEST_F(MemtrackHidlTest, BadTypeTest) {
ASSERT_TRUE(validStatus(s));
}
-/* Call memtrack on the surfaceflinger process and check that the results are
- * reasonable for all memory types, including valid flag combinations for
- * every MemtrackRecord returned.
+/* Call memtrack on this process and check that the results are reasonable
+ * for all memory types, including valid flag combinations for every
+ * MemtrackRecord returned.
*/
-TEST_F(MemtrackHidlTest, SurfaceflingerTest) {
- const char cmd[] = "/system/bin/surfaceflinger";
- const uint32_t len = sizeof(cmd);
- pid_t pid = getPidFromCmd(cmd, len);
- ASSERT_LE(0, pid) << "Surfaceflinger process not found";
+TEST_F(MemtrackHidlTest, GetMemoryTest) {
+ /* Opening this device causes the kernel to provide memtrack with memory
+ * info for this process.
+ */
+ unique_fd fd(open("/dev/kgsl-3d0", O_RDWR));
MemtrackStatus s;
hidl_vec<MemtrackRecord> v;
@@ -152,7 +119,7 @@ TEST_F(MemtrackHidlTest, SurfaceflingerTest) {
for (uint32_t i = 0; i < static_cast<uint32_t>(MemtrackType::NUM_TYPES);
i++) {
Return<void> ret =
- memtrack->getMemory(pid, static_cast<MemtrackType>(i), cb);
+ memtrack->getMemory(getpid(), static_cast<MemtrackType>(i), cb);
ASSERT_TRUE(ret.isOk());
switch (s) {