Loading cmds/dumpstate/DumpstateUtil.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -103,6 +103,12 @@ CommandOptions::CommandOptionsBuilder& CommandOptions::CommandOptionsBuilder::As return *this; } CommandOptions::CommandOptionsBuilder& CommandOptions::CommandOptionsBuilder::AsRootIfAvailable() { if (!PropertiesHelper::IsUserBuild()) values.account_mode_ = SU_ROOT; return *this; } CommandOptions::CommandOptionsBuilder& CommandOptions::CommandOptionsBuilder::DropRoot() { values.account_mode_ = DROP_ROOT; return *this; Loading cmds/dumpstate/DumpstateUtil.h +2 −0 Original line number Diff line number Diff line Loading @@ -89,6 +89,8 @@ class CommandOptions { CommandOptionsBuilder& Always(); /* Sets the command's PrivilegeMode as `SU_ROOT` */ CommandOptionsBuilder& AsRoot(); /* If !IsUserBuild(), sets the command's PrivilegeMode as `SU_ROOT` */ CommandOptionsBuilder& AsRootIfAvailable(); /* Sets the command's PrivilegeMode as `DROP_ROOT` */ CommandOptionsBuilder& DropRoot(); /* Sets the command's OutputMode as `REDIRECT_TO_STDERR` */ Loading cmds/dumpstate/dumpstate.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -1069,14 +1069,15 @@ static void dumpstate() { RunCommand( "HARDWARE HALS", {"lshal", std::string("--debug=") + kLsHalDebugPath}, CommandOptions::AS_ROOT); CommandOptions::WithTimeout(10).AsRootIfAvailable().Build()); ds.AddZipEntry("lshal-debug.txt", kLsHalDebugPath); unlink(kLsHalDebugPath.c_str()); } else { RunCommand( "HARDWARE HALS", {"lshal", "--debug"}, CommandOptions::AS_ROOT); "HARDWARE HALS", {"lshal", "--debug"}, CommandOptions::WithTimeout(10).AsRootIfAvailable().Build()); } RunCommand("PRINTENV", {"printenv"}); Loading cmds/dumpstate/tests/dumpstate_test.cpp +87 −0 Original line number Diff line number Diff line Loading @@ -477,6 +477,48 @@ TEST_F(DumpstateTest, RunCommandAsRootNonUserBuild) { EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnUserBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateTest.RunCommandAsRootIfAvailableOnUserBuild() on test suite\n") return; } if (!PropertiesHelper::IsUserBuild()) { // Emulates user build if necessarily. SetBuildType("user"); } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("2000\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnDebugBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateTest.RunCommandAsRootIfAvailableOnDebugBuild() on test suite\n") return; } if (PropertiesHelper::IsUserBuild()) { ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n"); return; } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("0\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateTest, DumpFileNotFoundNoTitle) { EXPECT_EQ(-1, DumpFile("", "/I/cant/believe/I/exist")); EXPECT_THAT(out, Loading Loading @@ -1053,6 +1095,51 @@ TEST_F(DumpstateUtilTest, RunCommandAsRootNonUserBuild) { EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateUtilTest, RunCommandAsRootIfAvailableOnUserBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootIfAvailableOnUserBuild() on test suite\n") return; } CreateFd("RunCommandAsRootIfAvailableOnUserBuild.txt"); if (!PropertiesHelper::IsUserBuild()) { // Emulates user build if necessarily. SetBuildType("user"); } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("2000\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateUtilTest, RunCommandAsRootIfAvailableOnDebugBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootIfAvailableOnDebugBuild() on test suite\n") return; } CreateFd("RunCommandAsRootIfAvailableOnDebugBuild.txt"); if (PropertiesHelper::IsUserBuild()) { ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n"); return; } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("0\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateUtilTest, RunCommandDropRoot) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping Loading Loading
cmds/dumpstate/DumpstateUtil.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -103,6 +103,12 @@ CommandOptions::CommandOptionsBuilder& CommandOptions::CommandOptionsBuilder::As return *this; } CommandOptions::CommandOptionsBuilder& CommandOptions::CommandOptionsBuilder::AsRootIfAvailable() { if (!PropertiesHelper::IsUserBuild()) values.account_mode_ = SU_ROOT; return *this; } CommandOptions::CommandOptionsBuilder& CommandOptions::CommandOptionsBuilder::DropRoot() { values.account_mode_ = DROP_ROOT; return *this; Loading
cmds/dumpstate/DumpstateUtil.h +2 −0 Original line number Diff line number Diff line Loading @@ -89,6 +89,8 @@ class CommandOptions { CommandOptionsBuilder& Always(); /* Sets the command's PrivilegeMode as `SU_ROOT` */ CommandOptionsBuilder& AsRoot(); /* If !IsUserBuild(), sets the command's PrivilegeMode as `SU_ROOT` */ CommandOptionsBuilder& AsRootIfAvailable(); /* Sets the command's PrivilegeMode as `DROP_ROOT` */ CommandOptionsBuilder& DropRoot(); /* Sets the command's OutputMode as `REDIRECT_TO_STDERR` */ Loading
cmds/dumpstate/dumpstate.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -1069,14 +1069,15 @@ static void dumpstate() { RunCommand( "HARDWARE HALS", {"lshal", std::string("--debug=") + kLsHalDebugPath}, CommandOptions::AS_ROOT); CommandOptions::WithTimeout(10).AsRootIfAvailable().Build()); ds.AddZipEntry("lshal-debug.txt", kLsHalDebugPath); unlink(kLsHalDebugPath.c_str()); } else { RunCommand( "HARDWARE HALS", {"lshal", "--debug"}, CommandOptions::AS_ROOT); "HARDWARE HALS", {"lshal", "--debug"}, CommandOptions::WithTimeout(10).AsRootIfAvailable().Build()); } RunCommand("PRINTENV", {"printenv"}); Loading
cmds/dumpstate/tests/dumpstate_test.cpp +87 −0 Original line number Diff line number Diff line Loading @@ -477,6 +477,48 @@ TEST_F(DumpstateTest, RunCommandAsRootNonUserBuild) { EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnUserBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateTest.RunCommandAsRootIfAvailableOnUserBuild() on test suite\n") return; } if (!PropertiesHelper::IsUserBuild()) { // Emulates user build if necessarily. SetBuildType("user"); } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("2000\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnDebugBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateTest.RunCommandAsRootIfAvailableOnDebugBuild() on test suite\n") return; } if (PropertiesHelper::IsUserBuild()) { ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n"); return; } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("0\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateTest, DumpFileNotFoundNoTitle) { EXPECT_EQ(-1, DumpFile("", "/I/cant/believe/I/exist")); EXPECT_THAT(out, Loading Loading @@ -1053,6 +1095,51 @@ TEST_F(DumpstateUtilTest, RunCommandAsRootNonUserBuild) { EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateUtilTest, RunCommandAsRootIfAvailableOnUserBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootIfAvailableOnUserBuild() on test suite\n") return; } CreateFd("RunCommandAsRootIfAvailableOnUserBuild.txt"); if (!PropertiesHelper::IsUserBuild()) { // Emulates user build if necessarily. SetBuildType("user"); } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("2000\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateUtilTest, RunCommandAsRootIfAvailableOnDebugBuild) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping // to Shell - need to refactor tests to avoid this problem) MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootIfAvailableOnDebugBuild() on test suite\n") return; } CreateFd("RunCommandAsRootIfAvailableOnDebugBuild.txt"); if (PropertiesHelper::IsUserBuild()) { ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n"); return; } DropRoot(); EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}, CommandOptions::WithTimeout(1).AsRootIfAvailable().Build())); EXPECT_THAT(out, StrEq("0\nstdout\n")); EXPECT_THAT(err, StrEq("stderr\n")); } TEST_F(DumpstateUtilTest, RunCommandDropRoot) { if (!IsStandalone()) { // TODO: temporarily disabled because it might cause other tests to fail after dropping Loading