X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-bundle.c;h=9a658396797fcbe246c596a21ff244bff6908e18;hb=HEAD;hp=f5b24b4a3f6a5925bd207162d075ecbfdf7c864b;hpb=67680b012be30d9c26eab999b83b08c6eb32dbd2;p=sliver-openvswitch.git diff --git a/tests/test-bundle.c b/tests/test-bundle.c index f5b24b4a3..9a6583967 100644 --- a/tests/test-bundle.c +++ b/tests/test-bundle.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, 2012 Nicira, Inc. +/* Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,15 +23,15 @@ #include "flow.h" #include "ofp-actions.h" #include "ofpbuf.h" -#include "random.h" #include "util.h" +#include "ovstest.h" #define N_FLOWS 50000 #define MAX_SLAVES 8 /* Maximum supported by this test framework. */ struct slave { - uint16_t slave_id; + ofp_port_t slave_id; bool enabled; size_t flow_count; @@ -43,7 +43,7 @@ struct slave_group { }; static struct slave * -slave_lookup(struct slave_group *sg, uint16_t slave_id) +slave_lookup(struct slave_group *sg, ofp_port_t slave_id) { size_t i; @@ -57,7 +57,7 @@ slave_lookup(struct slave_group *sg, uint16_t slave_id) } static bool -slave_enabled_cb(uint16_t slave_id, void *aux) +slave_enabled_cb(ofp_port_t slave_id, void *aux) { struct slave *slave; @@ -71,10 +71,15 @@ parse_bundle_actions(char *actions) struct ofpact_bundle *bundle; struct ofpbuf ofpacts; struct ofpact *action; + char *error; ofpbuf_init(&ofpacts, 0); - bundle_parse_load(actions, &ofpacts); - action = ofpacts.data; + error = bundle_parse_load(actions, &ofpacts); + if (error) { + ovs_fatal(0, "%s", error); + } + + action = ofpbuf_data(&ofpacts); bundle = ofpact_get_BUNDLE(xmemdup(action, action->len)); ofpbuf_uninit(&ofpacts); @@ -100,8 +105,8 @@ mask_str(uint8_t mask, size_t n_bits) return str; } -int -main(int argc, char *argv[]) +static void +test_bundle_main(int argc, char *argv[]) { bool ok = true; struct ofpact_bundle *bundle; @@ -111,7 +116,6 @@ main(int argc, char *argv[]) int old_active; set_program_name(argv[0]); - random_init(); if (argc != 2) { ovs_fatal(0, "usage: %s bundle_action", program_name); @@ -122,7 +126,7 @@ main(int argc, char *argv[]) /* Generate 'slaves' array. */ sg.n_slaves = 0; for (i = 0; i < bundle->n_slaves; i++) { - uint16_t slave_id = bundle->slaves[i]; + ofp_port_t slave_id = bundle->slaves[i]; if (slave_lookup(&sg, slave_id)) { ovs_fatal(0, "Redundant slaves are not supported. "); @@ -135,10 +139,8 @@ main(int argc, char *argv[]) /* Generate flows. */ flows = xmalloc(N_FLOWS * sizeof *flows); for (i = 0; i < N_FLOWS; i++) { - random_bytes(&flows[i], sizeof flows[i]); - memset(flows[i].zeros, 0, sizeof flows[i].zeros); - flows[i].mpls_depth = 0; - flows[i].regs[0] = OFPP_NONE; + flow_random_hash_fields(&flows[i]); + flows[i].regs[0] = ofp_to_u16(OFPP_NONE); } /* Cycles through each possible liveness permutation for the given @@ -186,11 +188,13 @@ main(int argc, char *argv[]) changed = 0; for (j = 0; j < N_FLOWS; j++) { struct flow *flow = &flows[j]; - uint16_t old_slave_id, ofp_port; + ofp_port_t old_slave_id, ofp_port; + struct flow_wildcards wc; - old_slave_id = flow->regs[0]; - ofp_port = bundle_execute(bundle, flow, slave_enabled_cb, &sg); - flow->regs[0] = ofp_port; + old_slave_id = u16_to_ofp(flow->regs[0]); + ofp_port = bundle_execute(bundle, flow, &wc, slave_enabled_cb, + &sg); + flow->regs[0] = ofp_to_u16(ofp_port); if (ofp_port != OFPP_NONE) { slave_lookup(&sg, ofp_port)->flow_count++; @@ -261,5 +265,7 @@ main(int argc, char *argv[]) free(bundle); free(flows); - return ok ? 0 : 1; + exit(ok ? 0 : 1); } + +OVSTEST_REGISTER("test-bundle", test_bundle_main);