Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
233963f
Feat: Implementing Unit Tests for DFD part of the analysis, still wor…
01Parzival10 Jan 20, 2025
825ef74
Fix: One class not saved
01Parzival10 Jan 20, 2025
cfafd3d
Feat: Moving Utility to Util class. WIP
01Parzival10 Jan 27, 2025
7fb8d47
Feat: Create proper Unit test classes, remove duplicate functionality
01Parzival10 Jan 27, 2025
535bec4
Doc: Add Java Doc for tests and util classes
01Parzival10 Jan 28, 2025
7ee9d56
Merge pull request #231 from DataFlowAnalysis/dsl-serialization
Nicolas-Boltz Feb 4, 2025
ca1527d
feat(pcm): add tests for characteristics and data flow variables
Entenwilli Nov 9, 2024
3a7fa90
test: add baseline model integration testing framework
Entenwilli Nov 26, 2024
4d0419d
test(examplemodels): clean up example models structure
Entenwilli Nov 26, 2024
8dbc904
test(integration): remove dependency on unique ids
Entenwilli Jan 13, 2025
b49176d
feat(core): remove unique identifiers from vertices
Entenwilli Jan 13, 2025
e367b42
chore: merge upstream changes
Entenwilli Jan 13, 2025
b82683c
test(core): implement unit tests for transpose flow graph
Entenwilli Jan 20, 2025
45b7fc5
test(core): add unit tests for abstract vertex
Entenwilli Jan 20, 2025
e868e8c
test(core): implement the integration testing framework from the exam…
Entenwilli Mar 30, 2025
25a3fec
refactor(dfd): refactor code after rebase
Entenwilli Mar 30, 2025
70a04b3
fix(dsl): fix wrong results with data characteristics selector
Entenwilli Apr 15, 2025
1c1211d
feat(pcm): add support for NOT in assignments
Entenwilli Apr 15, 2025
1aad77b
feat(tests): update testmodels from testmodel PR in example models
Entenwilli Apr 15, 2025
c3f7a11
refactor(tests): update tests after refactoring into packages
Entenwilli Apr 15, 2025
b185a31
test(unit): add unit test for PCM data characteristics calculator
Entenwilli Apr 28, 2025
9848142
fix(pcm): prevent references to blank variables in StoEx; Fix node ch…
Entenwilli Apr 28, 2025
756090d
refactor(dsl): parse source selectors in the container class instead …
Entenwilli Apr 29, 2025
5656ecb
fix(dsl): fix missing walk back when parsing vertex selector
Entenwilli Apr 29, 2025
4debab9
test(dsl): ensure that selectors are parsed fully and return the same…
Entenwilli Apr 29, 2025
9640176
test(dsl): add test for parsing both or either types of source selectors
Entenwilli Apr 29, 2025
e0e5ada
test(dsl): fix incorrect assertion for data selectors
Entenwilli Apr 29, 2025
225b1d7
fix(dsl): reorder parsing of data characteristics to ensure that list…
Entenwilli Apr 29, 2025
ca33c64
fix(dsl): ensure all elements are present in characteristic list sele…
Entenwilli Apr 29, 2025
efbba49
test(pcm): test vertex characteristics calculator
Entenwilli Apr 29, 2025
18e4750
fix(dfd): fix issues introduced by rebasing incorrect changes to simp…
Entenwilli May 2, 2025
8f36996
test(demo): fix paths according to refactor of example models
Entenwilli May 2, 2025
eeae88d
style(tree-wide): remove unused imports
Entenwilli May 6, 2025
bd7e46b
docs(tests): add documentation for DummyResourceProvider
Entenwilli May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public String getValueId() {
public Label getLabel() {
return this.label;
}

@Override
public String toString() {
return String.format("%s.%s", this.getTypeName(), this.getValueName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private List<CharacteristicValue> getCharacteristicValuesForPin(Pin pin, Map<Pin

/**
* Combines all Incoming Labels from relevant input pins
* @param assignment Assignment to determine relevant input pins
* @param abstractAssignment Assignment to determine relevant input pins
* @param inputPinsIncomingLabelMap Maps all input pins to all incoming labels
* @return List of relevant labels
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dataflowanalysis.analysis.dfd.simple;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import org.dataflowanalysis.analysis.core.AbstractTransposeFlowGraph;
Expand All @@ -27,7 +26,6 @@ public DFDSimpleTransposeFlowGraph(AbstractVertex<?> sink) {
@Override
public AbstractTransposeFlowGraph evaluate() {
DFDSimpleVertex newSink = ((DFDSimpleVertex) sink).copy(new IdentityHashMap<>());
newSink.unify(new HashSet<>());
newSink.evaluateDataFlow();
return new DFDSimpleTransposeFlowGraph(newSink);
}
Expand All @@ -39,7 +37,6 @@ public AbstractTransposeFlowGraph copy() {

public AbstractTransposeFlowGraph copy(Map<DFDSimpleVertex, DFDSimpleVertex> mapping) {
DFDSimpleVertex copiedSink = ((DFDSimpleVertex) sink).copy(mapping);
copiedSink.unify(new HashSet<>());
return new DFDSimpleTransposeFlowGraph(copiedSink);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public List<? extends AbstractTransposeFlowGraph> findTransposeFlowGraphs(List<?

for (Node endNode : getEndNodes(dataFlowDiagram.getNodes())) {
DFDSimpleVertex sink = determineSinks(endNode);
sink.unify(new HashSet<>());
transposeFlowGraphs.add(new DFDSimpleTransposeFlowGraph(sink));
}
return transposeFlowGraphs;
Expand Down Expand Up @@ -132,6 +131,9 @@ private boolean verifySimplicity(Node node) {
.anyMatch(it -> ((Assignment) it).getInputPins()
.equals(node.getBehavior()
.getInPin()))
|| node.getBehavior()
.getInPin()
.size() == 0
|| node.getBehavior()
.getOutPin()
.size() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -61,16 +61,13 @@ public void evaluateDataFlow() {
if (super.isEvaluated()) {
return;
}

previousVertices.forEach(it -> it.evaluateDataFlow());
previousVertices.forEach(DFDSimpleVertex::evaluateDataFlow);

List<CharacteristicValue> vertexCharacteristics = determineNodeCharacteristics();

List<DataCharacteristic> incomingCharacteristics = previousVertices.stream()
.map(it -> it.getAllOutgoingDataCharacteristics())
.flatMap(List::stream)
.collect(Collectors.toList());

List<DataCharacteristic> incomingCharacteristics = previousVertices.stream().map(AbstractVertex::getAllOutgoingDataCharacteristics).flatMap(List::stream).collect(Collectors.toList());

Map<Pin, Set<Label>> outgoingLabelPerPin = new HashMap<>();
referencedElement.getBehavior()
.getAssignment()
Expand All @@ -95,7 +92,7 @@ private List<CharacteristicValue> determineNodeCharacteristics() {

/**
* Calculates outgoing labels for assignment and adds them into mapOutputPinToOutgoingLabels
* @param assignment Assignment to be evaluated
* @param abstractAssignment Assignment to be evaluated
* @param incomingDataCharacteristics incoming characteristics as list
* @param outgoingLabelPerPin Maps Output Pins to Outgoing Labels, to be filled by method
*/
Expand Down Expand Up @@ -129,10 +126,10 @@ private void handleOutgoingAssignments(AbstractAssignment abstractAssignment, Li
.collect(Collectors.toSet());

var outPin = abstractAssignment.getOutputPin();
if (outPin == null)
if (outPin == null) {
return;
if (outgoingLabelPerPin.get(outPin) == null)
outgoingLabelPerPin.put(outPin, new HashSet<>());
}
outgoingLabelPerPin.computeIfAbsent(outPin, k -> new LinkedHashSet<>());

if (abstractAssignment instanceof ForwardingAssignment forwardingAssignment) {
outgoingLabelPerPin.get(forwardingAssignment.getOutputPin())
Expand Down Expand Up @@ -178,12 +175,12 @@ private List<DataCharacteristic> createDataCharacteristicsFromLabels(Map<Pin, Se
* @param pinToLabelMap Mapping of a pin to the assigned labels
* @return Returns a list of characteristic values assigned to the given pin
*/
private Set<CharacteristicValue> getCharacteristicValuesForPin(Pin pin, Map<Pin, Set<Label>> pinToLabelMap) {
private List<CharacteristicValue> getCharacteristicValuesForPin(Pin pin, Map<Pin, Set<Label>> pinToLabelMap) {
return pinToLabelMap.get(pin)
.stream()
.map(label -> new DFDCharacteristicValue((LabelType) label.eContainer(), label))
.filter(distinctByKey(CharacteristicValue::getValueId))
.collect(Collectors.toSet());
.collect(Collectors.toList());
}

/**
Expand Down Expand Up @@ -256,7 +253,7 @@ public void unify(Set<DFDSimpleVertex> vertices) {
* Creates a clone of the vertex without considering data characteristics nor vertex characteristics
*/
public DFDSimpleVertex copy(Map<DFDSimpleVertex, DFDSimpleVertex> mapping) {
Set<DFDSimpleVertex> previousVerticesNew = new HashSet<>();
Set<DFDSimpleVertex> previousVerticesNew = new LinkedHashSet<>();
this.previousVertices.forEach(it -> {
var newVertice = mapping.getOrDefault(it, it.copy(mapping));
previousVerticesNew.add(newVertice);
Expand All @@ -276,6 +273,15 @@ public List<AbstractVertex<Node>> getPreviousElements() {
.map(it -> (AbstractVertex<Node>) it)
.toList();
}

public boolean equalsSemantically(DFDSimpleVertex other) {
if (this.equals(other)) return true;
if (!this.mapPinToFlow.equals(other.getPinFlowMap())) return false;
if (this.previousVertices.size() == 0 && other.previousVertices.size() == 0) return true;
return this.previousVertices.stream().allMatch(previousVertex -> {
return other.getPreviousElements().stream().map(DFDSimpleVertex.class::cast).anyMatch(it -> it.equalsSemantically(previousVertex));
});
}

/**
* Returns the mapping between pins of the node and the connected input flows connecting the vertex to the previous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public Deque<AssemblyContext> getContext() {
return context;
}


/**
* Determines whether a vertex is equivalent to another vertex in the context of the PCM model
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.EnumCharacteristicType;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.Literal;

public record PCMCharacteristicValue(EnumCharacteristicType characteristicType, Literal characteristicLiteral) implements CharacteristicValue {
import java.util.Objects;

public final class PCMCharacteristicValue implements CharacteristicValue {
private final EnumCharacteristicType characteristicType;
private final Literal characteristicLiteral;

public PCMCharacteristicValue(EnumCharacteristicType characteristicType, Literal characteristicLiteral) {
if (Objects.isNull(characteristicType) || Objects.isNull(characteristicType.getName()) || characteristicType.getName().isBlank()) {
throw new IllegalArgumentException("Characteristic type cannot be null or empty");
}
if (Objects.isNull(characteristicLiteral) || Objects.isNull(characteristicLiteral.getName()) || characteristicLiteral.getName().isBlank()) {
throw new IllegalArgumentException("Characteristic literal cannot be null or empty");
}
this.characteristicType = characteristicType;
this.characteristicLiteral = characteristicLiteral;
}

@Override
public String getTypeName() {
Expand All @@ -23,4 +38,32 @@ public String getValueId() {
return this.characteristicLiteral()
.getId();
}

@Override
public String toString() {
return String.format("%s.%s", this.getTypeName(), this.getValueName());
}

public EnumCharacteristicType characteristicType() {
return characteristicType;
}

public Literal characteristicLiteral() {
return characteristicLiteral;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (PCMCharacteristicValue) obj;
return Objects.equals(this.characteristicType, that.characteristicType) &&
Objects.equals(this.characteristicLiteral, that.characteristicLiteral);
}

@Override
public int hashCode() {
return Objects.hash(characteristicType, characteristicLiteral);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.Literal;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.expressions.And;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.expressions.False;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.expressions.Not;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.expressions.Or;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.expressions.Term;
import org.dataflowanalysis.pcm.extension.dictionary.characterized.DataDictionaryCharacterized.expressions.True;
Expand Down Expand Up @@ -50,7 +51,9 @@ public PCMDataCharacteristicsCalculator(List<DataCharacteristic> initialCharacte
*/
private void createNodeCharacteristicsContainer(List<CharacteristicValue> vertexCharacteristics) {
DataCharacteristic vertexCharacteristicsContainer = new DataCharacteristic("container");
vertexCharacteristics.forEach(vertexCharacteristicsContainer::addCharacteristic);
for (CharacteristicValue vertexCharacteristic : vertexCharacteristics) {
Comment thread
Entenwilli marked this conversation as resolved.
vertexCharacteristicsContainer = vertexCharacteristicsContainer.addCharacteristic(vertexCharacteristic);
}
this.currentVariables.add(vertexCharacteristicsContainer);
}

Expand All @@ -72,6 +75,9 @@ public void evaluate(ConfidentialityVariableCharacterisation variableCharacteris

AbstractNamedReference reference = variableCharacterisation.getVariableUsage_VariableCharacterisation()
.getNamedReference__VariableUsage();
if (reference.getReferenceName().isBlank()) {
throw new IllegalArgumentException("Variable Name may not be null!");
}
DataCharacteristic existingCharacteristic = this.getDataCharacteristicByReference(reference)
.orElse(new DataCharacteristic(reference.getReferenceName()));

Expand Down Expand Up @@ -178,6 +184,8 @@ private boolean evaluateTerm(Term term, CharacteristicValue characteristicValue)
return evaluateTerm(andTerm.getLeft(), characteristicValue) && evaluateTerm(andTerm.getRight(), characteristicValue);
} else if (term instanceof Or orTerm) {
return evaluateTerm(orTerm.getLeft(), characteristicValue) || evaluateTerm(orTerm.getRight(), characteristicValue);
} else if(term instanceof Not notTerm) {
return !evaluateTerm(notTerm.getTerm(), characteristicValue);
} else {
throw new IllegalArgumentException("Unknown type: " + term.getClass()
.getName());
Expand All @@ -191,6 +199,9 @@ private boolean evaluateTerm(Term term, CharacteristicValue characteristicValue)
* @return Returns, whether the characteristic reference evaluates to true or false (or is undefined)
*/
private boolean evaluateNamedReference(NamedEnumCharacteristicReference characteristicReference, CharacteristicValue characteristicValue) {
if(characteristicReference.getNamedReference().getReferenceName().isBlank()) {
throw new IllegalArgumentException("Variable Name in right hand side of StoEx may not be blank!");
}
var optionalDataCharacteristic = getDataCharacteristicByReference(characteristicReference.getNamedReference());
if (optionalDataCharacteristic.isEmpty()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayDeque;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.dataflowanalysis.analysis.core.CharacteristicValue;
import org.dataflowanalysis.analysis.core.DataCharacteristic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.dataflowanalysis.analysis.core;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -156,37 +153,6 @@ public List<String> getVertexCharacteristicNames(String requiredCharacteristicTy
.collect(Collectors.toList());
}

/**
* Returns a list of data characteristics with the given name
* <p>
* See {@link AbstractVertex#getVertexCharacteristics(String)} for a similar method for vertex characteristics
* @param requiredDataCharacteristicName Name of the data characteristic
* @return Returns a list of all data characteristics with the given name
*/
public List<DataCharacteristic> getDataCharacteristics(String requiredDataCharacteristicName) {
return this.getAllIncomingDataCharacteristics()
.stream()
.filter(it -> it.getVariableName()
.equals(requiredDataCharacteristicName))
.collect(Collectors.toList());
}

/**
* Returns a list of data characteristic names with the given required data characteristic name
* <p>
* See {@link AbstractVertex#getVertexCharacteristicNames(String)} for a similar method for vertex characteristics
* @param requiredDataCharacteristicName Name of the data characteristic
* @return Returns a list of all data characteristics with the given name
*/
public List<String> getDataCharacteristicNames(String requiredDataCharacteristicName) {
return this.getAllIncomingDataCharacteristics()
.stream()
.filter(it -> it.getVariableName()
.equals(requiredDataCharacteristicName))
.map(DataCharacteristic::variableName)
.collect(Collectors.toList());
}

/**
* Returns a map containing the characteristic values with the given characteristic type for each data characteristic
* <p>
Expand Down Expand Up @@ -242,7 +208,7 @@ public String createPrintableNodeInformation() {
* @return a comma separated list of the format: "CharacteristicType.CharacteristicLiteral,
* CharacteristicType.CharacteristicLiteral"
*/
public String createPrintableCharacteristicsList(List<CharacteristicValue> characteristics) {
private String createPrintableCharacteristicsList(List<CharacteristicValue> characteristics) {
List<String> entries = characteristics.stream()
.map(it -> String.format("%s.%s", it.getTypeName(), it.getValueName()))
.toList();
Expand Down
Loading