Exemplo n.º 1
0
def test_ust_tracepoint_abi_api_vs_ust_base(tmpdir, ust_label, tools_label, scenario):

    nb_loop = 100
    if scenario != tracing_unavailable:
        nb_expected_events = 200
    else:
        nb_expected_events = 0


    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
        tools_runtime_path
    ) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, "trace")

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_preload_provider_folder, app_path)

        # Make the probe provider in the tools runtime
        runtime_tools.run("make provider", cwd=app_path)

        # Use the ust env to test tracepoint instrumentation
        runtime_app.run("make app", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run("lttng create trace --output={}".format(trace_path))

        runtime_tools.run("lttng enable-event -u tp:tptest,tp:tpenum")
        runtime_tools.run("lttng start")

        # Run application in the tools runtime
        cmd = "./app {}".format(nb_loop)
        runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp.so")

        # Stop tracing
        runtime_tools.run("lttng stop")
        runtime_tools.run("lttng destroy -a")
        runtime_tools.subprocess_terminate(sessiond)

        # Read trace with babeltrace and check for event count via number of line
        cmd = "babeltrace {}".format(trace_path)
        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
        assert utils.line_count(cp_out) == nb_expected_events
Exemplo n.º 2
0
def test_babeltrace_base_modules(tmpdir, babeltrace_l, modules_l, tools_l):
    modules = ProjectFactory.get_precook(modules_l)
    if modules.skip:
        pytest.skip("{} cannot be built on this kernel".format(modules.label))
    tools = ProjectFactory.get_precook(tools_l)
    babeltrace = ProjectFactory.get_precook(babeltrace_l)

    nb_events = 100

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(modules)
        runtime.add_project(tools)
        runtime.add_project(babeltrace)

        sessiond = utils.sessiond_spawn(runtime)
        runtime.load_test_module()

        runtime.run("lttng create trace")
        runtime.run("lttng enable-event -k lttng_test_filter_event")
        runtime.run("lttng start")
        with open(Settings.lttng_test_procfile, 'w') as procfile:
            procfile.write("{}".format(nb_events))

        runtime.run("lttng stop")
        runtime.run("lttng destroy -a")

        sessiond = runtime.subprocess_terminate(sessiond)
        if sessiond.returncode != 0:
            pytest.fail("Return value of sessiond is not zero")
            return

        babeltrace_cmd = 'babeltrace {}'.format(runtime.lttng_home)
        cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
        assert (utils.line_count(cp_out) == nb_events)
Exemplo n.º 3
0
def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, outcome):

    nb_events = 100

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, "trace")

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_app.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run("lttng create trace --output={}".format(trace_path))

        runtime_tools.run("lttng enable-event -u tp:tptest")
        runtime_tools.run("lttng start")

        # Run application
        cmd = "./app {}".format(nb_events)
        runtime_app.run(cmd, cwd=app_path)

        # Stop tracing
        runtime_tools.run("lttng stop")
        runtime_tools.run("lttng destroy -a")
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        cmd = "babeltrace {}".format(trace_path)
        if outcome == "Success":
            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
            assert utils.line_count(cp_out) == nb_events
        else:
            with pytest.raises(subprocess.CalledProcessError):
                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
            if outcome == "Unsupported version":
                assert utils.file_contains(
                    runtime_tools.get_subprocess_stderr_path(sessiond),
                    [event_registration_error],
                )
