test506: verify aa68848451

After the fixed cookie lock deadlock, this test now passes and it
detects double-locking and double-unlocking of mutexes.
This commit is contained in:
Daniel Stenberg
2014-07-16 00:09:58 +02:00
parent aa68848451
commit 4cb2521595
2 changed files with 41 additions and 17 deletions

View File

@@ -156,33 +156,31 @@ unlock: share [Pigs in space]: 53
CURLOPT_COOKIEJAR CURLOPT_COOKIEJAR
CURLOPT_COOKIELIST FLUSH CURLOPT_COOKIELIST FLUSH
lock: cookie [Pigs in space]: 54 lock: cookie [Pigs in space]: 54
lock: cookie [Pigs in space]: 55 unlock: cookie [Pigs in space]: 55
unlock: cookie [Pigs in space]: 56
unlock: cookie [Pigs in space]: 57
PERFORM PERFORM
lock: dns [Pigs in space]: 58 lock: dns [Pigs in space]: 56
unlock: dns [Pigs in space]: 59 unlock: dns [Pigs in space]: 57
lock: cookie [Pigs in space]: 58
unlock: cookie [Pigs in space]: 59
lock: cookie [Pigs in space]: 60 lock: cookie [Pigs in space]: 60
unlock: cookie [Pigs in space]: 61 unlock: cookie [Pigs in space]: 61
lock: cookie [Pigs in space]: 62 lock: cookie [Pigs in space]: 62
unlock: cookie [Pigs in space]: 63 unlock: cookie [Pigs in space]: 63
lock: cookie [Pigs in space]: 64
unlock: cookie [Pigs in space]: 65
run 3: overwrite cookie 1 and 4 run 3: overwrite cookie 1 and 4
lock: dns [Pigs in space]: 66 lock: dns [Pigs in space]: 64
unlock: dns [Pigs in space]: 67 unlock: dns [Pigs in space]: 65
try SHARE_CLEANUP... try SHARE_CLEANUP...
lock: share [Pigs in space]: 68 lock: share [Pigs in space]: 66
unlock: share [Pigs in space]: 69 unlock: share [Pigs in space]: 67
SHARE_CLEANUP failed, correct SHARE_CLEANUP failed, correct
CLEANUP CLEANUP
lock: cookie [Pigs in space]: 70 lock: cookie [Pigs in space]: 68
unlock: cookie [Pigs in space]: 71 unlock: cookie [Pigs in space]: 69
lock: share [Pigs in space]: 70
unlock: share [Pigs in space]: 71
SHARE_CLEANUP
lock: share [Pigs in space]: 72 lock: share [Pigs in space]: 72
unlock: share [Pigs in space]: 73 unlock: share [Pigs in space]: 73
SHARE_CLEANUP
lock: share [Pigs in space]: 74
unlock: share [Pigs in space]: 75
GLOBAL_CLEANUP GLOBAL_CLEANUP
</stdout> </stdout>
<stderr> <stderr>

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -40,12 +40,15 @@ struct userdata {
int counter; int counter;
}; };
int lock[3];
/* lock callback */ /* lock callback */
static void my_lock(CURL *handle, curl_lock_data data, curl_lock_access laccess, static void my_lock(CURL *handle, curl_lock_data data, curl_lock_access laccess,
void *useptr ) void *useptr )
{ {
const char *what; const char *what;
struct userdata *user = (struct userdata *)useptr; struct userdata *user = (struct userdata *)useptr;
int locknum;
(void)handle; (void)handle;
(void)laccess; (void)laccess;
@@ -53,17 +56,28 @@ static void my_lock(CURL *handle, curl_lock_data data, curl_lock_access laccess,
switch ( data ) { switch ( data ) {
case CURL_LOCK_DATA_SHARE: case CURL_LOCK_DATA_SHARE:
what = "share"; what = "share";
locknum = 0;
break; break;
case CURL_LOCK_DATA_DNS: case CURL_LOCK_DATA_DNS:
what = "dns"; what = "dns";
locknum = 1;
break; break;
case CURL_LOCK_DATA_COOKIE: case CURL_LOCK_DATA_COOKIE:
what = "cookie"; what = "cookie";
locknum = 2;
break; break;
default: default:
fprintf(stderr, "lock: no such data: %d\n", (int)data); fprintf(stderr, "lock: no such data: %d\n", (int)data);
return; return;
} }
/* detect locking of locked locks */
if(lock[locknum]) {
printf("lock: double locked %s\n", what);
return;
}
lock[locknum]++;
printf("lock: %-6s [%s]: %d\n", what, user->text, user->counter); printf("lock: %-6s [%s]: %d\n", what, user->text, user->counter);
user->counter++; user->counter++;
} }
@@ -73,21 +87,33 @@ static void my_unlock(CURL *handle, curl_lock_data data, void *useptr )
{ {
const char *what; const char *what;
struct userdata *user = (struct userdata *)useptr; struct userdata *user = (struct userdata *)useptr;
int locknum;
(void)handle; (void)handle;
switch ( data ) { switch ( data ) {
case CURL_LOCK_DATA_SHARE: case CURL_LOCK_DATA_SHARE:
what = "share"; what = "share";
locknum = 0;
break; break;
case CURL_LOCK_DATA_DNS: case CURL_LOCK_DATA_DNS:
what = "dns"; what = "dns";
locknum = 1;
break; break;
case CURL_LOCK_DATA_COOKIE: case CURL_LOCK_DATA_COOKIE:
what = "cookie"; what = "cookie";
locknum = 2;
break; break;
default: default:
fprintf(stderr, "unlock: no such data: %d\n", (int)data); fprintf(stderr, "unlock: no such data: %d\n", (int)data);
return; return;
} }
/* detect unlocking of unlocked locks */
if(!lock[locknum]) {
printf("unlock: double unlocked %s\n", what);
return;
}
lock[locknum]--;
printf("unlock: %-6s [%s]: %d\n", what, user->text, user->counter); printf("unlock: %-6s [%s]: %d\n", what, user->text, user->counter);
user->counter++; user->counter++;
} }