| 1 | # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
| 2 | # |
| 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | # of this software and associated documentation files (the "Software"), to deal |
| 5 | # in the Software without restriction, including without limitation the rights |
| 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | # copies of the Software, and to permit persons to whom the Software is |
| 8 | # furnished to do so, subject to the following conditions: |
| 9 | # |
| 10 | # The above copyright notice and this permission notice shall be included in all |
| 11 | # copies or substantial portions of the Software. |
| 12 | # |
| 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | # SOFTWARE. |
| 20 | |
| 21 | import pytest |
| 22 | import subprocess |
| 23 | import platform |
| 24 | import shutil |
| 25 | import os |
| 26 | |
| 27 | import lttng_ivc.utils.ProjectFactory as ProjectFactory |
| 28 | import lttng_ivc.utils.utils as utils |
| 29 | import lttng_ivc.utils.runtime as Run |
| 30 | import lttng_ivc.settings as Settings |
| 31 | |
| 32 | """ |
| 33 | FC: Fully Compatible |
| 34 | I: Incompatible |
| 35 | |
| 36 | +------------------------------------------------------------------------------+ |
| 37 | | LTTng consumer daemon vs LTTng session daemon | |
| 38 | +--------------------------+------------+------------+------------+------------+ |
| 39 | | Consumerd/Sessiond | 2.7 | 2.8 | 2.9 | 2.10 | |
| 40 | +--------------------------+------------+------------+------------+------------+ |
| 41 | | 2.7 | FC | I | I | I | |
| 42 | | 2.8 | I | FC | I | I | |
| 43 | | 2.9 | I | I | FC | I | |
| 44 | | 2.10 | I | I | I | FC | |
| 45 | +--------------------------+------------+------------+------------+------------+ |
| 46 | |
| 47 | """ |
| 48 | |
| 49 | test_matrix_consumerd = [ |
| 50 | ("lttng-tools-2.7", "lttng-tools-2.7", True), |
| 51 | ("lttng-tools-2.7", "lttng-tools-2.8", False), |
| 52 | ("lttng-tools-2.7", "lttng-tools-2.9", False), |
| 53 | ("lttng-tools-2.7", "lttng-tools-2.10", False), |
| 54 | ("lttng-tools-2.8", "lttng-tools-2.7", False), |
| 55 | ("lttng-tools-2.8", "lttng-tools-2.8", True), |
| 56 | ("lttng-tools-2.8", "lttng-tools-2.9", True), |
| 57 | ("lttng-tools-2.8", "lttng-tools-2.10", False), |
| 58 | ("lttng-tools-2.9", "lttng-tools-2.7", False), |
| 59 | ("lttng-tools-2.9", "lttng-tools-2.8", True), |
| 60 | ("lttng-tools-2.9", "lttng-tools-2.9", True), |
| 61 | ("lttng-tools-2.9", "lttng-tools-2.10", False), |
| 62 | ("lttng-tools-2.10", "lttng-tools-2.7", False), |
| 63 | ("lttng-tools-2.10", "lttng-tools-2.8", False), |
| 64 | ("lttng-tools-2.10", "lttng-tools-2.9", False), |
| 65 | ("lttng-tools-2.10", "lttng-tools-2.10", True), |
| 66 | ] |
| 67 | |
| 68 | runtime_matrix_consumerd = [] |
| 69 | |
| 70 | if not Settings.test_only: |
| 71 | runtime_matrix_consumerd = test_matrix_consumerd |
| 72 | else: |
| 73 | for tup in test_matrix_consumerd: |
| 74 | if (tup[0] in Settings.test_only or tup[1] in |
| 75 | Settings.test_only): |
| 76 | runtime_matrix_consumerd.append(tup) |
| 77 | |
| 78 | |
| 79 | @pytest.mark.parametrize("consumerd_l,tools_l,should_work", runtime_matrix_consumerd) |
| 80 | def test_consumerd_vs_sessiond(tmpdir, consumerd_l, tools_l, should_work): |
| 81 | """ |
| 82 | Scenario: |
| 83 | Point a lttng-tools to a consumerd of another version and see what |
| 84 | happen. We do not expect anything good to come out of this since for |
| 85 | now lttng-tools(2.10) no versioning exist between sessiond and |
| 86 | consumerd. |
| 87 | """ |
| 88 | |
| 89 | nb_event = 100; |
| 90 | |
| 91 | consumerd = ProjectFactory.get_precook(consumerd_l) |
| 92 | tools = ProjectFactory.get_precook(tools_l) |
| 93 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 94 | |
| 95 | app_path = os.path.join(str(tmpdir), "app") |
| 96 | |
| 97 | replacement_consumerd = utils.find_file(consumerd.installation_path, "lttng-consumerd") |
| 98 | assert(replacement_consumerd) |
| 99 | |
| 100 | c_dict = {"32bit": "--consumerd32-path", "64bit": "--consumerd64-path"} |
| 101 | platform_type = platform.architecture()[0] |
| 102 | |
| 103 | sessiond_opt_args = "{}={}".format(c_dict[platform_type], replacement_consumerd) |
| 104 | |
| 105 | with Run.get_runtime(str(tmpdir)) as runtime: |
| 106 | runtime.add_project(tools) |
| 107 | runtime.add_project(babeltrace) |
| 108 | |
| 109 | shutil.copytree(Settings.apps_gen_events_folder, app_path) |
| 110 | runtime.run("make V=1", cwd=app_path) |
| 111 | |
| 112 | utils.sessiond_spawn(runtime, sessiond_opt_args) |
| 113 | |
| 114 | # Consumer is only called on channel creation |
| 115 | runtime.run("lttng create") |
| 116 | try: |
| 117 | runtime.run("lttng enable-event -u tp:tptest", timeout=5) |
| 118 | runtime.run("lttng start", timeout=5) |
| 119 | |
| 120 | # Run application |
| 121 | cmd = './app {}'.format(100) |
| 122 | runtime.run(cmd, cwd=app_path) |
| 123 | |
| 124 | runtime.run("lttng stop", timeout=5) |
| 125 | runtime.run("lttng destroy -a", timeout=5) |
| 126 | cp, cp_out, cp_err = runtime.run("babeltrace {}".format(runtime.lttng_home)) |
| 127 | assert(utils.line_count(cp_out) == nb_event) |
| 128 | except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e: |
| 129 | if should_work: |
| 130 | raise e |
| 131 | else: |
| 132 | # Expecting some error |
| 133 | return |
| 134 | if not should_work: |
| 135 | raise Exception("Supposed to fail") |