Best Python code snippet using avocado_python
transparent_hugepages.py
Source:transparent_hugepages.py
...44 "mem_size", default=memory.meminfo.MemFree.m)45 self.dd_timeout = self.params.get("dd_timeout", default=900)46 self.thp_split = None47 try:48 memory.read_from_vmstat("thp_split_page")49 self.thp_split = "thp_split_page"50 except IndexError:51 self.thp_split = "thp_split"52 # Set block size as hugepage size * 253 self.block_size = memory.meminfo.Hugepagesize.m * 254 self.count = free_mem // self.block_size55 # Mount device as per free memory size56 if not os.path.exists(self.mem_path):57 os.makedirs(self.mem_path)58 self.device = Partition(device="none", mountpoint=self.mem_path)59 self.device.mount(mountpoint=self.mem_path, fstype="tmpfs",60 args='-o size=%dM' % free_mem, mnt_check=False)61 def test(self):62 '''63 Enables THP , Runs the dd workload and checks whether THP64 has been allocated.65 '''66 # Enables THP67 try:68 memory.set_thp_value("enabled", "always")69 except Exception as details:70 self.fail("Failed %s" % details)71 # Read thp values before stressing the system72 thp_alloted_before = int(memory.read_from_vmstat("thp_fault_alloc"))73 thp_split_before = int(memory.read_from_vmstat(self.thp_split))74 thp_collapse_alloc_before = int(memory.read_from_vmstat75 ("thp_collapse_alloc"))76 # Start Stresssing the System77 self.log.info('Stress testing using dd command')78 for iterator in range(self.count):79 stress_cmd = 'dd if=/dev/zero of=%s/%d bs=%dM count=1'\80 % (self.mem_path, iterator, self.block_size)81 if(process.system(stress_cmd, timeout=self.dd_timeout,82 verbose=False, ignore_status=True, shell=True)):83 self.fail('dd command failed %s' % stress_cmd)84 # Read thp values after stressing the system85 thp_alloted_after = int(memory.read_from_vmstat("thp_fault_alloc"))86 thp_split_after = int(memory.read_from_vmstat(self.thp_split))87 thp_collapse_alloc_after = int(memory.read_from_vmstat88 ("thp_collapse_alloc"))89 # Check whether THP is Used or not90 if thp_alloted_after <= thp_alloted_before:91 e_msg = "Thp usage count has not increased\n"92 e_msg += "Before Stress:%d\nAfter stress:%d" % (thp_alloted_before,93 thp_alloted_after)94 self.fail(e_msg)95 else:96 thp_fault_alloc = thp_alloted_after - thp_alloted_before97 thp_split = thp_split_after - thp_split_before98 thp_collapse_alloc = (thp_collapse_alloc_after -99 thp_collapse_alloc_before)100 self.log.info("\nTest statistics, changes during test run:")...
mlock_basic.py
Source:mlock_basic.py
...50 Start mlock basic test51 """52 error_context.context("Get nr_mlock and nr_unevictable in host"53 " before VM start!", logging.info)54 self.mlock_pre = read_from_vmstat("nr_mlock")55 self.unevictable_pre = read_from_vmstat("nr_unevictable")56 logging.info("mlock_pre is %d and unevictable_pre is %d.",57 self.mlock_pre, self.unevictable_pre)58 self.params["start_vm"] = "yes"59 error_context.context("Starting VM!", logging.info)60 env_process.preprocess_vm(self.test, self.params,61 self.env, self.params["main_vm"])62 self.vm = self.env.get_vm(self.params["main_vm"])63 self.vm.verify_alive()64 error_context.context("Get nr_mlock and nr_unevictable in host"65 " after VM start!", logging.info)66 self.mlock_post = read_from_vmstat("nr_mlock")67 self.unevictable_post = read_from_vmstat("nr_unevictable")68 logging.info("mlock_post is %d and unevictable_post is %d.",69 self.mlock_post, self.unevictable_post)70 self._check_mlock_unevictable()71@error_context.context_aware72def run(test, params, env):73 """74 [Mlock] Basic test, this case will:75 1) Get nr_mlock and nr_unevictable in host before VM start.76 2) Start the VM.77 3) Get nr_mlock and nr_unevictable in host after VM start.78 4) Check nr_mlock and nr_unevictable with VM memory.79 5) Check kernel crash80 :param test: QEMU test object81 :param params: Dictionary with the test parameters...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!