summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/host/test
diff options
context:
space:
mode:
Diffstat (limited to 'digital/avr/modules/host/test')
-rw-r--r--digital/avr/modules/host/test/Makefile3
-rw-r--r--digital/avr/modules/host/test/test_mex.c106
-rw-r--r--digital/avr/modules/host/test/test_mex.py25
3 files changed, 133 insertions, 1 deletions
diff --git a/digital/avr/modules/host/test/Makefile b/digital/avr/modules/host/test/Makefile
index 5f8343c4..aca134a5 100644
--- a/digital/avr/modules/host/test/Makefile
+++ b/digital/avr/modules/host/test/Makefile
@@ -1,6 +1,7 @@
BASE = ../../..
-HOST_PROGS = test_host
+HOST_PROGS = test_host test_mex
test_host_SOURCES = test_host.c
+test_mex_SOURCES = test_mex.c
MODULES = host
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
diff --git a/digital/avr/modules/host/test/test_mex.c b/digital/avr/modules/host/test/test_mex.c
new file mode 100644
index 00000000..1e5d303e
--- /dev/null
+++ b/digital/avr/modules/host/test/test_mex.c
@@ -0,0 +1,106 @@
+/* test_mex.c */
+/* avr.host - Host fonctions modules. {{{
+ *
+ * Copyright (C) 2008 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+#include "modules/host/host.h"
+#include "modules/host/mex.h"
+
+#include <stdio.h>
+
+void
+a82 (void *user, mex_msg_t *msg)
+{
+ printf ("oucouc\n");
+ u8 nb;
+ mex_msg_pop (msg, "B", &nb);
+ nb++;
+ mex_msg_t *m = mex_msg_new (mex_msg_mtype (msg));
+ mex_msg_push (m, "B", nb);
+ mex_node_response (m);
+}
+
+void
+a801 (void *user, mex_msg_t *msg)
+{
+ printf ("coucou\n");
+ u8 b;
+ u16 h;
+ u32 l;
+ mex_msg_pop (msg, "BHL", &b, &h, &l);
+ if (mex_msg_mtype (msg) == 0x80)
+ assert (b == 1 && h == 2 && l == 3);
+ else
+ assert (b == 4 && h == 5 && l == 6);
+}
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ printf ("reset\n");
+ host_init (argc, argv);
+ if (argc != 2 || !((argv[1][0] == '1' || argv[1][0] == '2')
+ && argv[1][1] == '\0'))
+ {
+ fprintf (stderr, "%s 1|2\n", argv[0]);
+ return 1;
+ }
+ if (argv[1][0] == '1')
+ {
+ mex_node_register (0x82, a82, NULL);
+ mex_node_connect ();
+ i = host_fetch_integer ("reseted");
+ if (i == -1)
+ {
+ mex_msg_t *m = mex_msg_new (0x80);
+ mex_msg_push (m, "BHL", 1, 2, 3);
+ mex_node_send (m);
+ host_register_integer ("reseted", 1);
+ host_reset ();
+ }
+ else
+ {
+ mex_msg_t *m = mex_msg_new (0x81);
+ mex_msg_push (m, "BHL", 4, 5, 6);
+ mex_node_send (m);
+ mex_node_wait ();
+ }
+ }
+ else
+ {
+ mex_node_register (0x80, a801, NULL);
+ mex_node_register (0x81, a801, NULL);
+ mex_node_connect ();
+ mex_msg_t *m = mex_msg_new (0x82);
+ mex_msg_push (m, "B", 42);
+ mex_msg_t *r = mex_node_request (m);
+ assert (mex_msg_mtype (r) == 0x82);
+ u8 rb;
+ mex_msg_pop (r, "B", &rb);
+ assert (rb == 43);
+ mex_node_wait_date (42);
+ mex_node_wait ();
+ }
+ return 0;
+}
diff --git a/digital/avr/modules/host/test/test_mex.py b/digital/avr/modules/host/test/test_mex.py
new file mode 100644
index 00000000..7de5555d
--- /dev/null
+++ b/digital/avr/modules/host/test/test_mex.py
@@ -0,0 +1,25 @@
+import sys
+sys.path.append (sys.path[0] + '/../../../../../host/mex')
+
+from mex.hub import Hub
+from mex.msg import Msg
+
+import os, signal
+
+def log (x):
+ print x
+
+h = Hub (min_clients = 2, log = log)
+
+pid1 = os.spawnl (os.P_NOWAIT, './test_mex.host', './test_mex.host', '1')
+pid2 = os.spawnl (os.P_NOWAIT, './test_mex.host', './test_mex.host', '2')
+
+try:
+ h.wait ()
+finally:
+ os.kill (pid1, signal.SIGTERM)
+ os.waitpid (pid1, 0)
+ os.kill (pid2, signal.SIGTERM)
+ os.waitpid (pid2, 0)
+ import time
+ time.sleep (1)