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") # 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) cp_process, cp_out, cp_err = runtime_tools.run(cmd) assert utils.line_count(cp_out) == nb_events
def test_relayd_vs_consumerd_streaming_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 --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)
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)
def test_ust_tracepoint_probe_abi_api_vs_ust_base(tmpdir, ust_label, tools_label, scenario): nb_loop = 100 nb_expected_events = 200 # 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 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 application 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)
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)
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_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)
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
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)
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_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)
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")
def test_output_path_snapshot_relayd_add_output(tmpdir, client, server, mode, state): """ Test of output path for relayd snapshot output created with 'lttng snapshot add-output'. """ nb_loop = 10 datetime_re = "[0-9]{8}-[0-9]{6}" snapshot_re = "snapshot-1-{}-0".format(datetime_re) trailing = "{}/ust/{}".format(snapshot_re, mode) hostname = socket.gethostname() Output_test = namedtuple("Output_test", ["name", "command", "path_regex"]) # Prepare environment lttng_tools = ProjectFactory.get_precook(client) relay = ProjectFactory.get_precook(server) 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") shutil.copytree(Settings.apps_gen_events_folder, app_path) tools_runtime_path = os.path.join(str(tmpdir), "client") relayd_runtime_path = os.path.join(str(tmpdir), "relayd") app_path = os.path.join(str(tmpdir), "app") with Run.get_runtime(tools_runtime_path) as rt_tools, Run.get_runtime( relayd_runtime_path) as rt_relayd: rt_tools.add_project(lttng_tools) rt_relayd.add_project(relay) # Make application using the runtime rt_tools.run("make V=1", cwd=app_path) sessiond = utils.sessiond_spawn(rt_tools) relayd, ctrl_port, data_port, live_port = utils.relayd_spawn(rt_relayd) base_path = "{}/{}/{}".format(rt_relayd.lttng_home, "lttng-traces", hostname) path_with_session_name_tests = [ Output_test( "test", "net://127.0.0.1:{}:{}".format(ctrl_port, data_port), "{}/test-{}/{}".format(base_path, datetime_re, trailing), ), Output_test( "test1", "net://127.0.0.1:{}:{}/".format(ctrl_port, data_port), "{}/test1-{}/{}".format(base_path, datetime_re, trailing), ), Output_test( "test-20190319-120000", "net://127.0.0.1:{}:{}".format(ctrl_port, data_port), "{}/test-20190319-120000-{}/{}".format(base_path, datetime_re, trailing), ), Output_test( "test4", "--ctrl-url=tcp4://127.0.0.1:{} --data-url=tcp4://127.0.0.1:{}" .format(ctrl_port, data_port), "{}/test4-{}/{}".format(base_path, datetime_re, trailing), ), Output_test( "test6", "--ctrl-url=tcp4://127.0.0.1:{} --data-url=tcp4://127.0.0.1:{}/custom_output3" .format(ctrl_port, data_port), "{}/test6-{}/{}".format(base_path, datetime_re, trailing), ), ] custom_output_tests = [ Output_test( "test3", "net://127.0.0.1:{}:{}/custom_output".format( ctrl_port, data_port), "{}/custom_output/{}".format(base_path, trailing), ), Output_test( "test5", "--ctrl-url=tcp4://127.0.0.1:{}/custom_output2 --data-url=tcp4://127.0.0.1:{}" .format(ctrl_port, data_port), "{}/custom_output2/{}".format(base_path, trailing), ), Output_test( "test7", "--ctrl-url=tcp4://127.0.0.1:{}/custom_output4 --data-url=tcp4://127.0.0.1:{}/custom_output4" .format(ctrl_port, data_port), "{}/custom_output4/{}".format(base_path, trailing), ), ] tests = custom_output_tests if state != "buggy_client": tests += path_with_session_name_tests # Create session using mi to get path and session name failed_tests = [] for test in tests: rt_tools.run("lttng create {} --snapshot --no-output".format( test.name)) rt_tools.run( "lttng enable-channel -u --buffers-{} channel".format(mode)) rt_tools.run("lttng enable-event -u tp:tptest -c channel") rt_tools.run( "lttng snapshot add-output --name snapshot-1 {}".format( test.command)) rt_tools.run("lttng start") # Run application asynchronously since per-pid and snapshot mode # need the application alive at snapshot time. It does not matter # in per-uid buffering mode. cmd = "./app {} 0 {} {}".format(nb_loop, app_sync_start, app_sync_end) app_id = rt_tools.spawn_subprocess(cmd, cwd=app_path) utils.wait_for_file(app_sync_start) rt_tools.run("lttng snapshot record") utils.create_empty_file(app_sync_end) rt_tools.run("lttng stop") rt_tools.run("lttng destroy -a") rt_tools.subprocess_terminate(app_id) if not utils.path_exists_regex(base_path, test.path_regex): failed_tests.append(test) os.remove(app_sync_start) os.remove(app_sync_end) rt_tools.subprocess_terminate(sessiond) rt_relayd.subprocess_terminate(relayd) if failed_tests: s = StringIO() utils.tree(base_path, s) pytest.fail(pformat(failed_tests) + "\n" + s.getvalue())
def test_ust_tracepoint_abi_api_vs_ust_enum(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") # Copy app source files shutil.copytree(Settings.apps_preload_provider_folder, app_path) # Use the testing tool runtime to make the probe if scenario == fail_provider: with pytest.raises(subprocess.CalledProcessError): runtime_tools.run("make provider-enum", cwd=app_path) return else: runtime_tools.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_app.run("make app-enum", cwd=app_path) return else: runtime_app.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("ldd ./libtp-enum.so", cwd=app_path) runtime_tools.run("ldd ./app-enum", cwd=app_path) runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp-enum.so", ld_debug=True) # 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
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)
def test_save_load_timer_interval(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') trace_name = "saved_trace" channel_name = "my_channel" trace_filename = trace_name + Settings.save_ext trace_file_path = os.path.join(save_load_path, trace_filename) monitor_timer_interval = 1000 # 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-channel -u --monitor-timer={} {}".format( monitor_timer_interval, channel_name)) runtime.run("lttng save --output-path={}".format(save_load_path)) assert (os.path.isfile(trace_file_path)) cp = runtime.subprocess_terminate(sessiond) if cp.returncode != 0: pytest.fail("Sessiond on save return code") assert (os.path.isfile(trace_file_path)) xpath_monitor_interval = '/sessions/session/domains/domain[type="UST"]/channels/channel/monitor_timer_interval' node = xpath_query(trace_file_path, xpath_monitor_interval) assert (len(node) == 1) assert (node[0].text == str(monitor_timer_interval)) # 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) if should_load: runtime.run("lttng load --input-path={} {}".format( save_load_path, trace_name)) else: with pytest.raises(subprocess.CalledProcessError): runtime.run("lttng load --input-path={} {}".format( save_load_path, trace_name)) cp = runtime.subprocess_terminate(sessiond) if cp.returncode != 0: pytest.fail("Sessiond on load return code") return cp, mi_out, err = runtime.run( "lttng --mi xml list {}".format(trace_name)) cp = runtime.subprocess_terminate(sessiond) if cp.returncode != 0: pytest.fail("Sessiond on load return code") assert (os.path.isfile(mi_out)) xpath_mi = '/command/output/sessions/session/domains/domain/channels/channel/attributes/monitor_timer_interval' node = xpath_query(mi_out, xpath_mi) assert (len(node) == 1) assert (node[0].text == str(monitor_timer_interval))
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)
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_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_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 runtime_app.run("ldd ./app", cwd=app_path) 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], )
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
def test_output_path_snapshot_local_add_output(tmpdir, version, mode): """ Test of output path for local snapshot output created with 'lttng snapshot add-output'. """ nb_loop = 10 datetime_re = "[0-9]{8}-[0-9]{6}" snapshot_re = "snapshot-1-{}-0".format(datetime_re) trailing = "{}/ust/{}".format(snapshot_re, mode) Output_test = namedtuple("Output_test", ["name", "command", "path_regex"]) # Prepare environment lttng_tools = ProjectFactory.get_precook(version) 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") shutil.copytree(Settings.apps_gen_events_folder, app_path) with Run.get_runtime(tmpdir) as runtime: base_path = runtime.lttng_home tests = [ Output_test( "test1", "--ctrl-url=file://{}/custom_output".format(str(base_path)) + " --data-url=''", "{}/custom_output/{}".format(str(base_path), trailing), ), Output_test( "test2", "file://{}/custom_output2".format(str(base_path)), "{}/custom_output2/{}".format(str(base_path), trailing), ), ] runtime.add_project(lttng_tools) # Make application using the runtime runtime.run("make V=1", cwd=app_path) sessiond = utils.sessiond_spawn(runtime) # Create session using mi to get path and session name failed_tests = [] for test in tests: runtime.run("lttng create {} --snapshot --no-output".format( test.name)) runtime.run( "lttng enable-channel -u --buffers-{} channel".format(mode)) runtime.run("lttng enable-event -u tp:tptest -c channel") runtime.run( "lttng snapshot add-output --name snapshot-1 {}".format( test.command)) runtime.run("lttng start") # Run application asynchronously since per-pid and snapshot mode # need the application alive at snapshot time. It does not matter # in per-uid buffering mode. cmd = "./app {} 0 {} {}".format(nb_loop, app_sync_start, app_sync_end) app_id = runtime.spawn_subprocess(cmd, cwd=app_path) utils.wait_for_file(app_sync_start) runtime.run("lttng snapshot record") utils.create_empty_file(app_sync_end) runtime.run("lttng stop") runtime.run("lttng destroy -a") runtime.subprocess_terminate(app_id) if not utils.path_exists_regex(base_path, test.path_regex): failed_tests.append(test) os.remove(app_sync_start) os.remove(app_sync_end) runtime.subprocess_terminate(sessiond) if failed_tests: s = StringIO() utils.tree(base_path, s) pytest.fail(pformat(failed_tests) + "\n" + s.getvalue())
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
def test_output_path_relayd(tmpdir, client, server, mode): nb_loop = 10 datetime_regex = "[0-9]{8}-[0-9]{6}" trailing = "ust/{}".format(mode) hostname = socket.gethostname() Output_test = namedtuple("Output_test", ["name", "command", "path_regex"]) # Prepare environment lttng_tools = ProjectFactory.get_precook(client) relay = ProjectFactory.get_precook(server) tools_runtime_path = os.path.join(str(tmpdir), "client") relayd_runtime_path = os.path.join(str(tmpdir), "relayd") app_path = os.path.join(str(tmpdir), "app") shutil.copytree(Settings.apps_gen_events_folder, app_path) with Run.get_runtime(tools_runtime_path) as rt_tools, Run.get_runtime( relayd_runtime_path) as rt_relayd: rt_tools.add_project(lttng_tools) rt_relayd.add_project(relay) # Make application using the lttng_tools runtime rt_tools.run("make V=1", cwd=app_path) sessiond = utils.sessiond_spawn(rt_tools) relayd, ctrl_port, data_port, live_port = utils.relayd_spawn(rt_relayd) base_path = "{}/{}/{}".format(rt_relayd.lttng_home, "lttng-traces", hostname) tests = [ Output_test( "", "--set-url=net://127.0.0.1:{}:{}".format(ctrl_port, data_port), "{}/auto-{}/{}".format(base_path, datetime_regex, trailing), ), Output_test( "test", "--set-url=net://127.0.0.1:{}:{}".format(ctrl_port, data_port), "{}/test-{}/{}".format(base_path, datetime_regex, trailing), ), Output_test( "test1", "--set-url=net://127.0.0.1:{}:{}/".format( ctrl_port, data_port), "{}/test1-{}/{}".format(base_path, datetime_regex, trailing), ), Output_test( "test-20190319-120000", "--set-url=net://127.0.0.1:{}:{}".format(ctrl_port, data_port), "{}/test-20190319-120000-{}/{}".format(base_path, datetime_regex, trailing), ), Output_test( "test3", "--set-url=net://127.0.0.1:{}:{}/custom_output".format( ctrl_port, data_port), "{}/custom_output/{}".format(base_path, trailing), ), Output_test( "test4", "--ctrl-url=tcp4://127.0.0.1:{} --data-url=tcp4://127.0.0.1:{}" .format(ctrl_port, data_port), "{}/test4-{}/{}".format(base_path, datetime_regex, trailing), ), Output_test( "test5", "--ctrl-url=tcp4://127.0.0.1:{}/custom_output2 --data-url=tcp4://127.0.0.1:{}" .format(ctrl_port, data_port), "{}/custom_output2/{}".format(base_path, trailing), ), Output_test( "test6", "--ctrl-url=tcp4://127.0.0.1:{} --data-url=tcp4://127.0.0.1:{}/custom_output3" .format(ctrl_port, data_port), "{}/test6-{}/{}".format(base_path, datetime_regex, trailing), ), ] failed_tests = [] for test in tests: rt_tools.run("lttng create {} {}".format(test.name, test.command)) rt_tools.run( "lttng enable-channel -u --buffers-{} channel".format(mode)) rt_tools.run("lttng enable-event -u tp:tptest -c channel") rt_tools.run("lttng start") cmd = "./app {}".format(nb_loop) rt_tools.run(cmd, cwd=app_path) rt_tools.run("lttng stop") rt_tools.run("lttng destroy -a") if not utils.path_exists_regex(base_path, test.path_regex): failed_tests.append(test) rt_tools.subprocess_terminate(sessiond) rt_relayd.subprocess_terminate(relayd) if failed_tests: s = StringIO() utils.tree(base_path, s) pytest.fail(pformat(failed_tests) + "\n" + s.getvalue())
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)
def test_output_path_local(tmpdir, version, mode): nb_loop = 10 datetime_regex = "[0-9]{8}-[0-9]{6}" trailing = "ust/{}".format(mode) Output_test = namedtuple("Output_test", ["name", "command", "path_regex"]) # Prepare environment lttng_tools = ProjectFactory.get_precook(version) app_path = os.path.join(str(tmpdir), "app") with Run.get_runtime(tmpdir) as runtime: base_path = runtime.lttng_home tests = [ Output_test( "", "", "{}/lttng-traces/auto-{}/{}".format(str(base_path), datetime_regex, trailing), ), Output_test( "test", "", "{}/lttng-traces/test-{}/{}".format(str(base_path), datetime_regex, trailing), ), Output_test( "test-20190319-120000", "", "{}/lttng-traces/test-20190319-120000-{}/{}".format( str(base_path), datetime_regex, trailing), ), Output_test( "test1", "--output='{}/custom_output'".format(str(base_path)), "{}/custom_output/{}".format(str(base_path), trailing), ), Output_test( "test2", "--set-url=file://{}/custom_output2".format(str(base_path)), "{}/custom_output2/{}".format(str(base_path), trailing), ), ] runtime.add_project(lttng_tools) # Make application using the runtime 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 failed_tests = [] for test in tests: runtime.run("lttng create {} {}".format(test.name, test.command)) runtime.run( "lttng enable-channel -u --buffers-{} channel".format(mode)) runtime.run("lttng enable-event -u tp:tptest -c channel") runtime.run("lttng start") cmd = "./app {}".format(nb_loop) runtime.run(cmd, cwd=app_path) runtime.run("lttng stop") runtime.run("lttng destroy -a") if not utils.path_exists_regex(base_path, test.path_regex): failed_tests.append(test) runtime.subprocess_terminate(sessiond) if failed_tests: s = StringIO() utils.tree(base_path, s) pytest.fail(pformat(failed_tests) + "\n" + s.getvalue())
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