1 | /*
|
---|
2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <as.h>
|
---|
30 | #include <errno.h>
|
---|
31 | #include <mem.h>
|
---|
32 | #include <stdint.h>
|
---|
33 | #include <stdio.h>
|
---|
34 | #include <stdlib.h>
|
---|
35 | #include <ipc_test.h>
|
---|
36 | #include "../tester.h"
|
---|
37 |
|
---|
38 | enum {
|
---|
39 | rw_buf_size = 1024
|
---|
40 | };
|
---|
41 |
|
---|
42 | static uint8_t rw_buf[rw_buf_size];
|
---|
43 |
|
---|
44 | const char *test_readwrite(void)
|
---|
45 | {
|
---|
46 | ipc_test_t *test = NULL;
|
---|
47 | size_t i;
|
---|
48 | errno_t rc;
|
---|
49 |
|
---|
50 | rc = ipc_test_create(&test);
|
---|
51 | if (rc != EOK)
|
---|
52 | return "Error contacting IPC test service.";
|
---|
53 |
|
---|
54 | rc = ipc_test_set_rw_buf_size(test, rw_buf_size);
|
---|
55 | if (rc != EOK)
|
---|
56 | return "Error getting read-only area size.";
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * Write all zeroes to remote buffer
|
---|
60 | */
|
---|
61 | memset(rw_buf, 0x00, rw_buf_size);
|
---|
62 | rc = ipc_test_write(test, rw_buf, rw_buf_size);
|
---|
63 | if (rc != EOK)
|
---|
64 | return "Error writing remote buffer.";
|
---|
65 |
|
---|
66 | TPRINTF("Successfully wrote zeroes to remote buffer.\n");
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * Read back contents of remote buffer and verify
|
---|
70 | */
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * Make sure the contents of local buffer are different from what
|
---|
74 | * we expect to read.
|
---|
75 | */
|
---|
76 | memset(rw_buf, 0xff, rw_buf_size);
|
---|
77 | rc = ipc_test_read(test, rw_buf, rw_buf_size);
|
---|
78 | if (rc != EOK)
|
---|
79 | return "Error reading remote buffer.";
|
---|
80 |
|
---|
81 | TPRINTF("Successfully read back remote buffer.\n");
|
---|
82 |
|
---|
83 | /* Now verify what we have read */
|
---|
84 | for (i = 0; i < rw_buf_size; i++) {
|
---|
85 | if (rw_buf[i] != 0x00)
|
---|
86 | return "Failed verification of read data.";
|
---|
87 | }
|
---|
88 |
|
---|
89 | TPRINTF("Read data succeeded verification.\n");
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * Write all binary ones to remote buffer
|
---|
93 | */
|
---|
94 | memset(rw_buf, 0xff, rw_buf_size);
|
---|
95 | rc = ipc_test_write(test, rw_buf, rw_buf_size);
|
---|
96 | if (rc != EOK)
|
---|
97 | return "Error writing remote buffer.";
|
---|
98 |
|
---|
99 | TPRINTF("Successfully wrote binary ones to remote buffer.\n");
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * Read back contents of remote buffer and verify
|
---|
103 | */
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * Make sure the contents of local buffer are different from what
|
---|
107 | * we expect to read.
|
---|
108 | */
|
---|
109 | memset(rw_buf, 0x00, rw_buf_size);
|
---|
110 | rc = ipc_test_read(test, rw_buf, rw_buf_size);
|
---|
111 | if (rc != EOK)
|
---|
112 | return "Error reading remote buffer.";
|
---|
113 |
|
---|
114 | TPRINTF("Successfully read back remote buffer.\n");
|
---|
115 |
|
---|
116 | /* Now verify what we have read */
|
---|
117 | for (i = 0; i < rw_buf_size; i++) {
|
---|
118 | if (rw_buf[i] != 0xff)
|
---|
119 | return "Failed verification of read data.";
|
---|
120 | }
|
---|
121 |
|
---|
122 | TPRINTF("Read data succeeded verification.\n");
|
---|
123 |
|
---|
124 | ipc_test_destroy(test);
|
---|
125 | return NULL;
|
---|
126 | }
|
---|