Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Feature Model Analysis

v1.1.2-alpha-11

groupID
at.tugraz.ist.ase
artifactID
fma

Table of Contents

  1. Introduction
  2. How tos
    1. Simple usage
    2. Usage of FMAnalyzer’s run method
    3. Usage of a specific analysis builder and explanation
    4. Monitoring the progress of analysis
    5. Implementing your new analysis operation

Introduction

TBD

How tos

Simple usage

The following example shows a simple usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
File fileFM = new File("src/test/resources/basic_featureide_multiple1.xml");

// 1. Create the factory for anomaly feature models
IFeatureBuildable featureBuilder = new AnomalyAwareFeatureBuilder();
FMParserFactory<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    factory = FMParserFactory.getInstance(featureBuilder);

// 2. Create the parser
@Cleanup("dispose")
FeatureModelParser<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    parser = factory.getParser(fileFM.getName());

// 3. Parse the feature model
FeatureModel<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    featureModel = parser.parse(fileFM);

// 4. Create an analyzer
FMAnalyzer analyzer = new FMAnalyzer(featureModel);

// 5. Select analysis operations to be performed
EnumSet<AnomalyType> options = EnumSet.of(AnomalyType.DEAD,
                                        AnomalyType.FULLMANDATORY,
                                        AnomalyType.REDUNDANT);

// 6. Generate VoidFMAnalysis, DeadFeatureAnalysis, FullMandatoryAnalysis, and RedundancyAnalysis
// And Run the analyzer
// (true - trigger the corresponding explanator if the assumption is violated)
analyzer.generateAndRun(options, true);

// 7. Print the result
AutomatedAnalysisExplanation explanation = new AutomatedAnalysisExplanation();
System.out.println(explanation.getDescriptiveExplanation(analyzer.getAnalyses(), options));
// generated explanations depends on options
// in this case where options don't include VOID, the VoidFMAnalysis' results won't be printed

If you want to perform all built-in analyses, you can replace the statement in Step 5 by the following statement:

1
EnumSet<AnomalyType> options = EnumSet.allOf(AnomalyType.class);

Example

testMultiple_1

Usage of FMAnalyzer’s run method

Use run method if you read test cases from a file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
File fileFM = new File("src/test/resources/basic_featureide_multiple1.xml");

// 1. Create the factory for anomaly feature models
IFeatureBuildable featureBuilder = new AnomalyAwareFeatureBuilder();
FMParserFactory<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    factory = FMParserFactory.getInstance(featureBuilder);

// 2. Create the parser
@Cleanup("dispose")
FeatureModelParser<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    parser = factory.getParser(fileFM.getName());
// 3. Parse the feature model
FeatureModel<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    featureModel = parser.parse(fileFM);

// 4. Create an analyzer
FMAnalyzer analyzer = new FMAnalyzer(featureModel);

// 5. Read test cases from a file and add to analyzer
EnumSet<AnomalyType> options = EnumSet.allOf(AnomalyType.class);

// read pre-generated test cases from a file
XMLAssumptionAwareTestSuiteReader reader = new XMLAssumptionAwareTestSuiteReader(featureModel);
XMLAssumptionAwareTestCaseBuilder builder = new XMLAssumptionAwareTestCaseBuilder(featureModel);
@Cleanup
InputStream is = getInputStream(FMAnalyzerTest.class.getClassLoader(), "testsuite_multiple1.xml");
TestSuite testSuite = reader.read(is, builder);
// generates analyses and add them to the analyzer
AutomatedAnalysisBuilder analysisBuilder = new AutomatedAnalysisBuilder();
analysisBuilder.build(featureModel, testSuite, analyzer);

// 6. Run the analyzer
// (true - trigger the corresponding explanator if the assumption is violated)
// execute the VoidFMAnalysis first if there is any
analyzer.run(true);

// 8. Print the result
EnumSet<AnomalyType> options = EnumSet.allOf(AnomalyType.class);
AutomatedAnalysisExplanation explanation = new AutomatedAnalysisExplanation();
System.out.println(explanation.getDescriptiveExplanation(analyzer.getAnalyses(), options));

AutomatedAnalysisBuilder and AutomatedAnalysisExplanation are utility classes that provides useful and shortcut ways to build built-in analyses and explanations.

Example

testMultiple_0

Usage of a specific analysis builder and explanation

You can also use directly specific builder and explanation classes to build and explain analyses. The following example shows how to analysis dead features by using DeadFeatureAnalysisBuilder and CompactExplanation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
File fileFM = new File("src/test/resources/bamboobike_featureide_deadfeature1.xml");

// 1. Create the factory for anomaly feature models
IFeatureBuildable featureBuilder = new AnomalyAwareFeatureBuilder();
FMParserFactory<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    factory = FMParserFactory.getInstance(featureBuilder);

// 2. Create the parser
@Cleanup("dispose")
FeatureModelParser<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    parser = factory.getParser(fileFM.getName());
// 3. Parse the feature model
FeatureModel<AnomalyAwareFeature, AbstractRelationship<AnomalyAwareFeature>, CTConstraint>
    featureModel = parser.parse(fileFM);

// 4. Create an analyzer
FMAnalyzer analyzer = new FMAnalyzer(featureModel);

// (omitted) 5. Select analysis operations to be performed

// 6. Generates analyses and add them to the analyzer (USING DeadFeatureAnalysisBuilder)
DeadFeatureAnalysisBuilder deadFeatureAnalysisBuilder = new DeadFeatureAnalysisBuilder();
deadFeatureAnalysisBuilder.build(featureModel, analyzer);

// 7. Run the analyzer
// (true - trigger the corresponding explanator if the assumption is violated)
analyzer.run(true);

// 8. Print the result (USING CompactExplanation)
CompactExplanation explanation = new CompactExplanation();
System.out.println(explanation.getDescriptiveExplanation(analyzer.getAnalyses(), DeadFeatureAnalysis.class, AnomalyType.DEAD));

CompactExplanation provides explanations for four analyses, including DeadFeatureAnalysis, FalseOptionalAnalysis, FullMandatoryAnalysis, and ConditionallyDeadAnalysis.

Example

testDeadFeature_0

Monitoring the progress of analysis

Before executing the analyzer, you can register a listener to monitor the progress of analysis.

1
2
3
analyzer.setMonitor(new ProgressMonitor()); // MONITOR
// 7. Run the analyzer
analyzer.run(true);

ProgressMonitor as default will print the progress of analysis to the console. By conforming the interface IAnalysisMonitor, you can direct the output of analysis to other streams.

Example

testLargeModel_2

Implementing your new analysis operation

  1. Create a new enum type that conforms the interface IAnomalyType. Ex: AnomalyType.
  2. Create a new “Assumptions” class that conforms the class IFMAnalysisAssumptionCreatable. Assumptions classes are used to generate test cases for the analysis operation. Ex: DeadFeatureAssumptions.
  3. Create a new “Analysis” class that extends the class AbstractFMAnalysis. Analysis classes are used to perform the analysis operation. Ex: DeadFeatureAnalysis.
  4. Create a new “Explanator” class that extends the class AbstractAnomalyExplanator. Explanator classes identify diagnoses for violated assumptions. Ex: DeadFeatureExplanator.
  5. Create a new “Builder” class that conforms the class IAnalysisBuildable. Builder classes generate analyses. Ex: DeadFeatureAnalysisBuilder.
  6. Create a new “Explanation” class conforming the class IAnalysisExplanation. Explanation classes take charge in generating explanations for the analysis results. Ex: CompactExplanation.