| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2014 École Polytechnique de Montréal |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Mathieu Rail - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.tracecompass.tmf.tests.stubs.analysis; |
| 14 | |
| 15 | import java.util.HashMap; |
| 16 | import java.util.Map; |
| 17 | |
| 18 | import org.eclipse.core.runtime.IProgressMonitor; |
| 19 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule; |
| 20 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement; |
| 21 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel; |
| 22 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; |
| 23 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
| 24 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; |
| 25 | |
| 26 | /** |
| 27 | * Analysis type to test requirements acquisition |
| 28 | */ |
| 29 | @SuppressWarnings({ "javadoc", "nls" }) |
| 30 | public class TestRequirementAnalysis extends TmfAbstractAnalysisModule { |
| 31 | /* Test requirement types */ |
| 32 | public static final String EVENT_TYPE = "event"; |
| 33 | public static final String FIELD_TYPE = "field"; |
| 34 | |
| 35 | /* A few event names */ |
| 36 | public static final String EXIT_SYSCALL = "exit_syscall"; |
| 37 | public static final String SCHED_SWITCH = "sched_switch"; |
| 38 | public static final String SCHED_WAKEUP = "sched_wakeup"; |
| 39 | |
| 40 | /* A few fields */ |
| 41 | public static final String PID = "pid"; |
| 42 | public static final String TID = "tid"; |
| 43 | |
| 44 | @Override |
| 45 | public boolean canExecute(ITmfTrace trace) { |
| 46 | /* This just makes sure the trace is a ctf stub trace */ |
| 47 | return (TmfTraceStub.class.isAssignableFrom(trace.getClass())); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void canceling() { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected boolean executeAnalysis(final IProgressMonitor monitor) { |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean setTrace(ITmfTrace trace) throws TmfAnalysisException { |
| 62 | return super.setTrace(trace); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() { |
| 67 | Map<String, TmfAnalysisRequirement> requirements = new HashMap<>(); |
| 68 | |
| 69 | /* Event type requirement and values */ |
| 70 | TmfAnalysisRequirement eventReqs = new TmfAnalysisRequirement(EVENT_TYPE); |
| 71 | eventReqs.addValue(EXIT_SYSCALL, ValuePriorityLevel.MANDATORY); |
| 72 | eventReqs.addValue(SCHED_SWITCH, ValuePriorityLevel.MANDATORY); |
| 73 | eventReqs.addValue(SCHED_WAKEUP, ValuePriorityLevel.MANDATORY); |
| 74 | requirements.put(EVENT_TYPE, eventReqs); |
| 75 | |
| 76 | /* Field type requirement and values */ |
| 77 | TmfAnalysisRequirement fieldReqs = new TmfAnalysisRequirement(FIELD_TYPE); |
| 78 | fieldReqs.addValue(PID, ValuePriorityLevel.MANDATORY); |
| 79 | fieldReqs.addValue(TID, ValuePriorityLevel.MANDATORY); |
| 80 | requirements.put(FIELD_TYPE, fieldReqs); |
| 81 | |
| 82 | return requirements.values(); |
| 83 | } |
| 84 | } |