1/**
2 * \file
3 * \brief Test termination of spannign
4 */
5
6/*
7 * Copyright (c) 2016, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitatsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <stdio.h>
16#include <barrelfish/barrelfish.h>
17
18/**
19 * @brief callback when domain is spanned.
20 *
21 * @param arg supplied arguemtn
22 * @param err outcome of the error
23 */
24static void domain_init_done(void *arg, errval_t err)
25{
26    debug_printf("domain_init_done t:%p\n", thread_self());
27}
28
29static int start_thread(void *a)
30{
31    debug_printf("start_thread t:%p\n", thread_self());
32    return 0;
33}
34
35int main(int argc, char **argv)
36{
37    errval_t err;
38    debug_printf("program started. Main thread is t:%p\n", thread_self());
39
40    uint64_t num_threads = 2;
41    if (argc == 2) {
42        num_threads = strtol(argv[1], NULL, 10);
43    }
44    debug_printf("Spanning domain to %" PRIu64 " cores\n", num_threads);
45
46    for (uint64_t i=1; i<num_threads; i++) {
47        coreid_t core = i;
48        debug_printf("Spanning domain (%03" PRIuCOREID "/%03" PRIu64 ")\n", core,
49                     num_threads);
50        err = domain_new_dispatcher(core, domain_init_done, NULL);
51        if (err_is_fail(err)) {
52            USER_PANIC("FAILURE: Domain span\n");
53        }
54    }
55
56    for (uint64_t i=1; i<num_threads; i++) {
57        coreid_t core = i;
58        debug_printf("Starting thread on dispatcher (%03" PRIuCOREID "/%03" PRIu64 ")\n",
59                     core, num_threads);
60        err = domain_thread_create_on(core, start_thread, NULL, NULL);
61        if (err_is_fail(err)) {
62            USER_PANIC("FAILURE: Thread Create\n");
63        }
64        assert(err_is_ok(err));
65    }
66
67    printf("\nSPAN_TEST_DONE.\n");
68}
69