def run_once(self, testdir = None, extra_args = '', nproc = '1000', nops = '1000'): if not testdir: testdir = self.tmpdir args = '-d %s -p %s -n %s %s' % (testdir, nproc, nops, extra_args) cmd = self.srcdir + '/fsstress ' + args utils.system(cmd)
def save_build(build_dir, dest_dir): logging.debug('Saving the result of the build on %s', dest_dir) base_name = os.path.basename(build_dir) tarball_name = base_name + '.tar.bz2' os.chdir(os.path.dirname(build_dir)) utils.system('tar -cjf %s %s' % (tarball_name, base_name)) shutil.move(tarball_name, os.path.join(dest_dir, tarball_name))
def install(self, tag='', prefix = '/', extraversion='autotest'): """make install in the kernel tree""" self.log('Installing ...') os.chdir(self.build_dir) if not os.path.isdir(prefix): os.mkdir(prefix) self.boot_dir = os.path.join(prefix, 'boot') if not os.path.isdir(self.boot_dir): os.mkdir(self.boot_dir) # remember what we are going to install xen_version = '%s-%s' % (self.get_xen_build_ver(), extraversion) self.xen_image = self.boot_dir + '/xen-' + xen_version + '.gz' self.xen_syms = self.boot_dir + '/xen-syms-' + xen_version self.log('Installing Xen ...') os.environ['XEN_EXTRAVERSION'] = '-unstable-%s'% extraversion # install xen utils.system('make DESTDIR=%s -C xen install' % prefix) # install tools utils.system('make DESTDIR=%s -C tools install' % prefix) # install kernel ktag = self.kjob.get_kernel_build_ver() kprefix = prefix self.kjob.install(tag=ktag, prefix=kprefix)
def setup(tarball, topdir): srcdir = os.path.join(topdir, 'src') utils.extract_tarball_to_dir(tarball, srcdir) os.chdir(srcdir) utils.system ('make') utils.system ('make prefix=%s install' % topdir) os.chdir(topdir)
def setup(self, tarball='NPB3.3.tar.gz'): tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir) # Prepare the makefile and benchmarks to generate. utils.system('patch -p1 < ../enable-all-tests.patch') utils.system('cd NPB3.3-OMP && make suite')
def create(pool, fs): if pool == "": raise error.TestFail("cannot create file system : Missing pool name..") if fs == "": raise error.TestFail("cannot create file system : Missing file system name..") utils.system("zfs create " + pool + "/" + fs) return SUCCESS
def setup(tarball, topdir): srcdir = os.path.join(topdir, 'src') if not os.path.exists(tarball): utils.get_file('http://mirror.x10.com/mirror/mysql/Downloads/MySQL-5.0/mysql-5.0.45.tar.gz', tarball) utils.extract_tarball_to_dir(tarball, 'src') os.chdir(srcdir) utils.configure('--prefix=%s/mysql --enable-thread-safe-client' \ % topdir) utils.make('-j %d' % utils.count_cpus()) utils.make('install') # # MySQL doesn't create this directory on it's own. # This is where database logs and files are created. # try: os.mkdir(topdir + '/mysql/var') except Exception: pass # # Initialize the database. # utils.system('%s/mysql/bin/mysql_install_db' % topdir) os.chdir(topdir)
def run_clock_getres(test, params, env): """ Verify if guests using kvm-clock as the time source have a sane clock resolution. @param test: kvm test object. @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ t_name = "test_clock_getres" base_dir = "/tmp" deps_dir = os.path.join(test.bindir, "deps", t_name) os.chdir(deps_dir) try: utils.system("make clean") utils.system("make") except: raise error.TestError("Failed to compile %s" % t_name) test_clock = os.path.join(deps_dir, t_name) if not os.path.isfile(test_clock): raise error.TestError("Could not find %s" % t_name) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) vm.copy_files_to(test_clock, base_dir) session.cmd(os.path.join(base_dir, t_name)) logging.info("PASS: Guest reported appropriate clock resolution") logging.info("Guest's dmesg:\n%s", session.cmd_output("dmesg").strip())
def setup(self, tarball = 'spew-1.0.5.tgz'): self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(self.tarball, self.srcdir) os.chdir(self.srcdir) utils.system('./configure') utils.system('make')
def unmount(pool, fs): if pool == "": raise error.TestFail("cannot unmount file system : Missing pool name..") if fs == "": raise error.TestFail("cannot unmount file system : Missing file system name..") utils.system("zfs unmount " + pool + "/" + fs) return SUCCESS
def setup(self, tarball='ebizzy-0.3.tar.gz'): tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir) utils.system('[ -x configure ] && ./configure') utils.system('make')
def _clean_previous_installs(self): kill_qemu_processes() removable_packages = "" for pkg in self.pkg_list: removable_packages += " %s" % pkg utils.system("yum remove -y %s" % removable_packages)
def run_once(self, args = ''): if not args: threads = 2*utils.count_cpus() args = '-c %d -i %d -m %d -d %d -t 60 -v' % \ (threads, threads, threads, threads) utils.system(self.srcdir + '/src/stress ' + args)
def execute(self, eth='eth0', count=50000, clone_skb=1, \ dst_ip='192.168.210.210', dst_mac='01:02:03:04:05:07'): if not os.path.exists('/proc/net/pktgen'): utils.system('/sbin/modprobe pktgen') if not os.path.exists('/proc/net/pktgen'): raise error.TestError('pktgen not loaded') logging.info('Adding devices to run') self.pgdev = '/proc/net/pktgen/kpktgend_0' self.pgset('rem_device_all') self.pgset('add_device ' + eth) self.pgset('max_before_softirq 10000') # Configure the individual devices logging.info('Configuring devices') self.ethdev='/proc/net/pktgen/' + eth self.pgdev=self.ethdev if clone_skb: self.pgset('clone_skb %d' % (count)) self.pgset('min_pkt_size 60') self.pgset('max_pkt_size 60') self.pgset('dst ' + dst_ip) self.pgset('dst_mac ' + dst_mac) self.pgset('count %d' % (count)) # Time to run self.pgdev='/proc/net/pktgen/pgctrl' self.pgset('start') output = os.path.join(self.resultsdir, eth) utils.system ('cp %s %s' % (self.ethdev, output))
def setup(self, tarball = 'lockstat-1.4.11.tar.bz2'): self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(self.tarball, self.srcdir) os.chdir(self.srcdir) utils.system('make') self.cmd = self.srcdir + '/lockstat'
def run_once(self): # Make sure Chrome minidumps are written locally. minidumps_file = "/mnt/stateful_partition/etc/enable_chromium_minidumps" if not os.path.exists(minidumps_file): open(minidumps_file, "w").close() pgrep_process = subprocess.Popen(["pgrep", "session_manager"], stdout=subprocess.PIPE) old_pid = pgrep_process.communicate()[0].strip() subprocess.call(["pkill", constants.SESSION_MANAGER]) utils.poll_for_condition(lambda: self._session_manager_ready(old_pid), timeout=20) assert os.path.exists(minidumps_file) # Enable chrome testing interface and Login deps_dir = os.path.join(self.autodir, "deps") pyautolib_dir = os.path.join(self.cr_source_dir, "chrome", "test", "pyautolib") login_cmd = cros_ui.xcommand_as( "python %s chromeos_utils.ChromeosUtils.LoginToDefaultAccount " "-v --no-http-server" % os.path.join(pyautolib_dir, "chromeos", "chromeos_utils.py") ) utils.system(login_cmd) # Run pyauto tests in the "FULL" suite functional_cmd = cros_ui.xcommand_as( "%s/chrome_test/test_src/chrome/test/functional/" "pyauto_functional.py --suite=FULL -v" % deps_dir ) utils.system(functional_cmd)
def setup(self, tarball = 'unixbench-4.1.0.tar.bz2'): tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir) utils.system('patch -p1 < ../unixbench.patch') utils.system('make')
def initialize(self, dir = None, pages_requested = 20): self.dir = None self.job.require_gcc() utils.check_kernel_ver("2.6.16") # Check huge page number pages_available = 0 if os.path.exists('/proc/sys/vm/nr_hugepages'): utils.write_one_line('/proc/sys/vm/nr_hugepages', str(pages_requested)) nr_hugepages = utils.read_one_line('/proc/sys/vm/nr_hugepages') pages_available = int(nr_hugepages) else: raise error.TestNAError('Kernel does not support hugepages') if pages_available < pages_requested: raise error.TestError('%d huge pages available, < %d pages requested' % (pages_available, pages_requested)) # Check if hugetlbfs has been mounted if not utils.file_contains_pattern('/proc/mounts', 'hugetlbfs'): if not dir: dir = os.path.join(self.tmpdir, 'hugetlbfs') os.makedirs(dir) utils.system('mount -t hugetlbfs none %s' % dir) self.dir = dir
def run_once(self): logging.info("In run_once function.. ") logging.info("create pool..") disks = libzfs_common.get_free_disks() version = "1" status = libzpool.create(TESTPOOL, disks[0]) if status != SUCCESS: raise error.TestFail("zpool create failed.. ") logging.info("create zvol on pool..") status = libzfs.create_zvol(TESTPOOL, "2G", TESTVOL) if status != SUCCESS: raise error.TestFail("cannot create zvol..") list_args = ["list", "list -r", "list "+TESTPOOL+"/"+TESTVOL, "list -r "+TESTPOOL+"/"+TESTVOL, "list -H "+TESTPOOL+"/"+TESTVOL, "list -Hr "+TESTPOOL+"/"+TESTVOL, "list -rH "+TESTPOOL+"/"+TESTVOL, "list -o name "+TESTPOOL+"/"+TESTVOL, "list -r -o name "+TESTPOOL+"/"+TESTVOL, "list -H -o name "+TESTPOOL+"/"+TESTVOL, "list -rH -o name "+TESTPOOL+"/"+TESTVOL] logging.info("Executing well-formed 'zfs list' commands") for i in list_args: utils.system("zfs " + i + " > /dev/null") logging.info("Executing zfs list on volume works as expected")
def setup(self): os.mkdir(self.srcdir) os.chdir(self.bindir) utils.system('cp disktest.c src/') os.chdir(self.srcdir) cflags = '-D_FILE_OFFSET_BITS=64 -D _GNU_SOURCE -static -Wall' utils.system('cc disktest.c ' + cflags + ' -o disktest')
def run_once(self): logging.info("In run_once function.. ") logging.info("Here we will create the pool..") disks = libzfs_common.get_free_disks() status = libzpool.create(TESTPOOL, disks[0]) if status != SUCCESS: raise error.TestFail("zpool create failed..") logging.info("Create a file system and set its mount point....") utils.system("mkdir -p " + TESTDIR) libzfs.create(TESTPOOL, fs1) libzfs.set_property(TESTPOOL, fs1, "mountpoint", TESTDIR) logging.info("Create nested file system..") libzfs.create(TESTPOOL, fs2) status = libzfs.destroy(TESTPOOL, fs1) if status == SUCCESS: raise error.TestFail("Parent file system destroyed..") logging.info("The nestedfs test passed successfully..") return SUCCESS
def start(self, test): """ Start ftrace profiler @param test: Autotest test in which the profiler will operate on. """ # Make sure debugfs is mounted and tracing disabled. utils.system('%s reset' % self.trace_cmd) output_dir = os.path.join(test.profdir, 'ftrace') if not os.path.isdir(output_dir): os.makedirs(output_dir) self.output = os.path.join(output_dir, 'trace.dat') cmd = [self.trace_cmd, 'record', '-o', self.output] cmd += self.trace_cmd_args self.record_job = utils.BgJob(self.join_command(cmd), stderr_tee=utils.TEE_TO_LOGS) # Wait for tracing to be enabled. If trace-cmd dies before enabling # tracing, then there was a problem. tracing_on = os.path.join(self.tracing_dir, 'tracing_on') while (self.record_job.sp.poll() is None and utils.read_file(tracing_on).strip() != '1'): time.sleep(0.1) if self.record_job.sp.poll() is not None: utils.join_bg_jobs([self.record_job]) raise error.CmdError(self.record_job.command, self.record_job.sp.returncode, 'trace-cmd exited early.')
def run_once(self): RPMS_dir = os.path.join(self.BUIDROOT, "RPMS/x86_64") os.chdir(RPMS_dir) rpmballs = os.listdir(RPMS_dir) # remove xen rpmball for item in rpmballs: if "xen" in item: rpmballs.remove(item) rpmstr = string.join(rpmballs, " ") rpm_install_cmd = "rpm -Uvh %s --force 2>&1" % rpmstr cmd_result = utils.system(rpm_install_cmd) if cmd_result != 0: raise error.TestFail("Libvirt RPM install FAIL") libvirtd_restart_cmd = "service libvirtd restart" cmd_result = utils.system(libvirtd_restart_cmd) if cmd_result != 0: raise error.TestFail("libvirtd restart FAIL") virsh_cmd = "virsh uri" cmd_result = utils.system(virsh_cmd) if cmd_result != 0: raise error.TestFail("virsh command FAIL") utils.system("touch %s" % self.success_flag)
def get_git_branch(repository, branch, srcdir, commit=None, lbranch=None): """ Retrieves a given git code repository. @param repository: Git repository URL """ logging.info("Fetching git [REP '%s' BRANCH '%s' TAG '%s'] -> %s", repository, branch, commit, srcdir) if not os.path.exists(srcdir): os.makedirs(srcdir) os.chdir(srcdir) if os.path.exists(".git"): utils.system("git reset --hard") else: utils.system("git init") if not lbranch: lbranch = branch utils.system("git fetch -q -f -u -t %s %s:%s" % (repository, branch, lbranch)) utils.system("git checkout %s" % lbranch) if commit: utils.system("git checkout %s" % commit) h = utils.system_output('git log --pretty=format:"%H" -1') desc = utils.system_output("git describe") logging.info("Commit hash for %s is %s (%s)" % (repository, h.strip(), desc)) return srcdir
def plot_2d_graphs(self): """ For each one of the throughput parameters, generate a set of gnuplot commands that will create a parametric surface with file size vs. record size vs. throughput. """ datasource_2d = os.path.join(self.output_dir, '2d-datasource-file') for index, label in zip(range(2, 15), _LABELS[2:]): commands_path = os.path.join(self.output_dir, '2d-%s.do' % label) commands = "" commands += "set title 'Iozone performance: %s'\n" % label commands += "set logscale x\n" commands += "set xlabel 'File size (KB)'\n" commands += "set ylabel 'Througput (MB/s)'\n" commands += "set terminal png small size 450 350\n" commands += "set output '%s'\n" % os.path.join(self.output_dir, '2d-%s.png' % label) commands += ("plot '%s' using 1:%s title '%s' with lines \n" % (datasource_2d, index, label)) commands_file = open(commands_path, 'w') commands_file.write(commands) commands_file.close() try: utils.system("%s %s" % (self.gnuplot, commands_path)) except error.CmdError: logging.error("Problem plotting from commands file %s", commands_path)
def create_image(params, root_dir): """ Create an image using qemu_image. @param params: Dictionary containing the test parameters. @param root_dir: Base directory for relative filenames. @note: params should contain: image_name -- the name of the image file, without extension image_format -- the format of the image (qcow2, raw etc) image_cluster_size (optional) -- the cluster size for the image image_size -- the requested size of the image (a string qemu-img can understand, such as '10G') """ qemu_img_cmd = virt_utils.get_path(root_dir, params.get("qemu_img_binary", "qemu-img")) qemu_img_cmd += " create" format = params.get("image_format", "qcow2") qemu_img_cmd += " -f %s" % format image_cluster_size = params.get("image_cluster_size", None) if image_cluster_size is not None: qemu_img_cmd += " -o cluster_size=%s" % image_cluster_size image_filename = get_image_filename(params, root_dir) qemu_img_cmd += " %s" % image_filename size = params.get("image_size", "10G") qemu_img_cmd += " %s" % size utils.system(qemu_img_cmd) return image_filename
def server_start(self, cpu_affinity): utils.system('killall netserver', ignore_status=True) cmd = self.server_prog if cpu_affinity: cmd = 'taskset %s %s' % (cpu_affinity, cmd) self.results.append(utils.system_output(cmd, retain_output=True))
def setup(self, tarball = 'ext3-tools.tar.gz'): self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(self.tarball, self.srcdir) os.chdir(self.srcdir) utils.system('patch -p1 < ../fsstress-ltp.patch') utils.system('make fsstress')
def start(self, test): result = utils.system("mount | grep '%s'" % self.mountpoint, ignore_status=True) if result: utils.system('mount -t debugfs debugfs /sys/kernel/debug') device = self.get_device(test) self.blktrace_job = utils.BgJob('%s /dev/%s' % (self.blktrace, device))
def prepare_disks(job, fs_desc, disk1_only=False, disk_list=None): """ Prepare drive(s) to contain the file system type / options given in the description line 'fs_desc'. When 'disk_list' is not None, we prepare all the drives in that list; otherwise we pick the first available data drive (which is usually hdc3) and prepare just that one drive. Args: fs_desc: A partition.FsOptions instance describing the test -OR- a legacy string describing the same in '/' separated format: 'fstype / mkfs opts / mount opts / short name'. disk1_only: Boolean, defaults to False. If True, only test the first disk. disk_list: A list of disks to prepare. If None is given we default to asking get_disk_list(). Returns: (mount path of the first disk, short name of the test, list of disks) OR (None, '', None) if no fs_desc was given. """ # Special case - do nothing if caller passes no description. if not fs_desc: return (None, '', None) if not isinstance(fs_desc, partition.FsOptions): fs_desc = _legacy_str_to_test_flags(fs_desc) # If no disk list was given, we'll get it ourselves if not disk_list: disk_list = get_disk_list() # Make sure we have the appropriate 'mkfs' binary for the file system mkfs_bin = 'mkfs.' + fs_desc.filesystem if fs_desc.filesystem == 'ext4': mkfs_bin = 'mkfs.ext4dev' try: utils.system('which ' + mkfs_bin) except Exception: try: mkfs_bin = os.path.join(job.toolsdir, mkfs_bin) utils.system('cp -ufp %s /sbin' % mkfs_bin) except Exception: raise error.TestError('No mkfs binary available for ' + fs_desc.filesystem) # For 'ext4' we need to add '-E test_fs' to the mkfs options if fs_desc.filesystem == 'ext4': fs_desc.mkfs_flags += ' -E test_fs' # If the caller only needs one drive, grab the first one only if disk1_only: disk_list = disk_list[0:1] # We have all the info we need to format the drives mkfs_all_disks(job, disk_list, fs_desc.filesystem, fs_desc.mkfs_flags, fs_desc.mount_options) # Return(mount path of the first disk, test tag value, disk_list) return (disk_list[0]['mountpt'], fs_desc.fs_tag, disk_list)
def extraversion(self, tag, append=True): os.chdir(self.build_dir) extraversion_sub = r's/^CONFIG_LOCALVERSION=\s*"\(.*\)"/CONFIG_LOCALVERSION=' cfg = self.build_dir + '/.config' if append: p = extraversion_sub + '"\\1-%s"/' % tag else: p = extraversion_sub + '"-%s"/' % tag utils.system('mv %s %s.old' % (cfg, cfg)) utils.system("sed '%s' < %s.old > %s" % (p, cfg, cfg)) self.config(make='oldconfig')
def __del__(self): """ Unmount all cgroups and remove the mountdir """ for i in range(len(self.modules[0])): if self.modules[2][i]: try: utils.system('umount %s -l' % self.modules[1][i]) except Exception, failure_detail: logging.warn("CGM: Couldn't unmount %s directory: %s", self.modules[1][i], failure_detail)
def postprocess_iteration(self): os.chdir(self.resultsdir) utils.system("grep -h elapsed %s >> time" % self.timefile) results = open(self.timefile).read() (user, system, elapsed) = utils.extract_all_time_results(results)[0] self.write_perf_keyval({ 'user': user, 'system': system, 'elapsed': elapsed })
def _kill_qemu_processes(self): """ Kills all qemu processes and all processes holding /dev/kvm down @return: None """ logging.debug("Killing any qemu processes that might be left behind") utils.system("pkill qemu", ignore_status=True) # Let's double check to see if some other process is holding /dev/kvm if os.path.isfile("/dev/kvm"): utils.system("fuser -k /dev/kvm", ignore_status=True)
def remove(self, name): """ Removes package [name]. """ r_cmd = self.base_command + ' ' + 'erase' + ' ' + name try: utils.system(r_cmd) return True except Exception: return False
def setup(self, tarball='ltp-full-20120104.bz2'): tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir) ltpbin_dir = os.path.join(self.srcdir, 'bin') os.mkdir(ltpbin_dir) utils.system('cp ../scan.c pan/') # saves having lex installed utils.configure('--prefix=%s' % ltpbin_dir) utils.make('-j %d all' % utils.count_cpus()) utils.system('yes n | make SKIP_IDCHECK=1 install')
def play_sine(channel, odev='default', freq=1000, duration=10, sample_size=16): """Generates a sine wave and plays to odev. @param channel: 0 for left, 1 for right; otherwize, mono. @param odev: alsa output device. @param freq: frequency of the generated sine tone. @param duration: duration of the generated sine tone. @param sample_size: output audio sample size. Default to 16. """ cmdargs = get_play_sine_args(channel, odev, freq, duration, sample_size) utils.system(' '.join(cmdargs))
def upgrade(self): """ Upgrades all packages of the system. """ u_cmd = self.base_command + ' update -l' try: utils.system(u_cmd) return True except Exception: return False
def run_once(self): """ Set hwclock back to a date in 1980 and verify if the changes took effect in the system. """ logging.info('Setting hwclock to 2/2/80 03:04:00') utils.system('/sbin/hwclock --set --date "2/2/80 03:04:00"') date = utils.system_output('LC_ALL=C /sbin/hwclock') if not re.match('Sat *Feb *2 *03:04:.. 1980', date): raise error.TestFail("Failed to set hwclock back to the eighties. " "Output of hwclock is '%s'" % date)
def run_once(self, memsize="1000000000", args=''): vma_re = re.compile("([0-9,a-f]+)-([0-9,a-f]+)") memory_re = re.compile("(\d+) bytes @(0x[0-9,a-f]+)") vma_max_shift = 0 if os.access("/proc/sys/vm/vma_max_shift", os.R_OK): vma_max_shift = int( open("/proc/sys/vm/vma_max_shift").read().rstrip()) p1 = subprocess.Popen('%s/memory_api ' % self.tmpdir + memsize, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) while p1.poll() is None: output = p1.stdout.readline().rstrip() m = memory_re.search(output) mem_start = 0 mem_len = 0 if m: mem_start = int(m.group(2), 16) mem_len = int(m.group(1)) else: continue map_output = open("/proc/%s/maps_backing" % p1.pid).readlines() vma_count = 0 vma_start = 0 vma_len = 0 expected_vma_count = 1 for line in map_output: m = vma_re.search(line) if m: vma_start = int("0x%s" % m.group(1), 16) vma_end = int("0x%s" % m.group(2), 16) if ((vma_start >= mem_start) and (vma_start < (mem_start + mem_len))): vma_count += 1 if (('file' not in output) and (vma_max_shift != 0)): expected_vma_count = mem_len >> vma_max_shift if (mem_len % (1 << vma_max_shift)): expected_vma_count += 1 if expected_vma_count != vma_count: raise error.TestFail("VmaCountMismatch") logging.info("%s %s %d %d", hex(mem_start), hex(mem_len), vma_count, expected_vma_count) if p1.poll() is None: p1.stdin.write("\n") p1.stdin.flush() if p1.poll() != 0: raise error.TestFail("Unexpected application abort") utils.system('%s/mremaps ' % self.tmpdir + '100000000')
def add_repo(self, url): """ Adds repository [url]. @param url: URL for the package repository. """ ar_cmd = self.base_command + ' addrepo ' + url try: utils.system(ar_cmd) return True except: return False
def _prepare_crasher(self): """Extract the crasher and set its permissions. crasher is only gzipped to subvert Portage stripping. """ self._crasher_path = os.path.join(self.srcdir, 'crasher_nobreakpad') utils.system('cd %s; tar xzf crasher.tgz-unmasked' % self.srcdir) # Make sure all users (specifically chronos) have access to # this directory and its decendents in order to run crasher # executable as different users. utils.system('chmod -R a+rx ' + self.bindir)
def remove(self, name): """ Removes package [name]. @param name: Package name (eg. 'ipython'). """ r_cmd = self.base_command + ' ' + 'erase' + ' ' + name try: utils.system(r_cmd) return True except: return False
def mount_hugepage_fs(self): """ Verify if there's a hugetlbfs mount set. If there's none, will set up a hugetlbfs mount using the class attribute that defines the mount point. """ error.context("mounting hugepages path") if not os.path.ismount(self.hugepage_path): if not os.path.isdir(self.hugepage_path): os.makedirs(self.hugepage_path) cmd = "mount -t hugetlbfs none %s" % self.hugepage_path utils.system(cmd)
def remove_repo(self, url): """ Removes repository [url]. @param url: URL for the package repository. """ rr_cmd = self.base_command + ' removerepo ' + url try: utils.system(rr_cmd) return True except: return False
def setup(self, tarball = 'libhugetlbfs-2.0.tar.gz'): tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir) utils.system('patch -p1 < ../elflink.patch') # make might fail if there are no proper headers for the 32 bit # version, in that case try only for the 64 bit version try: utils.make() except: utils.make('OBJDIRS=obj64')
def _kill_running_sender(self): """Kill the the crash_sender process if running. We use the PID file to find the process ID, then kill it with signal 9. """ if not os.path.exists(self._CRASH_SENDER_RUN_PATH): return running_pid = int(utils.read_file(self._CRASH_SENDER_RUN_PATH)) logging.warning('Detected running crash sender (%d), killing', running_pid) utils.system('kill -9 %d' % running_pid) os.remove(self._CRASH_SENDER_RUN_PATH)
def execute(self, testdir='', args=''): dirs = [] results = [] passed = 0 failed = 0 # spawn vncserver if needed if not os.environ.has_key('DISPLAY'): logging.info( "No DISPLAY set in environment, spawning vncserver...") display = self.__create_vncserver(os.path.expanduser("~/.vnc")) logging.info("Setting DISPLAY=%s" % (display)) os.environ['DISPLAY'] = display # build a list of dirs with 'vm.log' files os.path.walk(testdir, self.__has_vmlog, dirs) for d in dirs: replaydir = os.path.join(self.resultsdir, os.path.basename(d)) os.mkdir(replaydir) logfile = replaydir + "/%s.log" % (os.path.basename(d)) os.chdir(d) rv = utils.system("kvm-test-replay > %s" % (logfile), 1) results.append((d, rv)) if rv != 0: screenshot = self.__get_expected_file(logfile) expected = "expected-%03d.png" % random.randint(0, 999) dest = os.path.join(replaydir, expected) # make a copy of the screen shot utils.system("cp %s %s" % (screenshot, dest), 1) # move the failure utils.system("mv failure-*.png %s" % replaydir, 1) # generate html output self.__format_results(results) # produce pass/fail output for (x, y) in results: if y != 0: logging.error("FAIL: '%s' with rv %s" % (x, y)) failed = failed + 1 else: logging.info("PASS: '******' with rv %s" % (x, y)) passed = passed + 1 logging.info("Summary: Passed %d Failed %d" % (passed, failed)) # if we had any tests not passed, fail entire test if failed != 0: raise error.TestError('kvm-test-replay')
def _dump_udev_attrs(self): """Log udev attributes for selected devices to the debug directory.""" for device in self._input_devices(): devname = os.path.basename(device.device_node) outfile = os.path.join(self.debugdir, "udevattrs.%s" % devname) utils.system('udevadm info --attribute-walk --path=%s > %s' % (device.sys_path, outfile)) outfile = os.path.join(self.debugdir, "udevprops.%s" % devname) utils.system('udevadm info --query=property --path=%s > %s' % (device.sys_path, outfile))
def log_after_each_iteration(self, test, iteration=None): """Logging hook called after a test iteration. @param test: A test object. @param iteration: A test iteration. """ if not iteration: iteration = test.iteration logdir = self._get_iteration_subdir(test, iteration) _run_loggables_ignoring_errors(self.after_iteration_loggables, logdir) utils.system('logger "autotest finished iteration %s"' % logdir, ignore_status=True)
def _build(self): make_jobs = utils.count_cpus() os.chdir(self.srcdir) # For testing purposes, it's better to build qemu binaries with # debugging symbols, so we can extract more meaningful stack traces. cfg = "./configure --prefix=%s" % self.prefix if "--disable-strip" in self.configure_options: cfg += " --disable-strip" steps = [cfg, "make clean", "make -j %s" % make_jobs] logging.info("Building KVM") for step in steps: utils.system(step)
def get_binaries(test, url=None): """Fetch and unpack Ceph binary tarball.""" machine = os.uname()[4] CEPH_TARBALL_DEFAULT_URL = 'http://ceph.newdream.net/gitbuilder/output/ref/origin_master/ceph.{machine}.tgz'.format( machine=machine) if url is None: url = CEPH_TARBALL_DEFAULT_URL tarball = os.path.join(test.tmpdir, 'ceph-bin.tgz') utils.get_file(url, tarball) utils.system('tar xzf {tarball} -C {bindir}'.format(tarball=tarball, bindir=test.bindir)) log.info('Finished unpacking binary tarball in: %s', test.bindir)
def _set_timezone(self, new_zone): if not new_zone: yield return try: utils.system('restart cros-disks TZ=":%s"' % new_zone) self.reconnect_client(self.RECONNECT_TIMEOUT_SECONDS) yield finally: utils.system('restart cros-disks') self.reconnect_client(self.RECONNECT_TIMEOUT_SECONDS)
def run_once(self, args = ''): os.chdir(self.tmpdir) libs = self.autodir+'/deps/libaio/lib/' ld_path = utils.prepend_path(libs, utils.environ('LD_LIBRARY_PATH')) var_ld_path = 'LD_LIBRARY_PATH=' + ld_path cmd = self.srcdir + '/aio-stress ' + args + ' poo' stderr = os.path.join(self.debugdir, 'stderr') utils.system('%s %s 2> %s' % (var_ld_path, cmd, stderr)) report = open(stderr) self.format_results(report)
def __init__(self, logdir, method=sys_power.do_suspend, throw=False, device_times=False): """Prepare environment for suspending.""" self.disconnect_3G_time = 0 self.successes = [] self.failures = [] self._logdir = logdir self._suspend = method self._throw = throw self._reset_pm_print_times = False self._restart_tlsdated = False self._log_file = None if device_times: self.device_times = [] # stop tlsdated, make sure we/hwclock have /dev/rtc for ourselves if utils.system_output('initctl status tlsdated').find('start') != -1: utils.system('initctl stop tlsdated') self._restart_tlsdated = True # give process's file descriptors time to asynchronously tear down time.sleep(0.1) # prime powerd_suspend RTC timestamp saving and make sure hwclock works utils.open_write_close(self.HWCLOCK_FILE, '') hwclock_output = utils.system_output('hwclock -r --debug --utc', ignore_status=True) if not re.search('Using.*/dev interface to.*clock', hwclock_output): raise error.TestError('hwclock cannot find rtc: ' + hwclock_output) # activate device suspend timing debug output if hasattr(self, 'device_times'): if not int(utils.read_one_line('/sys/power/pm_print_times')): self._set_pm_print_times(True) self._reset_pm_print_times = True # Shut down 3G to remove its variability from suspend time measurements flim = flimflam.FlimFlam() service = flim.FindCellularService(0) if service: logging.info('Found 3G interface, disconnecting.') start_time = time.time() (success, status) = flim.DisconnectService(service=service, wait_timeout=60) if success: logging.info('3G disconnected successfully.') self.disconnect_3G_time = time.time() - start_time else: logging.error('Could not disconnect: %s.', status) self.disconnect_3G_time = -1
def install(self, tag='autotest', install_vmlinux=True): self.installed_as = tag self.image = None self.initrd = '' for rpm_pack in self.rpm_package: rpm_name = utils.system_output('rpm -qp ' + rpm_pack) # install utils.system('rpm -i --force ' + rpm_pack) # get file list files = utils.system_output('rpm -ql ' + rpm_name).splitlines() # search for vmlinuz for file in files: if file.startswith('/boot/vmlinuz'): self.full_version = file[len('/boot/vmlinuz-'):] self.image = file self.rpm_flavour = rpm_name.split('-')[1] # get version and release number self.version, self.release = utils.system_output( 'rpm --queryformat="%{VERSION}\\n%{RELEASE}\\n" -q ' + rpm_name).splitlines()[0:2] # prefer /boot/kernel-version before /boot/kernel if self.full_version: break # search for initrd for file in files: if file.startswith('/boot/init'): self.initrd = file # prefer /boot/initrd-version before /boot/initrd if len(file) > len('/boot/initrd'): break if self.image == None: errmsg = "specified rpm file(s) don't contain /boot/vmlinuz" raise error.TestError(errmsg) # install vmlinux if install_vmlinux: for rpm_pack in self.rpm_package: vmlinux = utils.system_output( 'rpm -q -l -p %s | grep /boot/vmlinux' % rpm_pack) utils.system('cd /; rpm2cpio %s | cpio -imuv .%s 2>&1' % (rpm_pack, vmlinux)) if not os.path.exists(vmlinux): raise error.TestError('%s does not exist after installing %s' % (vmlinux, rpm_pack))
def run_once(self, args=[]): """Runs the PyAuto performance tests.""" options, test_args = self.parse_args(args) test_args = ' '.join(test_args) # Enable Chrome testing interface and login to a default account. deps_dir = os.path.join(self.autodir, 'deps') pyautolib_dir = os.path.join(self.cr_source_dir, 'chrome', 'test', 'pyautolib') login_cmd = cros_ui.xcommand_as( 'python %s chromeos_utils.ChromeosUtils.LoginToDefaultAccount ' '-v --no-http-server' % os.path.join(pyautolib_dir, 'chromeos', 'chromeos_utils.py')) utils.system(login_cmd) # Run the PyAuto performance tests. functional_cmd = cros_ui.xcommand_as( '%s/chrome_test/test_src/chrome/test/functional/' 'pyauto_functional.py --suite=CHROMEOS_PERF -v %s' % (deps_dir, test_args)) environment = os.environ.copy() if options.num_iterations: environment['NUM_ITERATIONS'] = str(options.num_iterations) if options.max_timeouts: environment['MAX_TIMEOUT_COUNT'] = str(options.max_timeouts) proc = subprocess.Popen(functional_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=environment) output = proc.communicate()[0] print output # Ensure pyauto test output is stored in autotest logs. # Output perf keyvals for any perf results recorded during the tests. re_compiled = re.compile( '%s(.+)%s' % (self._PERF_MARKER_PRE, self._PERF_MARKER_POST)) perf_lines = [ line for line in output.split('\n') if re_compiled.match(line) ] if perf_lines: perf_dict = dict([ eval(re_compiled.match(line).group(1)) for line in perf_lines ]) self.write_perf_keyval(perf_dict) # Fail the autotest if any pyauto tests failed. This is done after # writing perf keyvals so that any computed results from passing tests # are still graphed. if proc.returncode != 0: raise error.TestFail( 'Unexpected return code from pyauto_functional.py when running ' 'with the CHROMEOS_PERF suite: %d' % proc.returncode)
def kill_pid_file(self, pid_file, missing_ok=False): """Kills the process belonging to |pid_file| in the chroot. @param pid_file string filename within the chroot to gain the process ID which this method will kill. @param missing_ok bool indicating whether a missing pid file is okay, and should be ignored. """ pid = self.get_pid_file(pid_file, missing_ok=missing_ok) if missing_ok and pid == 0: return utils.system('kill %d' % pid, ignore_status=True)
def play_sound(duration_seconds=None, audio_file_path=None): """Plays a sound file found at |audio_file_path| for |duration_seconds|. If |audio_file_path|=None, plays a default audio file. If |duration_seconds|=None, plays audio file in its entirety. @param duration_seconds: Duration to play sound. @param audio_file_path: Path to the audio file. """ if not audio_file_path: audio_file_path = '/usr/local/autotest/cros/audio/sine440.wav' duration_arg = ('-d %d' % duration_seconds) if duration_seconds else '' utils.system('aplay %s %s' % (duration_arg, audio_file_path))
def cleanup(self): # Remove intermediate files for path in self._files_to_delete: utils.system('rm -f %s' % path) if self._storage and os.path.ismount(self._storage['mountpoint']): self.scanner.umount_volume(storage_dict=self._storage) if self._ramdisk_path and os.path.ismount(self._ramdisk_path.name): umount_ramdisk(self._ramdisk_path.name) self._ramdisk_path.clean() super(hardware_MultiReaderPowerConsumption, self).cleanup()