Exemplo n.º 4
0
def test_consumerd_vs_sessiond(tmpdir, consumerd_l, tools_l, should_work):
    """
    Scenario:
        Point a lttng-tools to a consumerd of another version and see what
        happen. We do not expect anything good to come out of this since for
        now lttng-tools(2.10) no versionning exist between sessiond and
        consumerd.
    """

    nb_event = 100

    consumerd = ProjectFactory.get_precook(consumerd_l)
    tools = ProjectFactory.get_precook(tools_l)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    app_path = os.path.join(str(tmpdir), "app")

    replacement_consumerd = utils.find_file(consumerd.installation_path,
                                            "lttng-consumerd")
    assert replacement_consumerd

    c_dict = {"32bit": "--consumerd32-path", "64bit": "--consumerd64-path"}
    platform_type = platform.architecture()[0]

    sessiond_opt_args = "{}={}".format(c_dict[platform_type],
                                       replacement_consumerd)

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(tools)
        runtime.add_project(babeltrace)

        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime.run("make V=1", cwd=app_path)

        utils.sessiond_spawn(runtime, sessiond_opt_args)

        # Consumer is only called on channel creation
        runtime.run("lttng create")
        try:
            runtime.run("lttng enable-event -u tp:tptest", timeout=5)
            runtime.run("lttng start", timeout=5)

            # Run application
            cmd = "./app {}".format(100)
            runtime.run(cmd, cwd=app_path)

            runtime.run("lttng stop", timeout=5)
            runtime.run("lttng destroy -a", timeout=5)
            cp, cp_out, cp_err = runtime.run("babeltrace {}".format(
                runtime.lttng_home))
            assert utils.line_count(cp_out) == nb_event
        except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
            if should_work:
                raise e
            else:
                # Expecting some error
                return
        if not should_work:
            raise Exception("Supposed to fail")
def test_ust_app_tools_update_tracing_available(tmpdir, ust_label, tools_label,
                                                success):

    nb_events = 100

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_app.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run('lttng create trace --output={}'.format(trace_path))

        runtime_tools.run('lttng enable-event -u tp:tptest')
        runtime_tools.run('lttng start')

        # Run application
        cmd = './app {}'.format(nb_events)
        runtime_tools.run(cmd, cwd=app_path)

        runtime_tools.run("objdump -p ./app", cwd=app_path)
        runtime_app.run("objdump -p ./app", cwd=app_path)

        # Stop tracing
        runtime_tools.run('lttng stop')
        runtime_tools.run('lttng destroy -a')
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        cmd = 'babeltrace {}'.format(trace_path)
        if success:
            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
            assert (utils.line_count(cp_out) == nb_events)
        else:
            with pytest.raises(subprocess.CalledProcessError):
                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
