Softwareproduktlinien - Analyse von Produktlinien Christian Kästner (CMU) Sven Apel (Universität Passau) Gunter Saake, Thomas Thüm (Universität Magdeburg)
Das Problem
Variability = Complexity
33 optional, independent features a unique variant for every person on this planet
320 optional, independent features more variants than estimated atoms in the universe
Correctness?
Maintenance? Comprehension?
Checking Products 2000 Features 100 Printers 30 New Printers per Year Printer Firmware
Checking Products 10000 Features? Products Linux Kernel
Checking Product Line Implementation with 10000 Features #ifdef, Frameworks, FOP, AOP, Linux Kernel
Analyse von Feature-Modellen
Fragen an Feature-Modell und Konfigurationen Domain Eng. Feature-Modell Wiederverwendbare Implementierungsartefakte Application Eng. 13 Feature-Auswahl Generator Fertiges Program
Fragen an Feature-Modell Feature-Modell Ist das Modell konsistent? Welche Features muss man auswählen? Welche Features darf man nicht auswählen? Wie viele gültige Produkte gibt es? Sind zwei Feature-Modelle äquivalent?
Fragen an Feature-Modell und Konfigurationen Feature-Modell Feature-Auswahl Ist das Modell konsistent? Welche Features muss man auswählen? Welche Features darf man nicht auswählen? Wie viele gültige Produkte gibt es? Sind zwei Feature-Modelle äquivalent? Ist eine Feature-Auswahl gültig? Welche Features werden durch eine partielle Konfiguration bereits festgelegt?
Wiederholung: Feature-Modelle & Aussagenlogik Repräsentation von Feature-Modellen als Liste von Konfigurationen Aussagenlogischer Ausdruck Feature-Diagramm SPL OS ( Unix Win) ( Unix Win) ( Txn Write)
Wiederholung: Feature-Modell in Aussagenlogik übersetzen Wobei P für Parent und Ci für Child steht + Wurzel ist immer ausgewählt + alle Cross-Tree Constraints (Zusatzbedingungen) Alle diese Ausdrücke in Konjunktion verknüpfen
Analyse von Feature-Modellen Ist Feature-Auswahl gültig? {Root, Base, F1, F4} {Root, Base, F2, F3} Variablen in Formel ersetzen true wenn Feature in Auswahl, sonst false Formel ergibt true für gültige Auswahl
Ist das Feature-Modell konsistent? Gibt es mindestens eine Variante/Produkt? Formel erfüllbar? Anfrage an SAT-Solver SAT(FM)
Tote (Dead) Features Gegeben ein Feature-Modell Welche Features können ausgewählt werden? Welche Features müssen ausgewählt werden? Feature F auswählbar wenn SAT(FM F) Feature F abwählbar wenn SAT(FM F)
Partielle Konfigurationen Gegeben eine partielle Konfiguration Welche Features können noch ausgewählt werden? Welche Features müssen noch ausgewählt werden? Ausgewählte Features in Formel aufnehmen, dann wie tote Features Feature F noch auswählbar wenn SAT(FM AF F) Feature F noch abwählbar wenn SAT(FM AF F)
Änderungen von Feature-Modellen Welche Konsequenzen hat eine Änderung im Feature- Modell auf die Produktmenge? Refaktorisierungen, Spezialisierungen, Generalisierungen
Generalisierung von Feature-Modellen Informell (FM wird in FM verändert): Produkte aus FM bleiben erhalten, keine neuen Abhängigkeiten in FM Formal wenn Tautologie gilt: TAUT(FM => FM ) Also wenn: SAT( (FM => FM )) (Sonderbehandlung für hinzugefügte/entfernte Features sowie abstrakte Features nötig)
Generalisierung von Feature-Modellen
Spezialisierung von Feature-Modellen Informell: Keine neuen Produkte, Abhängigkeiten bleiben erhalten Formal wenn Tautologie gilt: TAUT(FM => FM) Also wenn: SAT( (FM => FM)) (Sonderbehandlung für hinzugefügte/entfernte Features sowie abstrakte Features nötig)
Spezialisierung von Feature-Modellen
Refaktorisierung von Feature-Modellen Informell: gleiche Produktmengen Informell: Spezialisierung + Generalisierung Formal wenn Tautologie gilt: TAUT(FM <=> FM ) Also wenn: SAT( (FM <=> FM )) (Sonderbehandlung für hinzugefügte/entfernte Features sowie abstrakte Features nötig)
Refaktorisierung von Feature-Modellen
Reasoning in FeatureIDE
Analyse der Implementierung
Fragen an die Implementierung Domain Eng. Feature-Modell Wiederverwendbare Implementierungsartefakte Application Eng. 31 Feature-Auswahl Generator Fertiges Program
Fragen an die Implementierung Kann ein Code-Block ausgewählt werden? Ändert eine Annotation etwas am Gesamt-Code? Wiederverwendbare Implementierungsartefakte
Annotationen bei Präprozessoren true WORLD BYE true
Berechnung von Presence Conditions line 1 #ifdef A line 2 #ifndef B line 3 #endif line 4 #elif defined(x) line 5 #else line 6 #endif true A A B A A X A X
Toter Quelltext (Dead Code) line 1 #ifdef A line 2 #ifndef A line 3 #endif line 4 #elif defined(x) line 5 #else line 6 #endif true A A A (= PC) A A X A X Kann nicht ausgewählt werden Analyse: SAT(PC)
Überflüssige (Superfluous) Annotation line 1 #ifdef A line 2 #ifdef A line 3 #endif line 4 #elif defined(x) line 5 #else line 6 #endif true A (= PC) A A (= PC ) A A X A X Immer gewählt wenn äußerer Block gewählt Analyse: SAT(PC PC )
Fragen an die Implementierung und das Feature-Modell Domain Eng. Feature-Modell Wiederverwendbare Implementierungsartefakte Application Eng. 37 Feature-Auswahl Generator Fertiges Program
Toter Quelltext (Dead Code) line 1 #ifdef A line 2 #ifdef B line 3 #endif line 4 #elif defined(x) line 5 #else line 6 #endif true A A B (=PC) A A X not A ^ not X Kann nicht ausgewählt werden Analyse: SAT(FM PC) Kombinierte Analyse von Feature-Modell und Implementierung
Überflüssige (Superfluous) Annotation line 1 #ifdef A line 2 #ifndef B line 3 #endif line 4 #elif defined(x) line 5 #else line 6 #endif true A (= PC) A B (= PC ) A A X A X Immer gewählt wenn äußerer Block gewählt Analyse: SAT(FM PC PC )
Analyse der Implementierung Fehler in Bezug auf das Feature-zu-Code-Mapping: Toter Quelltext (mit/ohne Feature-Modell) Überflüssige Annotationen (mit/ohne Feature-Modell) Feature verwendet, aber existiert nicht in Feature-Modell Feature aus Feature-Modell nicht verwendet Weitere wichtige Fehlerklasse: Typfehler Klasse/Methode/Feld wird Varianten aufgerufen, in denen sie/es nicht definiert ist Bei FOP: Methode enthält original, aber nicht in allen Varianten gibt es eine vorherige Rolle
Typsysteme für Produktlinien
Type Checking #include <stdio.h> char *msg = "Hello World"; int main() { printf(msg); } Reference Type errors: referenced variable does not exist,
Variability-Aware Type Checking #include <stdio.h> #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); }
Variability-Aware Type Checking #include <stdio.h> #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } Reference? Conflict?
Variability-Aware Type Checking Presence conditions: true HELLO BYE true #include <stdio.h> #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } Reference? Conflict?
Variability-Aware Type Checking true HELLO BYE TAUT(true -> true)? true #include <stdio.h> #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } Reference? TAUT(true -> (HELLO v BYE))? TAUT( (HELLO BYE))? Conflict?
Reachability: PC(Source) -> PC(Target) Conflicts: (PC(Def1) PC(Def2)) true HELLO BYE TAUT(true -> true)? true #include <stdio.h> #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } Reference? TAUT(true -> (HELLO v BYE))? TAUT( (HELLO BYE))? Conflict?
Einbeziehung des Feature-Modells true HELLO BYE #include <stdio.h> TAUT(FM -> (true -> true))? true #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } TAUT(FM -> (HELLO BYE))? Reference? TAUT(FM -> (true -> (HELLO v BYE)))? Conflict?
Einbeziehung des Feature-Modells true HELLO BYE #include <stdio.h> TAUT(FM -> (true -> true))? true #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } TAUT(FM -> (HELLO BYE))? Reference? TAUT(FM -> (true -> (HELLO v BYE)))? Conflict?
Einbeziehung des Feature-Modells true HELLO BYE #include <stdio.h> TAUT(FM -> (true -> true))? true #ifdef HELLO char *msg = "Hello World"; #endif #ifdef BYE char *msg = "Bye bye!"; #endif int main() { printf(msg); } TAUT(FM -> (HELLO BYE))? Reference? TAUT(FM -> (true -> (HELLO v BYE)))? Conflict?
AST with Variability Information WORLD BYE 52 WORLD BYE Extended Reference lookup mechanism
Variability-Aware Analysis of Linux > 7000 files: avg 30 secs parsing-time per file 85 hours total Up to ~2 6000 10 1800 variants: we are immensely faster Challenges for evaluation Extracting feature model Build scripts are also conditional and unstructured SAT solving still not a problem
Zusammenfassung Variabilität Komplexität Analysen auf Feature-Modellen und Implementierung sind notwendig Analyse aller validen Produkte ist nicht praktikabel Variabilitätsgewahre Analysen
Literatur David Benavides, Sergio Segura, Antonio Ruiz Cortés: Automated analysis of feature models 20 years later: A literature review. Inf. Syst. 35(6): 615-636 (2010) [Überblick Feature-Modell-Analysen] Thomas Thüm, Christian Kästner, Sebastian Erdweg, and Norbert Siegmund. 2011. Abstract Features in Feature Modeling. In SPLC. IEEE Computer Society, Washington, DC, USA, 191-200. [Vergleich von Feature-Modellen] Thomas Thüm, Sven Apel, Christian Kästner, Ina Schaefer, and Gunter Saake. 2014. A Classification and Survey of Analysis Strategies for Software Product Lines. ACM Comput. Surv. 47, 1, Article 6 (June 2014), 45 pages. [Überblick variabilitätsgewahre Analysen]