source: mainline/uspace/lib/c/test/loc.c@ 7d7f5e3

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7d7f5e3 was 7d7f5e3, checked in by Jiri Svoboda <jiri@…>, 22 months ago

loc_server_register() should be callable more than once (implementation)

We create a new session for each loc_server_register() / loc_srv_t
object. Alternatively we could multiplex all to a single connection
and then demultiplex them in the server, but this seemed simpler
at the moment.

We add a test case to libc test suite.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2023 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <errno.h>
30#include <loc.h>
31#include <pcut/pcut.h>
32
33PCUT_INIT;
34
35PCUT_TEST_SUITE(loc);
36
37/** loc_server_register() can be called multiple times */
38PCUT_TEST(server_register)
39{
40 errno_t rc;
41 loc_srv_t *sa, *sb;
42 service_id_t svca, svcb;
43 char *na, *nb;
44 char *sna, *snb;
45
46 rc = loc_server_register("test-a", &sa);
47 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
48
49 rc = loc_server_register("test-b", &sb);
50 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
51
52 // XXX Without a unique name this is not reentrant
53 rc = loc_service_register(sa, "test/libc-service-a", &svca);
54 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
55
56 // XXX Without a unique name this is not reentrant
57 rc = loc_service_register(sb, "test/libc-service-b", &svcb);
58 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
59
60 rc = loc_service_get_name(svca, &na);
61 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
62 PCUT_ASSERT_STR_EQUALS("test/libc-service-a", na);
63
64 rc = loc_service_get_server_name(svca, &sna);
65 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
66 PCUT_ASSERT_STR_EQUALS("test-a", sna);
67
68 rc = loc_service_get_name(svcb, &nb);
69 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
70 PCUT_ASSERT_STR_EQUALS("test/libc-service-b", nb);
71
72 rc = loc_service_get_server_name(svcb, &snb);
73 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
74 PCUT_ASSERT_STR_EQUALS("test-b", snb);
75
76 rc = loc_service_unregister(sa, svca);
77 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
78 rc = loc_service_unregister(sb, svcb);
79 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
80
81 loc_server_unregister(sa);
82 loc_server_unregister(sb);
83}
84
85PCUT_EXPORT(loc);
Note: See TracBrowser for help on using the repository browser.