1.1 --- a/dstest_test_client.cc Sun Feb 14 23:11:41 2021 +0100
1.2 +++ b/dstest_test_client.cc Mon Feb 15 00:32:23 2021 +0100
1.3 @@ -26,8 +26,6 @@
1.4 #include <string.h>
1.5 #include <stdlib.h>
1.6
1.7 -#include <mutex>
1.8 -#include <set>
1.9 #include <thread>
1.10
1.11 #include <ipc/cap_alloc.h>
1.12 @@ -41,44 +39,20 @@
1.13
1.14
1.15
1.16 -const unsigned int ACTIVITY_ITERATIONS = 100;
1.17 +/* Test parameters affected by capability limits. */
1.18 +
1.19 const unsigned long NUMBER_OF_FILES = 10;
1.20 const unsigned int START_LIMIT = 10;
1.21 +const unsigned int ACTIVITY_ITERATIONS = 20;
1.22 +
1.23 +/* Test parameters unaffected by any capability limits. */
1.24 +
1.25 const unsigned int MAP_PAGES = 20;
1.26 +const unsigned int REGION_ITERATIONS = 10;
1.27
1.28
1.29
1.30 -static std::mutex _lock;
1.31 -static std::set<void *> _memory;
1.32 -
1.33 -static long attach_dataspace(l4_cap_idx_t cap, unsigned long size, void **memory)
1.34 -{
1.35 - std::lock_guard<std::mutex> guard(_lock);
1.36 -
1.37 - long err = ipc_attach_dataspace(cap, size, memory);
1.38 -
1.39 - if (err)
1.40 - return err;
1.41 -
1.42 - if (_memory.find(*memory) != _memory.end())
1.43 - {
1.44 - printf("Memory assigned again: %p\n", *memory);
1.45 - return -L4_EINVAL;
1.46 - }
1.47 -
1.48 - _memory.insert(*memory);
1.49 - return L4_EOK;
1.50 -}
1.51 -
1.52 -static long detach_dataspace(void *memory)
1.53 -{
1.54 - std::lock_guard<std::mutex> guard(_lock);
1.55 -
1.56 - _memory.erase(memory);
1.57 - return ipc_detach_dataspace(memory);
1.58 -}
1.59 -
1.60 -
1.61 +/* An activity opening and reading from a file. */
1.62
1.63 static long activity(l4_cap_idx_t context_ref, unsigned long fileid, unsigned int start_page)
1.64 {
1.65 @@ -118,16 +92,11 @@
1.66 return err;
1.67 }
1.68
1.69 - //printf("Mapped region from %ld to %ld with content %ld.\n",
1.70 - // start_pos, end_pos, data_end);
1.71 -
1.72 size = end_pos - start_pos;
1.73
1.74 - //printf("Attach region of size %ld...\n", size);
1.75 -
1.76 char *memory;
1.77
1.78 - err = attach_dataspace(file_ref, size, (void **) &memory);
1.79 + err = ipc_attach_dataspace(file_ref, size, (void **) &memory);
1.80
1.81 if (err)
1.82 {
1.83 @@ -136,40 +105,39 @@
1.84 return err;
1.85 }
1.86
1.87 - //printf("Mapped memory from %lx / %ld at %p\n", file_ref, page(start_page), memory);
1.88 -
1.89 if (data_end < size)
1.90 size = data_end;
1.91
1.92 - for (unsigned long offset = 0; offset < size; offset += step)
1.93 - {
1.94 - unsigned long remaining = size - offset;
1.95 - unsigned long sample_remaining = remaining < sample ? remaining : sample;
1.96 + /* Read the region a number of times. */
1.97
1.98 - strncpy(buf, (memory + offset), sample_remaining);
1.99 - buf[sample_remaining] = '\0';
1.100 - //printf("%p: %s\n", (memory + offset), buf);
1.101 + for (unsigned int read_counter = 0; read_counter < REGION_ITERATIONS; read_counter++)
1.102 + {
1.103 + for (unsigned long offset = 0; offset < size; offset += step)
1.104 + {
1.105 + unsigned long remaining = size - offset;
1.106 + unsigned long sample_remaining = remaining < sample ? remaining : sample;
1.107
1.108 - /* Test the data obtained. */
1.109 + strncpy(buf, (memory + offset), sample_remaining);
1.110 + buf[sample_remaining] = '\0';
1.111 +
1.112 + /* Test the data obtained. */
1.113
1.114 - unsigned long filepos = start_pos + offset;
1.115 - unsigned long _fileid = 0, _filepos = 0;
1.116 - char *sep = strchr(buf, ':');
1.117 + unsigned long filepos = start_pos + offset;
1.118 + unsigned long _fileid = 0, _filepos = 0;
1.119 + char *sep = strchr(buf, ':');
1.120
1.121 - if (sep != NULL)
1.122 - {
1.123 - *sep = '\0'; sep++;
1.124 - _fileid = atol(buf); _filepos = atol(sep);
1.125 + if (sep != NULL)
1.126 + {
1.127 + *sep = '\0'; sep++;
1.128 + _fileid = atol(buf); _filepos = atol(sep);
1.129 + }
1.130 +
1.131 + if ((fileid != _fileid) || (filepos != _filepos))
1.132 + printf("! %ld:%ld is not %ld:%ld\n", _fileid, _filepos, fileid, filepos);
1.133 }
1.134 -
1.135 - if ((fileid != _fileid) || (filepos != _filepos))
1.136 - printf("! %ld:%ld is not %ld:%ld\n", _fileid, _filepos, fileid, filepos);
1.137 }
1.138
1.139 - detach_dataspace(memory);
1.140 -
1.141 - //printf("Unmapped memory from %ld at %p\n", page(start_page), memory);
1.142 -
1.143 + ipc_detach_dataspace(memory);
1.144 ipc_cap_free_um(file_ref);
1.145
1.146 return L4_EOK;
1.147 @@ -190,7 +158,6 @@
1.148 break;
1.149 }
1.150
1.151 - //printf("Ending: %ld @ %d\n", fileid, start_page);
1.152 return err;
1.153 }
1.154
1.155 @@ -225,7 +192,7 @@
1.156
1.157 /* Map context memory to write the filename. */
1.158
1.159 - err = attach_dataspace(*context_ref, size, (void **) filename);
1.160 + err = ipc_attach_dataspace(*context_ref, size, (void **) filename);
1.161
1.162 if (err)
1.163 {
1.164 @@ -273,7 +240,7 @@
1.165
1.166 /* Discard the context. */
1.167
1.168 - detach_dataspace(filename);
1.169 + ipc_detach_dataspace(filename);
1.170 ipc_cap_free_um(context_ref);
1.171
1.172 printf("End: %ld\n", fileid);