git » libfiu » commit d107e96

libfiu: Add a test for errors on remote control command parsing

author Alberto Bertogli
2020-03-06 10:58:22 UTC
committer Alberto Bertogli
2020-03-06 10:58:22 UTC
parent dfa9363992e49c5843375f84acacef173199a0ac

libfiu: Add a test for errors on remote control command parsing

This patch adds a test to check how errors in remote control command
parsing are handled, and printed out.

While at it, it adjusts the printed error message to make it more
uniform with others.

libfiu/fiu-rc.c +1 -1
tests/test-fiu_ctrl.py +13 -0

diff --git a/libfiu/fiu-rc.c b/libfiu/fiu-rc.c
index 71e682e..1d3b092 100644
--- a/libfiu/fiu-rc.c
+++ b/libfiu/fiu-rc.c
@@ -205,7 +205,7 @@ static int rc_do_command(int fdr, int fdw)
 
 	r = fiu_rc_string(buf, &error);
 	if (r < 0)
-		fprintf(stderr, "fiu_rc_string error: %s\n", error);
+		fprintf(stderr, "libfiu: rc parsing error: %s\n", error);
 
 	reply_len = snprintf(reply, MAX_LINE, "%d\n", r);
 	r = write(fdw, reply, reply_len);
diff --git a/tests/test-fiu_ctrl.py b/tests/test-fiu_ctrl.py
index 398d58e..4fe84e7 100644
--- a/tests/test-fiu_ctrl.py
+++ b/tests/test-fiu_ctrl.py
@@ -49,6 +49,19 @@ cmd.disable('posix/io/rw/*')
 out, err = p.communicate('test\n')
 assert out == 'test\n', (out, err)
 
+# Bad command.
+cmd = run_cat(fiu_enable_posix = True)
+p = cmd.start()
+exc = None
+try:
+    cmd.run_raw_cmd('badcommand', ["name=a"])
+except Exception as e:
+    exc = e
+assert isinstance(exc, fiu_ctrl.CommandError), "got exception: %r" % exc
+out, err = p.communicate('test\n')
+assert out == 'test\n', out
+assert err == 'libfiu: rc parsing error: Unknown command\n', err
+
 # Enable random.
 # This relies on cat doing a reasonably small number of read and writes, which
 # our small-cat does.