Skip to content

Commit 8e54444

Browse files
committed
Construct feasible races-mhp regression tests for improved history thread ID may_create
1 parent 9744751 commit 8e54444

File tree

6 files changed

+159
-13
lines changed

6 files changed

+159
-13
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// PARAM: --set ana.activated[+] mhp --disable ana.thread.include-node
2+
#include <pthread.h>
3+
4+
int g;
5+
6+
void *b(void *arg) {
7+
int *gp = arg;
8+
if (gp)
9+
(*gp)++; // NORACE
10+
return NULL;
11+
}
12+
13+
void *a(void *arg) {
14+
pthread_t id;
15+
pthread_create(&id, NULL, b, arg);
16+
return NULL;
17+
}
18+
19+
int main() {
20+
pthread_t id, id2;
21+
pthread_create(&id, NULL, b, NULL);
22+
g++; // NORACE
23+
pthread_create(&id2, NULL, a, &g);
24+
return 0;
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// PARAM: --set ana.activated[+] mhp --disable ana.thread.include-node
2+
#include <pthread.h>
3+
4+
int g;
5+
6+
void *a(void *arg) {
7+
int *gp = arg;
8+
if (gp)
9+
(*gp)++; // RACE (self-race in non-unique thread)
10+
return NULL;
11+
}
12+
13+
void *b(void *arg) {
14+
pthread_t id, id2;
15+
pthread_create(&id, NULL, a, NULL);
16+
pthread_create(&id2, NULL, a, &g);
17+
return NULL;
18+
}
19+
20+
21+
int main() {
22+
pthread_t id, id2;
23+
pthread_create(&id, NULL, a, NULL);
24+
g++; // NORACE
25+
pthread_create(&id2, NULL, b, NULL);
26+
return 0;
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// PARAM: --set ana.activated[+] mhp --disable ana.thread.include-node
2+
#include <pthread.h>
3+
4+
int g;
5+
6+
void *d(void *arg) {
7+
int *gp = arg;
8+
if (gp)
9+
(*gp)++; // RACE (self-race in non-unique thread)
10+
return NULL;
11+
}
12+
13+
void *c(void *arg) {
14+
pthread_t id, id2;
15+
pthread_create(&id, NULL, d, NULL);
16+
pthread_create(&id2, NULL, d, &g);
17+
return NULL;
18+
}
19+
20+
void *b(void *arg) {
21+
return NULL;
22+
}
23+
24+
void *a(void *arg) {
25+
pthread_t id, id2;
26+
pthread_create(&id, NULL, b, NULL);
27+
g++; // NORACE
28+
pthread_create(&id2, NULL, c, NULL);
29+
return NULL;
30+
}
31+
32+
int main() {
33+
pthread_t id;
34+
pthread_create(&id, NULL, a, NULL);
35+
return 0;
36+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// PARAM: --set ana.activated[+] mhp --disable ana.thread.include-node
2+
#include <pthread.h>
3+
4+
int g;
5+
6+
void *a(void *arg) {
7+
int *gp = arg;
8+
if (gp)
9+
(*gp)++; // RACE (self-race in non-unique thread)
10+
return NULL;
11+
}
12+
13+
void *b(void *arg) {
14+
pthread_t id, id2;
15+
pthread_create(&id, NULL, a, NULL);
16+
pthread_create(&id2, NULL, a, &g);
17+
return NULL;
18+
}
19+
20+
int main() {
21+
pthread_t id, id2, id3;
22+
pthread_create(&id, NULL, a, NULL);
23+
pthread_create(&id, NULL, a, NULL);
24+
g++; // NORACE
25+
pthread_create(&id, NULL, b, NULL);
26+
return 0;
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// PARAM: --set ana.activated[+] mhp --disable ana.thread.include-node
2+
#include <pthread.h>
3+
4+
int g;
5+
6+
void *b(void *arg) {
7+
return NULL;
8+
}
9+
10+
void *c(void *arg) {
11+
int *gp = arg;
12+
if (gp)
13+
(*gp)++; // RACE (self-race in non-unique thread)
14+
return NULL;
15+
}
16+
17+
void *a(void *arg) {
18+
pthread_t id, id2, id3, id4;
19+
pthread_create(&id, NULL, b, NULL);
20+
pthread_create(&id2, NULL, b, NULL);
21+
g++; // NORACE
22+
pthread_create(&id, NULL, c, NULL);
23+
pthread_create(&id2, NULL, c, &g);
24+
return NULL;
25+
}
26+
27+
int main() {
28+
pthread_t id;
29+
pthread_create(&id, NULL, a, NULL);
30+
return 0;
31+
}

tests/unit/cdomains/threadIdDomainTest.ml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ let test_history_may_create _ =
5050
assert_equal true (may_create main (main >> a));
5151
assert_equal true (may_create main (main >> a >> b));
5252
assert_equal true (may_create (main >> a) (main >> a >> b));
53-
assert_equal false (may_create (main >> a) (main >> a));
54-
assert_equal false (may_create (main >> b) (main >> a >> b));
55-
assert_equal false (may_create (main >> a >> a) (main >> a >> b));
53+
assert_equal false (may_create (main >> a) (main >> a)); (* infeasible for race: definitely_not_started allows equality *)
54+
assert_equal false (may_create (main >> b) (main >> a >> b)); (* 53-races-mhp/04-not-created2 *)
55+
assert_equal false (may_create (main >> a >> a) (main >> a >> b)); (* infeasible for race: cannot create non-unique (main >> a >> a) before unique (main >> a >> b) *)
5656

5757
(* unique creates non-unique and is prefix: added elements cannot be in prefix *)
5858
assert_equal true (may_create main (main >> a >> a));
@@ -64,22 +64,22 @@ let test_history_may_create _ =
6464
assert_equal true (may_create (main >> a) (main >> a >> a));
6565
assert_equal true (may_create (main >> a >> b) (main >> a >> b >> b));
6666
assert_equal true (may_create (main >> a >> b) (main >> a >> b >> a));
67-
assert_equal false (may_create (main >> a >> b) (main >> a >> a));
68-
assert_equal false (may_create (main >> a >> b) (main >> b >> b));
67+
assert_equal false (may_create (main >> a >> b) (main >> a >> a)); (* infeasible for race: definitely_not_started requires (main >> a), where this must happen, to be must parent for (main >> a >> a), which it is not *)
68+
assert_equal false (may_create (main >> a >> b) (main >> b >> b)); (* infeasible for race: definitely_not_started requires (main >> a), where this must happen, to be must parent for (main >> b >> b), which it is not *)
6969

7070
(* unique creates non-unique and prefixes are incompatible *)
71-
assert_equal false (may_create (main >> a) (main >> b >> a >> a));
72-
assert_equal false (may_create (main >> a >> b) (main >> b >> a >> c >> c));
73-
assert_equal false (may_create (main >> a >> b) (main >> a >> c >> d >> d));
71+
assert_equal false (may_create (main >> a) (main >> b >> a >> a)); (* 53-races-mhp/05-not-created3 *)
72+
assert_equal false (may_create (main >> a >> b) (main >> b >> a >> c >> c)); (* infeasible for race: definitely_not_started requires (main >> a), where this must happen, to be must parent for (main >> b >> a >> c >> c), which it is not *)
73+
assert_equal false (may_create (main >> a >> b) (main >> a >> c >> d >> d)); (* 53-races-mhp/06-not-created4, also passes with simple may_create *)
7474

7575
(* non-unique creates non-unique: prefix must not lengthen *)
76-
assert_equal false (may_create (main >> a >> a) (main >> a >> b >> b));
77-
assert_equal false (may_create (main >> a >> a) (main >> b >> a >> a));
76+
assert_equal false (may_create (main >> a >> a) (main >> a >> b >> b)); (* infeasible for race: cannot create non-unique (main >> a >> a) before unique prefix-ed (main >> a >> b >> b) *)
77+
assert_equal false (may_create (main >> a >> a) (main >> b >> a >> a)); (* 53-races-mhp/07-not-created5 *)
7878
(* non-unique creates non-unique: prefix must be compatible *)
79-
assert_equal false (may_create (main >> a >> b >> c >> c) (main >> b >> a >> c >> c));
79+
assert_equal false (may_create (main >> a >> b >> c >> c) (main >> b >> a >> c >> c)); (* infeasible for race: definitely_not_started requires (main >> a >> b or main >> a >> b >> c), where this must happen, to be must parent for (main >> b >> a >> c >> c), which it is not *)
8080
(* non-unique creates non-unique: elements must not be removed *)
81-
assert_equal false (may_create (main >> a >> b >> b) (main >> a >> c >> c)); (* from set *)
82-
assert_equal false (may_create (main >> a >> b >> b) (main >> b >> b)); (* from prefix *)
81+
assert_equal false (may_create (main >> a >> b >> b) (main >> a >> c >> c)); (* from set *) (* 53-races-mhp/08-not-created6, also passes with simple may_create *)
82+
assert_equal false (may_create (main >> a >> b >> b) (main >> b >> b)); (* from prefix *) (* infeasible for race: definitely_not_started requires (main >> a or main >> a >> b), where this must happen, to be must parent for (main >> b >> b), which it is not *)
8383
(* non-unique creates non-unique: removed elements and set must be in new set *)
8484
(* assert_equal false (may_create (main >> a >> b >> c >> c) (main >> a >> c >> c)); *)
8585
(* TODO: cannot test due because by construction after prefix check? *)

0 commit comments

Comments
 (0)