def testBuildFirmwareArchive(self): """Verifies that firmware archiver includes proper files""" # Assorted set of file names, some of which are supposed to be included in # the archive. fw_files = ( 'dts/emeraldlake2.dts', 'image-link.rw.bin', 'nv_image-link.bin', 'pci8086,0166.rom', 'seabios.cbfs', 'u-boot.elf', 'u-boot_netboot.bin', 'updater-link.rw.sh', 'x86-memtest') # Files which should be included in the archive. fw_archived_files = ( 'dts/emeraldlake2.dts', 'image-link.rw.bin', 'nv_image-link.bin', 'updater-link.rw.sh') board = 'link' fw_test_root = os.path.join(self.tempdir, os.path.basename(__file__)) fw_files_root = os.path.join(fw_test_root, 'chroot/build/%s/firmware' % board) # Generate a representative set of files produced by a typical build. cros_test_lib.CreateOnDiskHierarchy(fw_files_root, fw_files) # Create an archive from the simulated firmware directory tarball = os.path.join( fw_test_root, commands.BuildFirmwareArchive(fw_test_root, board, fw_test_root)) # Verify the tarball contents. cros_test_lib.VerifyTarball(tarball, fw_archived_files)
def testBundleVmFiles(self): """Verifies that the correct files are bundled""" # Create the chroot instance. chroot_path = os.path.join(self.tempdir, 'chroot') chroot = chroot_lib.Chroot(path=chroot_path) # Create the test_results_dir test_results_dir = 'test/results' # Create a set of files where some should get bundled up as VM files. # Add a suffix (123) to one of the files matching the VM pattern prefix. vm_files = ('file1.txt', 'file2.txt', 'chromiumos_qemu_disk.bin' + '123', 'chromiumos_qemu_mem.bin') target_test_dir = os.path.join(chroot_path, test_results_dir) cros_test_lib.CreateOnDiskHierarchy(target_test_dir, vm_files) # Create the output directory. output_dir = os.path.join(self.tempdir, 'output_dir') osutils.SafeMakedirs(output_dir) archives = artifacts.BundleVmFiles(chroot, test_results_dir, output_dir) expected_archive_files = [ output_dir + '/chromiumos_qemu_disk.bin' + '123.tar', output_dir + '/chromiumos_qemu_mem.bin.tar' ] self.assertCountEqual(archives, expected_archive_files)
def setUp(self): """Setup the filesystem.""" self.board = 'board' self.chroot_container = os.path.join(self.tempdir, 'outside') self.outside_result_dir = os.path.join(self.chroot_container, 'results') self.inside_result_dir_inside = '/inside/results_inside' self.inside_result_dir_outside = os.path.join(self.chroot_container, 'inside/results_inside') self.image_dir_inside = '/inside/build/board/latest' self.image_dir_outside = os.path.join(self.chroot_container, 'inside/build/board/latest') D = cros_test_lib.Directory filesystem = (D('outside', ( D('results', ()), D('inside', ( D('results_inside', ()), D('build', (D('board', (D('latest', ('%s.bin' % constants.BASE_IMAGE_NAME, )), )), )), )), )), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
def setUp(self): # Build set of expected scripts. D = cros_test_lib.Directory filesystem = ( D('hooks', ( '8_invalid_gap', '10_run_success', '11_run_success', '12_run_success', )), 'version_file', ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) self.chroot_path = os.path.join(self.tempdir, 'chroot') self.version_file = os.path.join( self.chroot_path, cros_sdk_lib.CHROOT_VERSION_FILE.lstrip(os.sep)) osutils.WriteFile(self.version_file, '0', makedirs=True) self.hooks_dir = os.path.join(self.tempdir, 'hooks') self.earliest_version = 8 self.latest_version = 12 self.deprecated_versions = (6, 7, 8) self.invalid_versions = (13, ) self.success_versions = (9, 10, 11, 12)
def setUp(self): D = cros_test_lib.Directory filesystem = ( D('board', ('recovery_image.bin', )), 'other_image.bin', ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
def setUp(self): file_layout = (D( 'src', ['build_config.json', 'audio_file', 'firmware.bin']), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) self.build_config_path = os.path.join('src', 'build_config.json') self.audio_path = os.path.join('src', 'audio_file') self.firmware_path = os.path.join('src', 'firmware.bin') build_config = { 'chromeos': { 'configs': [ { 'name': 'A', 'field1': 1, 'field2': 2, }, { 'name': 'B', 'field1': 3, 'field2': 4, }, ] } } self.WriteTempFile(self.build_config_path, json.dumps(build_config)) self.WriteTempFile(self.audio_path, '[Speaker A Settings]') self.WriteTempFile(self.firmware_path, bytes(123), mode='wb') self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir)
def test_uprev_ebuild(self): """Tests uprev of ebuild with version path""" file_layout = (D(self.package, [self.ebuild, self.unstable_ebuild, self.manifest]), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) package_path = os.path.join(self.tempdir, self.package) ebuild_path = os.path.join(package_path, self.ebuild) self.WriteTempFile(ebuild_path, 'KEYWORDS="*"\n') result = packages.uprev_ebuild_from_pin(package_path, self.new_version, chroot=Chroot()) self.assertEqual( len(result.modified), 1, 'unexpected number of results: %s' % len(result.modified)) mod = result.modified[0] self.assertEqual(mod.new_version, self.new_version + '-r1', 'unexpected version number: %s' % mod.new_version) old_ebuild_path = os.path.join(package_path, self.ebuild_template % self.version) new_ebuild_path = os.path.join(package_path, self.ebuild_template % self.new_version) manifest_path = os.path.join(package_path, 'Manifest') expected_modified_files = [ old_ebuild_path, new_ebuild_path, manifest_path ] self.assertCountEqual(mod.files, expected_modified_files) self.assertCommandContains(['ebuild', 'manifest'])
def testFindFilesWithPattern(self): """Verifies FindFilesWithPattern searches and excludes files properly""" search_files = ( 'file1', 'test1', 'file2', 'dir1/file1', 'dir1/test1', 'dir2/file2', ) search_files_root = os.path.join(self.tempdir, 'FindFilesWithPatternTest') cros_test_lib.CreateOnDiskHierarchy(search_files_root, search_files) find_all = commands.FindFilesWithPattern('*', target=search_files_root) expected_find_all = self.findFilesWithPatternExpectedResults( search_files_root, search_files) self.assertEquals(set(find_all), set(expected_find_all)) find_test_files = commands.FindFilesWithPattern('test*', target=search_files_root) find_test_expected = self.findFilesWithPatternExpectedResults( search_files_root, ['test1', 'dir1/test1']) self.assertEquals(set(find_test_files), set(find_test_expected)) find_exclude = commands.FindFilesWithPattern( '*', target=search_files_root, exclude_dirs=(os.path.join(search_files_root, 'dir1'),)) find_exclude_expected = self.findFilesWithPatternExpectedResults( search_files_root, ['file1', 'test1', 'file2', 'dir2/file2']) self.assertEquals(set(find_exclude), set(find_exclude_expected))
def testReplicateDestinationExists(self): """Test existing files are overwritten.""" file_layout = (D('dst', ['audio_file']), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) audio_dst_path = os.path.join('dst', 'audio_file') self.WriteTempFile(audio_dst_path, 'Original audio data') replication_config = ReplicationConfig(file_replication_rules=[ FileReplicationRule( source_path=self.audio_path, destination_path=audio_dst_path, file_type=FILE_TYPE_OTHER, replication_type=REPLICATION_TYPE_COPY, ), ]) replication_lib.Replicate(replication_config) expected_file_layout = ( D('src', ['build_config.json', 'audio_file', 'firmware.bin']), D('dst', ['audio_file']), ) cros_test_lib.VerifyOnDiskHierarchy(self.tempdir, expected_file_layout) self.assertTempFileContents(audio_dst_path, '[Speaker A Settings]')
def setUp(self): file_layout = (D('src', ['audio_file']), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) self.audio_path = os.path.join('src', 'audio_file') self.WriteTempFile(self.audio_path, '[Speaker A Settings]') self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir)
def setUp(self): # Set up fake public and private chromeos-config overlays. private_package_root = ( 'src/private-overlays/overlay-coral-private/chromeos-base/' 'chromeos-config-bsp') self.public_package_root = ( 'src/overlays/overlay-coral/chromeos-base/chromeos-config-bsp') file_layout = ( D(os.path.join(private_package_root, 'files'), ['build_config.json']), D(private_package_root, ['replication_config.jsonpb']), D(os.path.join(self.public_package_root, 'files'), ['build_config.json']), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) # Private config contains 'a' and 'b' fields. self.private_config_path = os.path.join(private_package_root, 'files', 'build_config.json') self.WriteTempFile( self.private_config_path, json.dumps({'chromeos': { 'configs': [{ 'a': 3, 'b': 2 }] }})) # Public config only contains the 'a' field. Note that the value of 'a' is # 1 in the public config; it will get updated to 3 when the private config # is replicated. self.public_config_path = os.path.join(self.public_package_root, 'files', 'build_config.json') self.WriteTempFile(self.public_config_path, json.dumps({'chromeos': { 'configs': [{ 'a': 1 }] }})) # Put a ReplicationConfig JSONPB in the private package. Note that it # specifies only the 'a' field is replicated. self.replication_config_path = os.path.join( self.tempdir, private_package_root, 'replication_config.jsonpb') replication_config = ReplicationConfig(file_replication_rules=[ FileReplicationRule(source_path=self.private_config_path, destination_path=self.public_config_path, file_type=FILE_TYPE_JSON, replication_type=REPLICATION_TYPE_FILTER, destination_fields=FieldMask(paths=['a'])) ]) osutils.WriteFile(self.replication_config_path, json_format.MessageToJson(replication_config)) self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir) self.rc.SetDefaultCmdResult(side_effect=self._write_generated_c_files)
def setUp(self): self.PatchObject(commandline.ArgumentParser, 'ConfigureCacheDir') dir_struct = [ 'repo/.repo/', ] cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct) self.repo_root = os.path.join(self.tempdir, 'repo') self.cwd_mock = self.PatchObject(os, 'getcwd') self.parser = commandline.ArgumentParser(caching=True)
def setUp(self): os.environ.pop("BOTO_CONFIG", None) self.bad_path = os.path.join(self.tempdir, 'nonexistent') file_list = ['gsutil_bin', 'boto_file', 'acl_file'] cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_list) for f in file_list: setattr(self, f, os.path.join(self.tempdir, f)) self.StartPatcher(PatchGS('DEFAULT_BOTO_FILE', new=self.boto_file)) self.StartPatcher(PatchGS('DEFAULT_GSUTIL_BIN', new=self.gsutil_bin))
def test_no_ebuild(self): """Tests assertion is raised if package has no ebuilds""" file_layout = (D(self.package, [self.manifest]), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) package_path = os.path.join(self.tempdir, self.package) with self.assertRaises(packages.UprevError): packages.uprev_ebuild_from_pin(package_path, self.new_version, chroot=Chroot())
def setUp(self): D = cros_test_lib.Directory filesystem = (D('configs', ('cros_common.config', )), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) self.config_file = os.path.join(self.tempdir, 'configs/cros_common.config') self.hash = 'abc123' content = '[signer]\nvboot_stable_hash = %s' % self.hash osutils.WriteFile(self.config_file, content)
def setUp(self): self.board = 'board' self.board_dir = os.path.join(self.tempdir, self.board) D = cros_test_lib.Directory filesystem = ( D(self.board, ('recovery_image.bin', 'other_image.bin')), 'full_path_image.bin', ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) self.full_path = os.path.join(self.tempdir, 'full_path_image.bin')
def test_multiple_unstable_ebuilds(self): """Tests assertion is raised if multiple unstable ebuilds are present""" file_layout = (D( self.package, [self.ebuild, self.ebuild_template % '1.2.1', self.manifest]), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout) package_path = os.path.join(self.tempdir, self.package) with self.assertRaises(packages.UprevError): packages.uprev_ebuild_from_pin(package_path, self.new_version, chroot=Chroot())
def setUp(self): dir_struct = [ 'repo/.repo/', 'repo/manifest/', 'gclient/.gclient', ] cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct) self.repo_root = os.path.join(self.tempdir, 'repo') self.gclient_root = os.path.join(self.tempdir, 'gclient') self.nocheckout_root = os.path.join(self.tempdir, 'nothing') self.rc_mock = self.StartPatcher(cros_test_lib.RunCommandMock()) self.cwd_mock = self.PatchObject(os, 'getcwd')
def testUpdateDefaultChromeVersion(self): """We pick up the right LKGM version from the Chrome tree.""" dir_struct = ['gclient_root/.gclient'] cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct) gclient_root = os.path.join(self.tempdir, 'gclient_root') self.PatchObject(os, 'getcwd', return_value=gclient_root) lkgm_file = os.path.join(gclient_root, 'src', constants.PATH_TO_CHROME_LKGM) osutils.Touch(lkgm_file, makedirs=True) osutils.WriteFile(lkgm_file, self.VERSION) self.sdk_mock.UnMockAttr('UpdateDefaultVersion') self.sdk.UpdateDefaultVersion() self.assertEqual(self.sdk.GetDefaultVersion(), self.VERSION)
def _CopyAndVerify(self, path, src_struct, dest_struct, error=None, strict=False, sloppy=False): cros_test_lib.CreateOnDiskHierarchy(self.src_base, src_struct) if error: self.assertRaises(error, path.Copy, self.src_base, self.dest_base, None, strict, sloppy) return path.Copy(self.src_base, self.dest_base, self.copier, strict, sloppy) cros_test_lib.VerifyOnDiskHierarchy(self.dest_base, dest_struct)
def RunTest(self, dir_struct, cwd, expected_root, expected_type, expected_src): """Run a test with specific parameters and expected results.""" cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct) cwd = os.path.join(self.tempdir, cwd) checkout_info = path_util.DetermineCheckout(cwd) full_root = expected_root if expected_root is not None: full_root = os.path.join(self.tempdir, expected_root) full_src = expected_src if expected_src is not None: full_src = os.path.join(self.tempdir, expected_src) self.assertEqual(checkout_info.root, full_root) self.assertEqual(checkout_info.type, expected_type) self.assertEqual(checkout_info.chrome_src_dir, full_src)
def setUp(self): self.PatchObject(commandline.ArgumentParser, 'ConfigureCacheDir') dir_struct = [ 'repo/.repo/', 'gclient/.gclient', 'submodule/.git/', ] cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct) self.repo_root = os.path.join(self.tempdir, 'repo') self.gclient_root = os.path.join(self.tempdir, 'gclient') self.submodule_root = os.path.join(self.tempdir, 'submodule') self.nocheckout_root = os.path.join(self.tempdir, 'nothing') self.rc_mock = self.StartPatcher(cros_build_lib_unittest.RunCommandMock()) self.rc_mock.AddCmdResult( partial_mock.In('config'), output=constants.CHROMIUM_GOB_URL) self.cwd_mock = self.PatchObject(os, 'getcwd') self.parser = commandline.ArgumentParser(caching=True)
def setUp(self): """Setup the test environment.""" # Fake being root to avoid running all filesystem commands with sudo_run. self.PatchObject(os, 'getuid', return_value=0) self.PatchObject(os, 'geteuid', return_value=0) self.sysroot = sysroot_lib.Sysroot(self.tempdir) self.make_conf_generic_target = os.path.join( self.tempdir, 'make.conf.generic-target') self.make_conf_user = os.path.join(self.tempdir, 'make.conf.user') D = cros_test_lib.Directory filesystem = ( D('etc', ()), 'make.conf.generic-target', 'make.conf.user', ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
def setUp(self): D = cros_test_lib.Directory filesystem = ( D('chroot', (D('tmp', (D('tempdir', ()), )), )), D('sources', ( D('single_file', ('single_file.txt', )), D('nested_directories', ( 'basedir_file.log', D('nested1', ( 'nested1.txt', D('nested2', ('nested2.txt', )), )), )), )), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) self.chroot = os.path.join(self.tempdir, 'chroot') self.chroot_tmp = os.path.join(self.chroot, 'tmp') self.destination = os.path.join(self.chroot_tmp, 'tempdir') self.inside_path = '/tmp/tempdir' self.single_file_src = os.path.join(self.tempdir, 'sources', 'single_file') self.sf_src_file = os.path.join(self.single_file_src, 'single_file.txt') self.sf_dest_file = os.path.join(self.destination, 'single_file.txt') self.nested_dirs_src = (os.path.join(self.tempdir, 'sources', 'nested_directories')) self.nested_src_files = ( os.path.join(self.nested_dirs_src, 'basedir_file.log'), os.path.join(self.nested_dirs_src, 'nested1', 'nested1.txt'), os.path.join(self.nested_dirs_src, 'nested1', 'nested2', 'nested2.txt'), ) self.nested_dest_files = ( os.path.join(self.destination, 'basedir_file.log'), os.path.join(self.destination, 'nested1', 'nested1.txt'), os.path.join(self.destination, 'nested1', 'nested2', 'nested2.txt'), ) self.message = build_api_test_pb2.TestRequestMessage()
def setUp(self): D = cros_test_lib.Directory filesystem = ( D('build', ( D('board', ( D('etc', ( 'make.conf.board_setup', )), )), )), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) self.chost_value = 'chost' osutils.WriteFile(os.path.join(self.tempdir, 'build/board/etc/make.conf.board_setup'), 'CHOST="%s"' % self.chost_value) self.sysroot_dir = os.path.join(self.tempdir, 'build/board')
def testArchiveVMFiles(self): """Validate ArchiveVMFiles success in archiving files.""" test_buildroot = os.path.join(self.tempdir, 'buildroot') image_dir = os.path.join(test_buildroot, 'chroot', 'testResultsDir') test_path_archive_output = os.path.join(self.tempdir, 'testResultsDir') os.makedirs(test_path_archive_output) vm_files = ['abc.txt', 'chromiumos_qemu_mem.bin'] cros_test_lib.CreateOnDiskHierarchy(image_dir, vm_files) result = vm_test_stages.ArchiveVMFiles(test_buildroot, 'testResultsDir', test_path_archive_output) # The expected output is the test_path_archive_output with the one file that # matches the constants VM pattern prefix, which will be converted to a # .bin.tar file. expected_result = [ os.path.join(test_path_archive_output, 'chromiumos_qemu_mem.bin.tar') ] self.assertEqual(result, expected_result)
def setUp(self): D = cros_test_lib.Directory filesystem = (D('path', ( D('to', ('example.txt', 'example.csv', 'thing.txt', 'another.csv')), D('excluded', ('example.txt', )), )), ) cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) base_path = os.path.join(self.tempdir, 'path', 'to') another_csv = os.path.join(base_path, 'another.csv') example_csv = os.path.join(base_path, 'example.csv') example_txt = os.path.join(base_path, 'example.txt') thing_txt = os.path.join(base_path, 'thing.txt') self.csvs = [another_csv, example_csv] self.txts = [example_txt, thing_txt] self.excluded = os.path.join(self.tempdir, 'path', 'excluded')
def testBundleEBuildLogsTarball(self): """Verifies that the correct EBuild tar files are bundled.""" board = 'samus' # Create chroot object and sysroot object chroot_path = os.path.join(self.tempdir, 'chroot') chroot = chroot_lib.Chroot(path=chroot_path) sysroot_path = os.path.join('build', board) sysroot = sysroot_lib.Sysroot(sysroot_path) # Create parent dir for logs log_parent_dir = os.path.join(chroot.path, 'build') # Names of log files typically found in a build directory. log_files = ( '', 'x11-libs:libdrm-2.4.81-r24:20170816-175008.log', 'x11-libs:libpciaccess-0.12.902-r2:20170816-174849.log', 'x11-libs:libva-1.7.1-r2:20170816-175019.log', 'x11-libs:libva-intel-driver-1.7.1-r4:20170816-175029.log', 'x11-libs:libxkbcommon-0.4.3-r2:20170816-174908.log', 'x11-libs:pango-1.32.5-r1:20170816-174954.log', 'x11-libs:pixman-0.32.4:20170816-174832.log', 'x11-misc:xkeyboard-config-2.15-r3:20170816-174908.log', 'x11-proto:kbproto-1.0.5:20170816-174849.log', 'x11-proto:xproto-7.0.31:20170816-174849.log', ) tarred_files = [os.path.join('logs', x) for x in log_files] log_files_root = os.path.join(log_parent_dir, '%s/tmp/portage/logs' % board) # Generate a representative set of log files produced by a typical build. cros_test_lib.CreateOnDiskHierarchy(log_files_root, log_files) archive_dir = self.tempdir tarball = artifacts.BundleEBuildLogsTarball(chroot, sysroot, archive_dir) self.assertEqual('ebuild_logs.tar.xz', tarball) # Verify the tarball contents. tarball_fullpath = os.path.join(self.tempdir, tarball) cros_test_lib.VerifyTarball(tarball_fullpath, tarred_files)
def testBundleFpmcuUnittests(self): """Verifies that the resulting tarball includes proper files""" unittest_files = ( 'bloonchipper/test_rsa.bin', 'dartmonkey/test_utils.bin', ) board = 'hatch' unittest_files_root = os.path.join( self.tempdir, 'chroot/build/%s/firmware/chromeos-fpmcu-unittests' % board) cros_test_lib.CreateOnDiskHierarchy(unittest_files_root, unittest_files) chroot_path = os.path.join(self.tempdir, 'chroot') chroot = chroot_lib.Chroot(path=chroot_path) sysroot = sysroot_lib.Sysroot('/build/%s' % board) tarball = os.path.join( self.tempdir, artifacts.BundleFpmcuUnittests(chroot, sysroot, self.tempdir)) cros_test_lib.VerifyTarball( tarball, unittest_files + ('bloonchipper/', 'dartmonkey/'))
def testBundleChromeOSConfig(self): """Verifies that the correct ChromeOS config file is bundled.""" # Create parent dir for ChromeOS Config output. config_parent_dir = os.path.join(self.chroot.path, 'build') # Names of ChromeOS Config files typically found in a build directory. config_files = ('config.json', cros_test_lib.Directory('yaml', [ 'config.c', 'config.yaml', 'ec_config.c', 'ec_config.h', 'model.yaml', 'private-model.yaml' ])) config_files_root = os.path.join( config_parent_dir, '%s/usr/share/chromeos-config' % self.board) # Generate a representative set of config files produced by a typical build. cros_test_lib.CreateOnDiskHierarchy(config_files_root, config_files) # Write a payload to the config.yaml file. test_config_payload = { 'chromeos': { 'configs': [{ 'identity': { 'platform-name': 'Samus' } }] } } with open(os.path.join(config_files_root, 'yaml', 'config.yaml'), 'w') as f: json.dump(test_config_payload, f) config_filename = artifacts.BundleChromeOSConfig( self.chroot, self.sysroot, self.archive_dir) self.assertEqual('config.yaml', config_filename) with open(os.path.join(self.archive_dir, config_filename), 'r') as f: self.assertEqual(test_config_payload, json.load(f))