summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschodet2006-03-10 22:50:27 +0000
committerschodet2006-03-10 22:50:27 +0000
commit5b1d2edb7a9b97afc30b8d4c28010b3f5adb8a07 (patch)
treebd82d3b5930aceb5b725082dd58e47b0f213b603
parentf0dedd3171a2eab5674ec37a2e97766cbbb794ab (diff)
Correction d'un bug si NDEBUG est défini.
Support du passage d'arguments au reset.
-rw-r--r--n/avr/modules/host/host.h7
-rw-r--r--n/avr/modules/host/host.host.c24
-rw-r--r--n/avr/modules/host/test/test_host.c16
3 files changed, 31 insertions, 16 deletions
diff --git a/n/avr/modules/host/host.h b/n/avr/modules/host/host.h
index 22cd347..d1a00af 100644
--- a/n/avr/modules/host/host.h
+++ b/n/avr/modules/host/host.h
@@ -3,7 +3,7 @@
/* host.h */
/* avr.host - Host fonctions modules. {{{
*
- * Copyright (C) 2005 Nicolas Schodet
+ * Copyright (C) 2005-2006 Nicolas Schodet
*
* Robot APB Team/Efrei 2006.
* Web: http://assos.efrei.fr/robot/
@@ -53,11 +53,8 @@ host_fetch_integer (const char *name);
const char *
host_fetch_string (const char *name);
-void
-host_reset (void) __attribute__ ((noreturn));
-
/** Reset the program. */
void
-host_reset (void);
+host_reset (void) __attribute__ ((noreturn));
#endif /* host_h */
diff --git a/n/avr/modules/host/host.host.c b/n/avr/modules/host/host.host.c
index e3f5a32..bcfd7d2 100644
--- a/n/avr/modules/host/host.host.c
+++ b/n/avr/modules/host/host.host.c
@@ -1,7 +1,7 @@
-/* host.c */
+/* host.host.c */
/* avr.host - Host fonctions modules. {{{
*
- * Copyright (C) 2005 Nicolas Schodet
+ * Copyright (C) 2005-2006 Nicolas Schodet
*
* Robot APB Team/Efrei 2006.
* Web: http://assos.efrei.fr/robot/
@@ -23,27 +23,36 @@
*
* }}} */
#define _GNU_SOURCE
+#include "common.h"
#include "host.h"
#include <errno.h>
-#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
+/* Saved arguments. Uninitialised global variables are set to 0 by the
+ * compiler. */
+static int host_saved_argc;
+static char **host_saved_argv;
+
/** Initialise host modules. */
void
host_init (int argc, char **argv)
{
+ host_saved_argc = argc;
+ host_saved_argv = argv;
}
/** Register a host integer. */
void
host_register_integer (const char *name, int val)
{
+ int r;
char sval[256];
/* Convert to string, and register the string. */
- assert (snprintf (sval, sizeof (sval), "%d", val) < (int) sizeof (sval));
+ r = snprintf (sval, sizeof (sval), "%d", val);
+ assert (r < (int) sizeof (sval));
host_register_string (name, sval);
}
@@ -51,7 +60,9 @@ host_register_integer (const char *name, int val)
void
host_register_string (const char *name, const char *val)
{
- assert (setenv (name, val, 1) == 0);
+ int r;
+ r = setenv (name, val, 1);
+ assert (r == 0);
}
/** Fetch a host integer, return -1 if non existant. */
@@ -73,7 +84,8 @@ host_fetch_string (const char *name)
void
host_reset (void)
{
- execlp (program_invocation_name, program_invocation_name, 0);
+ execv (program_invocation_name, host_saved_argv);
assert_perror (errno);
abort ();
}
+
diff --git a/n/avr/modules/host/test/test_host.c b/n/avr/modules/host/test/test_host.c
index 3b839dd..db8161f 100644
--- a/n/avr/modules/host/test/test_host.c
+++ b/n/avr/modules/host/test/test_host.c
@@ -1,7 +1,7 @@
/* test_host.c */
/* avr.host - Host fonctions modules. {{{
*
- * Copyright (C) 2005 Nicolas Schodet
+ * Copyright (C) 2005-2006 Nicolas Schodet
*
* Robot APB Team/Efrei 2006.
* Web: http://assos.efrei.fr/robot/
@@ -26,24 +26,30 @@
#include "modules/host/host.h"
#include <string.h>
-#include <assert.h>
#include <stdio.h>
int
-main (void)
+main (int argc, char **argv)
{
- int i = host_fetch_integer ("avr_integer");
- const char *s = host_fetch_string ("avr_string");
+ int i;
+ const char *s;
printf ("reset\n");
+ host_init (argc, argv);
+ i = host_fetch_integer ("avr_integer");
+ s = host_fetch_string ("avr_string");
if (i != -1)
{
printf ("get\n");
+ assert_print (argc == 2 && strcmp (argv[1], "ni") == 0,
+ "argument passing not working");
assert (i == 42);
assert (strcmp (s, "Ni!") == 0);
}
else
{
printf ("set\n");
+ assert_print (argc == 2 && strcmp (argv[1], "ni") == 0,
+ "please provide \"ni\" as the first argument");
host_register_integer ("avr_integer", 42);
host_register_string ("avr_string", "Ni!");
host_reset ();