1*4882a593Smuzhiyunimport os 2*4882a593Smuzhiyunimport shutil 3*4882a593Smuzhiyun 4*4882a593Smuzhiyunfrom tests.download.gitremote import GitRemote 5*4882a593Smuzhiyun 6*4882a593Smuzhiyunimport infra 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun 9*4882a593Smuzhiyunclass GitTestBase(infra.basetest.BRConfigTest): 10*4882a593Smuzhiyun config = \ 11*4882a593Smuzhiyun """ 12*4882a593Smuzhiyun BR2_BACKUP_SITE="" 13*4882a593Smuzhiyun """ 14*4882a593Smuzhiyun gitremotedir = infra.filepath("tests/download/git-remote") 15*4882a593Smuzhiyun gitremote = None 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun def setUp(self): 18*4882a593Smuzhiyun super(GitTestBase, self).setUp() 19*4882a593Smuzhiyun self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile) 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun def tearDown(self): 22*4882a593Smuzhiyun self.show_msg("Cleaning up") 23*4882a593Smuzhiyun if self.gitremote: 24*4882a593Smuzhiyun self.gitremote.stop() 25*4882a593Smuzhiyun if self.b and not self.keepbuilds: 26*4882a593Smuzhiyun self.b.delete() 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun def check_hash(self, package): 29*4882a593Smuzhiyun # store downloaded tarball inside the output dir so the test infra 30*4882a593Smuzhiyun # cleans it up at the end 31*4882a593Smuzhiyun env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"), 32*4882a593Smuzhiyun "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)} 33*4882a593Smuzhiyun self.b.build(["{}-dirclean".format(package), 34*4882a593Smuzhiyun "{}-source".format(package)], 35*4882a593Smuzhiyun env) 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun def check_download(self, package): 38*4882a593Smuzhiyun # store downloaded tarball inside the output dir so the test infra 39*4882a593Smuzhiyun # cleans it up at the end 40*4882a593Smuzhiyun dl_dir = os.path.join(self.builddir, "dl") 41*4882a593Smuzhiyun # enforce we test the download 42*4882a593Smuzhiyun if os.path.exists(dl_dir): 43*4882a593Smuzhiyun shutil.rmtree(dl_dir) 44*4882a593Smuzhiyun env = {"BR2_DL_DIR": dl_dir, 45*4882a593Smuzhiyun "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)} 46*4882a593Smuzhiyun self.b.build(["{}-dirclean".format(package), 47*4882a593Smuzhiyun "{}-legal-info".format(package)], 48*4882a593Smuzhiyun env) 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun 51*4882a593Smuzhiyunclass TestGitHash(GitTestBase): 52*4882a593Smuzhiyun br2_external = [infra.filepath("tests/download/br2-external/git-hash")] 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun def test_run(self): 55*4882a593Smuzhiyun with self.assertRaises(SystemError): 56*4882a593Smuzhiyun self.check_hash("bad") 57*4882a593Smuzhiyun self.check_hash("good") 58*4882a593Smuzhiyun self.check_hash("nohash") 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun 61*4882a593Smuzhiyunclass TestGitRefs(GitTestBase): 62*4882a593Smuzhiyun br2_external = [infra.filepath("tests/download/br2-external/git-refs")] 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun def test_run(self): 65*4882a593Smuzhiyun with self.assertRaises(SystemError): 66*4882a593Smuzhiyun self.check_download("git-wrong-content") 67*4882a593Smuzhiyun with self.assertRaises(SystemError): 68*4882a593Smuzhiyun self.check_download("git-wrong-sha1") 69*4882a593Smuzhiyun self.check_download("git-partial-sha1-branch-head") 70*4882a593Smuzhiyun self.check_download("git-partial-sha1-reachable-by-branch") 71*4882a593Smuzhiyun self.check_download("git-partial-sha1-reachable-by-tag") 72*4882a593Smuzhiyun self.check_download("git-partial-sha1-tag-itself") 73*4882a593Smuzhiyun self.check_download("git-partial-sha1-tag-points-to") 74*4882a593Smuzhiyun self.check_download("git-sha1-branch-head") 75*4882a593Smuzhiyun self.check_download("git-sha1-reachable-by-branch") 76*4882a593Smuzhiyun self.check_download("git-sha1-reachable-by-tag") 77*4882a593Smuzhiyun self.check_download("git-sha1-tag-itself") 78*4882a593Smuzhiyun self.check_download("git-sha1-tag-points-to") 79*4882a593Smuzhiyun self.check_download("git-submodule-disabled") 80*4882a593Smuzhiyun self.check_download("git-submodule-enabled") 81*4882a593Smuzhiyun self.check_download("git-tag") 82