Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Fix atom_packages, processes, rpm_packages flakiness #6518

Merged
merged 2 commits into from Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/integration/tables/atom_packages.cpp
Expand Up @@ -9,6 +9,7 @@
// Sanity check integration test for atom_packages
// Spec file: specs/atom_packages.table

#include <osquery/logger.h>
#include <osquery/tests/integration/tables/helper.h>

namespace osquery {
Expand All @@ -23,13 +24,20 @@ class atomPackages : public testing::Test {

TEST_F(atomPackages, test_sanity) {
auto const data = execute_query("select * from atom_packages");
if (data.empty()) {
LOG(WARNING) << "Empty results of query from 'atom_packages', assume there "
"is no atom on the system";
return;
}

ValidationMap row_map = {
{"name", NormalType},
{"version", NormalType},
{"description", NormalType},
{"path", NormalType},
{"license", NormalType},
{"homepage", NormalType},
{"uid", IntType},
};
validate_rows(data, row_map);
}
Expand Down
40 changes: 26 additions & 14 deletions tests/integration/tables/processes.cpp
Expand Up @@ -34,7 +34,22 @@ TEST_F(ProcessesTest, test_sanity) {
auto const now = std::time(nullptr);
auto const boot_time = now - getUptime() - 1;

EXPECT_GE(now, boot_time);
// The getUptime API does not work how we expect it should on Windows.
if (!isPlatform(PlatformType::TYPE_WINDOWS)) {
EXPECT_GE(now, boot_time);
}

auto timeSanityCheck = [&now, &boot_time](auto value) {
auto start_time_exp = tryTo<std::time_t>(value);
if (start_time_exp.isError()) {
return false;
}
auto const start_time = start_time_exp.take();
if (start_time == -1) {
return true;
}
return start_time <= now && boot_time <= start_time;
};

ValidationMap row_map = {
{"pid", IntType},
Expand All @@ -58,30 +73,27 @@ TEST_F(ProcessesTest, test_sanity) {
{"system_time", IntType},
{"disk_bytes_read", NormalType},
{"disk_bytes_written", NormalType},
{"start_time",
[&now, &boot_time](auto value) {
auto start_time_exp = tryTo<std::time_t>(value);
if (start_time_exp.isError()) {
return false;
}
auto const start_time = start_time_exp.take();
if (start_time == -1) {
return true;
}
return start_time <= now && boot_time <= start_time;
}},

{"parent", IntType},
{"pgroup", IntType},
{"threads", IntType},
{"nice", IntType},
};

// The getUptime API does not work how we expect it should on Windows.
if (isPlatform(PlatformType::TYPE_WINDOWS)) {
row_map.emplace("start_time", IntType);
} else {
row_map.emplace("start_time", timeSanityCheck);
}

// Add the platform-specific columns.
if (isPlatform(PlatformType::TYPE_WINDOWS)) {
row_map.emplace("is_elevated_token", NormalType);
row_map.emplace("elapsed_time", IntType);
row_map.emplace("handle_count", IntType);
row_map.emplace("percent_processor_time", IntType);
}

if (isPlatform(PlatformType::TYPE_OSX)) {
row_map.emplace("upid", IntType);
row_map.emplace("uppid", IntType);
Expand Down
43 changes: 21 additions & 22 deletions tests/integration/tables/rpm_packages.cpp
Expand Up @@ -13,8 +13,6 @@
#include <osquery/tests/integration/tables/helper.h>
#include <osquery/utils/info/platform_type.h>

#include <osquery/logger.h>

namespace osquery {
namespace table_tests {

Expand All @@ -27,27 +25,28 @@ class rpmPackages : public testing::Test {

TEST_F(rpmPackages, test_sanity) {
auto rows = execute_query("select * from rpm_packages");
if (rows.size() > 0) {
ValidationMap row_map = {{"name", NonEmptyString},
{"version", NormalType},
{"release", NormalType},
{"source", NormalType},
{"size", IntType},
{"sha1", NonEmptyString},
{"arch", NonEmptyString},
{"epoch", IntType},
{"install_time", IntType},
{"vendor", NonEmptyString},
{"package_group", NonEmptyString}};

validate_rows(rows, row_map);

if (isPlatform(PlatformType::TYPE_LINUX)) {
validate_container_rows("rpm_packages", row_map);
}
} else {
if (rows.empty()) {
LOG(WARNING) << "Empty results of query from 'rpm_packages', assume there "
"is no rpm in the system";
"is no rpm on the system";
return;
}

ValidationMap row_map = {{"name", NonEmptyString},
{"version", NormalType},
{"release", NormalType},
{"source", NormalType},
{"size", IntType},
{"sha1", NonEmptyString},
{"arch", NonEmptyString},
{"epoch", IntOrEmpty},
{"install_time", IntType},
{"vendor", NonEmptyString},
{"package_group", NonEmptyString}};

validate_rows(rows, row_map);

if (isPlatform(PlatformType::TYPE_LINUX)) {
validate_container_rows("rpm_packages", row_map);
}
}
} // namespace table_tests
Expand Down