diff options
author | Maarten Lankhorst <maarten.lankhorst@canonical.com> | 2013-06-20 07:31:30 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2013-06-26 06:10:57 -0400 |
commit | 2fe3d4b149ccebbb384062fbbe6634439f2bf120 (patch) | |
tree | cc868c534a58bc75f8704d11d9a845a50fe85c17 /lib | |
parent | 1de994452f44005e4b1f5c6c77eae4a26f86d484 (diff) |
mutex: Add more tests to lib/locking-selftest.c
None of the ww_mutex codepaths should be taken in the 'normal'
mutex calls. The easiest way to verify this is by using the
normal mutex calls, and making sure o.ctx is unmodified.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: dri-devel@lists.freedesktop.org
Cc: linaro-mm-sig@lists.linaro.org
Cc: robclark@gmail.com
Cc: rostedt@goodmis.org
Cc: daniel@ffwll.ch
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20130620113130.4001.45423.stgit@patser
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/locking-selftest.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index 996226224bcf..37faefdbb678 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c | |||
@@ -1162,6 +1162,67 @@ static void ww_test_fail_acquire(void) | |||
1162 | #endif | 1162 | #endif |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | static void ww_test_normal(void) | ||
1166 | { | ||
1167 | int ret; | ||
1168 | |||
1169 | WWAI(&t); | ||
1170 | |||
1171 | /* | ||
1172 | * None of the ww_mutex codepaths should be taken in the 'normal' | ||
1173 | * mutex calls. The easiest way to verify this is by using the | ||
1174 | * normal mutex calls, and making sure o.ctx is unmodified. | ||
1175 | */ | ||
1176 | |||
1177 | /* mutex_lock (and indirectly, mutex_lock_nested) */ | ||
1178 | o.ctx = (void *)~0UL; | ||
1179 | mutex_lock(&o.base); | ||
1180 | mutex_unlock(&o.base); | ||
1181 | WARN_ON(o.ctx != (void *)~0UL); | ||
1182 | |||
1183 | /* mutex_lock_interruptible (and *_nested) */ | ||
1184 | o.ctx = (void *)~0UL; | ||
1185 | ret = mutex_lock_interruptible(&o.base); | ||
1186 | if (!ret) | ||
1187 | mutex_unlock(&o.base); | ||
1188 | else | ||
1189 | WARN_ON(1); | ||
1190 | WARN_ON(o.ctx != (void *)~0UL); | ||
1191 | |||
1192 | /* mutex_lock_killable (and *_nested) */ | ||
1193 | o.ctx = (void *)~0UL; | ||
1194 | ret = mutex_lock_killable(&o.base); | ||
1195 | if (!ret) | ||
1196 | mutex_unlock(&o.base); | ||
1197 | else | ||
1198 | WARN_ON(1); | ||
1199 | WARN_ON(o.ctx != (void *)~0UL); | ||
1200 | |||
1201 | /* trylock, succeeding */ | ||
1202 | o.ctx = (void *)~0UL; | ||
1203 | ret = mutex_trylock(&o.base); | ||
1204 | WARN_ON(!ret); | ||
1205 | if (ret) | ||
1206 | mutex_unlock(&o.base); | ||
1207 | else | ||
1208 | WARN_ON(1); | ||
1209 | WARN_ON(o.ctx != (void *)~0UL); | ||
1210 | |||
1211 | /* trylock, failing */ | ||
1212 | o.ctx = (void *)~0UL; | ||
1213 | mutex_lock(&o.base); | ||
1214 | ret = mutex_trylock(&o.base); | ||
1215 | WARN_ON(ret); | ||
1216 | mutex_unlock(&o.base); | ||
1217 | WARN_ON(o.ctx != (void *)~0UL); | ||
1218 | |||
1219 | /* nest_lock */ | ||
1220 | o.ctx = (void *)~0UL; | ||
1221 | mutex_lock_nest_lock(&o.base, &t); | ||
1222 | mutex_unlock(&o.base); | ||
1223 | WARN_ON(o.ctx != (void *)~0UL); | ||
1224 | } | ||
1225 | |||
1165 | static void ww_test_two_contexts(void) | 1226 | static void ww_test_two_contexts(void) |
1166 | { | 1227 | { |
1167 | WWAI(&t); | 1228 | WWAI(&t); |
@@ -1415,6 +1476,7 @@ static void ww_tests(void) | |||
1415 | 1476 | ||
1416 | print_testname("ww api failures"); | 1477 | print_testname("ww api failures"); |
1417 | dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW); | 1478 | dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW); |
1479 | dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW); | ||
1418 | dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW); | 1480 | dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW); |
1419 | printk("\n"); | 1481 | printk("\n"); |
1420 | 1482 | ||