Example #1
0
    def __cgexec_infinite_loop(config, controller, cgname, sleep_time=1):
        cmd = [
            "/usr/bin/perl", "-e",
            "'while(1){{sleep({})}};'".format(sleep_time)
        ]

        try:
            Cgroup.cgexec(config, controller, cgname, cmd)
        except RunError:
            # When this process is killed, it will throw a run error.
            # Ignore it.
            pass
def test(config):
    config.process.create_process_in_cgroup(config,
                                            CONTROLLER,
                                            CGNAME,
                                            cgclassify=False)

    pids = Cgroup.get_pids_in_cgroup(config, CGNAME, CONTROLLER)
    if pids is None:
        result = consts.TEST_FAILED
        cause = 'No processes were found in cgroup {}'.format(CGNAME)
        return result, cause

    # run cgexec -h
    ret = Cgroup.cgexec(config,
                        controller=CONTROLLER,
                        cgname=CGNAME,
                        cmdline=None,
                        cghelp=True)
    if 'Run the task in given control group(s)' not in ret:
        result = consts.TEST_FAILED
        cause = 'Failed to print cgexec help text: {}'.format(ret)
        return result, cause

    return consts.TEST_PASSED, None