def test_relayd_vs_consumerd_live_base(tmpdir, relayd_label, consumerd_label,
                                       scenario):

    nb_loop = 100
    nb_expected_events = 100

    # Prepare environment
    relayd = ProjectFactory.get_precook(relayd_label)
    consumerd = ProjectFactory.get_precook(consumerd_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    relayd_runtime_path = os.path.join(str(tmpdir), "relayd")
    consumerd_runtime_path = os.path.join(str(tmpdir), "consumerd")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(
            relayd_runtime_path) as runtime_relayd, Run.get_runtime(
                consumerd_runtime_path) as runtime_consumerd:
        runtime_relayd.add_project(relayd)
        runtime_relayd.add_project(babeltrace)
        runtime_consumerd.add_project(consumerd)

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_consumerd.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        relayd = runtime_relayd.spawn_subprocess('lttng-relayd -vvv')
        # FIX: No way to know if good to go...
        time.sleep(1)

        sessiond = utils.sessiond_spawn(runtime_consumerd)

        url = "net://localhost"

        # Create session using mi to get path and session name
        runtime_consumerd.run(
            'lttng create --live --set-url={} trace '.format(url))

        runtime_consumerd.run('lttng enable-event -u tp:tptest')
        runtime_consumerd.run('lttng start')

        # Run application
        cmd = './app {}'.format(nb_loop)
        runtime_consumerd.run(cmd, cwd=app_path)

        # Stop tracing
        runtime_consumerd.run('lttng stop')
        runtime_consumerd.run('lttng destroy -a')
        runtime_consumerd.subprocess_terminate(sessiond)

        # TODO check for error.
        runtime_relayd.subprocess_terminate(relayd)

        # Read trace with babeltrace and check for event count via number of line
        cmd = 'babeltrace {}'.format(runtime_relayd.lttng_home)
        cp_process, cp_out, cp_err = runtime_relayd.run(cmd)
        assert (utils.line_count(cp_out) == nb_expected_events)
Exemplo n.º 7
0
def test_ust_java_agent_tracing_available(tmpdir, ust_label, tools_label,
                                          app_version, should_trace):

    nb_iter = 100
    nb_events = 3 * nb_iter

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, "trace")

        # Make application using the ust runtime
        shutil.copytree(version_to_app[app_version], app_path)
        runtime_app.run("javac App.java", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run("lttng create trace --output={}".format(trace_path))

        runtime_tools.run("lttng enable-event -j jello")
        runtime_tools.run("lttng start")

        # Run application
        cmd = "java App {}".format(nb_iter)
        runtime_app.run(cmd, cwd=app_path)

        # Stop tracing
        runtime_tools.run("lttng stop")
        runtime_tools.run("lttng destroy -a")
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        # Read trace with babeltrace and check for event count via number of line
        cmd = "babeltrace {}".format(trace_path)
        if should_trace:
            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
            assert utils.line_count(cp_out) == nb_events
        else:
            with pytest.raises(subprocess.CalledProcessError):
                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
Exemplo n.º 8
0
def test_modules_starglobing_enabler(tmpdir, modules_label, tools_label, scenario):
    modules = ProjectFactory.get_precook(modules_label)
    if modules.skip:
        pytest.skip("{} cannot be built on this kernel".format(modules.label))
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    nb_events = 100

    if scenario == "Unsupported by modules":
        expected_events = 0
    else:
        expected_events = nb_events

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(modules)
        runtime.add_project(tools)
        runtime.add_project(babeltrace)

        trace_path = os.path.join(runtime.lttng_home, "trace")
        babeltrace_cmd = "babeltrace {}".format(trace_path)

        sessiond = sessiond_spawn(runtime)
        runtime.load_test_module()

        runtime.run("lttng create trace -o {}".format(trace_path))

        if scenario == "Unsupported by tools":
            with pytest.raises(subprocess.CalledProcessError):
                runtime.run("lttng enable-event -k 'lttng_test_*_even*'")
            sessiond = runtime.subprocess_terminate(sessiond)
            if sessiond.returncode != 0:
                pytest.fail("Return value of sessiond is not zero")
            return

        runtime.run("lttng enable-event -k 'lttng_test_*_even*'")
        runtime.run("lttng start")

        # Generate some event
        with open(Settings.lttng_test_procfile, "w") as procfile:
            procfile.write("{}".format(nb_events))

        runtime.run("lttng stop")
        runtime.run("lttng destroy -a")

        sessiond = runtime.subprocess_terminate(sessiond)
        if sessiond.returncode != 0:
            pytest.fail("Return value of sessiond is not zero")

        cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
        assert line_count(cp_out) == expected_events
Exemplo n.º 9
0
def test_babeltrace_same_trace_ust(tmpdir, babeltrace_list, tools_l):
    tools = ProjectFactory.get_precook(tools_l)

    nb_events = 100

    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(tools)

        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime.run("make V=1", cwd=app_path)

        sessiond = utils.sessiond_spawn(runtime)

        # Create session using mi to get path and session name
        runtime.run('lttng create trace')
        runtime.run('lttng enable-event -u tp:tptest')
        runtime.run('lttng start')

        # Run application
        cmd = './app {}'.format(nb_events)
        runtime.run(cmd, cwd=app_path)

        # Stop tracing
        runtime.run('lttng stop')
        runtime.run('lttng destroy -a')
        cp = runtime.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        # Actual testing
        processed_trace_files = {}
        # Gather text traces
        for label in babeltrace_list:
            babeltrace = ProjectFactory.get_precook(label)
            runtime.add_project(babeltrace)
            babeltrace_cmd = 'babeltrace {}'.format(runtime.lttng_home)
            cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
            assert (utils.line_count(cp_out) == nb_events)
            processed_trace_files[label] = cp_out
            runtime.remove_project(babeltrace)

        # Perform combinations and validate that traces match
        for a, b in combinations(processed_trace_files, 2):
            version_a = processed_trace_files[a]
            version_b = processed_trace_files[b]
            assert (filecmp.cmp(
                version_a,
                version_b)), "Processed trace from {} and {} differ.".format(
                    a, b)
Exemplo n.º 10
0
def test_babeltrace_same_trace_modules(tmpdir, babeltrace_list, modules_l,
                                       tools_l):
    modules = ProjectFactory.get_precook(modules_l)
    if modules.skip:
        pytest.skip("{} cannot be built on this kernel".format(modules.label))
    tools = ProjectFactory.get_precook(tools_l)

    nb_events = 100

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(modules)
        runtime.add_project(tools)

        sessiond = utils.sessiond_spawn(runtime)
        runtime.load_test_module()

        runtime.run("lttng create trace")
        runtime.run("lttng enable-event -k lttng_test_filter_event")
        runtime.run("lttng start")
        with open(Settings.lttng_test_procfile, 'w') as procfile:
            procfile.write("{}".format(nb_events))

        runtime.run("lttng stop")
        runtime.run("lttng destroy -a")

        sessiond = runtime.subprocess_terminate(sessiond)
        if sessiond.returncode != 0:
            pytest.fail("Return value of sessiond is not zero")
            return

        # Actual testing
        processed_trace_files = {}
        # Gather text traces
        for label in babeltrace_list:
            babeltrace = ProjectFactory.get_precook(label)
            runtime.add_project(babeltrace)
            babeltrace_cmd = 'babeltrace {}'.format(runtime.lttng_home)
            cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
            assert (utils.line_count(cp_out) == nb_events)
            processed_trace_files[label] = cp_out
            runtime.remove_project(babeltrace)

        # Perform combinations and validate that traces match
        for a, b in combinations(processed_trace_files, 2):
            version_a = processed_trace_files[a]
            version_b = processed_trace_files[b]
            assert (filecmp.cmp(
                version_a,
                version_b)), "Processed trace from {} and {} differ.".format(
                    a, b)
Exemplo n.º 11
0
def test_babeltrace_lost_patcket(tmpdir, babeltrace_l, supported):
    babeltrace = ProjectFactory.get_precook(babeltrace_l)

    trace_path = Settings.trace_lost_packet

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(babeltrace)
        cmd = "babeltrace {}".format(trace_path)
        cp, cp_out, cp_err = runtime.run(cmd)
        if supported:
            assert (utils.file_contains(cp_err, "Tracer lost 3 trace packets"))
            assert (utils.file_contains(cp_err, "Tracer lost 2 trace packets"))
            assert (utils.file_contains(cp_err, "Tracer lost 1 trace packets"))
        else:
            os.path.getsize(cp_err) > 0

        assert (utils.line_count(cp_out) == 8)
Exemplo n.º 12
0
def test_babeltrace_base_ust(tmpdir, babeltrace_l, tools_l):

    nb_events = 100

    # Prepare environment
    babeltrace = ProjectFactory.get_precook(babeltrace_l)
    tools = ProjectFactory.get_precook(tools_l)

    runtime_path = os.path.join(str(tmpdir), "runtime")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(runtime_path) as runtime:
        runtime.add_project(tools)
        runtime.add_project(babeltrace)

        # Make application using the runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime)

        # Create session using mi to get path and session name
        runtime.run('lttng create trace')
        runtime.run('lttng enable-event -u tp:tptest')
        runtime.run('lttng start')

        # Run application
        cmd = './app {}'.format(nb_events)
        runtime.run(cmd, cwd=app_path)

        # Stop tracing
        runtime.run('lttng stop')
        runtime.run('lttng destroy -a')
        cp = runtime.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        # Do not validate the metadata only the return code of babeltrace
        cmd = 'babeltrace -o ctf-metadata {}'.format(runtime.lttng_home)
        runtime.run(cmd)

        cmd = 'babeltrace {}'.format(runtime.lttng_home)
        cp_process, cp_out, cp_err = runtime.run(cmd)
        assert (utils.line_count(cp_out) == nb_events)
Exemplo n.º 13
0
def test_ust_java_agent_interface(tmpdir, ust_label, tools_label, app_version,
                                  outcome):
    """
    Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
    """

    nb_iter = 100
    nb_events = 3 * nb_iter

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, "trace")

        # Make application using the ust runtime
        shutil.copytree(version_to_app[app_version], app_path)
        runtime_app.run("javac App.java", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run("lttng create trace --output={}".format(trace_path))

        runtime_tools.run("lttng enable-event -j jello")
        runtime_tools.run("lttng start")

        # Steal the classpath from ust project
        ust_classpath = ust.special_env_variables["CLASSPATH"]

        # Run application with tools runtime
        cmd = "java App {}".format(nb_iter)
        runtime_tools.run(cmd, cwd=app_path, classpath=ust_classpath)

        # Stop tracing
        runtime_tools.run("lttng stop")
        runtime_tools.run("lttng destroy -a")
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        # Read trace with babeltrace and check for event count via number of line
        cmd = "babeltrace {}".format(trace_path)
        if outcome == "Success":
            assert utils.file_contains(
                runtime_tools.get_subprocess_stderr_path(sessiond),
                [
                    "New registration for pid",
                    "New registration for agent application: pid"
                ],
            )
            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
            assert utils.line_count(cp_out) == nb_events
        else:
            if outcome == "Unsupported protocol":
                assert not (utils.file_contains(
                    runtime_tools.get_subprocess_stderr_path(sessiond),
                    [
                        "New registration for pid",
                        "New registration for agent application: pid"
                    ],
                ))
                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
                assert utils.line_count(cp_out) == 0
def test_ust_tracepoint_probe_abi_api_vs_ust_enum(tmpdir, ust_label,
                                                  tools_label, scenario,
                                                  expected_event):

    nb_loop = 100
    nb_expected_events = expected_event

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_ust, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_ust.add_project(ust)
        runtime_ust.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, "trace")

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_preload_provider_folder, app_path)

        # Make the probe using the ust runtime
        if scenario == fail_provider:
            with pytest.raises(subprocess.CalledProcessError):
                runtime_ust.run("make provider-enum", cwd=app_path)
            return
        else:
            runtime_ust.run("make provider-enum", cwd=app_path)

        # Make the application using the ust runtime
        runtime_ust.run("make app-enum", cwd=app_path)

        # Start lttng-sessiond.
        sessiond = utils.sessiond_spawn(runtime_tools)
        runtime_tools.run("lttng create trace --output={}".format(trace_path))
        runtime_tools.run("lttng enable-event -u tp:tptest,tp:tpenum")
        runtime_tools.run("lttng start")

        # Run application under the tools runtime.
        cmd = "./app-enum {}".format(nb_loop)
        if scenario in fail_so_errors:
            cp_process, cp_out, cp_err = runtime_tools.run(
                cmd,
                cwd=app_path,
                ld_preload="./libtp-enum.so",
                check_return=False)
            assert cp_process.returncode == 127
            assert utils.file_contains(cp_err, [fail_so_errors[scenario]])

            # Nothing else to check.
            return
        else:
            runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp-enum.so")

        # Stop tracing
        runtime_tools.run("lttng stop")
        runtime_tools.run("lttng destroy -a")
        runtime_tools.subprocess_terminate(sessiond)

        # Read trace with babeltrace and check for event count via number of line
        cmd = "babeltrace {}".format(trace_path)
        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
        assert utils.line_count(cp_out) == nb_expected_events
