Skip to content

Commit 91963df

Browse files
committed
test(instr-c): Add tests for C++ method call chain instrumentation
1 parent 0d8b3ae commit 91963df

File tree

7 files changed

+143
-0
lines changed

7 files changed

+143
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
#include <cstdlib>
3+
4+
class A
5+
{
6+
int _x;
7+
8+
public:
9+
A (int x) : _x (x){};
10+
11+
int
12+
get_x () const
13+
{
14+
return this->_x;
15+
}
16+
};
17+
18+
class B
19+
{
20+
A _a;
21+
22+
public:
23+
B (A a) : _a (a){};
24+
25+
A
26+
get_a () const
27+
{
28+
// Purposely exit early after dumping the buffers.
29+
/* GNATCOV_DUMP_BUFFERS */
30+
exit (0);
31+
return this->_a;
32+
}
33+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "pkg.h"
2+
3+
int
4+
main (void)
5+
{
6+
A a (5); // # var-decl
7+
B b (a); // # var-decl
8+
9+
// .get_a() exits the program with 0 status code.
10+
b // # var-ref
11+
.get_a (); // # method-call
12+
13+
// Program should not reach this point.
14+
}
15+
16+
//# test_exiting_method.cpp
17+
// /var-decl/ l+ ## 0
18+
// /var-ref/ l+ ## 0
19+
// /method-call/ l+ ## 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "pkg.h"
2+
3+
int
4+
main (void)
5+
{
6+
A a (5); // # var-decl
7+
B b (a); // # var-decl
8+
9+
// .get_a() exits the program with 0 status code.
10+
b // # var-ref
11+
.get_a () // # method-call
12+
.get_x (); // # not-reached
13+
14+
/* GNATCOV_DUMP_BUFFERS */
15+
}
16+
17+
//# test_shortcut_method_chain.cpp
18+
// /var-decl/ l+ ## 0
19+
// /var-ref/ l+ ## 0
20+
// /method-call/ l+ ## 0
21+
// /not-reached/ l! ## c-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "pkg.h"
2+
3+
int
4+
main (void)
5+
{
6+
A a (5); // # var-decl
7+
8+
a // # var-ref
9+
.get_x (); // # method-call
10+
11+
/* GNATCOV_DUMP_BUFFERS */
12+
}
13+
14+
//# test_simple_call.cpp
15+
// /var-decl/ l+ ## 0
16+
// /var-ref/ l+ ## 0
17+
// /method-call/ l+ ## 0
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
This test ensures that method call instrumentation behaves correctly and
3+
produces the expected coverage.
4+
"""
5+
6+
from SCOV.tc import TestCase
7+
from SCOV.tctl import CAT, CovControl
8+
from SUITE.context import thistest
9+
10+
TestCase(category=CAT.stmt, fun_call_lvl=True).run(
11+
covcontrol=CovControl(dump_trigger="manual")
12+
)
13+
thistest.result()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class A
2+
{
3+
int _x;
4+
5+
public:
6+
A (int x) : _x (x){};
7+
8+
int
9+
get_x () const
10+
{
11+
return this->_x;
12+
}
13+
14+
int
15+
get_x_plus_one () const
16+
{
17+
return get_x () + 1; // # non-prefix-call
18+
}
19+
};
20+
21+
int
22+
main (void)
23+
{
24+
A (5).get_x_plus_one (); // # method-call
25+
}
26+
27+
//# test_non_prefix.cpp
28+
// /non-prefix-call/ l+ ## 0
29+
// /method-call/ l+ ## 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
This test makes sure that the instrumentation of non-prefixed method calls
3+
works correctly.
4+
"""
5+
6+
from SCOV.tc import TestCase
7+
from SCOV.tctl import CAT
8+
from SUITE.context import thistest
9+
10+
TestCase(category=CAT.stmt, fun_call_lvl=True).run()
11+
thistest.result()

0 commit comments

Comments
 (0)