Skip to content

Commit c3ae41d

Browse files
committed
synch: add rwlock tests
Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent 6f29502 commit c3ae41d

34 files changed

+1247
-0
lines changed

tests/.hgignore

+33
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ test_nvl
3838
test_nvl_pack
3939
test_padding
4040
test_qstring
41+
test_rwlock-destroy-memcpy
42+
test_rwlock-destroy-null
43+
test_rwlock-destroy-rheld
44+
test_rwlock-destroy-wheld
45+
test_rwlock-destroy.core
46+
test_rwlock-init-null-both
47+
test_rwlock-init-null-class
48+
test_rwlock-init-null-lock
49+
test_rwlock-rlock-destroyed
50+
test_rwlock-rlock-held-class
51+
test_rwlock-rlock-held-multi-first
52+
test_rwlock-rlock-held-multi-second
53+
test_rwlock-rlock-held-multi-third
54+
test_rwlock-rlock-held-nesting
55+
test_rwlock-rlock-memcpy
56+
test_rwlock-rlock-null
57+
test_rwlock-rlock-rheld
58+
test_rwlock-rlock-wheld
59+
test_rwlock-unlock-.core
60+
test_rwlock-unlock-destroyed
61+
test_rwlock-unlock-memcpy
62+
test_rwlock-unlock-null
63+
test_rwlock-unlock-unheld
64+
test_rwlock-wlock-destroyed
65+
test_rwlock-wlock-held-class
66+
test_rwlock-wlock-held-multi-first
67+
test_rwlock-wlock-held-multi-second
68+
test_rwlock-wlock-held-multi-third
69+
test_rwlock-wlock-held-nesting
70+
test_rwlock-wlock-memcpy
71+
test_rwlock-wlock-null
72+
test_rwlock-wlock-rheld
73+
test_rwlock-wlock-wheld
4174
test_sexpr_parser
4275
test_sexpr_compact
4376
test_sexpr_eval

tests/CMakeLists.txt

+35
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,41 @@ build_test_bin_and_run(mutex-unlock-unheld)
6666
endif()
6767
build_test_bin_and_run(nvl)
6868
build_test_bin_and_run(padding)
69+
build_test_bin_and_run(rwlock-destroy-memcpy)
70+
build_test_bin_and_run(rwlock-destroy-null)
71+
build_test_bin_and_run(rwlock-init-null-both)
72+
build_test_bin_and_run(rwlock-init-null-class)
73+
build_test_bin_and_run(rwlock-init-null-lock)
74+
build_test_bin_and_run(rwlock-rlock-destroyed)
75+
build_test_bin_and_run(rwlock-rlock-held-class)
76+
build_test_bin_and_run(rwlock-rlock-held-nesting)
77+
build_test_bin_and_run(rwlock-rlock-memcpy)
78+
build_test_bin_and_run(rwlock-rlock-null)
79+
build_test_bin_and_run(rwlock-unlock-destroyed)
80+
build_test_bin_and_run(rwlock-unlock-memcpy)
81+
build_test_bin_and_run(rwlock-unlock-null)
82+
build_test_bin_and_run(rwlock-wlock-destroyed)
83+
build_test_bin_and_run(rwlock-wlock-held-class)
84+
build_test_bin_and_run(rwlock-wlock-held-nesting)
85+
build_test_bin_and_run(rwlock-wlock-memcpy)
86+
build_test_bin_and_run(rwlock-wlock-null)
87+
if(JEFFPC_LOCK_TRACKING)
88+
# NOTE: These tests rely on checks that are not performed when lock tracking
89+
# is disabled.
90+
build_test_bin_and_run(rwlock-destroy-rheld)
91+
build_test_bin_and_run(rwlock-destroy-wheld)
92+
build_test_bin_and_run(rwlock-rlock-rheld)
93+
build_test_bin_and_run(rwlock-rlock-wheld)
94+
build_test_bin_and_run(rwlock-rlock-held-multi-first)
95+
build_test_bin_and_run(rwlock-rlock-held-multi-second)
96+
build_test_bin_and_run(rwlock-rlock-held-multi-third)
97+
build_test_bin_and_run(rwlock-unlock-unheld)
98+
build_test_bin_and_run(rwlock-wlock-rheld)
99+
build_test_bin_and_run(rwlock-wlock-wheld)
100+
build_test_bin_and_run(rwlock-wlock-held-multi-first)
101+
build_test_bin_and_run(rwlock-wlock-held-multi-second)
102+
build_test_bin_and_run(rwlock-wlock-held-multi-third)
103+
endif()
69104
build_test_bin_and_run(sexpr_compact)
70105
build_test_bin_and_run(sexpr_eval)
71106
build_test_bin_and_run(sexpr_iter)

tests/test_rwlock-destroy-memcpy.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
LOCK_CLASS(lc);
30+
struct rwlock a;
31+
struct rwlock b;
32+
33+
RWINIT(&a, &lc);
34+
35+
b = a;
36+
37+
test_set_panic_string("lockdep: Aborting - bad rwlock magic");
38+
39+
RWDESTROY(&b);
40+
}

tests/test_rwlock-destroy-null.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
test_set_panic_string("lockdep: invalid call to RWDESTROY");
30+
31+
RWDESTROY(NULL);
32+
}

tests/test_rwlock-destroy-rheld.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
LOCK_CLASS(lc);
30+
struct rwlock a;
31+
32+
RWINIT(&a, &lc);
33+
RWLOCK(&a, false);
34+
35+
test_set_panic_string("lockdep: Aborting - destroying held rwlock");
36+
37+
RWDESTROY(&a);
38+
}

tests/test_rwlock-destroy-wheld.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
LOCK_CLASS(lc);
30+
struct rwlock a;
31+
32+
RWINIT(&a, &lc);
33+
RWLOCK(&a, true);
34+
35+
test_set_panic_string("lockdep: Aborting - destroying held rwlock");
36+
37+
RWDESTROY(&a);
38+
}

tests/test_rwlock-init-null-both.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
test_set_panic_string("lockdep: invalid call to RWINIT");
30+
31+
RWINIT(NULL, NULL);
32+
}

tests/test_rwlock-init-null-class.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
struct rwlock a;
30+
31+
test_set_panic_string("lockdep: invalid call to RWINIT");
32+
33+
RWINIT(&a, NULL);
34+
}

tests/test_rwlock-init-null-lock.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
void test(void)
28+
{
29+
LOCK_CLASS(c1);
30+
31+
test_set_panic_string("lockdep: invalid call to RWINIT");
32+
33+
RWINIT(NULL, &c1);
34+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2018-2019 Josef 'Jeff' Sipek <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include <jeffpc/synch.h>
24+
25+
#include "test.c"
26+
27+
static LOCK_CLASS(lc1);
28+
static LOCK_CLASS(lc2);
29+
static LOCK_CLASS(lc3);
30+
static struct rwlock a;
31+
static struct rwlock b;
32+
static struct rwlock c;
33+
34+
static void test_setup(bool wr)
35+
{
36+
RWINIT(&a, &lc1);
37+
RWINIT(&b, &lc2);
38+
RWINIT(&c, &lc3);
39+
RWLOCK(&a, wr);
40+
RWLOCK(&b, wr);
41+
RWLOCK(&c, wr);
42+
43+
test_set_panic_string("lockdep: Aborting - deadlock");
44+
}

0 commit comments

Comments
 (0)