0% found this document useful (0 votes)
7 views

Exercise Sheet 09 Solution

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Exercise Sheet 09 Solution

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Software Engineering

WS 2022/23, Sheet 09

Prof. Dr. Sven Apel


Yannick Lehmen, Maurice Vincon
Handout: 09.01.2023

Task 1
a) What challenges does configurability pose when analyzing software systems?
b) What strategies exist for analyzing configurable systems? Discuss the pros and cons of each strategy.

Solution
a) The number of variants can grow exponentially with the number of features → one cannot analyze all variants.
b) Strategy pros cons
Brute-Force Analysis + complete information - does not scale
Sampling + scales to large systems - partial information
+ can use standard analyses - results might not be true for all variants
Variability-Aware Analysis + complete information - needs information about variability
+ scales to large systems - needs special implementation
Task 2
a) What is random sampling? Why do we want to sample configurations randomly?
b) Name different approaches for implementing random sampling and discuss their pros and cons.
c) Explain in your own words how distance-based sampling works.
d) Given the following feature model, give one valid configuration for each of the distances 1, 2, 3, and 4 using the
Hamming distance. Use the configuration {A} as the origin. Does this process yield a uniform sample?

B C F

D E

Solution
a) Random sampling draws a set Ĉ of configurations from the set of all valid configurations C such that for any
configuration c ∈ C the probability that this configuration is contained in the sample is the same. We use random
sampling to avoid having any bias caused by an unequal distribution of feature selections.
b) Implementation pros cons
Enumeration + uniform randomness - does not scale
SAT-Solver + scales to large systems - not uniform (clustering)
Distance-Based + scales to large systems - no guarantees for uniformity
+ no clustering
c) • Group configurations by distance to reference point (configuration)
• To get a sample of size n, do n times:
– randomly select a group
– select a new configuration from that group
d) distance 1: {A, B}
distance 2: {A, B, F }
distance 3: {A, B, C, D}
distance 4: {A, B, C, D, F }
Uniformity?
• Number of configurations | C |= 12
• Sample size n = 4
• For uniformity: ∀c ∈ C : P r(c ∈ Ĉ) = 4
|C| = 1
3

• Number of possible samples: 2 ∗ 3 ∗ 4 ∗ 2 = 48


• Samples containing {A, B} : 24 → P r({A, B} ∈ Ĉ) = 1
2 6= 1
3

• Samples containing {A, B, C, D} : 12 → P r({A, B, C, D} ∈ Ĉ) = 1


4 6= 1
3

⇒ No uniformity!
Task 3
a) What is coverage-based sampling? What are possible coverage criteria?
b) Why would one choose coverage-based sampling over random sampling?
c) Given the following feature model, give a set of configurations that achieves:
(i) pair-wise feature coverage
(ii) pair-wise interaction coverage
(iii) 3-wise feature coverage
(iv) Bonus task: 3-wise interaction coverage

B C F

D E

Solution
a) With coverage sampling, each sample has to fulfill one or more coverage criteria.
Possible coverage criteria:
• t-wise feature coverage
• t-wise interaction coverage
• code coverage
• one-disabled
• one-enabled
• most-enabled-disabled
• …
b) The following problems of random sampling can be circumvented by enforcing appropriate coverage criteria:
• not all features may appear in the sample
• not all combinations of features may appear in the sample
• not all code may be present in the sample
c) (i) {A, B, C, D, F }, {A, B, C, E, F }
(ii) {A, B}, {A, B, F }, {A, B, C, D}, {A, B, C, E}, {A, B, C, D, F }, {A, B, C, E, F }
(iii) {A, B, C, D, F }, {A, B, C, E, F }
(iv) {A, B}, {A, B, F }, {A, B, C, D}, {A, B, C, E}, {A, B, C, D, F }, {A, B, C, E, F }
Task 4
a) Annotate the presence conditions for each code block in the code example below.
b) Create the variational control-flow graph for the code example.
c) Determine all code lines containing dead code given the following feature models.

1 a = 1; b = 1;
2 #ifdef X
3 a++;
4 #ifdef Y
5 a = a * 2;
6 #endif
7 #endif
8 #ifdef Z B
9 b = 4;
10 #ifdef X
11 a = a - 2; X Y Z
12 #elif W
13 b = b - 1;
14 #else B W
15 b = 5;
16 #endif ¬(Y ∧ X)
17 b = b / a; W X Y Z
18 #endif
(a) (b)

Solution
(a) Presence Conditions (b) Variational CFG

1 a = 1; b = 1; // true
2 #ifdef X
3 a++; // X
4 #ifdef Y
5 a = a * 2; // X ∧ Y
6 #endif
7 #endif
8 #ifdef Z
9 b = 4; // Z
10 #ifdef X
11 a = a - 2; // X ∧ Z
12 #elif W
13 b = b - 1; // W ∧ ¬X ∧ Z
14 #else
15 b = 5; // ¬W ∧ ¬X ∧ Z
16 #endif
17 b = b / a; // Z
18 #endif

