1/*
2 * Copyright (c) 2007-12 ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
13
14#include <barrelfish/barrelfish.h>
15#include <barrelfish/dispatch.h>
16#include <barrelfish/ump_chan.h>
17
18#include <xeon_phi/xeon_phi.h>
19#include <xeon_phi/xeon_phi_domain.h>
20
21#define EXPECT_SUCCESS(err, msg) if(err_is_fail(err)) {USER_PANIC_ERR(err, msg); }
22#define EXPECT_EQUAL(res, exp) if ((res) != (exp)) {USER_PANIC("results dont match: expected: %lx, was: %lx", (exp), (res));}
23
24static void do_test(xphi_dom_id_t expected_result, coreid_t core)
25{
26    errval_t err;
27    xphi_dom_id_t result;
28
29#ifdef __k1om__
30    char *iface = xeon_phi_domain_build_iface("ns_test_iface", disp_xeon_phi_id(),
31                                              core);
32#else
33    char *iface = xeon_phi_domain_build_iface("ns_test_iface", XEON_PHI_DOMAIN_HOST,
34                                              core);
35#endif
36
37    debug_printf("Exact lookup: {%s}\n", iface);
38    err = xeon_phi_domain_lookup(iface, &result);
39    EXPECT_SUCCESS(err, "lookup exact");
40    EXPECT_EQUAL(result, expected_result);
41    free(iface);
42
43#ifdef __k1om__
44    iface = xeon_phi_domain_build_iface("ns_test_iface", disp_xeon_phi_id(),
45                                              XEON_PHI_DOMAIN_DONT_CARE);
46#else
47    iface = xeon_phi_domain_build_iface("ns_test_iface", XEON_PHI_DOMAIN_HOST,
48                                              XEON_PHI_DOMAIN_DONT_CARE);
49#endif
50    debug_printf("Core don't care lookup {%s}\n", iface);
51    err = xeon_phi_domain_lookup(iface, &result);
52    EXPECT_SUCCESS(err, "Core don't care lookup");
53    EXPECT_EQUAL(result, expected_result);
54
55    iface = xeon_phi_domain_build_iface("ns_test_iface", XEON_PHI_DOMAIN_DONT_CARE,
56                                        core);
57    debug_printf("Domain don't care lookup: {%s}\n", iface);
58    err = xeon_phi_domain_lookup(iface, &result);
59    EXPECT_SUCCESS(err, "lookup don't care domain");
60    EXPECT_EQUAL(result, expected_result);
61    free(iface);
62
63    iface = xeon_phi_domain_build_iface("ns_test_iface", XEON_PHI_DOMAIN_DONT_CARE,
64                                XEON_PHI_DOMAIN_DONT_CARE);
65    debug_printf("All don't care lookup: {%s}\n", iface);
66    err = xeon_phi_domain_lookup(iface, &result);
67    EXPECT_SUCCESS(err, "All don't care lookup:");
68    EXPECT_EQUAL(result, expected_result);
69    free(iface);
70}
71
72int main(int argc,
73         char **argv)
74{
75    errval_t err;
76
77    debug_printf("Xeon Phi Name Service Test started.\n");
78
79#ifdef __k1om__
80    char *iface = xeon_phi_domain_build_iface("ns_test_iface", disp_xeon_phi_id(),
81                                              disp_get_core_id());
82#else
83    char *iface = xeon_phi_domain_build_iface("ns_test_iface", XEON_PHI_DOMAIN_HOST,
84                    disp_get_core_id());
85#endif
86    debug_printf("registering: {%s} with 0xcafebabe\n", iface);
87
88    err = xeon_phi_domain_register(iface, 0xcafebabe);
89    assert(err_is_ok(err));
90    free(iface);
91
92    do_test(0xcafebabe, disp_get_core_id());
93
94#ifdef __k1om__
95    iface = xeon_phi_domain_build_iface("ns_test_iface", disp_xeon_phi_id(),
96                                              disp_get_core_id()+1);
97#else
98    iface = xeon_phi_domain_build_iface("ns_test_iface", XEON_PHI_DOMAIN_HOST,
99                                              disp_get_core_id()+1);
100#endif
101    debug_printf("registering: {%s} with 0xdeadbeef\n", iface);
102    err = xeon_phi_domain_register(iface, 0xdeadbeef);
103    assert(err_is_ok(err));
104    free(iface);
105
106    debug_printf("XXX: domain and all dont't care are expected to fail\n");
107    do_test(0xdeadbeef, disp_get_core_id()+1);
108}
109
110