On 01/28/2014 07:37 PM, Michal Privoznik wrote:
The test tries to set some QoS limits and check if the commands
that are actually executed are the expected ones.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tests/virnetdevbandwidthtest.c | 76 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c
index 989018e..044decd 100644
--- a/tests/virnetdevbandwidthtest.c
+++ b/tests/virnetdevbandwidthtest.c
@@ -104,6 +112,48 @@ cleanup:
}
static int
+testVirNetDevBandwidthSet(const void *data)
+{
+ int ret = -1;
+ const struct testSetStruct *info = data;
+ const char *iface = info->iface;
+ virNetDevBandwidthPtr band = NULL;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *actual_cmd = NULL;
+
+ PARSE(info->band, band);
+
+ if (!iface)
+ iface = "eth0";
+
+ virCommandSetDryRun(&buf);
+
+ if (virNetDevBandwidthSet(iface, band, info->hierarchical_class) < 0)
+ goto cleanup;
+
+ if (!(actual_cmd = virBufferContentAndReset(&buf))) {
+ int err = virBufferError(&buf);
+ if (err) {
+ fprintf(stderr, "buffer's in error state: %d", err);
+ goto cleanup;
+ }
+ /* This is interesting, no command has been executed.
+ * Maybe that's expected, actually. */
+ }
+
+ if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) {
+ virtTestDifference(stderr, info->exp_cmd, actual_cmd);
+ goto cleanup;
+ }
+
+ ret = 0;
+cleanup:
if virNetDevBandwidthSet executes some commands but fails, you should
virBufferFreeAndReset(&buf)
here
+ virNetDevBandwidthFree(band);
+ VIR_FREE(actual_cmd);
+ return ret;
+}
+
+static int
mymain(void)
{
int ret = 0;
ACK
Jan