OLD | NEW |
---|---|
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 // |
11 // These tests require write access to HKLM and HKCU. | 11 // These tests require write access to HKLM and HKCU. |
12 // | 12 // |
13 // The "GGLA" brand is used to test the normal code flow of the code, and the | 13 // The "GGLA" brand is used to test the normal code flow of the code, and the |
14 // "TEST" brand is used to test the supplementary brand code code flow. | 14 // "TEST" brand is used to test the supplementary brand code code flow. |
15 | 15 |
16 #include "base/eintr_wrapper.h" | |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 #include "rlz/lib/rlz_lib.h" | 22 #include "rlz/lib/rlz_lib.h" |
22 #include "rlz/test/rlz_test_helpers.h" | 23 #include "rlz/test/rlz_test_helpers.h" |
23 | 24 |
24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
25 #include <Windows.h> | 26 #include <Windows.h> |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 | 789 |
789 #if defined(OS_MACOSX) | 790 #if defined(OS_MACOSX) |
790 class ReadonlyRlzDirectoryTest : public RlzLibTestNoMachineState { | 791 class ReadonlyRlzDirectoryTest : public RlzLibTestNoMachineState { |
791 protected: | 792 protected: |
792 virtual void SetUp() OVERRIDE; | 793 virtual void SetUp() OVERRIDE; |
793 }; | 794 }; |
794 | 795 |
795 void ReadonlyRlzDirectoryTest::SetUp() { | 796 void ReadonlyRlzDirectoryTest::SetUp() { |
796 RlzLibTestNoMachineState::SetUp(); | 797 RlzLibTestNoMachineState::SetUp(); |
797 // Make the rlz directory non-writeable. | 798 // Make the rlz directory non-writeable. |
798 chmod(temp_dir_.path().value().c_str(), 0500); | 799 int chmod_result = chmod(temp_dir_.path().value().c_str(), 0500); |
800 ASSERT_EQ(0, chmod_result); | |
801 | |
799 } | 802 } |
800 | 803 |
801 TEST_F(ReadonlyRlzDirectoryTest, WriteFails) { | 804 TEST_F(ReadonlyRlzDirectoryTest, WriteFails) { |
802 // The rlz test runner runs every test twice: Once normally, and once with | 805 // 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 | 806 // a SupplementaryBranding on the stack. In the latter case, the rlz lock |
804 // has already been acquired before the rlz directory got changed to | 807 // 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 | 808 // read-only, which makes this test pointless. So run it only in the first |
806 // pass. | 809 // pass. |
807 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | 810 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) |
808 return; | 811 return; |
809 | 812 |
810 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 813 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
811 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | 814 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); |
812 } | 815 } |
813 | 816 |
814 // Regression test for http://crbug.com/121255 | 817 // Regression test for http://crbug.com/121255 |
815 TEST_F(ReadonlyRlzDirectoryTest, SupplementaryBrandingDoesNotCrash) { | 818 TEST_F(ReadonlyRlzDirectoryTest, SupplementaryBrandingDoesNotCrash) { |
816 // See the comment at the top of WriteFails. | 819 // See the comment at the top of WriteFails. |
817 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | 820 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) |
818 return; | 821 return; |
819 | 822 |
820 rlz_lib::SupplementaryBranding branding("TEST"); | 823 rlz_lib::SupplementaryBranding branding("TEST"); |
821 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 824 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
822 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); | 825 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); |
823 } | 826 } |
827 | |
828 // Regression test for http://crbug.com/141108 | |
829 TEST_F(RlzLibTest, ConcurrentStoreAccessWithProcessExitsWhileLockHeld) { | |
830 // See the comment at the top of WriteFails. | |
831 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | |
832 return; | |
833 | |
834 std::vector<pid_t> pids; | |
835 for (int i = 0; i < 10; ++i) { | |
836 pid_t pid = fork(); | |
837 ASSERT_NE(-1, pid); | |
838 if (pid == 0) { | |
839 // Child. | |
840 { | |
841 // SupplementaryBranding is a RAII object for the rlz lock. | |
842 rlz_lib::SupplementaryBranding branding("TEST"); | |
843 | |
844 // Simulate a crash while holding the lock in some of the children. | |
845 if (i > 0 && i % 3 == 0) | |
846 _exit(0); | |
847 | |
848 // Note: Since this is in a forked child, a failing expectation won't | |
849 // make the test fail. It does however cause lots of "check failed" | |
850 // error output. The parent process will then check the exit code | |
851 // below to make the test fail. | |
852 bool success = rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
853 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL); | |
854 EXPECT_TRUE(success); | |
855 _exit(success ? 0 : 1); | |
856 } | |
857 _exit(0); | |
858 } else { | |
859 // Parent. | |
860 pids.push_back(pid); | |
861 } | |
862 } | |
863 | |
864 int status; | |
865 for (size_t i = 0; i < pids.size(); ++i) { | |
866 if (HANDLE_EINTR(waitpid(pids[i], &status, 0)) != -1) | |
867 EXPECT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0); | |
868 } | |
869 | |
870 // No child should have the lock at this point, not even the crashed ones. | |
871 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | |
872 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); | |
873 } | |
Roger Tawa OOO till Jul 10th
2012/08/15 15:10:23
Should this test be wrapped in a #if defined(OS_MA
Mark Mentovai
2012/08/15 16:10:00
Roger Tawa wrote:
| |
824 #endif | 874 #endif |
OLD | NEW |