diff options
author | Jin Qian <jinqian@google.com> | 2017-01-23 15:31:04 -0800 |
---|---|---|
committer | Jin Qian <jinqian@google.com> | 2017-01-24 14:45:50 -0800 |
commit | 88ad33eff1fd70d276f9be70164afeb0dc639e58 (patch) | |
tree | 521f648a121cb7058431d9d9222d67393cbdef3b /storaged/tests | |
parent | 3790f5bfafc52ca881b9350b922ffe94e6a537bb (diff) | |
download | core-88ad33eff1fd70d276f9be70164afeb0dc639e58.tar.gz core-88ad33eff1fd70d276f9be70164afeb0dc639e58.tar.bz2 core-88ad33eff1fd70d276f9be70164afeb0dc639e58.zip |
storaged: remove task io code
Bug: 34612499
Change-Id: Id0599ee2ae025a186259e95363c1ddd0feae8079
Diffstat (limited to 'storaged/tests')
-rw-r--r-- | storaged/tests/storaged_test.cpp | 215 |
1 files changed, 1 insertions, 214 deletions
diff --git a/storaged/tests/storaged_test.cpp b/storaged/tests/storaged_test.cpp index 99b21ac0f..5395b9a41 100644 --- a/storaged/tests/storaged_test.cpp +++ b/storaged/tests/storaged_test.cpp @@ -30,7 +30,6 @@ #define MMC_DISK_STATS_PATH "/sys/block/mmcblk0/stat" #define SDA_DISK_STATS_PATH "/sys/block/sda/stat" #define EMMC_EXT_CSD_PATH "/d/mmc0/mmc0:0001/ext_csd" -#define INIT_TASK_IO_PATH "/proc/1/io" static void pause(uint32_t sec) { const char* path = "/cache/test"; @@ -144,46 +143,6 @@ TEST(storaged_test, emmc_info) { } } -TEST(storaged_test, task_info) { - // parse_task_info should read something other than 0 from /proc/1/* - struct task_info task_info; - memset(&task_info, 0, sizeof(task_info)); - - if (!parse_task_info(1, &task_info)) return; - - EXPECT_EQ((uint32_t)1, task_info.pid); - EXPECT_LT((uint64_t)0, task_info.rchar); - EXPECT_LT((uint64_t)0, task_info.wchar); - EXPECT_LT((uint64_t)0, task_info.syscr); - EXPECT_LT((uint64_t)0, task_info.syscw); - EXPECT_LT((uint64_t)0, task_info.read_bytes); - EXPECT_LT((uint64_t)0, task_info.write_bytes); - // cancelled_write_bytes of init could be 0, there is no need to test - EXPECT_LE((uint64_t)0, task_info.starttime); - EXPECT_NE((char*)NULL, strstr(task_info.cmd, "init")); - - // Entries in /proc/1/io should be increasing through time - struct task_info task_old, task_new; - memset(&task_old, 0, sizeof(task_old)); - memset(&task_new, 0, sizeof(task_new)); - - // parse_task_info should succeed at this point - ASSERT_TRUE(parse_task_info(1, &task_old)); - sleep(1); - ASSERT_TRUE(parse_task_info(1, &task_new)); - - EXPECT_EQ(task_old.pid, task_new.pid); - EXPECT_LE(task_old.rchar, task_new.rchar); - EXPECT_LE(task_old.wchar, task_new.wchar); - EXPECT_LE(task_old.syscr, task_new.syscr); - EXPECT_LE(task_old.syscw, task_new.syscw); - EXPECT_LE(task_old.read_bytes, task_new.read_bytes); - EXPECT_LE(task_old.write_bytes, task_new.write_bytes); - EXPECT_LE(task_old.cancelled_write_bytes, task_new.cancelled_write_bytes); - EXPECT_EQ(task_old.starttime, task_new.starttime); - EXPECT_EQ(0, strcmp(task_old.cmd, task_new.cmd)); -} - static double mean(std::deque<uint32_t> nums) { double sum = 0.0; for (uint32_t i : nums) { @@ -244,179 +203,6 @@ TEST(storaged_test, stream_stats) { } } -static void expect_increasing(struct task_info told, struct task_info tnew) { - ASSERT_EQ(told.pid, tnew.pid); - ASSERT_EQ(told.starttime, tnew.starttime); - ASSERT_EQ(strcmp(told.cmd, tnew.cmd), 0); - - EXPECT_LE(told.rchar, tnew.rchar); - EXPECT_LE(told.wchar, tnew.wchar); - EXPECT_LE(told.syscr, tnew.syscr); - EXPECT_LE(told.syscw, tnew.syscw); - EXPECT_LE(told.read_bytes, tnew.read_bytes); - EXPECT_LE(told.write_bytes, tnew.write_bytes); - EXPECT_LE(told.cancelled_write_bytes, tnew.cancelled_write_bytes); -} - -static void expect_equal(struct task_info told, struct task_info tnew) { - ASSERT_EQ(told.pid, tnew.pid); - ASSERT_EQ(told.starttime, tnew.starttime); - ASSERT_EQ(strcmp(told.cmd, tnew.cmd), 0); - - EXPECT_EQ(told.rchar, tnew.rchar); - EXPECT_EQ(told.wchar, tnew.wchar); - EXPECT_EQ(told.syscr, tnew.syscr); - EXPECT_EQ(told.syscw, tnew.syscw); - EXPECT_EQ(told.read_bytes, tnew.read_bytes); - EXPECT_EQ(told.write_bytes, tnew.write_bytes); - EXPECT_EQ(told.cancelled_write_bytes, tnew.cancelled_write_bytes); -} - -static std::set<uint32_t> find_overlap(std::unordered_map<uint32_t, struct task_info> t1, - std::unordered_map<uint32_t, struct task_info> t2) { - std::set<uint32_t> retval; - for (auto i : t1) { - if (t2.find(i.first) != t2.end()) { - retval.insert(i.first); - } - } - - return retval; -} - -static std::set<std::string> find_overlap(std::unordered_map<std::string, struct task_info> t1, - std::unordered_map<std::string, struct task_info> t2) { - std::set<std::string> retval; - for (auto i : t1) { - if (t2.find(i.first) != t2.end()) { - retval.insert(i.first); - } - } - - return retval; -} - -static bool cmp_app_name(struct task_info i, struct task_info j) { - return strcmp(i.cmd, j.cmd) > 0; -} - -static void expect_match(std::vector<struct task_info> v1, std::vector<struct task_info> v2) { - ASSERT_EQ(v1.size(), v2.size()); - std::sort(v1.begin(), v1.end(), cmp_app_name); - std::sort(v2.begin(), v2.end(), cmp_app_name); - - for (uint i = 0; i < v1.size(); ++i) { - expect_equal(v1[i], v2[i]); - } -} - -static void add_task_info(struct task_info* src, struct task_info* dst) { - ASSERT_EQ(0, strcmp(src->cmd, dst->cmd)); - - dst->pid = 0; - dst->rchar += src->rchar; - dst->wchar += src->wchar; - dst->syscr += src->syscr; - dst->syscw += src->syscw; - dst->read_bytes += src->read_bytes; - dst->write_bytes += src->write_bytes; - dst->cancelled_write_bytes += src->cancelled_write_bytes; - dst->starttime = 0; -} - -static std::vector<struct task_info> -categorize_tasks(std::unordered_map<uint32_t, struct task_info> tasks) { - std::unordered_map<std::string, struct task_info> tasks_cmd; - for (auto i : tasks) { - std::string cmd = i.second.cmd; - if (tasks_cmd.find(cmd) == tasks_cmd.end()) { - tasks_cmd[cmd] = i.second; - } else { - add_task_info(&i.second, &tasks_cmd[cmd]); - } - } - - std::vector<struct task_info> retval(tasks_cmd.size()); - int cnt = 0; - for (auto i : tasks_cmd) { - retval[cnt++] = i.second; - } - - return retval; -} - -#define TEST_LOOPS 20 -TEST(storaged_test, tasks_t) { - // pass this test if /proc/[pid]/io is not readable - const char* test_paths[] = {"/proc/1/io", "/proc/1/comm", "/proc/1/cmdline", "/proc/1/stat"}; - for (uint i = 0; i < sizeof(test_paths) / sizeof(const char*); ++i) { - if (access(test_paths[i], R_OK) < 0) return; - } - - tasks_t tasks; - EXPECT_EQ((uint32_t)0, tasks.mRunning.size()); - EXPECT_EQ((uint32_t)0, tasks.mOld.size()); - - tasks.update_running_tasks(); - - std::unordered_map<uint32_t, struct task_info> prev_running = tasks.mRunning; - std::unordered_map<std::string, struct task_info> prev_old = tasks.mOld; - - // hashmap maintaining - std::unordered_map<uint32_t, struct task_info> tasks_pid = tasks.mRunning; - - // get_running_tasks() should return something other than a null map - std::unordered_map<uint32_t, struct task_info> test = tasks.get_running_tasks(); - EXPECT_LE((uint32_t)1, test.size()); - - for (int i = 0; i < TEST_LOOPS; ++i) { - tasks.update_running_tasks(); - - std::set<uint32_t> overlap_running = find_overlap(prev_running, tasks.mRunning); - std::set<std::string> overlap_old = find_overlap(prev_old, tasks.mOld); - - // overlap_running should capture init(pid == 1), since init never get killed - EXPECT_LE((uint32_t)1, overlap_running.size()); - EXPECT_NE(overlap_running.find((uint32_t)1), overlap_running.end()); - // overlap_old should never capture init, since init never get killed - EXPECT_EQ(overlap_old.find("init"), overlap_old.end()); - - // overlapping entries in previous and current running-tasks map should have increasing contents - for (uint32_t i : overlap_running) { - expect_increasing(prev_running[i], tasks.mRunning[i]); - } - - // overlapping entries in previous and current killed-tasks map should have increasing contents - // and the map size should also be increasing - for (std::string i : overlap_old) { - expect_increasing(prev_old[i], tasks.mOld[i]); - } - EXPECT_LE(prev_old.size(), tasks.mRunning.size()); - - // update app name & tasks_pid - for (auto i : tasks.mRunning) { - // test will fail if the pid got wrapped - if (tasks_pid.find(i.first) != tasks_pid.end()) { - expect_increasing(tasks_pid[i.first], i.second); - tasks_pid[i.first] = i.second; - } else { - tasks_pid[i.first] = i.second; - } - } - - // get maintained tasks - std::vector<struct task_info> test_tasks = categorize_tasks(tasks_pid); - std::vector<struct task_info> real_tasks = tasks.get_tasks(); - - expect_match(test_tasks, real_tasks); - - prev_running = tasks.mRunning; - prev_old = tasks.mOld; - - pause(5); - } -} - static struct disk_perf disk_perf_multiply(struct disk_perf perf, double mul) { struct disk_perf retval; retval.read_perf = (double)perf.read_perf * mul; @@ -569,6 +355,7 @@ static void expect_increasing(struct disk_stats stats1, struct disk_stats stats2 EXPECT_LE(stats1.io_in_queue, stats2.io_in_queue); } +#define TEST_LOOPS 20 TEST(storaged_test, disk_stats_publisher) { // asserting that there is one file for diskstats ASSERT_TRUE(access(MMC_DISK_STATS_PATH, R_OK) >= 0 || access(SDA_DISK_STATS_PATH, R_OK) >= 0); |