|
@@ -0,0 +1,54 @@
|
|
1
|
+#include <assert.h>
|
|
2
|
+#include <gpxe/buffer.h>
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+struct buffer_test {
|
|
6
|
+ struct buffer buffer;
|
|
7
|
+ const char *source;
|
|
8
|
+ size_t source_len;
|
|
9
|
+ char *dest;
|
|
10
|
+ size_t dest_len;
|
|
11
|
+};
|
|
12
|
+
|
|
13
|
+static int test_fill_buffer ( struct buffer_test *test,
|
|
14
|
+ size_t start, size_t end ) {
|
|
15
|
+ const void *data = ( test->source + start );
|
|
16
|
+ size_t len = ( end - start );
|
|
17
|
+
|
|
18
|
+ assert ( end <= test->source_len );
|
|
19
|
+ assert ( end <= test->dest_len );
|
|
20
|
+
|
|
21
|
+ fill_buffer ( &test->buffer, data, start, len );
|
|
22
|
+ assert ( memcmp ( ( test->dest + start ), data, len ) == 0 );
|
|
23
|
+ assert ( test->buffer.free >= end );
|
|
24
|
+ return 0;
|
|
25
|
+}
|
|
26
|
+
|
|
27
|
+int test_buffer ( void ) {
|
|
28
|
+ char source[123];
|
|
29
|
+ char dest[123];
|
|
30
|
+ struct buffer_test test;
|
|
31
|
+
|
|
32
|
+ memset ( &test, 0, sizeof ( test ) );
|
|
33
|
+ test.source = source;
|
|
34
|
+ test.source_len = sizeof ( source );
|
|
35
|
+ test.dest = dest;
|
|
36
|
+ test.dest_len = sizeof ( dest );
|
|
37
|
+ test.buffer.addr = virt_to_phys ( dest );
|
|
38
|
+ test.buffer.len = sizeof ( dest );
|
|
39
|
+
|
|
40
|
+ test_fill_buffer ( &test, 20, 38 );
|
|
41
|
+ test_fill_buffer ( &test, 60, 61 );
|
|
42
|
+ test_fill_buffer ( &test, 38, 42 );
|
|
43
|
+ test_fill_buffer ( &test, 42, 60 );
|
|
44
|
+ test_fill_buffer ( &test, 16, 80 );
|
|
45
|
+ test_fill_buffer ( &test, 0, 16 );
|
|
46
|
+ test_fill_buffer ( &test, 99, 123 );
|
|
47
|
+ test_fill_buffer ( &test, 80, 99 );
|
|
48
|
+
|
|
49
|
+ assert ( test.buffer.fill == sizeof ( source ) );
|
|
50
|
+ assert ( test.buffer.free == sizeof ( source ) );
|
|
51
|
+ assert ( memcmp ( source, dest, sizeof ( source ) ) == 0 );
|
|
52
|
+
|
|
53
|
+ return 0;
|
|
54
|
+}
|