2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 package org.lttng.ust.agent.integration.events;
21 import static org.junit.Assert.assertEquals;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runners.Parameterized.Parameters;
33 import org.lttng.tools.ILttngSession;
36 * Base class testing the "lttng list" command when using loggers organized as a
39 * For example, if a "org.myapp" logger exists and has a LTTng handler attached,
40 * a "org.myapp.mycomponent" logger should show up in "lttng list", even if
41 * itself does not have a handler, because its parent's handler can catch the
42 * log events as UST tracepoints.
44 * @author Alexandre Montplaisir
46 public abstract class LoggerHierachyListITBase {
48 protected static final String PARENT_LOGGER = "org.lttng";
49 protected static final String CHILD_LOGGER = "org.lttng.mycomponent";
51 protected final boolean parentLoggerActive;
52 protected final boolean parentLoggerHasHandler;
53 protected final boolean childLoggerActive;
54 protected final boolean childLoggerHasHandler;
56 private ILttngSession session;
58 // ------------------------------------------------------------------------
59 // Test parameter definition
60 // ------------------------------------------------------------------------
63 * Generator for the test parameters.
65 * Generates all possible combinations of the 4 constructor parameters,
66 * except "parentActive" is necessarily true when "hasHandler" is true for a
69 * @return The test parameters
71 @Parameters(name = "{index}: parentActive={0}, parentHasHandler={1}, childActive={2}, childHasHandler={3}")
72 public static Iterable<Object[]> testCases() {
74 * Kept the whole array for clarity, but some cases are commented out:
75 * it is impossible to attach an handler if the logger itself is not
78 return Arrays.asList(new Object[][] {
79 { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE },
80 { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE },
81 // { Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE },
82 { Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE },
84 { Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE },
85 { Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE },
86 // { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE },
87 { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE },
89 // { Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE },
90 // { Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE },
91 // { Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE },
92 // { Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE },
94 { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE },
95 { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE },
96 // { Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE },
97 { Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE },
104 * @param parentLoggerActive
105 * Parent logger has been instantiated
106 * @param parentLoggerHasHandler
107 * Parent logger has a LTTng handler attached to it
108 * @param childLoggerActive
109 * Child logger has been instantiated
110 * @param childLoggerHasHandler
111 * Child logger has a LTTng handler attached to it
113 public LoggerHierachyListITBase(boolean parentLoggerActive,
114 boolean parentLoggerHasHandler,
115 boolean childLoggerActive,
116 boolean childLoggerHasHandler) {
117 this.parentLoggerActive = parentLoggerActive;
118 this.parentLoggerHasHandler = parentLoggerHasHandler;
119 this.childLoggerActive = childLoggerActive;
120 this.childLoggerHasHandler = childLoggerHasHandler;
123 protected ILttngSession getSession() {
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
135 public void testSetup() {
136 session = ILttngSession.createSession(null, getDomain());
140 * Common test teardown
143 public void testTeardown() {
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
151 protected abstract ILttngSession.Domain getDomain();
153 protected abstract void activateLoggers() throws IOException;
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
160 * Test the output of the "lttng list" command.
162 * @throws IOException
166 public void testList() throws IOException {
169 List<String> enabledEvents = session.listEvents();
170 List<String> expectedEvents = new ArrayList<>();
172 /* Reminder: "hasHandler" implies "isActive" */
174 if (parentLoggerHasHandler) {
175 expectedEvents.add(PARENT_LOGGER);
177 if (childLoggerHasHandler ||
178 (childLoggerActive && parentLoggerHasHandler)) {
179 expectedEvents.add(CHILD_LOGGER);
182 Collections.sort(enabledEvents);
183 Collections.sort(expectedEvents);
184 assertEquals(expectedEvents, enabledEvents);