Skip to content

Commit ff8b329

Browse files
[cfi][test] use more robust test patterns
When test output contains extra data (such as debug logs), tests can become flaky if there are strings like '12': the problem is that after successfully finding '1' in '12', the pattern '^2$' will find a full match in '2' following '1' (mentioned in #165899). To prevent this, use patterns that search for '1' or '2' as standalone strings on their own line.
1 parent 8484584 commit ff8b329

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed

compiler-rt/test/cfi/anon-namespace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ int main() {
7373
A *a = mkb();
7474
break_optimization(a);
7575

76-
// CFI: 1
77-
// NCFI: 1
76+
// CFI: {{^1$}}
77+
// NCFI: {{^1$}}
7878
fprintf(stderr, "1\n");
7979

8080
// CFI-DIAG: runtime error: control flow integrity check for type '(anonymous namespace)::B' failed during base-to-derived cast

compiler-rt/test/cfi/bad-cast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ int main(int argc, char **argv) {
9292
B *b = new B;
9393
break_optimization(b);
9494

95-
// FAIL: 1
96-
// PASS: 1
95+
// FAIL: {{^1$}}
96+
// PASS: {{^1$}}
9797
fprintf(stderr, "1\n");
9898

9999
A a;

compiler-rt/test/cfi/base-derived-destructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class B : public A<B> {
7777
};
7878

7979
int main() {
80-
// CFI: 1
81-
// NCFI: 1
80+
// CFI: {{^1$}}
81+
// NCFI: {{^1$}}
8282
fprintf(stderr, "1\n");
8383

8484
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during base-to-derived cast

compiler-rt/test/cfi/icall/bad-signature.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ void f() {
1313
}
1414

1515
int main() {
16-
// CFI: 1
17-
// NCFI: 1
16+
// CFI: {{^1$}}
17+
// NCFI: {{^1$}}
1818
fprintf(stderr, "1\n");
1919

2020
// CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
2121
// CFI-DIAG: f defined here
2222
((void (*)(int))f)(42); // UB here
2323

24-
// CFI-NOT: 2
25-
// NCFI: 2
24+
// CFI-NOT: {{^2$}}
25+
// NCFI: {{^2$}}
2626
fprintf(stderr, "2\n");
2727
}

compiler-rt/test/cfi/icall/external-call.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <math.h>
1313

1414
int main(int argc, char **argv) {
15-
// CFI: 1
15+
// CFI: {{^1$}}
1616
fprintf(stderr, "1\n");
1717

1818
double (*fn)(double);
@@ -23,6 +23,6 @@ int main(int argc, char **argv) {
2323

2424
fn(atof(argv[2]));
2525

26-
// CFI: 2
26+
// CFI: {{^2$}}
2727
fprintf(stderr, "2\n");
2828
}

compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ int f() {
2929
void f();
3030

3131
int main() {
32-
// CFI: 1
32+
// CFI: {{^1$}}
3333
fprintf(stderr, "1\n");
3434

3535
void (*volatile p)() = &f;
3636
p();
3737

38-
// CFI-NOT: 2
38+
// CFI-NOT: {{^2$}}
3939
fprintf(stderr, "2\n");
4040
}
4141
#endif

compiler-rt/test/cfi/multiple-inheritance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ int main(int argc, char **argv) {
5252
C *c = new C;
5353
break_optimization(c);
5454

55-
// CFI: 1
56-
// NCFI: 1
55+
// CFI: {{^1$}}
56+
// NCFI: {{^1$}}
5757
fprintf(stderr, "1\n");
5858

5959
if (argc > 1) {

compiler-rt/test/cfi/nvcall.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ int main() {
4545
A *a = new A;
4646
break_optimization(a);
4747

48-
// CFI: 1
49-
// NCFI: 1
48+
// CFI: {{^1$}}
49+
// NCFI: {{^1$}}
5050
fprintf(stderr, "1\n");
5151

5252
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during non-virtual call

compiler-rt/test/cfi/overwrite.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ int main() {
4545
*((void **)a) = fake_vtable + 2; // UB here
4646
break_optimization(a);
4747

48-
// CFI: 1
49-
// NCFI: 1
48+
// CFI: {{^1$}}
49+
// NCFI: {{^1$}}
5050
fprintf(stderr, "1\n");
5151

5252
// CFI-NOT: foo

compiler-rt/test/cfi/sibling.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ int main() {
4242
B *b = new B;
4343
break_optimization(b);
4444

45-
// CFI: 1
46-
// NCFI: 1
45+
// CFI: {{^1$}}
46+
// NCFI: {{^1$}}
4747
fprintf(stderr, "1\n");
4848

4949
((C *)b)->f(); // UB here
5050

51-
// CFI-NOT: 2
52-
// NCFI: 2
51+
// CFI-NOT: {{^2$}}
52+
// NCFI: {{^2$}}
5353
fprintf(stderr, "2\n");
5454
}

0 commit comments

Comments
 (0)