diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2015-05-07 21:29:19 +1000 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2015-08-02 00:29:25 +1000 |
commit | e7c9d609f0c6bfb230f10bcd40a8ceee282deaa1 (patch) | |
tree | 9aaae9a38a97d7c3cb3b3bba1a0a6946a2e94f9d | |
parent | f3160af8e033d56f02c8fb188557e42fcdffcf7b (diff) |
aga: Testcase for attempt to run concurrent algorithms
The aga algorithms can't be run concurrently, because they store state
information in the aga_node structures. However, they are supposed to
detect an attempt to re-enter and safely report an error. This adds a
testcase for this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | ccan/aga/test/api-concurrent.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/ccan/aga/test/api-concurrent.c b/ccan/aga/test/api-concurrent.c new file mode 100644 index 00000000..19d0eab6 --- /dev/null +++ b/ccan/aga/test/api-concurrent.c @@ -0,0 +1,52 @@ +#include "config.h" + +#include <stddef.h> +#include <assert.h> + +#include <ccan/aga/aga.h> + +#include <ccan/tap/tap.h> + +#include "simple-graph.h" + + +#define NUM_ALGOS 2 + +#define check_one_inner(algo) \ + ok1(aga_##algo##_start(&tg.sg.g) == -1); + +#define check_all_inner() \ + do { \ + check_one_inner(dfs); \ + check_one_inner(bfs); \ + } while (0) + +#define check_one_outer(algo) \ + do { \ + ok1(aga_##algo##_start(&tg.sg.g) == 0); \ + check_all_inner(); \ + aga_finish(&tg.sg.g); \ + } while (0) + +#define check_all_outer() \ + do { \ + check_one_outer(dfs); \ + check_one_outer(bfs); \ + } while (0) + +int main(void) +{ + struct trivial_graph tg; + + if (NUM_ALGOS) + plan_tests(NUM_ALGOS + NUM_ALGOS * NUM_ALGOS); + else + plan_skip_all("Nothing to test"); + + trivial_graph_init(&tg); + + check_all_outer(); + + /* This exits depending on whether all tests passed */ + return exit_status(); +} |