Best Python code snippet using avocado_python
hugepage_reset.py
Source:hugepage_reset.py
...51 hp_config = test_setup.HugePageConfig(params)52 hp_config.target_hugepages = origin_nr53 logging.info('Setup hugepage number to %s', origin_nr)54 hp_config.setup()55 hugepage_size = utils_memory.get_huge_page_size()56 params['start_vm'] = "yes"57 vm_name = params['main_vm']58 env_process.preprocess_vm(test, params, env, vm_name)59 vm = env.get_vm(vm_name)60 params['stress_args'] = '--vm %s --vm-bytes 256M --timeout 30s' % (61 mem // 512)62 logging.info('Loading stress on guest.')63 stress = utils_test.VMStress(vm, 'stress', params)64 stress.load_stress_tool()65 time.sleep(30)66 stress.unload_stress()67 set_hugepage()68 hp_config.cleanup()69 vm.verify_kernel_crash()
thp-usage.py
Source:thp-usage.py
...17 cmdline = open(p.joinpath('cmdline'), 'r').read().replace('\0', ' ').strip()18 yield pid, huge_kb, cmdline19 except OSError as e:20 print(e, file=sys.stderr)21def get_huge_page_size():22 re_huge_page_size = re.compile(rb'Hugepagesize:\s*(\d+)\s*kB\s*')23 for line in open('/proc/meminfo', 'rb'):24 if m := re_huge_page_size.match(line):25 return int(m[1])26 raise RuntimeError('/proc/meminfo: no Hugepagesize line.')27def main():28 row_fmt = '{:>7}\t{:>8}\t{:>12}\t{}'.format29 n_fmt = '{:,d}'.format30 print(row_fmt('pid', 'pages', 'MB', 'cmdline'))31 hps_kb = get_huge_page_size()32 total_huge_kb = 033 for pid, huge_kb, cmdline in sorted(find_thp_users(), reverse=True, key=lambda u: u[1]):34 total_huge_kb += huge_kb35 print(row_fmt(pid, n_fmt(huge_kb // hps_kb), n_fmt(huge_kb // 1024), cmdline))36 print(row_fmt(0, n_fmt(total_huge_kb // hps_kb), n_fmt(total_huge_kb // 1024), '<total>'))37if __name__ == "__main__":38 main()39# Local Variables:40# python-indent-offset: 441# tab-width: 442# indent-tabs-mode: nil43# coding: utf-8...
allocpages.py
Source:allocpages.py
...18 previous_allocation = get_num_huge_pages()19 logging.debug("Try to set '%s' huge pages."20 " Expected size: '%s'. Actual size: '%s'." %21 (number_of_huge_pages, expected_size,22 get_huge_page_size()))23 virsh.allocpages(expected_size, number_of_huge_pages,24 ignore_status=False)25 actual_allocation = get_num_huge_pages()26 if str(actual_allocation) != str(number_of_huge_pages):27 test.fail("Huge page allocation failed."28 " Expected '%s', got '%s'." %29 (number_of_huge_pages, actual_allocation))30 finally:31 if previous_allocation:32 logging.debug("Restore huge page allocation")...
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!!