Exemplo n.º 15
0
def test_modules_regen_metadata(tmpdir, modules_label, tools_label, command, scenario):
    modules = ProjectFactory.get_precook(modules_label)
    if modules.skip:
        pytest.skip("{} cannot be built on this kernel".format(modules.label))
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    nb_events = 10

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(modules)
        runtime.add_project(tools)
        runtime.add_project(babeltrace)

        trace_path = os.path.join(runtime.lttng_home, "trace")
        babeltrace_cmd = "babeltrace {}".format(trace_path)

        sessiond = sessiond_spawn(runtime)
        runtime.load_test_module()

        runtime.run("lttng create trace -o {}".format(trace_path))
        runtime.run("lttng enable-event -k lttng_test_filter_event")
        runtime.run("lttng start")
        with open(Settings.lttng_test_procfile, "w") as procfile:
            procfile.write("{}".format(nb_events))

        runtime.run("lttng stop")

        # Validate that we have all event base on the current metadata
        cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
        assert line_count(cp_out) == nb_events

        # Empty the metadata file
        open(get_metadata_file_path(trace_path), "w").close()

        # Babeltrace should never be able to parse the trace
        with pytest.raises(subprocess.CalledProcessError):
            runtime.run(babeltrace_cmd)

        runtime.run("lttng start")

        # TODO: rework this a bit to differentiate each errors and rework how
        # the condition are meet
        if scenario == "Unsupported by tools" or scenario == "Unsupported by modules":
            if (
                modules_label == "lttng-modules-2.7"
                and scenario == "Unsupported by modules"
            ):
                # Error from lttng-modules-2.7 is not reported correctly by
                # sessiond. But it is reported on the sessiond side.
                # For now, run the command, validate that the error exist on
                # sessiond side and mark as xfail.
                runtime.run("lttng {}".format(command))
            else:
                with pytest.raises(subprocess.CalledProcessError):
                    runtime.run("lttng {}".format(command))

            # Make sure everything looks good on this side
            runtime.run("lttng stop")
            runtime.run("lttng destroy -a")
            stderr_path = runtime.get_subprocess_stderr_path(sessiond)
            sessiond = runtime.subprocess_terminate(sessiond)
            if scenario == "Unsupported by modules":
                error_msg = "Error: Failed to regenerate the kernel metadata"
                assert file_contains(stderr_path, [error_msg]), "Error message missing"
            if (
                modules_label == "lttng-modules-2.7"
                and scenario == "Unsupported by modules"
            ):
                pytest.xfail(
                    "Lttng-tools does not bubble up error from unsupported metadata regeneration"
                )

            return

        runtime.run("lttng {}".format(command))
        runtime.run("lttng stop")
        runtime.run("lttng destroy -a")

        sessiond = runtime.subprocess_terminate(sessiond)
        if sessiond.returncode != 0:
            pytest.fail("Return value of sessiond is not zero")

        cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
        assert line_count(cp_out) == nb_events
