Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc0f5bc4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "logd: remove failing test."

parents 20480a22 6427c363
Loading
Loading
Loading
Loading
+0 −107
Original line number Diff line number Diff line
@@ -3180,113 +3180,6 @@ TEST(liblog, __android_log_pmsg_file_read) {
}
#endif  // USING_LOGGER_DEFAULT

#ifdef USING_LOGGER_DEFAULT  // Do not retest event mapping functionality
#ifdef __ANDROID__
// must be: '<needle:> 0 kB'
static bool isZero(const std::string& content, std::string::size_type pos,
                   const char* needle) {
  std::string::size_type offset = content.find(needle, pos);
  return (offset != std::string::npos) &&
         ((offset = content.find_first_not_of(" \t", offset + strlen(needle))) !=
          std::string::npos) &&
         (content.find_first_not_of('0', offset) != offset);
}

// must not be: '<needle:> 0 kB'
static bool isNotZero(const std::string& content, std::string::size_type pos,
                      const char* needle) {
  std::string::size_type offset = content.find(needle, pos);
  return (offset != std::string::npos) &&
         ((offset = content.find_first_not_of(" \t", offset + strlen(needle))) !=
          std::string::npos) &&
         (content.find_first_not_of("123456789", offset) != offset);
}

static void event_log_tags_test_smap(pid_t pid) {
  std::string filename = android::base::StringPrintf("/proc/%d/smaps", pid);

  std::string content;
  if (!android::base::ReadFileToString(filename, &content)) return;

  bool shared_ok = false;
  bool private_ok = false;
  bool anonymous_ok = false;
  bool pass_ok = false;

  static const char event_log_tags[] = "event-log-tags";
  std::string::size_type pos = 0;
  while ((pos = content.find(event_log_tags, pos)) != std::string::npos) {
    pos += strlen(event_log_tags);

    // must not be: 'Shared_Clean: 0 kB'
    bool ok =
        isNotZero(content, pos, "Shared_Clean:") ||
        // If not /etc/event-log-tags, thus r/w, then half points
        // back for not 'Shared_Dirty: 0 kB'
        ((content.substr(pos - 5 - strlen(event_log_tags), 5) != "/etc/") &&
         isNotZero(content, pos, "Shared_Dirty:"));
    if (ok && !pass_ok) {
      shared_ok = true;
    } else if (!ok) {
      shared_ok = false;
    }

    // must be: 'Private_Dirty: 0 kB' and 'Private_Clean: 0 kB'
    ok = isZero(content, pos, "Private_Dirty:") ||
         isZero(content, pos, "Private_Clean:");
    if (ok && !pass_ok) {
      private_ok = true;
    } else if (!ok) {
      private_ok = false;
    }

    // must be: 'Anonymous: 0 kB'
    ok = isZero(content, pos, "Anonymous:");
    if (ok && !pass_ok) {
      anonymous_ok = true;
    } else if (!ok) {
      anonymous_ok = false;
    }

    pass_ok = true;
  }
  content = "";

  if (!pass_ok) return;
  if (shared_ok && anonymous_ok && private_ok) return;

  filename = android::base::StringPrintf("/proc/%d/comm", pid);
  android::base::ReadFileToString(filename, &content);
  content = android::base::StringPrintf(
      "%d:%s", pid, content.substr(0, content.find('\n')).c_str());

  EXPECT_TRUE(IsOk(shared_ok, content));
  EXPECT_TRUE(IsOk(private_ok, content));
  EXPECT_TRUE(IsOk(anonymous_ok, content));
}
#endif  // __ANDROID__

TEST(liblog, event_log_tags) {
#ifdef __ANDROID__
  std::unique_ptr<DIR, int (*)(DIR*)> proc_dir(opendir("/proc"), closedir);
  ASSERT_FALSE(!proc_dir);

  dirent* e;
  while ((e = readdir(proc_dir.get()))) {
    if (e->d_type != DT_DIR) continue;
    if (!isdigit(e->d_name[0])) continue;
    long long id = atoll(e->d_name);
    if (id <= 0) continue;
    pid_t pid = id;
    if (id != pid) continue;
    event_log_tags_test_smap(pid);
  }
#else
  GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
#endif  // USING_LOGGER_DEFAULT

#ifdef USING_LOGGER_DEFAULT  // Do not retest ratelimit
TEST(liblog, __android_log_ratelimit) {
  time_t state = 0;