OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Smoke tests for gclient.py. | 6 """Smoke tests for gclient.py. |
7 | 7 |
8 Shell out 'gclient' and run basic conformance tests. | 8 Shell out 'gclient' and run basic conformance tests. |
9 | 9 |
10 This test assumes GClientSmokeBase.URL_BASE is valid. | 10 This test assumes GClientSmokeBase.URL_BASE is valid. |
11 """ | 11 """ |
12 | 12 |
13 import logging | 13 import logging |
14 import os | 14 import os |
15 import re | 15 import re |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 import unittest | 18 import unittest |
19 | 19 |
20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
21 sys.path.insert(0, ROOT_DIR) | 21 sys.path.insert(0, ROOT_DIR) |
22 | 22 |
23 from testing_support.fake_repos import join, write | 23 from testing_support.fake_repos import join, write |
24 from testing_support.fake_repos import FakeReposTestBase, FakeRepoTransitive, \ | 24 from testing_support.fake_repos import FakeReposTestBase, FakeRepoTransitive, \ |
25 FakeRepoSkiaDEPS, FakeRepoBlinkDEPS | 25 FakeRepoSkiaDEPS |
26 | 26 |
27 import gclient_utils | 27 import gclient_utils |
28 import scm as gclient_scm | 28 import scm as gclient_scm |
29 | 29 |
30 import subprocess2 | 30 import subprocess2 |
31 | 31 |
32 GCLIENT_PATH = os.path.join(ROOT_DIR, 'gclient') | 32 GCLIENT_PATH = os.path.join(ROOT_DIR, 'gclient') |
33 COVERAGE = False | 33 COVERAGE = False |
34 | 34 |
35 | 35 |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 'src@%s' % pre_hash]) | 1531 'src@%s' % pre_hash]) |
1532 self.assertEqual(res[2], 0, 'Subsequent sync #2 failed.') | 1532 self.assertEqual(res[2], 0, 'Subsequent sync #2 failed.') |
1533 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], | 1533 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], |
1534 skia_gyp), gyp_git_url) | 1534 skia_gyp), gyp_git_url) |
1535 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], | 1535 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], |
1536 skia_include), include_git_url) | 1536 skia_include), include_git_url) |
1537 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], | 1537 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], |
1538 skia_src), src_git_url) | 1538 skia_src), src_git_url) |
1539 | 1539 |
1540 | 1540 |
1541 class BlinkDEPSTransitionSmokeTest(GClientSmokeBase): | |
1542 """Simulate the behavior of bisect bots as they transition across the Blink | |
1543 DEPS change.""" | |
1544 | |
1545 FAKE_REPOS_CLASS = FakeRepoBlinkDEPS | |
1546 | |
1547 def setUp(self): | |
1548 super(BlinkDEPSTransitionSmokeTest, self).setUp() | |
1549 self.enabled = self.FAKE_REPOS.set_up_git() | |
1550 self.checkout_path = os.path.join(self.root_dir, 'src') | |
1551 self.blink = os.path.join(self.checkout_path, 'third_party', 'WebKit') | |
1552 self.blink_git_url = self.FAKE_REPOS.git_base + 'repo_2' | |
1553 self.pre_merge_sha = self.githash('repo_1', 1) | |
1554 self.post_merge_sha = self.githash('repo_1', 2) | |
1555 | |
1556 def CheckStatusPreMergePoint(self): | |
1557 self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'], | |
1558 self.blink), self.blink_git_url) | |
1559 self.assertTrue(os.path.exists(join(self.blink, '.git'))) | |
1560 self.assertTrue(os.path.exists(join(self.blink, 'OWNERS'))) | |
1561 with open(join(self.blink, 'OWNERS')) as f: | |
1562 owners_content = f.read() | |
1563 self.assertEqual('OWNERS-pre', owners_content, 'OWNERS not updated') | |
1564 self.assertTrue(os.path.exists(join(self.blink, 'Source', 'exists_always'))) | |
1565 self.assertTrue(os.path.exists( | |
1566 join(self.blink, 'Source', 'exists_before_but_not_after'))) | |
1567 self.assertFalse(os.path.exists( | |
1568 join(self.blink, 'Source', 'exists_after_but_not_before'))) | |
1569 | |
1570 def CheckStatusPostMergePoint(self): | |
1571 # Check that the contents still exists | |
1572 self.assertTrue(os.path.exists(join(self.blink, 'OWNERS'))) | |
1573 with open(join(self.blink, 'OWNERS')) as f: | |
1574 owners_content = f.read() | |
1575 self.assertEqual('OWNERS-post', owners_content, 'OWNERS not updated') | |
1576 self.assertTrue(os.path.exists(join(self.blink, 'Source', 'exists_always'))) | |
1577 # Check that file removed between the branch point are actually deleted. | |
1578 self.assertTrue(os.path.exists( | |
1579 join(self.blink, 'Source', 'exists_after_but_not_before'))) | |
1580 self.assertFalse(os.path.exists( | |
1581 join(self.blink, 'Source', 'exists_before_but_not_after'))) | |
1582 # But not the .git folder | |
1583 self.assertFalse(os.path.exists(join(self.blink, '.git'))) | |
1584 | |
1585 def testBlinkDEPSChangeUsingGclient(self): | |
1586 """Checks that {src,blink} repos are consistent when syncing going back and | |
1587 forth using gclient sync src@revision.""" | |
1588 if not self.enabled: | |
1589 return | |
1590 | |
1591 self.gclient(['config', '--spec', | |
1592 'solutions=[' | |
1593 '{"name": "src",' | |
1594 ' "url": "' + self.git_base + 'repo_1",' | |
1595 '}]']) | |
1596 | |
1597 # Go back and forth two times. | |
1598 for _ in xrange(2): | |
1599 res = self.gclient(['sync', '--revision', 'src@%s' % self.pre_merge_sha]) | |
1600 self.assertEqual(res[2], 0, 'DEPS change sync failed.') | |
1601 self.CheckStatusPreMergePoint() | |
1602 | |
1603 res = self.gclient(['sync', '--revision', 'src@%s' % self.post_merge_sha]) | |
1604 self.assertEqual(res[2], 0, 'DEPS change sync failed.') | |
1605 self.CheckStatusPostMergePoint() | |
1606 | |
1607 | |
1608 def testBlinkDEPSChangeUsingGit(self): | |
1609 """Like testBlinkDEPSChangeGit, but move the main project using directly | |
1610 git and not gclient sync.""" | |
1611 if not self.enabled: | |
1612 return | |
1613 | |
1614 self.gclient(['config', '--spec', | |
1615 'solutions=[' | |
1616 '{"name": "src",' | |
1617 ' "url": "' + self.git_base + 'repo_1",' | |
1618 ' "managed": False,' | |
1619 '}]']) | |
1620 | |
1621 # Perform an initial sync to bootstrap the repo. | |
1622 res = self.gclient(['sync']) | |
1623 self.assertEqual(res[2], 0, 'Initial gclient sync failed.') | |
1624 | |
1625 # Go back and forth two times. | |
1626 for _ in xrange(2): | |
1627 subprocess2.check_call(['git', 'checkout', '-q', self.pre_merge_sha], | |
1628 cwd=self.checkout_path) | |
1629 res = self.gclient(['sync']) | |
1630 self.assertEqual(res[2], 0, 'gclient sync failed.') | |
1631 self.CheckStatusPreMergePoint() | |
1632 | |
1633 subprocess2.check_call(['git', 'checkout', '-q', self.post_merge_sha], | |
1634 cwd=self.checkout_path) | |
1635 res = self.gclient(['sync']) | |
1636 self.assertEqual(res[2], 0, 'DEPS change sync failed.') | |
1637 self.CheckStatusPostMergePoint() | |
1638 | |
1639 | |
1640 def testBlinkLocalBranchesArePreserved(self): | |
1641 """Checks that the state of local git branches are effectively preserved | |
1642 when going back and forth.""" | |
1643 if not self.enabled: | |
1644 return | |
1645 | |
1646 self.gclient(['config', '--spec', | |
1647 'solutions=[' | |
1648 '{"name": "src",' | |
1649 ' "url": "' + self.git_base + 'repo_1",' | |
1650 '}]']) | |
1651 | |
1652 # Initialize to pre-merge point. | |
1653 self.gclient(['sync', '--revision', 'src@%s' % self.pre_merge_sha]) | |
1654 self.CheckStatusPreMergePoint() | |
1655 | |
1656 # Create a branch named "foo". | |
1657 subprocess2.check_call(['git', 'checkout', '-qB', 'foo'], | |
1658 cwd=self.blink) | |
1659 | |
1660 # Cross the pre-merge point. | |
1661 self.gclient(['sync', '--revision', 'src@%s' % self.post_merge_sha]) | |
1662 self.CheckStatusPostMergePoint() | |
1663 | |
1664 # Go backwards and check that we still have the foo branch. | |
1665 self.gclient(['sync', '--revision', 'src@%s' % self.pre_merge_sha]) | |
1666 self.CheckStatusPreMergePoint() | |
1667 subprocess2.check_call( | |
1668 ['git', 'show-ref', '-q', '--verify', 'refs/heads/foo'], cwd=self.blink) | |
1669 | |
1670 | |
1671 class GClientSmokeFromCheckout(GClientSmokeBase): | 1541 class GClientSmokeFromCheckout(GClientSmokeBase): |
1672 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. | 1542 # WebKit abuses this. It has a .gclient and a DEPS from a checkout. |
1673 def setUp(self): | 1543 def setUp(self): |
1674 super(GClientSmokeFromCheckout, self).setUp() | 1544 super(GClientSmokeFromCheckout, self).setUp() |
1675 self.enabled = self.FAKE_REPOS.set_up_svn() | 1545 self.enabled = self.FAKE_REPOS.set_up_svn() |
1676 os.rmdir(self.root_dir) | 1546 os.rmdir(self.root_dir) |
1677 if self.enabled: | 1547 if self.enabled: |
1678 usr, pwd = self.FAKE_REPOS.USERS[0] | 1548 usr, pwd = self.FAKE_REPOS.USERS[0] |
1679 subprocess2.check_call( | 1549 subprocess2.check_call( |
1680 ['svn', 'checkout', self.svn_base + '/trunk/webkit', | 1550 ['svn', 'checkout', self.svn_base + '/trunk/webkit', |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 | 1638 |
1769 if '-c' in sys.argv: | 1639 if '-c' in sys.argv: |
1770 COVERAGE = True | 1640 COVERAGE = True |
1771 sys.argv.remove('-c') | 1641 sys.argv.remove('-c') |
1772 if os.path.exists('.coverage'): | 1642 if os.path.exists('.coverage'): |
1773 os.remove('.coverage') | 1643 os.remove('.coverage') |
1774 os.environ['COVERAGE_FILE'] = os.path.join( | 1644 os.environ['COVERAGE_FILE'] = os.path.join( |
1775 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 1645 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
1776 '.coverage') | 1646 '.coverage') |
1777 unittest.main() | 1647 unittest.main() |
OLD | NEW |