The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
remote_msg_map_test.c
Go to the documentation of this file.
1 
9 #include <test.h>
10 #include <test_rng.h>
11 
13 
14 #include <memory.h>
15 #include <stdatomic.h>
16 #include <stdint.h>
17 #include <stdlib.h>
18 
19 #define THREAD_CNT 2
20 #define MSG_COUNT 1000000
21 
22 static atomic_uint insert_calls;
23 
24 void msg_queue_insert(struct lp_msg *msg)
25 {
26  (void)msg;
27  if (!msg)
28  abort();
29  if(atomic_load_explicit(&msg->flags, memory_order_acquire) ==
30  (MSG_FLAG_ANTI | MSG_FLAG_PROCESSED)){
31  atomic_fetch_add_explicit(&insert_calls, 1U, memory_order_relaxed);
32  }
33 }
34 
35 static int remote_msg_map_test(void)
36 {
37  struct lp_msg *msgs = malloc(sizeof(*msgs) * MSG_COUNT);
38  memset(msgs, 0, sizeof(*msgs) * MSG_COUNT);
39 
40  for (uint64_t i = 0; i < MSG_COUNT; ++i) {
41  if(i % 3)
42  continue;
43  atomic_store_explicit(&msgs[i].flags, MSG_FLAG_PROCESSED,
44  memory_order_release);
45  }
46 
48 
49  for (uint64_t i = 0; i < MSG_COUNT; ++i) {
50  remote_msg_map_match(msg_id_get(&msgs[i], i & 1U), rid,
51  (i & 1U) ? &msgs[i] : NULL);
52  }
53 
54  for (uint64_t i = 0; i < MSG_COUNT; ++i) {
55  remote_msg_map_match(msg_id_get(&msgs[i], i & 1U) + 1, rid,
56  (i & 1U) ? NULL : &msgs[i]);
57  }
58 
60 
61  int ret = 0;
62  for(uint64_t i = 0; i < MSG_COUNT; ++i){
63  ret -= !(atomic_load_explicit(&msgs[i].flags,
64  memory_order_acquire) & MSG_FLAG_ANTI);
65  }
66  ret -= insert_calls != ((MSG_COUNT - 1) / 3 + 1) * THREAD_CNT;
67 
68  free(msgs);
69  return ret;
70 }
71 
72 static int remote_msg_map_test_init(void)
73 {
74  remote_msg_map_global_init();
75  return 0;
76 }
77 
78 static int remote_msg_map_test_fini(void)
79 {
80  remote_msg_map_global_fini();
81  return 0;
82 }
83 
84 const struct test_config test_config = {
85  .threads_count = THREAD_CNT,
86  .test_init_fnc = remote_msg_map_test_init,
87  .test_fini_fnc = remote_msg_map_test_fini,
88  .test_fnc = remote_msg_map_test
89 };
lp_msg::flags
atomic_int flags
The flags to handle local anti messages.
Definition: msg.h:49
lp_msg
A model simulation message.
Definition: msg.h:34
msg_queue_insert
void msg_queue_insert(struct lp_msg *msg)
Inserts a message in the queue.
Definition: remote_msg_map_test.c:24
test_config
A complete test configuration.
Definition: test.h:22
test_thread_barrier
bool test_thread_barrier(void)
Synchronizes threads on a barrier.
Definition: test.c:200
rid
__thread rid_t rid
The identifier of the thread.
Definition: core.c:16
test.h
Test framework header.
remote_msg_map.h
Message map datatype.
test_config::threads_count
unsigned threads_count
test_fnc is executed with that many cores
Definition: test.h:33
test_rng.h
Pseudo random number generator for tests.