summaryrefslogtreecommitdiff
path: root/libviengoos/t-rpc.c
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2008-12-17 13:11:52 +0100
committerNeal H. Walfield <neal@gnu.org>2008-12-17 13:11:52 +0100
commitca828476fdb64ad4615bc6f580c2a451e78fcc1c (patch)
tree320c2e89e34bbcd0ba82b64728f831b8536cc286 /libviengoos/t-rpc.c
parentf0d7e0e0ee0cb0362ee79739922a76faef17917c (diff)
Move viengoos header files to libviengoos.
/ 2008-12-17 Neal H. Walfield <neal@gnu.org> * libviengoos: New directory. * Makefile.am (SUBDIRS): Add libviengoos. * configure.ac: Include libviengoos/headers.m4. Generate libviengoos/Makefile. hurd/ 2008-12-17 Neal H. Walfield <neal@gnu.org> * activity.h: Move to ../libviengoos/viengoos. Update references. * addr-trans.h: Likewise. * addr.h: Likewise. * cap.h: Likewise. * folio.h: Likewise. * futex.h: Likewise. * ipc.h: Likewise. * message.h: Likewise. * messenger.h: Likewise. * rpc.h: Likewise. * thread.h: Move viengoos specific bits... * ../libviengoos/viengoos/thread.h: ... to this new file. * thread.h (struct hurd_utcb): New structure. * exceptions.h (hurd_utcb): Use a struct hurd_utcb *, not a struct vg_utcb *. Update users. (hurd_activation_state_alloc): Likewise. (hurd_activation_state_free): Likewise. (hurd_activation_handler_activated): Likewise. (hurd_activation_handler_normal): Likewise. * t-addr-trans.c: Move to ../libviengoos. * t-addr.c: Likewise. * t-rpc.c: Likewise. * Makefile.am (TESTS, check_PROGRAMS, t_addr_CPPFLAGS) (t_addr_SOURCES, t_addr_trans_CPPFLAGS, t_addr_trans_SOURCES) (t_rpc_CPPFLAGS, t_rpc_SOURCES): Move from this file... * ../libviengoos/Makefile.am. * Makefile.am (includehurd_HEADERS): Don't mention activity.h, addr-trans.h, addr.h, cap.h, folio.h, futex.h, ipc.h, message.h or messenger.h. * headers.m4: Don't create a link to hurd/addr.h, hurd/addr-trans.h, hurd/cap.h, hurd/folio.h, hurd/rpc.h, hurd/activity.h, hurd/futex.h, hurd/message.h, hurd/messenger.h or hurd/ipc.h. libviengoos/ 2008-12-17 Neal H. Walfield <neal@gnu.org> * Makefile.am: New file. * headers.m4: Likewise. * t-addr-trans.c: Move from ../hurd. * t-addr.c: Likewise. * t-rpc.c: Likewise. * viengoos.h: Likewise. * viengoos/activity.h: Likewise. * viengoos/addr-trans.h: Likewise. * viengoos/addr.h: Likewise. * viengoos/cap.h: Likewise. * viengoos/folio.h: Likewise. * viengoos/futex.h: Likewise. * viengoos/ipc.h: Likewise. * viengoos/message.h: Likewise. * viengoos/messenger.h: Likewise. * viengoos/rpc.h: Likewise. * viengoos/misc.h: Moved from ../viengoos/rm.h. * viengoos/thread.h: New file split from ../hurd/thread.h. libpthread/ 2008-12-17 Neal H. Walfield <neal@gnu.org> * Makefile.am: New file. * headers.m4: Likewise. * t-addr-trans.c: Move from ../hurd. * t-addr.c: Likewise. * t-rpc.c: Likewise. * viengoos.h: Likewise. * viengoos/activity.h: Likewise. * viengoos/addr-trans.h: Likewise. * viengoos/addr.h: Likewise. * viengoos/cap.h: Likewise. * viengoos/folio.h: Likewise. * viengoos/futex.h: Likewise. * viengoos/ipc.h: Likewise. * viengoos/message.h: Likewise. * viengoos/messenger.h: Likewise. * viengoos/rpc.h: Likewise. * viengoos/misc.h: Moved from ../viengoos/rm.h. * viengoos/thread.h: New file split from ../hurd/thread.h. viengoos/ 2008-12-17 Neal H. Walfield <neal@gnu.org> * rm.h: Move from here... * ../libviengoos/viengoos/misc.h: ... to here. Update users. * headers.m4: Don't link rm.h to hurd/rm.h. * Makefile.am (viengoos_SOURCES): Remove rm.h.
Diffstat (limited to 'libviengoos/t-rpc.c')
-rw-r--r--libviengoos/t-rpc.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/libviengoos/t-rpc.c b/libviengoos/t-rpc.c
new file mode 100644
index 0000000..0f40fe9
--- /dev/null
+++ b/libviengoos/t-rpc.c
@@ -0,0 +1,185 @@
+#include <stdbool.h>
+#include <stdint.h>
+#include <assert.h>
+
+char *program_name = "t-rpc";
+int output_debug = 1;
+
+#define RPC_STUB_PREFIX rpc
+#define RPC_ID_PREFIX RPC
+
+#include <viengoos/rpc.h>
+
+/* Exception message ids. */
+enum
+ {
+ RPC_noargs = 0x1ABE100,
+ RPC_onein,
+ RPC_oneout,
+ RPC_onlyin,
+ RPC_onlyout,
+ RPC_mix,
+ RPC_caps,
+ };
+
+struct foo
+{
+ int a;
+ char b;
+};
+
+RPC(noargs, 0, 0, 0)
+RPC(onein, 1, 0, 0, uint32_t, arg)
+RPC(oneout, 0, 1, 0, uint32_t, arg)
+RPC(onlyin, 4, 0, 0, uint32_t, arg, uint32_t, idx, struct foo, foo, bool, p)
+RPC(onlyout, 0, 4, 0, uint32_t, arg, uint32_t, idx, struct foo, foo, bool, p)
+RPC(mix, 2, 3, 0, uint32_t, arg, uint32_t, idx,
+ struct foo, foo, bool, p, int, i)
+RPC(caps, 3, 2, 2,
+ /* In: */
+ int, i, cap_t, c, struct foo, foo,
+ /* Out: */
+ int, a, int, b, cap_t, x, cap_t, y)
+
+#undef RPC_STUB_PREFIX
+#undef RPC_ID_PREFIX
+
+int
+main (int argc, char *argv[])
+{
+ printf ("Checking RPC... ");
+
+ error_t err;
+ struct vg_message *msg;
+
+
+#define REPLY ADDR (0x1000, ADDR_BITS - 12)
+ addr_t reply = REPLY;
+
+ msg = malloc (sizeof (*msg));
+ rpc_noargs_send_marshal (msg, REPLY);
+ err = rpc_noargs_send_unmarshal (msg, &reply);
+ assert (! err);
+ assert (ADDR_EQ (reply, REPLY));
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_noargs_reply_marshal (msg);
+ err = rpc_noargs_reply_unmarshal (msg);
+ assert (err == 0);
+ free (msg);
+
+
+ msg = malloc (sizeof (*msg));
+#define VALUE 0xfde8963a
+ uint32_t arg = VALUE;
+ uint32_t arg_out;
+
+ rpc_onein_send_marshal (msg, arg, REPLY);
+ err = rpc_onein_send_unmarshal (msg, &arg_out, &reply);
+ assert (! err);
+ assert (arg_out == VALUE);
+ assert (ADDR_EQ (reply, REPLY));
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_onein_reply_marshal (msg);
+ err = rpc_onein_reply_unmarshal (msg);
+ assert (! err);
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_oneout_send_marshal (msg, REPLY);
+ err = rpc_oneout_send_unmarshal (msg, &reply);
+ assert (! err);
+ assert (ADDR_EQ (reply, REPLY));
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_oneout_reply_marshal (msg, arg);
+ err = rpc_oneout_reply_unmarshal (msg, &arg_out);
+ assert (! err);
+ assert (arg_out == VALUE);
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+
+ struct foo foo;
+ foo.a = 1 << 31;
+ foo.b = 'l';
+ uint32_t idx_out;
+ struct foo foo_out;
+ bool p_out;
+
+ rpc_onlyin_send_marshal (msg, 0x1234567, 0xABC, foo, true, REPLY);
+ err = rpc_onlyin_send_unmarshal (msg, &arg_out, &idx_out, &foo_out, &p_out,
+ &reply);
+ assert (! err);
+ assert (arg_out == 0x1234567);
+ assert (idx_out == 0xABC);
+ assert (foo_out.a == foo.a);
+ assert (foo_out.b == foo.b);
+ assert (p_out == true);
+ assert (ADDR_EQ (reply, REPLY));
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_onlyin_reply_marshal (msg);
+ err = rpc_onlyin_reply_unmarshal (msg);
+ assert (! err);
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_onlyout_send_marshal (msg, REPLY);
+ err = rpc_onlyout_send_unmarshal (msg, &reply);
+ assert (! err);
+ assert (ADDR_EQ (reply, REPLY));
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_onlyout_reply_marshal (msg, 0x1234567, 321, foo, true);
+ err = rpc_onlyout_reply_unmarshal (msg, &arg_out, &idx_out,
+ &foo_out, &p_out);
+ assert (! err);
+ assert (arg_out == 0x1234567);
+ assert (idx_out == 321);
+ assert (foo_out.a == foo.a);
+ assert (foo_out.b == foo.b);
+ assert (p_out == true);
+ free (msg);
+
+
+ msg = malloc (sizeof (*msg));
+ rpc_mix_send_marshal (msg, arg, 456789, REPLY);
+ err = rpc_mix_send_unmarshal (msg, &arg_out, &idx_out, &reply);
+ assert (! err);
+ assert (arg_out == arg);
+ assert (idx_out == 456789);
+ assert (ADDR_EQ (reply, REPLY));
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ int i_out = 0;
+ rpc_mix_reply_marshal (msg, foo, false, 4200042);
+ err = rpc_mix_reply_unmarshal (msg, &foo_out, &p_out, &i_out);
+ assert (! err);
+ assert (foo_out.a == foo.a);
+ assert (foo_out.b == foo.b);
+ assert (p_out == false);
+ assert (i_out == 4200042);
+ free (msg);
+
+ msg = malloc (sizeof (*msg));
+ rpc_caps_send_marshal (msg, 54, ADDR (1, ADDR_BITS), foo, REPLY);
+ addr_t addr;
+ err = rpc_caps_send_unmarshal (msg, &i_out, &addr, &foo_out, &reply);
+ assert (! err);
+ assert (i_out == 54);
+ assert (ADDR_EQ (addr, ADDR (1, ADDR_BITS)));
+ assert (foo_out.a == foo.a);
+ assert (foo_out.b == foo.b);
+ free (msg);
+
+ printf ("ok\n");
+ return 0;
+}