-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some setjump/longjump test for race detection
- Loading branch information
1 parent
eb48502
commit fb7159c
Showing
4 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// PARAM: --enable ana.int.interval | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <setjmp.h> | ||
#include <goblint.h> | ||
#include <pthread.h> | ||
|
||
jmp_buf env_buffer; | ||
int global = 0; | ||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_fun(void *arg) { | ||
pthread_mutex_lock(&mutex1); | ||
global = 3; // NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
return NULL; | ||
} | ||
|
||
int bar() { | ||
pthread_mutex_lock(&mutex1); | ||
longjmp(env_buffer, 2); | ||
pthread_mutex_unlock(&mutex1); | ||
return 8; | ||
} | ||
|
||
int main() { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
|
||
if(!setjmp( env_buffer )) { | ||
bar(); | ||
} | ||
|
||
global = 5; // NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// PARAM: --enable ana.int.interval | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <setjmp.h> | ||
#include <goblint.h> | ||
#include <pthread.h> | ||
|
||
jmp_buf env_buffer; | ||
int global = 0; | ||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_fun(void *arg) { | ||
pthread_mutex_lock(&mutex1); | ||
global = 3; // NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
return NULL; | ||
} | ||
|
||
int bar() { | ||
pthread_mutex_lock(&mutex1); | ||
if(global ==3) { | ||
longjmp(env_buffer, 2); | ||
} | ||
return 8; | ||
} | ||
|
||
int main() { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
|
||
if(!setjmp( env_buffer )) { | ||
bar(); | ||
} | ||
|
||
global = 5; // NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// PARAM: --enable ana.int.interval | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <setjmp.h> | ||
#include <goblint.h> | ||
#include <pthread.h> | ||
|
||
jmp_buf env_buffer; | ||
int global = 0; | ||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_fun(void *arg) { | ||
pthread_mutex_lock(&mutex1); | ||
global = 3; // RACE | ||
pthread_mutex_unlock(&mutex1); | ||
return NULL; | ||
} | ||
|
||
int bar() { | ||
pthread_mutex_lock(&mutex1); | ||
if(global == 3) { | ||
longjmp(env_buffer, 2); | ||
} else { | ||
longjmp(env_buffer, 4); | ||
} | ||
return 8; | ||
} | ||
|
||
int main() { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
int n = 0; | ||
|
||
switch(setjmp( env_buffer )) { | ||
case 0: | ||
bar(); | ||
break; | ||
case 2: | ||
n=1; | ||
pthread_mutex_unlock(&mutex1); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
global = 5; //RACE | ||
|
||
if(n == 0) { | ||
pthread_mutex_unlock(&mutex1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// PARAM: --enable ana.int.interval | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <setjmp.h> | ||
#include <goblint.h> | ||
#include <pthread.h> | ||
|
||
jmp_buf env_buffer; | ||
int global = 0; | ||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_fun(void *arg) { | ||
pthread_mutex_lock(&mutex1); | ||
global = 3; //NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
return NULL; | ||
} | ||
|
||
int bar() { | ||
pthread_mutex_lock(&mutex1); | ||
if(global == 7) { | ||
longjmp(env_buffer, 2); | ||
} else { | ||
longjmp(env_buffer, 4); | ||
} | ||
return 8; | ||
} | ||
|
||
int main() { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
int n = 0; | ||
|
||
switch(setjmp( env_buffer )) { | ||
case 0: | ||
bar(); | ||
break; | ||
case 2: | ||
n=1; | ||
pthread_mutex_unlock(&mutex1); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
global = 5; //NORACE | ||
|
||
if(n == 0) { | ||
pthread_mutex_unlock(&mutex1); | ||
} | ||
} |