aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/test.c
blob: 2ce2016f7871a2f26f92cd95f17c02c0ee073b44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-2.0
#include <src/combined_source.c>

int x;
int y;

int __unbuffered_tpr_x;
int __unbuffered_tpr_y;

DEFINE_SRCU(ss);

void rcu_reader(void)
{
	int idx;

#ifndef FORCE_FAILURE_3
	idx = srcu_read_lock(&ss);
#endif
	might_sleep();

	__unbuffered_tpr_y = READ_ONCE(y);
#ifdef FORCE_FAILURE
	srcu_read_unlock(&ss, idx);
	idx = srcu_read_lock(&ss);
#endif
	WRITE_ONCE(x, 1);

#ifndef FORCE_FAILURE_3
	srcu_read_unlock(&ss, idx);
#endif
	might_sleep();
}

void *thread_update(void *arg)
{
	WRITE_ONCE(y, 1);
#ifndef FORCE_FAILURE_2
	synchronize_srcu(&ss);
#endif
	might_sleep();
	__unbuffered_tpr_x = READ_ONCE(x);

	return NULL;
}

void *thread_process_reader(void *arg)
{
	rcu_reader();

	return NULL;
}

int main(int argc, char *argv[])
{
	pthread_t tu;
	pthread_t tpr;

	if (pthread_create(&tu, NULL, thread_update, NULL))
		abort();
	if (pthread_create(&tpr, NULL, thread_process_reader, NULL))
		abort();
	if (pthread_join(tu, NULL))
		abort();
	if (pthread_join(tpr, NULL))
		abort();
	assert(__unbuffered_tpr_y != 0 || __unbuffered_tpr_x != 0);

#ifdef ASSERT_END
	assert(0);
#endif

	return 0;
}