Exemple #1
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],
                )
Exemple #2
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)
def test_tools_liblttng_ctl_vs_sessiond_basic_listing(tmpdir, client_label,
                                                      tools_label, outcome):

    # Prepare environment
    client = ProjectFactory.get_precook(client_label)
    tools = ProjectFactory.get_precook(tools_label)

    tools_runtime_path = os.path.join(str(tmpdir), "tools")

    lttng_client = os.path.join(client.installation_path, "bin/lttng")

    with Run.get_runtime(tools_runtime_path) as runtime_tools:
        runtime_tools.add_project(tools)

        sessiond = utils.sessiond_spawn(runtime_tools)

        cp, out, err = runtime_tools.run(
            "{} create trace".format(lttng_client),
            check_return=False,
            ld_debug=True)
        if outcome == "Missing symbol":
            assert cp.returncode != 0
            assert utils.file_contains(err, "Missing symbol")
            return
        if outcome == "Deprecated":
            assert cp.returncode == 38
            return

        assert cp.returncode == 0

        runtime_tools.run("{} enable-event -u tp:tptest".format(lttng_client))
        runtime_tools.run("{} start".format(lttng_client))

        # Stop tracing
        runtime_tools.run("{} stop".format(lttng_client))
        runtime_tools.run("{} destroy -a".format(lttng_client))
        cp = runtime_tools.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond return code")
Exemple #4
0
def test_save_load_app_contexts(tmpdir, tools_save_l, tools_load_l,
                                should_load):

    # Prepare environment
    t_save = ProjectFactory.get_precook(tools_save_l)
    t_load = ProjectFactory.get_precook(tools_load_l)

    t_save_runtime_path = os.path.join(str(tmpdir), "tools-save")
    t_load_runtime_path = os.path.join(str(tmpdir), "tools-load")
    save_load_path = os.path.join(str(tmpdir), 'save_load')
    validation_path = os.path.join(str(tmpdir), 'validation')

    trace_name = "saved_trace"
    trace_filename = trace_name + Settings.save_ext
    trace_file_path = os.path.join(save_load_path, trace_filename)

    validation_file_path = os.path.join(validation_path, trace_filename)

    # Craft the save
    with Run.get_runtime(t_save_runtime_path) as runtime:
        runtime.add_project(t_save)

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

        runtime.run("lttng create {}".format(trace_name))
        runtime.run("lttng enable-event --jul hello")
        runtime.run("lttng enable-event --log4j hello")
        # NOTE:  For now there is a bug/quirk for which app context is applied
        # everywhere. Might need to be revisited. This influence the number of
        # node we expect in the saved file.
        runtime.run("lttng add-context --jul --type='$app.myRetriever:intCtx'")
        runtime.run("lttng save --output-path={}".format(save_load_path))

        cp = runtime.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond on save return code")

    validate_app_context(trace_name, trace_file_path)

    # Load the save
    with Run.get_runtime(t_load_runtime_path) as runtime:
        runtime.add_project(t_load)

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

        cmd = "lttng load --input-path={} {}".format(save_load_path,
                                                     trace_name)

        if not should_load:
            cp, out, err = runtime.run(cmd, check_return=False)
            assert (cp.returncode != 0)
            assert (utils.file_contains(
                err, ['Session configuration file validation failed']))
            return

        runtime.run(cmd)

        # Since lttng list does not include context we need to re-save and
        # validate that the contexts are presend in the newly saved file.
        runtime.run("lttng save --output-path={}".format(validation_path))

        cp = runtime.subprocess_terminate(sessiond)
        if cp.returncode != 0:
            pytest.fail("Sessiond on load return code")

    validate_app_context(trace_name, validation_file_path)
Exemple #5
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
Exemple #6
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_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
def test_ust_tracepoint_probe_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_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 in the ust runtime
        runtime_ust.run("make provider", cwd=app_path)

        # Use the ust env to test tracepoint instrumentation
        runtime_ust.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 in the tools runtime application
        cmd = "./app {}".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.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.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