Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: rlz/lib/rlz_lib_test.cc

Issue 10823329: rlz/mac: Make sure a crashing process doesn't leave a stale lockfile behind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | rlz/mac/lib/rlz_value_store_mac.mm » ('j') | rlz/mac/lib/rlz_value_store_mac.mm » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // A test application for the RLZ library. 5 // A test application for the RLZ library.
6 // 6 //
7 // These tests should not be executed on the build server: 7 // These tests should not be executed on the build server:
8 // - They assert for the failed cases. 8 // - They assert for the failed cases.
9 // - They modify machine state (registry). 9 // - They modify machine state (registry).
10 // 10 //
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 788
789 #if defined(OS_MACOSX) 789 #if defined(OS_MACOSX)
790 class ReadonlyRlzDirectoryTest : public RlzLibTestNoMachineState { 790 class ReadonlyRlzDirectoryTest : public RlzLibTestNoMachineState {
791 protected: 791 protected:
792 virtual void SetUp() OVERRIDE; 792 virtual void SetUp() OVERRIDE;
793 }; 793 };
794 794
795 void ReadonlyRlzDirectoryTest::SetUp() { 795 void ReadonlyRlzDirectoryTest::SetUp() {
796 RlzLibTestNoMachineState::SetUp(); 796 RlzLibTestNoMachineState::SetUp();
797 // Make the rlz directory non-writeable. 797 // Make the rlz directory non-writeable.
798 chmod(temp_dir_.path().value().c_str(), 0500); 798 int chmod_result = chmod(temp_dir_.path().value().c_str(), 0500);
799 ASSERT_EQ(0, chmod_result);
800
799 } 801 }
800 802
801 TEST_F(ReadonlyRlzDirectoryTest, WriteFails) { 803 TEST_F(ReadonlyRlzDirectoryTest, WriteFails) {
802 // The rlz test runner runs every test twice: Once normally, and once with 804 // The rlz test runner runs every test twice: Once normally, and once with
803 // a SupplementaryBranding on the stack. In the latter case, the rlz lock 805 // a SupplementaryBranding on the stack. In the latter case, the rlz lock
804 // has already been acquired before the rlz directory got changed to 806 // has already been acquired before the rlz directory got changed to
805 // read-only, which makes this test pointless. So run it only in the first 807 // read-only, which makes this test pointless. So run it only in the first
806 // pass. 808 // pass.
807 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) 809 if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
808 return; 810 return;
809 811
810 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, 812 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER,
811 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); 813 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE));
812 } 814 }
813 815
814 // Regression test for http://crbug.com/121255 816 // Regression test for http://crbug.com/121255
815 TEST_F(ReadonlyRlzDirectoryTest, SupplementaryBrandingDoesNotCrash) { 817 TEST_F(ReadonlyRlzDirectoryTest, SupplementaryBrandingDoesNotCrash) {
816 // See the comment at the top of WriteFails. 818 // See the comment at the top of WriteFails.
817 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) 819 if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
818 return; 820 return;
819 821
820 rlz_lib::SupplementaryBranding branding("TEST"); 822 rlz_lib::SupplementaryBranding branding("TEST");
821 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, 823 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER,
822 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); 824 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL));
823 } 825 }
826
827 // Regression test for http://crbug.com/141108
828 TEST_F(RlzLibTest, ConcurrentStoreAccessWithProcessExitsWhileLockHeld) {
829 // See the comment at the top of WriteFails.
830 if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
831 return;
832
833 std::vector<pid_t> pids;
834 for (int i = 0; i < 10; ++i) {
835 pid_t pid = fork();
836 ASSERT_NE(-1, pid);
837 if (pid == 0) {
838 // Child.
839 {
840 // SupplementaryBranding is a RAII object for the rlz lock.
841 rlz_lib::SupplementaryBranding branding("TEST");
842
843 // Simulate a crash while holding the lock in some of the children.
844 if (i > 0 && i % 3 == 0)
845 _exit(0);
846
847 // Note: Since this is in a forked child, a failing expectation won't
848 // make the test fail. It does however cause lots of "check failed"
849 // error output. The parent process will then check the exit code
850 // below to make the test fail.
851 bool success = rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER,
852 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL);
853 EXPECT_TRUE(success);
854 _exit(success ? 0 : 1);
855 }
856 _exit(0);
857 } else {
858 // Parent.
859 pids.push_back(pid);
860 }
861 }
862
863 int status;
864 for (size_t i = 0; i < pids.size(); ++i) {
865 if (waitpid(pids[i], &status, 0) != -1)
Mark Mentovai 2012/08/15 13:36:28 HANDLE_EINTR
866 EXPECT_EQ(0, WEXITSTATUS(status));
Mark Mentovai 2012/08/15 13:36:28 WEXITSTATUS is only valid if WIFEXITED is true. Yo
867 }
868
869 // No child should have the lock at this point, not even the crashed ones.
870 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER,
871 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL));
872 }
824 #endif 873 #endif
OLDNEW
« no previous file with comments | « no previous file | rlz/mac/lib/rlz_value_store_mac.mm » ('j') | rlz/mac/lib/rlz_value_store_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698