c-template
wait_group_test.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <stdatomic.h>
4
#include <pthread.h>
5
#include <unistd.h>
6
#include <assert.h>
7
#include <stdarg.h>
8
#include <stddef.h>
9
#include <setjmp.h>
10
#include <cmocka.h>
11
#include "../../include/sync/wait_group.h"
12
13
#pragma GCC diagnostic ignored "-Wunused-parameter"
14
void
test_wait_group
(
void
**state) {
15
wait_group_t
*wg =
wait_group_new
();
16
wait_group_add
(wg, 1);
17
assert(wg->
active_processes
== 1);
18
wait_group_add
(wg, 2);
19
assert(wg->
active_processes
== 3);
20
wait_group_done
(wg);
21
assert(wg->
active_processes
== 2);
22
wait_group_done
(wg);
23
assert(wg->
active_processes
== 1);
24
wait_group_done
(wg);
25
assert(wg->
active_processes
== 0);
26
wait_group_wait
(wg);
27
int
rc =
wait_group_done
(wg);
28
assert(rc == -1);
29
}
30
31
int
main
(
void
) {
32
const
struct
CMUnitTest tests[] = {
33
cmocka_unit_test(
test_wait_group
),
34
};
35
return
cmocka_run_group_tests(tests, NULL, NULL);
36
}
wait_group_t::active_processes
int active_processes
Definition:
wait_group.h:22
wait_group_done
int wait_group_done(wait_group_t *wg)
used by a process to indicate it is done, decreasing the active process counter we include a return c...
Definition:
wait_group.c:70
wait_group_wait
void wait_group_wait(wait_group_t *wg)
used to wait until current active_processes reaches 0, polling every 0.75 seconds will run free on th...
Definition:
wait_group.c:45
main
int main(void)
Definition:
wait_group_test.c:31
wait_group_t
Definition:
wait_group.h:21
wait_group_add
void wait_group_add(wait_group_t *wg, int count)
incremements the total number of active processes managed by this wait group
Definition:
wait_group.c:64
test_wait_group
void test_wait_group(void **state)
Definition:
wait_group_test.c:14
wait_group_new
wait_group_t * wait_group_new()
returns a new and initialized wait_group_t pointer
Definition:
wait_group.c:9
src
sync
wait_group_test.c
Generated by
1.8.17