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_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_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())