Exemplo n.º 16
0
def test_ust_python_agent_interface(tmpdir, ust_label, tools_label, outcome):
    """
    Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
    """

    nb_iter = 100
    nb_events = 5 * nb_iter

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_python, app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run('lttng create trace --output={}'.format(trace_path))

        runtime_tools.run('lttng enable-event -p pello')
        runtime_tools.run('lttng start')

        # Steal the PYTHONPATH from ust project and force it on the tools
        # project
        python_path = ust.special_env_variables['PYTHONPATH']
        tools.special_env_variables['PYTHONPATH'] = python_path

        # Run application with tools runtime
        cmd = 'python app.py -i {}'.format(nb_iter)
        runtime_tools.run(cmd, cwd=app_path)

        # Stop tracing
        runtime_tools.run('lttng stop')
        runtime_tools.run('lttng destroy -a')
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        # Read trace with babeltrace and check for event count via number of line
        cmd = 'babeltrace {}'.format(trace_path)
        if outcome == "Success":
            assert (utils.file_contains(
                runtime_tools.get_subprocess_stderr_path(sessiond),
                ["New registration for pid"]))
            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
            assert (utils.line_count(cp_out) == nb_events)
        else:
            if outcome == "Unsupported protocol":
                assert (not (utils.file_contains(
                    runtime_tools.get_subprocess_stderr_path(sessiond),
                    ["New registration for pid"])))
                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
                assert (utils.line_count(cp_out) == 0)
