TracingArgumentsTest and TracingArgumentsParserTest updated correspondingly.
TracingArgumentsTest.isValid_ExclusiveOpts test removed as unrelevant anymore.
Change-Id: Iaa03813be3cee772564738b6925333272f42c910
private String device; // device serial number or IP address
private String application; // application name
private Template template; // analysis template
- private File customTemplate; // file with custom template configuration
private File output; // file with tracing output
// TODO duration actually is not supported yet by CLI, always set to 0
private long durationSec; // tracing duration in seconds (0 is for unlimited duration)
}
// Templates check
- if (template == null && customTemplate == null) {
+ if (template == null || template == Template.TEMPLATE_CUSTOM) {
result = false;
- msg += " * Template is not specified%n";
- } else if (template != null && customTemplate != null) {
- result = false;
- msg += " * Custom template is specified along with standard template%n";
- } else if (template != null && template == Template.TEMPLATE_CUSTOM) {
- result = false;
- msg += " * Standard template specified as custom%n";
+ msg += " * Proper template is not specified%n";
}
errMessage = result ? "" : String.format(msg).trim();
}
/**
- * @return the custom template file
- */
- public File getCustomTemplate() {
- return customTemplate;
- }
-
- /**
- * @param customTemplate the custom template file to set
- * @return this object to allow chained methods execution
- */
- public TracingArguments setCustomTemplate(File customTemplate) {
- this.customTemplate = customTemplate;
- return this;
- }
-
- /**
* @return the duration in seconds
*/
public long getDuration() {
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.tizen.dynamicanalyzer.setting.Template;
private static Option template = Option.builder("t")
.hasArg()
.argName("template")
+ .required()
.desc("tracing template")
.build();
.desc("redirect tracing output to file")
.build();
- private static Option customTemplate = Option.builder("c")
- .hasArg()
- .argName("template file")
- .desc("custom tracing template file")
- .build();
-
- // Mutually exclusive options
- private static OptionGroup templateGroup = new OptionGroup()
- .addOption(template)
- .addOption(customTemplate);
-
private static Options opts = new Options();
static {
- // One of template options is required
- templateGroup.setRequired(true);
opts.addOption(application)
// TODO duration option is not supported yet
// .addOption(duration)
.addOption(output)
- .addOptionGroup(templateGroup);
+ .addOption(template);
}
/**
result.setApplication(cmdline.getOptionValue(application.getOpt()));
// Get template or custom template file
- if (cmdline.hasOption(template.getOpt())) {
- String tempString = cmdline.getOptionValue(template.getOpt());
- result.setTemplate(Template.getTemplate(tempString));
- } else {
- String tempString = cmdline.getOptionValue(customTemplate.getOpt());
- result.setCustomTemplate(new File(tempString));
- }
+ String tempString = cmdline.getOptionValue(template.getOpt());
+ result.setTemplate(Template.getTemplate(tempString));
// Get duration
if (cmdline.hasOption(duration.getOpt())) {
result.add('-' + application.getOpt());
result.add(app);
- // Template or Custom Template
+ // Template
Template temp = args.getTemplate();
- File customTemp = args.getCustomTemplate();
- if (temp != null) {
- result.add('-' + template.getOpt());
- result.add(temp.getName());
- } else {
- result.add('-' + customTemplate.getOpt());
- result.add(customTemp.getAbsolutePath());
- }
+ result.add('-' + template.getOpt());
+ result.add(temp.getName());
// Duration
long dur = args.getDuration();
templateOpt, template.getName() });
assertNotNull(result);
assertTrue(result.isValid());
- assertNull(result.getCustomTemplate());
assertNull(result.getOutput());
assertEquals(0, result.getDuration());
}
}
@Test
- public void toStringArray_ExclusiveOpts() {
- TracingArguments args = new TracingArguments()
- .setDevice(device)
- .setApplication(application)
- .setTemplate(template)
- .setCustomTemplate(customTemplate);
- String[] result = TracingArgumentsParser.toStringArray(args);
- assertNull(result);
- }
-
- @Test
public void toStringArray_AllOpts() {
TracingArguments args = new TracingArguments()
.setDevice(device)
private final static String device = "device";
private final static String application = "application";
private final static Template template = Template.TEMPLATE_BOTTLENECK;
- private final static File customTemplate = new File("template.tpt");
private final static File output = new File("output.out");
@Before
}
@Test
- public void isValid_ExclusiveOpts() {
- TracingArguments args = new TracingArguments()
- .setDevice(device)
- .setApplication(application)
- .setTemplate(template)
- .setCustomTemplate(customTemplate);
- assertFalse(args.isValid());
- }
-
- @Test
public void isValid_AllOpts() {
TracingArguments args = new TracingArguments()
.setDevice(device)