Changeset 4011fa0 in mainline
- Timestamp:
- 2010-03-31T13:32:38Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 85c2a4b
- Parents:
- 7553689
- Location:
- uspace/srv/net/netstart
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netstart/netstart.c
r7553689 r4011fa0 28 28 29 29 /** @addtogroup net 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Starts the networking subsystem. 35 * Performs self test if configured to. 36 * @see configuration.h 34 * 35 * Start the networking subsystem. 36 * Perform networking self-test if executed 37 * with the -s argument. 38 * 37 39 */ 40 41 #define NAME "netstart" 38 42 39 43 #include <async.h> 40 44 #include <stdio.h> 41 45 #include <task.h> 42 43 46 #include <ipc/ipc.h> 44 47 #include <ipc/services.h> … … 47 50 #include <net_modules.h> 48 51 #include <net_net_messages.h> 52 49 53 #include "self_test.h" 50 54 51 /** Networking startup module name. 55 /** Start a module. 56 * 57 * @param[in] desc The module description 58 * @param[in] path The module absolute path. 59 * 60 * @returns true on succesful spanwning 61 * @returns false on failure 62 * 52 63 */ 53 #define NAME "Networking startup" 54 55 /** Starts the module. 56 * @param[in] fname The module absolute name. 57 * @returns The started module task identifier. 58 * @returns Other error codes as defined for the task_spawn() function. 59 */ 60 static task_id_t spawn(const char * fname){ 61 const char * argv[2]; 62 task_id_t res; 63 64 argv[0] = fname; 64 static bool spawn(const char *desc, const char *path) 65 { 66 printf("%s: Spawning %s (%s)\n", NAME, desc, path); 67 68 const char *argv[2]; 69 70 argv[0] = path; 65 71 argv[1] = NULL; 66 res = task_spawn(fname, argv);67 72 68 return res; 73 if (task_spawn(path, argv) == 0) { 74 fprintf(stderr, "%s: Error spawning %s\n", NAME, path); 75 return false; 76 } 77 78 return true; 69 79 } 70 80 71 /** Module entry point. 72 * @param[in] argc The number of command line parameters. 73 * @param[in] argv The command line parameters. 74 * @returns EOK on success. 75 * @returns EINVAL if the net module cannot be started. 76 * @returns Other error codes as defined for the self_test() function. 77 * @returns Other error codes as defined for the NET_NET_STARTUP message. 81 /** Network startup entry point. 82 * 83 * @param[in] argc The number of command line parameters. 84 * @param[in] argv The command line parameters. 85 * 86 * @returns EOK on success. 87 * @returns EINVAL if the net module cannot be started. 88 * @returns Other error codes as defined for the self_test() function. 89 * @returns Other error codes as defined for the NET_NET_STARTUP message. 90 * 78 91 */ 79 int main(int argc, char * argv[]){ 92 int main(int argc, char *argv[]) 93 { 80 94 ERROR_DECLARE; 81 82 int net_phone; 83 84 // print the module label 85 printf("Task %d - ", task_get_id()); 86 printf("%s\n", NAME); 87 88 // run self tests 89 ERROR_PROPAGATE(self_test()); 90 91 // start the networking service 92 if(! spawn("/srv/net")){ 93 fprintf(stderr, "Could not spawn net\n"); 95 96 /* Run self-tests */ 97 if ((argc > 1) && (str_cmp(argv[1], "-s") == 0)) 98 ERROR_PROPAGATE(self_test()); 99 100 if (!spawn("networking service", "/srv/net")) 94 101 return EINVAL; 102 103 printf("%s: Initializing networking\n", NAME); 104 105 int net_phone = connect_to_service(SERVICE_NETWORKING); 106 if (ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))) { 107 fprintf(stderr, "%s: Networking error %d\n", NAME, ERROR_CODE); 108 return ERROR_CODE; 95 109 } 96 97 // start the networking 98 net_phone = connect_to_service(SERVICE_NETWORKING); 99 if(ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))){ 100 printf("ERROR %d\n", ERROR_CODE); 101 return ERROR_CODE; 102 }else{ 103 printf("OK\n"); 104 } 105 110 106 111 return EOK; 107 112 } -
uspace/srv/net/netstart/self_test.c
r7553689 r4011fa0 28 28 29 29 /** @addtogroup net 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Self tests implementation. 35 */ 36 37 #include "configuration.h" 38 39 #if NET_SELF_TEST 34 * Networking self-tests implementation. 35 * 36 */ 40 37 41 38 #include <errno.h> … … 52 49 #include "self_test.h" 53 50 54 /** Tests the function, compares the result and remembers if the result differs. 55 * @param[in] name The test name. 51 /** Test the function, compare the result and remember if the result differs. 52 * 53 * @param[in] name The test name. 56 54 * @param[in] function_call The function to be called and checked. 57 * @param[in] result The expected result. 58 */ 59 #define TEST(name, function_call, result); { \ 60 printf("\n\t%s", (name)); \ 61 if((function_call) != (result)){ \ 62 printf("\tERROR\n"); \ 63 error = 1; \ 64 }else{ \ 65 printf("\tOK\n"); \ 66 } \ 67 } 68 69 #if NET_SELF_TEST_GENERIC_CHAR_MAP 70 71 GENERIC_CHAR_MAP_DECLARE(int_char_map, int) 72 73 GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int) 74 75 #endif 76 77 #if NET_SELF_TEST_GENERIC_FIELD 78 79 GENERIC_FIELD_DECLARE(int_field, int) 80 81 GENERIC_FIELD_IMPLEMENT(int_field, int) 82 83 #endif 84 85 #if NET_SELF_TEST_INT_MAP 86 87 INT_MAP_DECLARE(int_map, int); 88 89 INT_MAP_IMPLEMENT(int_map, int); 90 91 #endif 92 93 int self_test(void){ 94 int error; 95 int * x; 96 int * y; 97 int * z; 98 int * u; 99 int * v; 100 int * w; 101 102 error = 0; 103 104 #if NET_SELF_TEST_CHAR_MAP 55 * @param[in] result The expected result. 56 * 57 */ 58 #define TEST(statement, result) \ 59 do { \ 60 printf("\n\t%s == %s", #statement, #result); \ 61 if ((statement) != (result)) { \ 62 printf("\tfailed\n"); \ 63 fprintf(stderr, "\nNetwork self-test failed\n"); \ 64 return EINVAL; \ 65 } else \ 66 printf("\tOK"); \ 67 } while (0) 68 69 #define XMALLOC(var, type) \ 70 do { \ 71 (var) = (type *) malloc(sizeof(type)); \ 72 if ((var) == NULL) { \ 73 fprintf(stderr, "\nMemory allocation error\n"); \ 74 return ENOMEM; \ 75 } \ 76 } while (0) 77 78 GENERIC_CHAR_MAP_DECLARE(int_char_map, int); 79 GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int); 80 81 GENERIC_FIELD_DECLARE(int_field, int); 82 GENERIC_FIELD_IMPLEMENT(int_field, int); 83 84 INT_MAP_DECLARE(int_map, int); 85 INT_MAP_IMPLEMENT(int_map, int); 86 87 int self_test(void) 88 { 89 printf("Running networking self-tests\n"); 90 91 printf("\nChar map test"); 105 92 char_map_t cm; 106 107 printf("\nChar map test"); 108 TEST("update ucho 3 einval", char_map_update(&cm, "ucho", 0, 3), EINVAL); 109 TEST("initialize", char_map_initialize(&cm), EOK); 110 TEST("exclude bla null", char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL); 111 TEST("find bla null", char_map_find(&cm, "bla", 0), CHAR_MAP_NULL); 112 TEST("add bla 1 eok", char_map_add(&cm, "bla", 0, 1), EOK); 113 TEST("find bla 1", char_map_find(&cm, "bla", 0), 1); 114 TEST("add bla 10 eexists", char_map_add(&cm, "bla", 0, 10), EEXISTS); 115 TEST("update bla 2 eok", char_map_update(&cm, "bla", 0, 2), EOK); 116 TEST("find bla 2", char_map_find(&cm, "bla", 0), 2); 117 TEST("update ucho 2 eok", char_map_update(&cm, "ucho", 0, 2), EOK); 118 TEST("exclude bla 2", char_map_exclude(&cm, "bla", 0), 2); 119 TEST("exclude bla null", char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL); 120 TEST("find ucho 2", char_map_find(&cm, "ucho", 0), 2); 121 TEST("update ucho 3 eok", char_map_update(&cm, "ucho", 0, 3), EOK); 122 TEST("find ucho 3", char_map_find(&cm, "ucho", 0), 3); 123 TEST("add blabla 5 eok", char_map_add(&cm, "blabla", 0, 5), EOK); 124 TEST("find blabla 5", char_map_find(&cm, "blabla", 0), 5); 125 TEST("add bla 6 eok", char_map_add(&cm, "bla", 0, 6), EOK); 126 TEST("find bla 6", char_map_find(&cm, "bla", 0), 6); 127 TEST("exclude bla 6", char_map_exclude(&cm, "bla", 0), 6); 128 TEST("find bla null", char_map_find(&cm, "bla", 0), CHAR_MAP_NULL); 129 TEST("find blabla 5", char_map_find(&cm, "blabla", 0), 5); 130 TEST("add auto 7 eok", char_map_add(&cm, "auto", 0, 7), EOK); 131 TEST("find auto 7", char_map_find(&cm, "auto", 0), 7); 132 TEST("add kara 8 eok", char_map_add(&cm, "kara", 0, 8), EOK); 133 TEST("find kara 8", char_map_find(&cm, "kara", 0), 8); 134 TEST("add nic 9 eok", char_map_add(&cm, "nic", 0, 9), EOK); 135 TEST("find nic 9", char_map_find(&cm, "nic", 0), 9); 136 TEST("find blabla 5", char_map_find(&cm, "blabla", 0), 5); 137 TEST("add micnicnic 5 9 eok", char_map_add(&cm, "micnicnic", 5, 9), EOK); 138 TEST("find micni 9", char_map_find(&cm, "micni", 0), 9); 139 TEST("find micnicn 5 9", char_map_find(&cm, "micnicn", 5), 9); 140 TEST("add 10.0.2.2 4 15 eok", char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK); 141 TEST("find 10.0.2.2 4 15", char_map_find(&cm, "\x10\x0\x2\x2", 4), 15); 142 printf("\n\tdestroy"); 143 char_map_destroy(&cm); 144 TEST("update ucho 3 einval", char_map_update(&cm, "ucho", 0, 3), EINVAL); 145 printf("\nOK"); 146 147 if(error){ 148 return EINVAL; 149 } 150 151 #endif 152 153 #if NET_SELF_TEST_CRC 93 94 TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL); 95 TEST(char_map_initialize(&cm), EOK); 96 TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL); 97 TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL); 98 TEST(char_map_add(&cm, "bla", 0, 1), EOK); 99 TEST(char_map_find(&cm, "bla", 0), 1); 100 TEST(char_map_add(&cm, "bla", 0, 10), EEXISTS); 101 TEST(char_map_update(&cm, "bla", 0, 2), EOK); 102 TEST(char_map_find(&cm, "bla", 0), 2); 103 TEST(char_map_update(&cm, "ucho", 0, 2), EOK); 104 TEST(char_map_exclude(&cm, "bla", 0), 2); 105 TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL); 106 TEST(char_map_find(&cm, "ucho", 0), 2); 107 TEST(char_map_update(&cm, "ucho", 0, 3), EOK); 108 TEST(char_map_find(&cm, "ucho", 0), 3); 109 TEST(char_map_add(&cm, "blabla", 0, 5), EOK); 110 TEST(char_map_find(&cm, "blabla", 0), 5); 111 TEST(char_map_add(&cm, "bla", 0, 6), EOK); 112 TEST(char_map_find(&cm, "bla", 0), 6); 113 TEST(char_map_exclude(&cm, "bla", 0), 6); 114 TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL); 115 TEST(char_map_find(&cm, "blabla", 0), 5); 116 TEST(char_map_add(&cm, "auto", 0, 7), EOK); 117 TEST(char_map_find(&cm, "auto", 0), 7); 118 TEST(char_map_add(&cm, "kara", 0, 8), EOK); 119 TEST(char_map_find(&cm, "kara", 0), 8); 120 TEST(char_map_add(&cm, "nic", 0, 9), EOK); 121 TEST(char_map_find(&cm, "nic", 0), 9); 122 TEST(char_map_find(&cm, "blabla", 0), 5); 123 TEST(char_map_add(&cm, "micnicnic", 5, 9), EOK); 124 TEST(char_map_find(&cm, "micni", 0), 9); 125 TEST(char_map_find(&cm, "micnicn", 5), 9); 126 TEST(char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK); 127 TEST(char_map_find(&cm, "\x10\x0\x2\x2", 4), 15); 128 129 TEST((char_map_destroy(&cm), EOK), EOK); 130 TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL); 131 132 printf("\nCRC computation test"); 154 133 uint32_t value; 155 156 printf("\nCRC computation test"); 157 value = ~ compute_crc32(~ 0, "123456789", 8 * 9); 158 TEST("123456789", value, 0xCBF43926); 159 printf("\t=> %X", value); 160 value = ~ compute_crc32(~ 0, "1", 8); 161 TEST("1", value, 0x83DCEFB7); 162 printf("\t=> %X", value); 163 value = ~ compute_crc32(~ 0, "12", 8 * 2); 164 TEST("12", value, 0x4F5344CD); 165 printf("\t=> %X", value); 166 value = ~ compute_crc32(~ 0, "123", 8 * 3); 167 TEST("123", value, 0x884863D2); 168 printf("\t=> %X", value); 169 value = ~ compute_crc32(~ 0, "1234", 8 * 4); 170 TEST("1234", value, 0x9BE3E0A3); 171 printf("\t=> %X", value); 172 value = ~ compute_crc32(~ 0, "12345678", 8 * 8); 173 TEST("12345678", value, 0x9AE0DAAF); 174 printf("\t=> %X", value); 175 value = ~ compute_crc32(~ 0, "ahoj pane", 8 * 9); 176 TEST("ahoj pane", value, 0x5FC3D706); 177 printf("\t=> %X", value); 178 179 if(error){ 180 return EINVAL; 181 } 182 183 #endif 184 185 #if NET_SELF_TEST_DYNAMIC_FIFO 134 135 TEST(value = ~compute_crc32(~0, "123456789", 8 * 9), 0xcbf43926); 136 TEST(value = ~compute_crc32(~0, "1", 8), 0x83dcefb7); 137 TEST(value = ~compute_crc32(~0, "12", 8 * 2), 0x4f5344cd); 138 TEST(value = ~compute_crc32(~0, "123", 8 * 3), 0x884863d2); 139 TEST(value = ~compute_crc32(~0, "1234", 8 * 4), 0x9be3e0a3); 140 TEST(value = ~compute_crc32(~0, "12345678", 8 * 8), 0x9ae0daaf); 141 TEST(value = ~compute_crc32(~0, "ahoj pane", 8 * 9), 0x5fc3d706); 142 143 printf("\nDynamic fifo test"); 186 144 dyn_fifo_t fifo; 187 188 printf("\nDynamic fifo test"); 189 TEST("add 1 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL); 190 TEST("initialize", dyn_fifo_initialize(&fifo, 1), EOK); 191 TEST("add 1 eok", dyn_fifo_push(&fifo, 1, 0), EOK); 192 TEST("pop 1", dyn_fifo_pop(&fifo), 1); 193 TEST("pop enoent", dyn_fifo_pop(&fifo), ENOENT); 194 TEST("add 2 eok", dyn_fifo_push(&fifo, 2, 1), EOK); 195 TEST("add 3 enomem", dyn_fifo_push(&fifo, 3, 1), ENOMEM); 196 TEST("add 3 eok", dyn_fifo_push(&fifo, 3, 0), EOK); 197 TEST("pop 2", dyn_fifo_pop(&fifo), 2); 198 TEST("pop 3", dyn_fifo_pop(&fifo), 3); 199 TEST("add 4 eok", dyn_fifo_push(&fifo, 4, 2), EOK); 200 TEST("add 5 eok", dyn_fifo_push(&fifo, 5, 2), EOK); 201 TEST("add 6 enomem", dyn_fifo_push(&fifo, 6, 2), ENOMEM); 202 TEST("add 6 eok", dyn_fifo_push(&fifo, 6, 5), EOK); 203 TEST("add 7 eok", dyn_fifo_push(&fifo, 7, 5), EOK); 204 TEST("pop 4", dyn_fifo_pop(&fifo), 4); 205 TEST("pop 5", dyn_fifo_pop(&fifo), 5); 206 TEST("add 8 eok", dyn_fifo_push(&fifo, 8, 5), EOK); 207 TEST("add 9 eok", dyn_fifo_push(&fifo, 9, 5), EOK); 208 TEST("add 10 eok", dyn_fifo_push(&fifo, 10, 6), EOK); 209 TEST("add 11 eok", dyn_fifo_push(&fifo, 11, 6), EOK); 210 TEST("pop 6", dyn_fifo_pop(&fifo), 6); 211 TEST("pop 7", dyn_fifo_pop(&fifo), 7); 212 TEST("add 12 eok", dyn_fifo_push(&fifo, 12, 6), EOK); 213 TEST("add 13 eok", dyn_fifo_push(&fifo, 13, 6), EOK); 214 TEST("add 14 enomem", dyn_fifo_push(&fifo, 14, 6), ENOMEM); 215 TEST("add 14 eok", dyn_fifo_push(&fifo, 14, 8), EOK); 216 TEST("pop 8", dyn_fifo_pop(&fifo), 8); 217 TEST("pop 9", dyn_fifo_pop(&fifo), 9); 218 TEST("pop 10", dyn_fifo_pop(&fifo), 10); 219 TEST("pop 11", dyn_fifo_pop(&fifo), 11); 220 TEST("pop 12", dyn_fifo_pop(&fifo), 12); 221 TEST("pop 13", dyn_fifo_pop(&fifo), 13); 222 TEST("pop 14", dyn_fifo_pop(&fifo), 14); 223 TEST("destroy", dyn_fifo_destroy(&fifo), EOK); 224 TEST("add 15 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL); 225 if(error){ 226 return EINVAL; 227 } 228 229 #endif 230 231 #if NET_SELF_TEST_GENERIC_CHAR_MAP 145 146 TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL); 147 TEST(dyn_fifo_initialize(&fifo, 1), EOK); 148 TEST(dyn_fifo_push(&fifo, 1, 0), EOK); 149 TEST(dyn_fifo_pop(&fifo), 1); 150 TEST(dyn_fifo_pop(&fifo), ENOENT); 151 TEST(dyn_fifo_push(&fifo, 2, 1), EOK); 152 TEST(dyn_fifo_push(&fifo, 3, 1), ENOMEM); 153 TEST(dyn_fifo_push(&fifo, 3, 0), EOK); 154 TEST(dyn_fifo_pop(&fifo), 2); 155 TEST(dyn_fifo_pop(&fifo), 3); 156 TEST(dyn_fifo_push(&fifo, 4, 2), EOK); 157 TEST(dyn_fifo_push(&fifo, 5, 2), EOK); 158 TEST(dyn_fifo_push(&fifo, 6, 2), ENOMEM); 159 TEST(dyn_fifo_push(&fifo, 6, 5), EOK); 160 TEST(dyn_fifo_push(&fifo, 7, 5), EOK); 161 TEST(dyn_fifo_pop(&fifo), 4); 162 TEST(dyn_fifo_pop(&fifo), 5); 163 TEST(dyn_fifo_push(&fifo, 8, 5), EOK); 164 TEST(dyn_fifo_push(&fifo, 9, 5), EOK); 165 TEST(dyn_fifo_push(&fifo, 10, 6), EOK); 166 TEST(dyn_fifo_push(&fifo, 11, 6), EOK); 167 TEST(dyn_fifo_pop(&fifo), 6); 168 TEST(dyn_fifo_pop(&fifo), 7); 169 TEST(dyn_fifo_push(&fifo, 12, 6), EOK); 170 TEST(dyn_fifo_push(&fifo, 13, 6), EOK); 171 TEST(dyn_fifo_push(&fifo, 14, 6), ENOMEM); 172 TEST(dyn_fifo_push(&fifo, 14, 8), EOK); 173 TEST(dyn_fifo_pop(&fifo), 8); 174 TEST(dyn_fifo_pop(&fifo), 9); 175 TEST(dyn_fifo_pop(&fifo), 10); 176 TEST(dyn_fifo_pop(&fifo), 11); 177 TEST(dyn_fifo_pop(&fifo), 12); 178 TEST(dyn_fifo_pop(&fifo), 13); 179 TEST(dyn_fifo_pop(&fifo), 14); 180 TEST(dyn_fifo_destroy(&fifo), EOK); 181 TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL); 182 183 printf("\nGeneric char map test"); 184 185 int *x; 186 int *y; 187 int *z; 188 int *u; 189 int *v; 190 int *w; 191 192 XMALLOC(x, int); 193 XMALLOC(y, int); 194 XMALLOC(z, int); 195 XMALLOC(u, int); 196 XMALLOC(v, int); 197 XMALLOC(w, int); 198 232 199 int_char_map_t icm; 233 234 x = (int *) malloc(sizeof(int));235 y = (int *) malloc(sizeof(int));236 z = (int *) malloc(sizeof(int));237 u = (int *) malloc(sizeof(int));238 v = (int *) malloc(sizeof(int));239 w = (int *) malloc(sizeof(int));240 241 200 icm.magic = 0; 242 printf("\nGeneric char map test"); 243 TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL); 244 TEST("initialize", int_char_map_initialize(&icm), EOK); 245 printf("\n\texclude bla null"); 246 int_char_map_exclude(&icm, "bla", 0); 247 TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL); 248 TEST("add bla x eok", int_char_map_add(&icm, "bla", 0, x), EOK); 249 TEST("find bla x", int_char_map_find(&icm, "bla", 0), x); 250 TEST("add bla y eexists", int_char_map_add(&icm, "bla", 0, y), EEXISTS); 251 printf("\n\texclude bla y"); 252 int_char_map_exclude(&icm, "bla", 0); 253 printf("\n\texclude bla null"); 254 int_char_map_exclude(&icm, "bla", 0); 255 TEST("add blabla v eok", int_char_map_add(&icm, "blabla", 0, v), EOK); 256 TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v); 257 TEST("add bla w eok", int_char_map_add(&icm, "bla", 0, w), EOK); 258 TEST("find bla w", int_char_map_find(&icm, "bla", 0), w); 259 printf("\n\texclude bla"); 260 int_char_map_exclude(&icm, "bla", 0); 261 TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL); 262 TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v); 263 TEST("add auto u eok", int_char_map_add(&icm, "auto", 0, u), EOK); 264 TEST("find auto u", int_char_map_find(&icm, "auto", 0), u); 265 printf("\n\tdestroy"); 266 int_char_map_destroy(&icm); 267 TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL); 268 printf("\nOK"); 269 270 if(error){ 271 return EINVAL; 272 } 273 274 #endif 275 276 #if NET_SELF_TEST_GENERIC_FIELD 201 202 TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL); 203 TEST(int_char_map_initialize(&icm), EOK); 204 TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK); 205 TEST(int_char_map_find(&icm, "bla", 0), NULL); 206 TEST(int_char_map_add(&icm, "bla", 0, x), EOK); 207 TEST(int_char_map_find(&icm, "bla", 0), x); 208 TEST(int_char_map_add(&icm, "bla", 0, y), EEXISTS); 209 TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK); 210 TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK); 211 TEST(int_char_map_add(&icm, "blabla", 0, v), EOK); 212 TEST(int_char_map_find(&icm, "blabla", 0), v); 213 TEST(int_char_map_add(&icm, "bla", 0, w), EOK); 214 TEST(int_char_map_find(&icm, "bla", 0), w); 215 TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK); 216 TEST(int_char_map_find(&icm, "bla", 0), NULL); 217 TEST(int_char_map_find(&icm, "blabla", 0), v); 218 TEST(int_char_map_add(&icm, "auto", 0, u), EOK); 219 TEST(int_char_map_find(&icm, "auto", 0), u); 220 TEST((int_char_map_destroy(&icm), EOK), EOK); 221 TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL); 222 223 printf("\nGeneric field test"); 224 225 XMALLOC(x, int); 226 XMALLOC(y, int); 227 XMALLOC(z, int); 228 XMALLOC(u, int); 229 XMALLOC(v, int); 230 XMALLOC(w, int); 231 277 232 int_field_t gf; 278 279 x = (int *) malloc(sizeof(int));280 y = (int *) malloc(sizeof(int));281 z = (int *) malloc(sizeof(int));282 u = (int *) malloc(sizeof(int));283 v = (int *) malloc(sizeof(int));284 w = (int *) malloc(sizeof(int));285 286 233 gf.magic = 0; 287 printf("\nGeneric field test");288 TEST( "add x einval",int_field_add(&gf, x), EINVAL);289 TEST( "count -1",int_field_count(&gf), -1);290 TEST( "initialize",int_field_initialize(&gf), EOK);291 TEST( "count 0",int_field_count(&gf), 0);292 TEST( "get 1 null",int_field_get_index(&gf, 1), NULL);293 TEST( "add x 0",int_field_add(&gf, x), 0);294 TEST( "get 0 x",int_field_get_index(&gf, 0), x);295 int_field_exclude_index(&gf, 0);296 TEST( "get 0 null",int_field_get_index(&gf, 0), NULL);297 TEST( "add y 1",int_field_add(&gf, y), 1);298 TEST( "get 1 y",int_field_get_index(&gf, 1), y);299 TEST( "add z 2",int_field_add(&gf, z), 2);300 TEST( "get 2 z",int_field_get_index(&gf, 2), z);301 TEST( "get 1 y",int_field_get_index(&gf, 1), y);302 TEST( "count 3",int_field_count(&gf), 3);303 TEST( "add u 3",int_field_add(&gf, u), 3);304 TEST( "get 3 u",int_field_get_index(&gf, 3), u);305 TEST( "add v 4",int_field_add(&gf, v), 4);306 TEST( "get 4 v",int_field_get_index(&gf, 4), v);307 TEST( "add w 5",int_field_add(&gf, w), 5);308 TEST( "get 5 w",int_field_get_index(&gf, 5), w);309 TEST( "count 6",int_field_count(&gf), 6);310 int_field_exclude_index(&gf, 1);311 TEST( "get 1 null",int_field_get_index(&gf, 1), NULL);312 TEST( "get 3 u",int_field_get_index(&gf, 3), u);313 int_field_exclude_index(&gf, 7);314 TEST( "get 3 u",int_field_get_index(&gf, 3), u);315 TEST( "get 5 w",int_field_get_index(&gf, 5), w);316 int_field_exclude_index(&gf, 4);317 TEST( "get 4 null",int_field_get_index(&gf, 4), NULL);318 printf("\n\tdestroy");319 int_field_destroy(&gf);320 TEST("count -1", int_field_count(&gf), -1);321 printf("\n OK");322 323 if(error){324 return EINVAL;325 }326 327 #endif 328 329 #if NET_SELF_TEST_INT_MAP 234 235 TEST(int_field_add(&gf, x), EINVAL); 236 TEST(int_field_count(&gf), -1); 237 TEST(int_field_initialize(&gf), EOK); 238 TEST(int_field_count(&gf), 0); 239 TEST(int_field_get_index(&gf, 1), NULL); 240 TEST(int_field_add(&gf, x), 0); 241 TEST(int_field_get_index(&gf, 0), x); 242 TEST((int_field_exclude_index(&gf, 0), EOK), EOK); 243 TEST(int_field_get_index(&gf, 0), NULL); 244 TEST(int_field_add(&gf, y), 1); 245 TEST(int_field_get_index(&gf, 1), y); 246 TEST(int_field_add(&gf, z), 2); 247 TEST(int_field_get_index(&gf, 2), z); 248 TEST(int_field_get_index(&gf, 1), y); 249 TEST(int_field_count(&gf), 3); 250 TEST(int_field_add(&gf, u), 3); 251 TEST(int_field_get_index(&gf, 3), u); 252 TEST(int_field_add(&gf, v), 4); 253 TEST(int_field_get_index(&gf, 4), v); 254 TEST(int_field_add(&gf, w), 5); 255 TEST(int_field_get_index(&gf, 5), w); 256 TEST(int_field_count(&gf), 6); 257 TEST((int_field_exclude_index(&gf, 1), EOK), EOK); 258 TEST(int_field_get_index(&gf, 1), NULL); 259 TEST(int_field_get_index(&gf, 3), u); 260 TEST((int_field_exclude_index(&gf, 7), EOK), EOK); 261 TEST(int_field_get_index(&gf, 3), u); 262 TEST(int_field_get_index(&gf, 5), w); 263 TEST((int_field_exclude_index(&gf, 4), EOK), EOK); 264 TEST(int_field_get_index(&gf, 4), NULL); 265 TEST((int_field_destroy(&gf), EOK), EOK); 266 TEST(int_field_count(&gf), -1); 267 268 printf("\nInt map test"); 269 270 XMALLOC(x, int); 271 XMALLOC(y, int); 272 XMALLOC(z, int); 273 XMALLOC(u, int); 274 XMALLOC(v, int); 275 XMALLOC(w, int); 276 330 277 int_map_t im; 331 332 x = (int *) malloc(sizeof(int));333 y = (int *) malloc(sizeof(int));334 z = (int *) malloc(sizeof(int));335 u = (int *) malloc(sizeof(int));336 v = (int *) malloc(sizeof(int));337 w = (int *) malloc(sizeof(int));338 339 278 im.magic = 0; 340 printf("\nInt map test"); 341 TEST("add 1 x einval", int_map_add(&im, 1, x), EINVAL); 342 TEST("count -1", int_map_count(&im), -1); 343 TEST("initialize", int_map_initialize(&im), EOK); 344 TEST("count 0", int_map_count(&im), 0); 345 TEST("find 1 null", int_map_find(&im, 1), NULL); 346 TEST("add 1 x 0", int_map_add(&im, 1, x), 0); 347 TEST("find 1 x", int_map_find(&im, 1), x); 348 int_map_exclude(&im, 1); 349 TEST("find 1 null", int_map_find(&im, 1), NULL); 350 TEST("add 1 y 1", int_map_add(&im, 1, y), 1); 351 TEST("find 1 y", int_map_find(&im, 1), y); 352 TEST("add 4 z 2", int_map_add(&im, 4, z), 2); 353 TEST("get 2 z", int_map_get_index(&im, 2), z); 354 TEST("find 4 z", int_map_find(&im, 4), z); 355 TEST("find 1 y", int_map_find(&im, 1), y); 356 TEST("count 3", int_map_count(&im), 3); 357 TEST("add 2 u 3", int_map_add(&im, 2, u), 3); 358 TEST("find 2 u", int_map_find(&im, 2), u); 359 TEST("add 3 v 4", int_map_add(&im, 3, v), 4); 360 TEST("find 3 v", int_map_find(&im, 3), v); 361 TEST("get 4 v", int_map_get_index(&im, 4), v); 362 TEST("add 6 w 5", int_map_add(&im, 6, w), 5); 363 TEST("find 6 w", int_map_find(&im, 6), w); 364 TEST("count 6", int_map_count(&im), 6); 365 int_map_exclude(&im, 1); 366 TEST("find 1 null", int_map_find(&im, 1), NULL); 367 TEST("find 2 u", int_map_find(&im, 2), u); 368 int_map_exclude(&im, 7); 369 TEST("find 2 u", int_map_find(&im, 2), u); 370 TEST("find 6 w", int_map_find(&im, 6), w); 371 int_map_exclude_index(&im, 4); 372 TEST("get 4 null", int_map_get_index(&im, 4), NULL); 373 TEST("find 3 null", int_map_find(&im, 3), NULL); 374 printf("\n\tdestroy"); 375 int_map_destroy(&im); 376 TEST("count -1", int_map_count(&im), -1); 377 printf("\nOK"); 378 379 if(error){ 380 return EINVAL; 381 } 382 383 #endif 384 385 #if NET_SELF_TEST_MEASURED_STRINGS 386 measured_string_ref string; 387 279 280 TEST(int_map_add(&im, 1, x), EINVAL); 281 TEST(int_map_count(&im), -1); 282 TEST(int_map_initialize(&im), EOK); 283 TEST(int_map_count(&im), 0); 284 TEST(int_map_find(&im, 1), NULL); 285 TEST(int_map_add(&im, 1, x), 0); 286 TEST(int_map_find(&im, 1), x); 287 TEST((int_map_exclude(&im, 1), EOK), EOK); 288 TEST(int_map_find(&im, 1), NULL); 289 TEST(int_map_add(&im, 1, y), 1); 290 TEST(int_map_find(&im, 1), y); 291 TEST(int_map_add(&im, 4, z), 2); 292 TEST(int_map_get_index(&im, 2), z); 293 TEST(int_map_find(&im, 4), z); 294 TEST(int_map_find(&im, 1), y); 295 TEST(int_map_count(&im), 3); 296 TEST(int_map_add(&im, 2, u), 3); 297 TEST(int_map_find(&im, 2), u); 298 TEST(int_map_add(&im, 3, v), 4); 299 TEST(int_map_find(&im, 3), v); 300 TEST(int_map_get_index(&im, 4), v); 301 TEST(int_map_add(&im, 6, w), 5); 302 TEST(int_map_find(&im, 6), w); 303 TEST(int_map_count(&im), 6); 304 TEST((int_map_exclude(&im, 1), EOK), EOK); 305 TEST(int_map_find(&im, 1), NULL); 306 TEST(int_map_find(&im, 2), u); 307 TEST((int_map_exclude(&im, 7), EOK), EOK); 308 TEST(int_map_find(&im, 2), u); 309 TEST(int_map_find(&im, 6), w); 310 TEST((int_map_exclude_index(&im, 4), EOK), EOK); 311 TEST(int_map_get_index(&im, 4), NULL); 312 TEST(int_map_find(&im, 3), NULL); 313 TEST((int_map_destroy(&im), EOK), EOK); 314 TEST(int_map_count(&im), -1); 315 388 316 printf("\nMeasured strings test"); 389 string = measured_string_create_bulk("I am a measured string!", 0); 390 printf("\n%x, %s at %x of %d", string, string->value, string->value, string->length); 391 printf("\nOK"); 392 #endif 393 317 318 measured_string_ref string = 319 measured_string_create_bulk("I am a measured string!", 0); 320 printf("\n%x, %s at %x of %d\n", string, string->value, string->value, 321 string->length); 322 394 323 return EOK; 395 324 } 396 325 397 #endif398 399 326 /** @} 400 327 */ -
uspace/srv/net/netstart/self_test.h
r7553689 r4011fa0 28 28 29 29 /** @addtogroup net 30 * @{ 31 */ 32 33 /** @file 34 * Self tests. 35 * @see configuration.h 30 * @{ 36 31 */ 37 32 … … 39 34 #define __SELF_TEST_H__ 40 35 41 #include "configuration.h"42 43 /** Self test start function.44 * Runs all the configured self tests.45 * @see configuration.h46 * @returns EOK on success.47 * @returns The first error occurred.48 */49 #if NET_SELF_TEST50 51 36 extern int self_test(void); 52 53 #else54 55 #include <errno.h>56 57 #define self_test() EOK58 59 #endif60 37 61 38 #endif
Note:
See TracChangeset
for help on using the changeset viewer.