def test_ust_tracepoint_abi_api_vs_ust_enum(tmpdir, ust_label, tools_label,
                                            scenario, expected_event):

    nb_loop = 100
    nb_expected_events = expected_event

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_ust, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_ust.add_project(ust)
        runtime_ust.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_preload_provider_folder, app_path)

        # Use the testing env to make the probe
        if scenario == fail_provider:
            with pytest.raises(subprocess.CalledProcessError):
                runtime_ust.run("make provider-enum", cwd=app_path)
            return
        else:
            runtime_ust.run("make provider-enum", cwd=app_path)

        # Use the ust env to test tracepoint instrumentation
        if scenario == fail_app:
            with pytest.raises(subprocess.CalledProcessError):
                runtime_tools.run("make app-enum", cwd=app_path)
            return
        else:
            runtime_ust.run("make app-enum", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run('lttng create trace --output={}'.format(trace_path))

        runtime_tools.run('lttng enable-event -u tp:tptest,tp:tpenum')
        runtime_tools.run('lttng start')

        # Run application
        cmd = './app-enum {}'.format(nb_loop)
        runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp-enum.so")

        # Stop tracing
        runtime_tools.run('lttng stop')
        runtime_tools.run('lttng destroy -a')
        runtime_tools.subprocess_terminate(sessiond)

        # Read trace with babeltrace and check for event count via number of line
        cmd = 'babeltrace {}'.format(trace_path)
        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
        assert (utils.line_count(cp_out) == nb_expected_events)
Exemplo n.º 18
0
def test_relayd_vs_consumerd_streaming_regenerate_metadata(
        tmpdir, relayd_label, consumerd_label, command, scenario):

    nb_loop = 100
    nb_expected_events = 100

    # Prepare environment
    relayd = ProjectFactory.get_precook(relayd_label)
    consumerd = ProjectFactory.get_precook(consumerd_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    relayd_runtime_path = os.path.join(str(tmpdir), "relayd")
    consumerd_runtime_path = os.path.join(str(tmpdir), "consumerd")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(
            relayd_runtime_path) as runtime_relayd, Run.get_runtime(
                consumerd_runtime_path) as runtime_consumerd:
        runtime_relayd.add_project(relayd)
        runtime_relayd.add_project(babeltrace)
        runtime_consumerd.add_project(consumerd)

        babeltrace_cmd = "babeltrace {}".format(runtime_relayd.lttng_home)

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_consumerd.run("make V=1", cwd=app_path)

        # Start lttng-relayd
        relayd, ctrl_port, data_port, live_port = utils.relayd_spawn(
            runtime_relayd)
        sessiond = utils.sessiond_spawn(runtime_consumerd)

        url = "net://localhost:{}:{}".format(ctrl_port, data_port)

        # Create session using mi to get path and session name
        runtime_consumerd.run("lttng create --set-url={} trace ".format(url))

        runtime_consumerd.run("lttng enable-event -u tp:tptest")
        runtime_consumerd.run("lttng start")

        # Run application
        cmd = "./app {}".format(nb_loop)
        runtime_consumerd.run(cmd, cwd=app_path)

        # Stop tracing
        runtime_consumerd.run("lttng stop")

        # Empty the metadata file
        metadata = utils.find_file(runtime_relayd.lttng_home, "metadata")
        open(metadata, "w").close()

        # Babeltrace should never be able to parse the trace
        with pytest.raises(subprocess.CalledProcessError):
            runtime_relayd.run(babeltrace_cmd)

        runtime_consumerd.run("lttng start")

        # TODO: rework this a bit to differentiate each errors and rework how
        # the condition are meet
        if scenario in ("Unsupported by tools", "Unsupported by relayd"):
            with pytest.raises(subprocess.CalledProcessError):
                runtime_consumerd.run("lttng {}".format(command))

            # Make sure everything looks good on this side
            sessiond = runtime_consumerd.subprocess_terminate(sessiond)
            if sessiond.returncode != 0:
                pytest.fail("Return value of sessiond is not zero")
            relayd = runtime_relayd.subprocess_terminate(relayd)
            if relayd.returncode != 0:
                pytest.fail("Return value of relayd is not zero")
            return

        runtime_consumerd.run("lttng {}".format(command))

        runtime_consumerd.run("lttng stop")
        runtime_consumerd.run("lttng destroy -a")

        # Make sure everything looks good
        sessiond = runtime_consumerd.subprocess_terminate(sessiond)
        if sessiond.returncode != 0:
            pytest.fail("Return value of sessiond is not zero")
        relayd = runtime_relayd.subprocess_terminate(relayd)
        if relayd.returncode != 0:
            pytest.fail("Return value of relayd is not zero")

        # Read trace with babeltrace and check for event count via number of line
        cp_process, cp_out, cp_err = runtime_relayd.run(babeltrace_cmd)
        assert utils.line_count(cp_out) == nb_expected_events
Exemplo n.º 19
0
def test_ust_app_tools_update_tracing_available(tmpdir, ust_label, tools_label,
                                                tracing_available):

    if tracing_available:
        nb_events = 100
    else:
        nb_events = 0

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, "trace")

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_app.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run("lttng create trace --output={}".format(trace_path))

        runtime_tools.run("lttng enable-event -u tp:tptest")
        runtime_tools.run("lttng start")

        runtime_tools.run("objdump -p ./app", cwd=app_path)
        runtime_app.run("objdump -p ./app", cwd=app_path)

        # Run application
        cmd = "./app {}".format(nb_events)
        if tracing_available:
            runtime_tools.run(cmd, cwd=app_path)
        else:
            # The app should not even launch here since the .so for lttng-ust
            # does not match.
            with pytest.raises(subprocess.CalledProcessError):
                runtime_tools.run(cmd, cwd=app_path)
            # Return early, nothing left to do.
            return

        # Stop tracing
        runtime_tools.run("lttng stop")
        runtime_tools.run("lttng destroy -a")
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        cmd = "babeltrace {}".format(trace_path)
        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
        assert utils.line_count(cp_out) == nb_events
Exemplo n.º 20
0
def test_ust_app_starglobing_enabler(tmpdir, ust_label, tools_label, scenario):

    nb_events = 100

    if scenario == "Unsupported by ust":
        expected_events = 0
    else:
        expected_events = nb_events

    # Prepare environment
    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_app.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run('lttng create trace --output={}'.format(trace_path))

        # If unsupported by tools simply finish early
        if scenario == "Unsupported by tools":
            with pytest.raises(subprocess.CalledProcessError):
                runtime_tools.run('lttng enable-event -u "tp:*te*"')

            # TODO move this to internal runtime...
            cp = runtime_tools.subprocess_terminate(sessiond)
            if cp.returncode != 0:
                pytest.fail("Sessiond return code")
            return
        else:
            runtime_tools.run('lttng enable-event -u "tp:*te*"')

        runtime_tools.run('lttng start')

        # Run application
        cmd = './app {}'.format(nb_events)
        runtime_app.run(cmd, cwd=app_path)

        # Stop tracing
        runtime_tools.run('lttng stop')
        runtime_tools.run('lttng destroy -a')
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

            # Read trace with babeltrace and check for event count via number of line
        cmd = 'babeltrace {}'.format(trace_path)
        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
        assert (utils.line_count(cp_out) == expected_events)
Exemplo n.º 21
0
def test_ust_app_regen_statedump(tmpdir, ust_label, tools_label, success):
    nb_events = 100

    if success:
        expected_events = 4
    else:
        expected_events = 2

    ust = ProjectFactory.get_precook(ust_label)
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")
    ust_runtime_path = os.path.join(str(tmpdir), "ust")
    app_path = os.path.join(str(tmpdir), "app")

    app_sync_start = os.path.join(app_path, 'sync_start')
    app_sync_end = os.path.join(app_path, 'sync_end')

    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(
            tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)
        runtime_tools.add_project(babeltrace)

        runtime_app.add_project(ust)
        runtime_app.lttng_home = runtime_tools.lttng_home

        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')

        # Make application using the ust runtime
        shutil.copytree(Settings.apps_gen_events_folder, app_path)
        runtime_app.run("make V=1", cwd=app_path)

        # Start lttng-sessiond
        sessiond = utils.sessiond_spawn(runtime_tools)

        # Create session using mi to get path and session name
        runtime_tools.run('lttng create trace --output={}'.format(trace_path))

        runtime_tools.run(
            'lttng enable-event -u lttng_ust_statedump:start,lttng_ust_statedump:end'
        )
        runtime_tools.run('lttng start')

        # Run application
        cmd = './app {} 0 {} {}'.format(nb_events, app_sync_start,
                                        app_sync_end)
        runtime_app.spawn_subprocess(cmd, cwd=app_path)

        utils.wait_for_file(app_sync_start)

        if not success:
            with pytest.raises(subprocess.CalledProcessError):
                runtime_tools.run('lttng regenerate statedump')
        else:
            runtime_tools.run('lttng regenerate statedump')

        utils.create_empty_file(app_sync_end)

        # Stop tracing
        runtime_tools.run('lttng stop')
        runtime_tools.run('lttng destroy -a')
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")

        # Read trace with babeltrace and check for event count via number of line
        cmd = 'babeltrace {}'.format(trace_path)
        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
        assert (utils.line_count(cp_out) == expected_events)