blob: f4e985fa1358a64374ddf59c5ada47f99cb4b1e2 [file] [log] [blame]
Rich Laneccae0312013-07-21 23:34:13 -07001/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University */
2/* Copyright (c) 2011, 2012 Open Networking Foundation */
3/* Copyright (c) 2012, 2013 Big Switch Networks, Inc. */
4/* See the file LICENSE.loci which should have been included in the source distribution */
5
6/**
7 *
8 * AUTOMATICALLY GENERATED FILE. Edits will be lost on regen.
9 *
10 * Data file tests for all versions.
11 */
12
13#include <locitest/test_common.h>
14
15<?py
16def hexarray(data, indent):
17 i = 0
18 text = []
19 text.append(" " * indent)
20 for byte in data:
21 text.append("0x%02x, " % ord(byte))
22 i += 1
23 if i == 8:
24 text.append("\n" + " " * indent)
25 i = 0
26 #endif
27 #endfor
28 return "".join(text)
29#end
30?>
31
32static void
33hexdump(const uint8_t *data, int len)
34{
35 int i = 0, j;
36 while (i < len) {
37 printf("%02x: ", i);
38 for (j = 0; j < 8 && i < len; j++, i++) {
39 printf("%02x ", data[i]);
40 }
41 printf("\n");
42 }
43}
44
45static void
46show_failure(const uint8_t *a, int a_len, const uint8_t *b, int b_len)
47{
48 printf("\n--- Expected: (len=%d)\n", a_len);
49 hexdump(a, a_len);
50 printf("\n--- Actual: (len=%d)\n", b_len);
51 hexdump(b, b_len);
52}
53
54:: for test in tests:
55/* Generated from ${test['filename']} */
56static int
57test_${test['name']}(void) {
58 uint8_t binary[] = {
59${hexarray(test['binary'], indent=8)}
60 };
61
62 of_object_t *obj;
63
64${'\n'.join([' ' * 4 + x for x in test['c'].split("\n")])}
65
66 if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))
67 || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) {
68 show_failure(binary, sizeof(binary),
69 WBUF_BUF(OF_OBJECT_TO_WBUF(obj)),
70 WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)));
71 of_object_delete(obj);
72 return TEST_FAIL;
73 }
74
75 of_object_delete(obj);
76 return TEST_PASS;
77}
78
79:: #endfor
80
81int
82test_datafiles(void)
83{
84:: for test in tests:
85 RUN_TEST(${test['name']});
86:: #endfor
87 return TEST_PASS;
88}