def test_cpu_memory_usage_counterpoll(duthosts, enum_rand_one_per_hwsku_hostname, setup_thresholds, restore_counter_poll, counterpoll_type, counterpoll_cpu_threshold):
    'Check DUT memory usage and process cpu usage are within threshold.\n    Disable all counterpoll types except tested one\n    Collect memory and CPUs usage for 60 secs\n    Compare the memory usage with the memory threshold\n    Compare the average cpu usage with the cpu threshold for the specified progress\n    Restore counterpolls status\n    '
    duthost = duthosts[enum_rand_one_per_hwsku_hostname]
    program_to_check = get_manufacturer_program_to_check(duthost)
    if (program_to_check is None):
        pytest.skip('Skip no program is offered to check')
    (memory_threshold, _, _) = setup_thresholds
    counterpoll_cpu_usage_threshold = counterpoll_cpu_threshold[counterpoll_type]
    MonitResult = namedtuple('MonitResult', ['processes', 'memory'])
    disable_all_counterpoll_type_except_tested(duthost, counterpoll_type)
    monit_results = duthost.monit_process(iterations=60, delay_interval=1)['monit_results']
    poll_interval = (CounterpollConstants.COUNTERPOLL_INTERVAL[counterpoll_type] // 1000)
    outstanding_mem_polls = {}
    outstanding_procs = {}
    outstanding_procs_counter = Counter()
    cpu_usage_program_to_check = []
    prepare_ram_cpu_usage_results(MonitResult, counterpoll_cpu_usage_threshold, memory_threshold, monit_results, outstanding_mem_polls, outstanding_procs, outstanding_procs_counter, program_to_check, cpu_usage_program_to_check)
    log_cpu_usage_by_vendor(cpu_usage_program_to_check, counterpoll_type)
    cpu_usage_average = caculate_cpu_usge_average_value(extract_valid_cpu_usage_data(cpu_usage_program_to_check, poll_interval), cpu_usage_program_to_check)
    logging.info('Average cpu_usage is {}'.format(cpu_usage_average))
    assert (cpu_usage_average < counterpoll_cpu_usage_threshold), 'cpu_usage_average of {} exceeds the cpu threshold:{}'.format(program_to_check, counterpoll_cpu_usage_threshold)
    assert (not outstanding_mem_polls), ' Memory {} exceeds the memory threshold {} '.format(outstanding_mem_polls, memory_threshold)
Check DUT memory usage and process cpu usage are within threshold.
Disable all counterpoll types except tested one
Collect memory and CPUs usage for 60 secs
Compare the memory usage with the memory threshold
Compare the average cpu usage with the cpu threshold for the specified progress
Restore counterpolls status
def test_cpu_memory_usage_counterpoll(duthosts, enum_rand_one_per_hwsku_hostname, setup_thresholds, restore_counter_poll, counterpoll_type, counterpoll_cpu_threshold):
    'Check DUT memory usage and process cpu usage are within threshold.\n    Disable all counterpoll types except tested one\n    Collect memory and CPUs usage for 60 secs\n    Compare the memory usage with the memory threshold\n    Compare the average cpu usage with the cpu threshold for the specified progress\n    Restore counterpolls status\n    '
    duthost = duthosts[enum_rand_one_per_hwsku_hostname]
    program_to_check = get_manufacturer_program_to_check(duthost)
    if (program_to_check is None):
        pytest.skip('Skip no program is offered to check')
    (memory_threshold, _, _) = setup_thresholds
    counterpoll_cpu_usage_threshold = counterpoll_cpu_threshold[counterpoll_type]
    MonitResult = namedtuple('MonitResult', ['processes', 'memory'])
    disable_all_counterpoll_type_except_tested(duthost, counterpoll_type)
    monit_results = duthost.monit_process(iterations=60, delay_interval=1)['monit_results']
    poll_interval = (CounterpollConstants.COUNTERPOLL_INTERVAL[counterpoll_type] // 1000)
    outstanding_mem_polls = {}
    outstanding_procs = {}
    outstanding_procs_counter = Counter()
    cpu_usage_program_to_check = []
    prepare_ram_cpu_usage_results(MonitResult, counterpoll_cpu_usage_threshold, memory_threshold, monit_results, outstanding_mem_polls, outstanding_procs, outstanding_procs_counter, program_to_check, cpu_usage_program_to_check)
    log_cpu_usage_by_vendor(cpu_usage_program_to_check, counterpoll_type)
    cpu_usage_average = caculate_cpu_usge_average_value(extract_valid_cpu_usage_data(cpu_usage_program_to_check, poll_interval), cpu_usage_program_to_check)
    logging.info('Average cpu_usage is {}'.format(cpu_usage_average))
    assert (cpu_usage_average < counterpoll_cpu_usage_threshold), 'cpu_usage_average of {} exceeds the cpu threshold:{}'.format(program_to_check, counterpoll_cpu_usage_threshold)
    assert (not outstanding_mem_polls), ' Memory {} exceeds the memory threshold {} '.format(outstanding_mem_polls, memory_threshold)