Array of strings sys_dirs must be NULL-terminated
[helenos.git] / uspace / app / tester / ipc / readwrite.c
blob3e6d88204dd192d87ef0ed2438dc2d0b4d65c15f
1 /*
2 * Copyright (c) 2023 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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.
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"
38 enum {
39 rw_buf_size = 1024
42 static uint8_t rw_buf[rw_buf_size];
44 const char *test_readwrite(void)
46 ipc_test_t *test = NULL;
47 size_t i;
48 errno_t rc;
50 rc = ipc_test_create(&test);
51 if (rc != EOK)
52 return "Error contacting IPC test service.";
54 rc = ipc_test_set_rw_buf_size(test, rw_buf_size);
55 if (rc != EOK)
56 return "Error getting read-only area size.";
59 * Write all zeroes to remote buffer
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.";
66 TPRINTF("Successfully wrote zeroes to remote buffer.\n");
69 * Read back contents of remote buffer and verify
73 * Make sure the contents of local buffer are different from what
74 * we expect to read.
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.";
81 TPRINTF("Successfully read back remote buffer.\n");
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.";
89 TPRINTF("Read data succeeded verification.\n");
92 * Write all binary ones to remote buffer
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.";
99 TPRINTF("Successfully wrote binary ones to remote buffer.\n");
102 * Read back contents of remote buffer and verify
106 * Make sure the contents of local buffer are different from what
107 * we expect to read.
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.";
114 TPRINTF("Successfully read back remote buffer.\n");
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.";
122 TPRINTF("Read data succeeded verification.\n");
124 ipc_test_destroy(test);
125 return NULL;