def testExists(self): """Test chroot exists.""" chroot = chroot_lib.Chroot(self.tempdir) self.assertTrue(chroot.exists()) chroot = chroot_lib.Chroot(os.path.join(self.tempdir, 'DOES_NOT_EXIST')) self.assertFalse(chroot.exists())
def setUp(self): # Create the chroot and sysroot instances. self.chroot_path = os.path.join(self.tempdir, 'chroot_dir') self.chroot = chroot_lib.Chroot(path=self.chroot_path) self.sysroot_path = os.path.join(self.chroot_path, 'sysroot_dir') self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) # Create the output directory. self.output_dir = os.path.join(self.tempdir, 'output_dir') osutils.SafeMakedirs(self.output_dir) # The sysroot's /var/db/pkg prefix for the chrome package directories. var_db_pkg = os.path.join(self.sysroot_path, 'var', 'db', 'pkg') # Create the var/db/pkg dir so we have that much for no-chrome tests. osutils.SafeMakedirs(var_db_pkg) # Two versions of chrome to test the multiple version checks/handling. chrome_v1 = '%s-1.0.0-r1' % constants.CHROME_PN chrome_v2 = '%s-2.0.0-r1' % constants.CHROME_PN # Build the two chrome version paths. chrome_cat_dir = os.path.join(var_db_pkg, constants.CHROME_CN) self.chrome_v1_dir = os.path.join(chrome_cat_dir, chrome_v1) self.chrome_v2_dir = os.path.join(chrome_cat_dir, chrome_v2) # Directory tuple for verifying the result archive contents. self.expected_archive_contents = cros_test_lib.Directory( './', 'environment') # Create a environment.bz2 file to put into folders. env_file = os.path.join(self.tempdir, 'environment') osutils.Touch(env_file) cros_build_lib.run(['bzip2', env_file]) self.env_bz2 = '%s.bz2' % env_file
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 BundleChromeOSConfig(input_proto, output_proto, _config): """Output the ChromeOS Config payload for a build target. Args: input_proto (BundleRequest): The input proto. output_proto (BundleResponse): The output proto. _config (api_config.ApiConfig): The API call config. """ output_dir = input_proto.output_dir sysroot_path = input_proto.sysroot.path chroot = controller_util.ParseChroot(input_proto.chroot) # TODO(mmortensen) Cleanup legacy handling after it has been switched over. target = input_proto.build_target.name if target: # Legacy handling. build_root = constants.SOURCE_ROOT chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) sysroot_path = os.path.join('/build', target) sysroot = sysroot_lib.Sysroot(sysroot_path) chromeos_config = artifacts.BundleChromeOSConfig(chroot, sysroot, output_dir) if chromeos_config is None: cros_build_lib.Die( 'Could not create ChromeOS Config payload. No config found for %s.', sysroot.path) output_proto.artifacts.add().path = os.path.join(output_dir, chromeos_config)
def BundleSimpleChromeArtifacts(input_proto, output_proto, _config): """Create the simple chrome artifacts.""" # Required args. sysroot_path = input_proto.sysroot.path build_target_name = input_proto.sysroot.build_target.name output_dir = input_proto.output_dir # Optional args. chroot_path = input_proto.chroot.path or constants.DEFAULT_CHROOT_PATH cache_dir = input_proto.chroot.cache_dir # Build out the argument instances. build_target = build_target_util.BuildTarget(build_target_name) chroot = chroot_lib.Chroot(path=chroot_path, cache_dir=cache_dir) # Sysroot.path needs to be the fully qualified path, including the chroot. full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) sysroot = sysroot_lib.Sysroot(full_sysroot_path) # Quick sanity check that the sysroot exists before we go on. if not sysroot.Exists(): cros_build_lib.Die('The sysroot does not exist.') try: results = artifacts.BundleSimpleChromeArtifacts(chroot, sysroot, build_target, output_dir) except artifacts.Error as e: cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', type(e), e) for file_name in results: output_proto.artifacts.add().path = file_name
def setUp(self): self.board = 'board' self.build_target = build_target_util.BuildTarget(self.board) self.chroot = chroot_lib.Chroot(path=self.tempdir) # Make the chroot's tmp directory, used for the parallel emerge status file. tempdir = os.path.join(self.tempdir, 'tmp') osutils.SafeMakedirs(tempdir)
def setUp(self): self.builder = 'moblab-generic-vm/R12-3.4.5-67-890' self.image_dir = self.MockDirectory('files/image') self.payload_dir = self.MockDirectory('files/payload') self.results_dir = self.MockDirectory('results') self.vms = moblab_vm.MoblabVm(self.tempdir) self.chroot = chroot_lib.Chroot(path=self.tempdir)
def BundleEbuildLogs(input_proto, output_proto, config): """Tar the ebuild logs for a build target. Args: input_proto (BundleRequest): The input proto. output_proto (BundleResponse): The output proto. config (api_config.ApiConfig): The API call config. """ output_dir = input_proto.output_dir sysroot_path = input_proto.sysroot.path chroot = controller_util.ParseChroot(input_proto.chroot) # TODO(mmortensen) Cleanup legacy handling after it has been switched over. target = input_proto.build_target.name if target: # Legacy handling. build_root = constants.SOURCE_ROOT chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) sysroot_path = os.path.join('/build', target) # TODO(saklein): Switch to validation_complete decorator after legacy # handling has been cleaned up. if config.validate_only: return controller.RETURN_CODE_VALID_INPUT sysroot = sysroot_lib.Sysroot(sysroot_path) archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir) if archive is None: cros_build_lib.Die( 'Could not create ebuild logs archive. No logs found for %s.', sysroot.path) output_proto.artifacts.add().path = os.path.join(output_dir, archive)
def testHasPathVariadic(self): """Test multiple args to has path.""" path = ['some', 'file.txt'] tempdir_path = os.path.join(self.tempdir, *path) osutils.Touch(tempdir_path, makedirs=True) chroot = chroot_lib.Chroot(self.tempdir) self.assertTrue(chroot.has_path(*path))
def testHasPathSuccess(self): """Test has path for a valid path.""" path = 'some/file.txt' tempdir_path = os.path.join(self.tempdir, path) osutils.Touch(tempdir_path, makedirs=True) chroot = chroot_lib.Chroot(self.tempdir) self.assertTrue(chroot.has_path(path))
def setUp(self): self.chroot = chroot_lib.Chroot(self.tempdir) self.sysroot = sysroot_lib.Sysroot('/sysroot') sysroot_path = os.path.join(self.tempdir, 'sysroot') osutils.SafeMakedirs(sysroot_path) self.pin_dir = os.path.join(sysroot_path, constants.GUEST_IMAGES_PINS_PATH) osutils.SafeMakedirs(self.pin_dir)
def test_handle_empty_chroot_message(self): """Test handling of an empty chroot message.""" message = build_api_test_pb2.TestRequestMessage() empty_chroot = chroot_lib.Chroot(env={'FEATURES': 'separatedebug'}) chroot_handler = field_handler.ChrootHandler(clear_field=False) chroot = chroot_handler.handle(message) self.assertEqual(empty_chroot, chroot)
def setUp(self): self.path = '/chroot/dir' self.cache_dir = '/cache/dir' self.chrome_dir = '/chrome/dir' self.env = {'FEATURES': 'thing', 'CHROME_ORIGIN': 'LOCAL_SOURCE'} self.expected_chroot = chroot_lib.Chroot(path=self.path, cache_dir=self.cache_dir, chrome_root=self.chrome_dir, env=self.env)
def testChrootPath(self): """Test chroot_path functionality.""" chroot = chroot_lib.Chroot(self.tempdir) path1 = os.path.join(self.tempdir, 'some/path') path2 = '/bad/path' # Make sure that it gives an absolute path inside the chroot. self.assertEqual('/some/path', chroot.chroot_path(path1)) # Make sure it raises an error for paths not inside the chroot. self.assertRaises(chroot_lib.ChrootError, chroot.chroot_path, path2)
def setUp(self): self.board = 'samus' # Create chroot object and sysroot object chroot_path = os.path.join(self.tempdir, 'chroot') self.chroot = chroot_lib.Chroot(path=chroot_path) sysroot_path = os.path.join('build', self.board) self.sysroot = sysroot_lib.Sysroot(sysroot_path) self.archive_dir = self.tempdir
def setUp(self): self.chroot = chroot_lib.Chroot( path=os.path.join(self.tempdir, 'chroot/path')) self.sysroot = sysroot_lib.Sysroot('/sysroot/path') test_dir = os.path.join( self.chroot.full_path(self.sysroot.path, constants.UNITTEST_PKG_PATH)) osutils.SafeMakedirs(test_dir) self.result_path = os.path.join(self.tempdir, 'result')
def testTempdir(self): """Test the tempdir functionality.""" chroot = chroot_lib.Chroot(path=self.tempdir) osutils.SafeMakedirs(chroot.tmp) self.assertEqual(os.path.join(self.tempdir, 'tmp'), chroot.tmp) with chroot.tempdir() as tempdir: self.assertStartsWith(tempdir, chroot.tmp) self.assertNotExists(tempdir)
def testCodeCoverageExistingFlags(self): """Test adding use flags for coverage when existing flags.""" chroot = chroot_lib.Chroot(path=self.tempdir, env={'USE': 'foo bar'}) result = test.BuildTargetUnitTest(self.build_target, chroot, code_coverage=True) self.assertCommandContains( ['cros_run_unit_tests', '--board', self.board], extra_env=PartialDict('USE', 'foo bar coverage')) self.assertTrue(result.success)
def testEqual(self): """__eq__ method sanity check.""" path = '/chroot/path' cache_dir = '/cache/dir' chrome_root = '/chrome/root' env = {'USE': 'useflag', 'FEATURES': 'feature'} chroot1 = chroot_lib.Chroot(path=path, cache_dir=cache_dir, chrome_root=chrome_root, env=env) chroot2 = chroot_lib.Chroot(path=path, cache_dir=cache_dir, chrome_root=chrome_root, env=env) chroot3 = chroot_lib.Chroot(path=path) chroot4 = chroot_lib.Chroot(path=path) self.assertEqual(chroot1, chroot2) self.assertEqual(chroot3, chroot4) self.assertNotEqual(chroot1, chroot3)
def testFullPath(self): """Test full_path functionality.""" chroot = chroot_lib.Chroot(self.tempdir) path1 = 'some/path' path2 = '/some/path' # Make sure it's building out the path in the chroot. self.assertEqual(os.path.join(self.tempdir, path1), chroot.full_path(path1)) # Make sure it can handle absolute paths. self.assertEqual(chroot.full_path(path1), chroot.full_path(path2))
def setUp(self): self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir) self.chroot_path = os.path.join(self.tempdir, 'chroot') self.sysroot_path = '/build/foo' self.root = os.path.join(self.chroot_path, self.sysroot_path.lstrip('/'), 'packages') self.chroot = chroot_lib.Chroot(self.chroot_path) self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) self.build_target = build_target_lib.BuildTarget('foo') osutils.SafeMakedirs(self.root)
def setUp(self): self.output_dir = os.path.join(self.tempdir, 'output_dir') self.archive_dir = os.path.join(self.tempdir, 'archive_base_dir') sysroot_path = os.path.join(self.tempdir, 'sysroot') self.chroot = chroot_lib.Chroot(self.tempdir) self.sysroot = sysroot_lib.Sysroot('sysroot') self.sysroot_dne = sysroot_lib.Sysroot('sysroot_DNE') # Make sure we have the valid paths. osutils.SafeMakedirs(self.output_dir) osutils.SafeMakedirs(sysroot_path)
def setUp(self): # Create the build target. self.build_target = build_target_util.BuildTarget('board') # Create the chroot. self.chroot_dir = os.path.join(self.tempdir, 'chroot') self.chroot_tmp = os.path.join(self.chroot_dir, 'tmp') osutils.SafeMakedirs(self.chroot_tmp) self.chroot = chroot_lib.Chroot(path=self.chroot_dir) # Create the output directory. self.output_dir = os.path.join(self.tempdir, 'output_dir') osutils.SafeMakedirs(self.output_dir)
def testGetEnterArgsAll(self): """Test complete instance behavior.""" path = '/chroot/path' cache_dir = '/cache/dir' chrome_root = '/chrome/root' expected = [ '--chroot', path, '--cache-dir', cache_dir, '--chrome-root', chrome_root ] chroot = chroot_lib.Chroot(path=path, cache_dir=cache_dir, chrome_root=chrome_root) self.assertCountEqual(expected, chroot.get_enter_args())
def setUp(self): self.sysroot = sysroot_lib.Sysroot('/build/board') self.chroot = chroot_lib.Chroot(self.tempdir) self.chroot_tempdir = osutils.TempDir(base_dir=self.tempdir) self.PatchObject(self.chroot, 'tempdir', return_value=self.chroot_tempdir) self.output_dir = os.path.join(self.tempdir, 'output_dir') osutils.SafeMakedirs(self.output_dir) result_file = artifacts.CPE_RESULT_FILE_TEMPLATE % 'board' self.result_file = os.path.join(self.output_dir, result_file) warnings_file = artifacts.CPE_WARNINGS_FILE_TEMPLATE % 'board' self.warnings_file = os.path.join(self.output_dir, warnings_file)
def BundleTastFiles(input_proto, output_proto, config): """Tar the tast files for a build target. Args: input_proto (BundleRequest): The input proto. output_proto (BundleResponse): The output proto. config (api_config.ApiConfig): The API call config. """ target = input_proto.build_target.name output_dir = input_proto.output_dir build_root = constants.SOURCE_ROOT chroot = controller_util.ParseChroot(input_proto.chroot) sysroot_path = input_proto.sysroot.path # TODO(saklein) Cleanup legacy handling after it has been switched over. if target: # Legacy handling. chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) sysroot_path = os.path.join('/build', target) # New handling - chroot & sysroot based. # TODO(saklein) Switch this to the require decorator when legacy is removed. if not sysroot_path: cros_build_lib.Die('sysroot.path is required.') # TODO(saklein): Switch to the validation_complete decorator when legacy # handling is removed. if config.validate_only: return controller.RETURN_CODE_VALID_INPUT sysroot = sysroot_lib.Sysroot(sysroot_path) if not sysroot.Exists(chroot=chroot): cros_build_lib.Die('Sysroot must exist.') archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir) if archive is None: cros_build_lib.Die( 'Could not bundle Tast files. ' 'No Tast directories found for %s.', target) output_proto.artifacts.add().path = archive
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 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 = fw_files + ('dts/', ) board = 'link' # fw_test_root = os.path.join(self.tempdir, os.path.basename(__file__)) fw_test_root = self.tempdir 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 the chroot and sysroot instances. chroot_path = os.path.join(self.tempdir, 'chroot') chroot = chroot_lib.Chroot(path=chroot_path) sysroot = sysroot_lib.Sysroot('/build/link') # Create an archive from the simulated firmware directory tarball = os.path.join( fw_test_root, artifacts.BuildFirmwareArchive(chroot, sysroot, fw_test_root)) # Verify the tarball contents. cros_test_lib.VerifyTarball(tarball, fw_archived_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 setUp(self): # Setup the directories. self.chroot_dir = os.path.join(self.tempdir, 'chroot') self.source_dir = '/source' self.chroot_source = os.path.join(self.chroot_dir, self.source_dir.lstrip(os.sep)) self.source_dir2 = '/source2' self.chroot_source2 = os.path.join(self.chroot_dir, self.source_dir2.lstrip(os.sep)) self.dest_dir = os.path.join(self.tempdir, 'destination') osutils.SafeMakedirs(self.chroot_source) osutils.SafeMakedirs(self.chroot_source2) osutils.SafeMakedirs(self.dest_dir) # Two files in the same directory inside the chroot. self.source_file1 = os.path.join(self.chroot_source, 'file1') self.source_file1_inside = os.path.join(self.source_dir, 'file1') self.file1_contents = 'file 1' osutils.WriteFile(self.source_file1, self.file1_contents) self.file2_contents = 'some data' self.source_file2 = os.path.join(self.chroot_source, 'file2') self.source_file2_inside = os.path.join(self.source_dir, 'file2') osutils.WriteFile(self.source_file2, self.file2_contents) # Third file in a different location. self.file3_contents = 'another file' self.source_file3 = os.path.join(self.chroot_source2, 'file3') self.source_file3_inside = os.path.join(self.source_dir2, 'file3') osutils.WriteFile(self.source_file3, self.file3_contents) self.request = build_api_test_pb2.TestRequestMessage() self.request.result_path.path.path = self.dest_dir self.request.result_path.path.location = common_pb2.Path.OUTSIDE self.response = build_api_test_pb2.TestResultMessage() self.chroot = chroot_lib.Chroot(path=self.chroot_dir)