diff options
author | Yabin Cui <yabinc@google.com> | 2016-08-08 14:42:25 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2016-08-09 12:40:58 -0700 |
commit | 861f655538b17ed37cf5d9bcadc71f22d3a0a6e9 (patch) | |
tree | c3fa1def98c1cb159a3c225e3dfb07ab3d7f11f7 /simpleperf/cmd_report_test.cpp | |
parent | 879a2c8fa063f8c4c1676cb50bc096b0b2ea9e41 (diff) | |
download | extras-861f655538b17ed37cf5d9bcadc71f22d3a0a6e9.tar.gz |
simpleperf: fix --pids option.
--pids option was recognized as --tids because of logic
error. this patch fixes that and adds corresponding test.
Bug: http://b/30736228
Change-Id: I0515fc7e03f29f821f7b0aa32c608cf250e87662
Test: run simpleperf_unit_test.
Diffstat (limited to 'simpleperf/cmd_report_test.cpp')
-rw-r--r-- | simpleperf/cmd_report_test.cpp | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp index 4a2e8d70..a64ee181 100644 --- a/simpleperf/cmd_report_test.cpp +++ b/simpleperf/cmd_report_test.cpp @@ -195,29 +195,59 @@ static bool AllItemsWithString(std::vector<std::string>& lines, } TEST_F(ReportCommandTest, pid_filter_option) { - Report(PERF_DATA); - ASSERT_TRUE("success"); - ASSERT_FALSE(AllItemsWithString(lines, {"26083"})); - ASSERT_FALSE(AllItemsWithString(lines, {"26083", "26090"})); - Report(PERF_DATA, {"--pids", "26083"}); + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid"}); + ASSERT_TRUE(success); + ASSERT_FALSE(AllItemsWithString(lines, {"17441"})); + ASSERT_FALSE(AllItemsWithString(lines, {"17441", "17443"})); + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, + {"--sort", "pid", "--pids", "17441"}); ASSERT_TRUE(success); - ASSERT_TRUE(AllItemsWithString(lines, {"26083"})); - Report(PERF_DATA, {"--pids", "26083,26090"}); + ASSERT_TRUE(AllItemsWithString(lines, {"17441"})); + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, + {"--sort", "pid", "--pids", "17441,17443"}); + ASSERT_TRUE(success); + ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17443"})); + + // Test that --pids option is not the same as --tids option. + // Thread 17445 and 17441 are in process 17441. + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, + {"--sort", "tid", "--pids", "17441"}); ASSERT_TRUE(success); - ASSERT_TRUE(AllItemsWithString(lines, {"26083", "26090"})); + ASSERT_NE(content.find("17441"), std::string::npos); + ASSERT_NE(content.find("17445"), std::string::npos); +} + +TEST_F(ReportCommandTest, wrong_pid_filter_option) { + ASSERT_EXIT( + { + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--pids", "2,bogus"}); + exit(success ? 0 : 1); + }, + testing::ExitedWithCode(1), "invalid id in --pids option: bogus"); } TEST_F(ReportCommandTest, tid_filter_option) { - Report(PERF_DATA); - ASSERT_TRUE("success"); - ASSERT_FALSE(AllItemsWithString(lines, {"26083"})); - ASSERT_FALSE(AllItemsWithString(lines, {"26083", "26090"})); - Report(PERF_DATA, {"--tids", "26083"}); + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid"}); ASSERT_TRUE(success); - ASSERT_TRUE(AllItemsWithString(lines, {"26083"})); - Report(PERF_DATA, {"--tids", "26083,26090"}); + ASSERT_FALSE(AllItemsWithString(lines, {"17441"})); + ASSERT_FALSE(AllItemsWithString(lines, {"17441", "17445"})); + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, + {"--sort", "tid", "--tids", "17441"}); ASSERT_TRUE(success); - ASSERT_TRUE(AllItemsWithString(lines, {"26083", "26090"})); + ASSERT_TRUE(AllItemsWithString(lines, {"17441"})); + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, + {"--sort", "tid", "--tids", "17441,17445"}); + ASSERT_TRUE(success); + ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17445"})); +} + +TEST_F(ReportCommandTest, wrong_tid_filter_option) { + ASSERT_EXIT( + { + Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--tids", "2,bogus"}); + exit(success ? 0 : 1); + }, + testing::ExitedWithCode(1), "invalid id in --tids option: bogus"); } TEST_F(ReportCommandTest, comm_filter_option) { |