c) Dead Code
a) The feature model F M = B ∧ (W ⇒ B) ∧ (X ⇒ B) ∧ (Y ⇒ B) ∧ (Z ⇒ B) is equivalent to true.
→ no dead code if presence conditions (P C) do not contradict themselves: SAT (F M ∧ P C) = SAT (true ∧ P C)
b) F M = B ∧ (X ⇒ B) ∧ (W ⇒ X) ∧ (Y ⇔ B) ∧ (Z ⇒ B) ∧ ¬(X ∧ Y )
→ cannot select X or W
→ dead code in lines 3, 5, 11, and 13
Task 5
Provide type derivations for the following expressions:
a) true | ∅ ` let x = choice hA, false, 42i in x : (Bool, A), (Num, ¬A)
b) true | ∅ ` let x = choice hA, true, 42i in x < 1 : (Bool, true)
c) ¬A | ∅ ` let x = choice hA, true, 42i in x < 1 : (Bool, true)
d) A ⇔ B | ∅ ` if 1 < 0 then choice hA, true, 42i else choice hB, false, 7i : (Bool, A ∧ B), (Num, ¬A ∧ ¬B)

Solution
42 ∈ Z
T-False T-Num
A | ∅ ` false : (Bool, A) ¬A | ∅ ` 42 : (Num, ¬A) (x, (Bool, A), (Num, ¬A)) ∈ Γ true ⇒ A ∨ ¬A
a) T-Choice
true | ∅ ` choice hA, false, 42i : (Bool, A), (Num, ¬A)
x∈ / dom(∅) T-Id
true | (x, (Bool, A), (Num, ¬A)) ` x : (Bool, A), (Num, ¬A)
T-Let
true | ∅ ` let x = choice hA, false, 42i in x : (Bool, A), (Num, ¬A)

42 ∈ Z (x, (Num, true)) ∈ /Γ/ true ⇒ A ∨ ¬A 1∈Z


T-True T-Num T-Id T-Num
b) T-Choice
A | ∅ ` true : (Bool, A) ¬A | ∅ ` 42 : (Num, ¬A)
true | ∅ ` choice hA, true, 42i : (Bool, A), (Num, ¬A)
/ dom(∅)
x∈ T-Smaller
true | (x, (Bool, A), (Num, ¬A)) ` x : (Num, true) true | (x, (Bool, A), (Num, ¬A)) ` 1 : (Num, true)
true | (x, (Bool, A), (Num, ¬A)) ` x < 1 : (Bool, true)
T-Let
true | ∅ ` let x = choice hA, true, 42i in x < 1 : (Bool, true)

42 ∈ Z (x, (Num, ¬A)) ∈ Γ ¬A ⇒ ¬A 1∈Z


T-True T-Num T-Id T-Num
c) T-Choice
f alse | ∅ ` true : (Bool, false) ¬A | ∅ ` 42 : (Num, ¬A)
¬A | ∅ ` choice hA, true, 42i : (Num, ¬A)
x∈/ dom(∅) T-Smaller
¬A | (x, (Num, ¬A)) ` x : (Num, ¬A) ¬A | (x, (Num, ¬A)) ` 1 : (Num, true)
¬A | (x, (Num, ¬A)) ` x < 1 : (Bool, true)
T-Let
¬A | ∅ ` let x = choice hA, true, 42i in x < 1 : (Bool, true)

1∈Z 0∈Z 42 ∈ Z 7∈Z

d)
T-Num T-Num T-True T-Num T-False T-Num
A ⇔ B | ∅ ` 1 : (Num, A ⇔ B) A ⇔ B | ∅ ` 0 : (Num, A ⇔ B) A ∧ B | ∅ ` true : (Bool, A ∧ B) ¬A ∧ ¬B | ∅ ` 42 : (Num, ¬A ∧ ¬B) A ∧ B | ∅ ` false : (Bool, A ∧ B) ¬A ∧ ¬B | ∅ ` 7 : (Num, ¬A ∧ ¬B)
T-Smaller T-Choice T-Choice
A ⇔ B | ∅ ` 1 < 0 : (Bool, A ⇔ B) A ⇔ B | ∅ ` choice hA, true, 42i : (Bool, A ∧ B), (Num, ¬A ∧ ¬B) A ⇔ B | ∅ ` choice hB, false, 7i : (Bool, A ∧ B), (Num, ¬A ∧ ¬B)
T-If
A ⇔ B | ∅ ` if 1 < 0 then choice hA, true, 42i else choice hB, false, 7i : (Bool, A ∧ B), (Num, ¬A ∧ ¬B)

You might also like