Changeset 8ff0bd2 in mainline for uspace/drv/test
- Timestamp:
- 2011-09-04T11:30:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03bc76a
- Parents:
- d2c67e7 (diff), deac215e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/drv/test
- Files:
-
- 11 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test/test1/Makefile
rd2c67e7 r8ff0bd2 27 27 # 28 28 29 USPACE_PREFIX = ../.. 29 USPACE_PREFIX = ../../.. 30 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a 31 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -
uspace/drv/test/test1/test1.c
rd2c67e7 r8ff0bd2 1 1 /* 2 2 * Copyright (c) 2010 Vojtech Horky 3 * Copyright (c) 2011 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 40 41 41 42 static int test1_add_device(ddf_dev_t *dev); 43 static int test1_dev_remove(ddf_dev_t *dev); 44 static int test1_fun_online(ddf_fun_t *fun); 45 static int test1_fun_offline(ddf_fun_t *fun); 42 46 43 47 static driver_ops_t driver_ops = { 44 .add_device = &test1_add_device 48 .add_device = &test1_add_device, 49 .dev_remove = &test1_dev_remove, 50 .fun_online = &test1_fun_online, 51 .fun_offline = &test1_fun_offline 45 52 }; 46 53 … … 49 56 .driver_ops = &driver_ops 50 57 }; 58 59 typedef struct { 60 ddf_fun_t *fun_a; 61 ddf_fun_t *clone; 62 ddf_fun_t *child; 63 } test1_t; 51 64 52 65 /** Register child and inform user about it. … … 60 73 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 61 74 const char *name, const char *match_id, int match_score, 62 int expected_rc )75 int expected_rc, ddf_fun_t **pfun) 63 76 { 64 77 ddf_fun_t *fun = NULL; … … 74 87 } 75 88 76 rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);89 rc = ddf_fun_add_match_id(fun, match_id, match_score); 77 90 if (rc != EOK) { 78 91 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", … … 103 116 } 104 117 118 if (pfun != NULL) 119 *pfun = fun; 120 105 121 return rc; 106 122 } … … 126 142 { 127 143 ddf_fun_t *fun_a; 144 test1_t *test1; 128 145 int rc; 129 146 130 147 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 131 148 dev->name, (int) dev->handle); 149 150 test1 = ddf_dev_data_alloc(dev, sizeof(test1_t)); 151 if (test1 == NULL) { 152 ddf_msg(LVL_ERROR, "Failed allocating soft state.\n"); 153 return ENOMEM; 154 } 132 155 133 156 fun_a = ddf_fun_create(dev, fun_exposed, "a"); … … 137 160 } 138 161 162 test1->fun_a = fun_a; 163 139 164 rc = ddf_fun_bind(fun_a); 140 165 if (rc != EOK) { 141 166 ddf_msg(LVL_ERROR, "Failed binding function 'a'."); 167 ddf_fun_destroy(fun_a); 142 168 return rc; 143 169 } 144 170 145 ddf_fun_add_to_c lass(fun_a, "virtual");171 ddf_fun_add_to_category(fun_a, "virtual"); 146 172 147 173 if (str_cmp(dev->name, "null") == 0) { 148 174 fun_a->ops = &char_device_ops; 149 ddf_fun_add_to_c lass(fun_a, "virt-null");175 ddf_fun_add_to_category(fun_a, "virt-null"); 150 176 } else if (str_cmp(dev->name, "test1") == 0) { 151 177 (void) register_fun_verbose(dev, 152 178 "cloning myself ;-)", "clone", 153 "virtual&test1", 10, EOK );179 "virtual&test1", 10, EOK, &test1->clone); 154 180 (void) register_fun_verbose(dev, 155 181 "cloning myself twice ;-)", "clone", 156 "virtual&test1", 10, EEXISTS );182 "virtual&test1", 10, EEXISTS, NULL); 157 183 } else if (str_cmp(dev->name, "clone") == 0) { 158 184 (void) register_fun_verbose(dev, 159 185 "run by the same task", "child", 160 "virtual&test1&child", 10, EOK );186 "virtual&test1&child", 10, EOK, &test1->child); 161 187 } 162 188 … … 164 190 165 191 return EOK; 192 } 193 194 static int fun_remove(ddf_fun_t *fun, const char *name) 195 { 196 int rc; 197 198 ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name); 199 rc = ddf_fun_offline(fun); 200 if (rc != EOK) { 201 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name); 202 return rc; 203 } 204 205 rc = ddf_fun_unbind(fun); 206 if (rc != EOK) { 207 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name); 208 return rc; 209 } 210 211 ddf_fun_destroy(fun); 212 return EOK; 213 } 214 215 static int test1_dev_remove(ddf_dev_t *dev) 216 { 217 test1_t *test1 = (test1_t *)dev->driver_data; 218 int rc; 219 220 ddf_msg(LVL_DEBUG, "test1_dev_remove(%p)", dev); 221 222 if (test1->fun_a != NULL) { 223 rc = fun_remove(test1->fun_a, "a"); 224 if (rc != EOK) 225 return rc; 226 } 227 228 if (test1->clone != NULL) { 229 rc = fun_remove(test1->clone, "clone"); 230 if (rc != EOK) 231 return rc; 232 } 233 234 if (test1->child != NULL) { 235 rc = fun_remove(test1->child, "child"); 236 if (rc != EOK) 237 return rc; 238 } 239 240 return EOK; 241 } 242 243 static int test1_fun_online(ddf_fun_t *fun) 244 { 245 ddf_msg(LVL_DEBUG, "test1_fun_online()"); 246 return ddf_fun_online(fun); 247 } 248 249 static int test1_fun_offline(ddf_fun_t *fun) 250 { 251 ddf_msg(LVL_DEBUG, "test1_fun_offline()"); 252 return ddf_fun_offline(fun); 166 253 } 167 254 -
uspace/drv/test/test2/Makefile
rd2c67e7 r8ff0bd2 27 27 # 28 28 29 USPACE_PREFIX = ../.. 29 USPACE_PREFIX = ../../.. 30 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a 31 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -
uspace/drv/test/test2/test2.c
rd2c67e7 r8ff0bd2 41 41 42 42 static int test2_add_device(ddf_dev_t *dev); 43 static int test2_dev_remove(ddf_dev_t *dev); 44 static int test2_fun_online(ddf_fun_t *fun); 45 static int test2_fun_offline(ddf_fun_t *fun); 43 46 44 47 static driver_ops_t driver_ops = { 45 .add_device = &test2_add_device 48 .add_device = &test2_add_device, 49 .dev_remove = &test2_dev_remove, 50 .fun_online = &test2_fun_online, 51 .fun_offline = &test2_fun_offline 46 52 }; 47 53 … … 50 56 .driver_ops = &driver_ops 51 57 }; 58 59 /* Device soft state */ 60 typedef struct { 61 ddf_dev_t *dev; 62 63 ddf_fun_t *fun_a; 64 ddf_fun_t *fun_err; 65 ddf_fun_t *child; 66 ddf_fun_t *test1; 67 } test2_t; 52 68 53 69 /** Register child and inform user about it. … … 60 76 */ 61 77 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 62 const char *name, const char *match_id, int match_score )78 const char *name, const char *match_id, int match_score, ddf_fun_t **pfun) 63 79 { 64 80 ddf_fun_t *fun; … … 89 105 } 90 106 107 *pfun = fun; 108 91 109 ddf_msg(LVL_NOTE, "Registered child device `%s'", name); 92 110 return EOK; … … 100 118 static int postponed_birth(void *arg) 101 119 { 102 ddf_dev_t *dev = (ddf_dev_t *) arg;120 test2_t *test2 = (test2_t *) arg; 103 121 ddf_fun_t *fun_a; 104 122 int rc; … … 106 124 async_usleep(1000); 107 125 108 (void) register_fun_verbose( dev, "child driven by the same task",109 "child", "virtual&test2", 10 );110 (void) register_fun_verbose( dev, "child driven by test1",111 "test1", "virtual&test1", 10 );112 113 fun_a = ddf_fun_create( dev, fun_exposed, "a");126 (void) register_fun_verbose(test2->dev, "child driven by the same task", 127 "child", "virtual&test2", 10, &test2->child); 128 (void) register_fun_verbose(test2->dev, "child driven by test1", 129 "test1", "virtual&test1", 10, &test2->test1); 130 131 fun_a = ddf_fun_create(test2->dev, fun_exposed, "a"); 114 132 if (fun_a == NULL) { 115 133 ddf_msg(LVL_ERROR, "Failed creating function 'a'."); … … 123 141 } 124 142 125 ddf_fun_add_to_class(fun_a, "virtual"); 126 143 ddf_fun_add_to_category(fun_a, "virtual"); 144 test2->fun_a = fun_a; 145 146 return EOK; 147 } 148 149 static int fun_remove(ddf_fun_t *fun, const char *name) 150 { 151 int rc; 152 153 ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name); 154 rc = ddf_fun_offline(fun); 155 if (rc != EOK) { 156 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name); 157 return rc; 158 } 159 160 rc = ddf_fun_unbind(fun); 161 if (rc != EOK) { 162 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name); 163 return rc; 164 } 165 166 ddf_fun_destroy(fun); 127 167 return EOK; 128 168 } … … 130 170 static int test2_add_device(ddf_dev_t *dev) 131 171 { 172 test2_t *test2; 173 132 174 ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)", 133 175 dev->name, (int) dev->handle); 134 176 177 test2 = ddf_dev_data_alloc(dev, sizeof(test2_t)); 178 if (test2 == NULL) { 179 ddf_msg(LVL_ERROR, "Failed allocating soft state."); 180 return ENOMEM; 181 } 182 183 test2->dev = dev; 184 135 185 if (str_cmp(dev->name, "child") != 0) { 136 fid_t postpone = fibril_create(postponed_birth, dev);186 fid_t postpone = fibril_create(postponed_birth, test2); 137 187 if (postpone == 0) { 138 188 ddf_msg(LVL_ERROR, "fibril_create() failed."); … … 142 192 } else { 143 193 (void) register_fun_verbose(dev, "child without available driver", 144 "ERROR", "non-existent.match.id", 10); 145 } 146 147 return EOK; 194 "ERROR", "non-existent.match.id", 10, &test2->fun_err); 195 } 196 197 return EOK; 198 } 199 200 static int test2_dev_remove(ddf_dev_t *dev) 201 { 202 test2_t *test2 = (test2_t *)dev->driver_data; 203 int rc; 204 205 ddf_msg(LVL_DEBUG, "test2_dev_remove(%p)", dev); 206 207 if (test2->fun_a != NULL) { 208 rc = fun_remove(test2->fun_a, "a"); 209 if (rc != EOK) 210 return rc; 211 } 212 213 if (test2->fun_err != NULL) { 214 rc = fun_remove(test2->fun_err, "ERROR"); 215 if (rc != EOK) 216 return rc; 217 } 218 219 if (test2->child != NULL) { 220 rc = fun_remove(test2->child, "child"); 221 if (rc != EOK) 222 return rc; 223 } 224 225 if (test2->test1 != NULL) { 226 rc = fun_remove(test2->test1, "test1"); 227 if (rc != EOK) 228 return rc; 229 } 230 231 return EOK; 232 } 233 234 235 static int test2_fun_online(ddf_fun_t *fun) 236 { 237 ddf_msg(LVL_DEBUG, "test2_fun_online()"); 238 return ddf_fun_online(fun); 239 } 240 241 static int test2_fun_offline(ddf_fun_t *fun) 242 { 243 ddf_msg(LVL_DEBUG, "test2_fun_offline()"); 244 return ddf_fun_offline(fun); 148 245 } 149 246 -
uspace/drv/test/test3/Makefile
rd2c67e7 r8ff0bd2 27 27 # 28 28 29 USPACE_PREFIX = ../.. 29 USPACE_PREFIX = ../../.. 30 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a 31 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -
uspace/drv/test/test3/test3.c
rd2c67e7 r8ff0bd2 39 39 #define NAME "test3" 40 40 41 #define NUM_FUNCS 20 42 41 43 static int test3_add_device(ddf_dev_t *dev); 44 static int test3_dev_remove(ddf_dev_t *dev); 45 static int test3_fun_online(ddf_fun_t *fun); 46 static int test3_fun_offline(ddf_fun_t *fun); 42 47 43 48 static driver_ops_t driver_ops = { 44 .add_device = &test3_add_device 49 .add_device = &test3_add_device, 50 .dev_remove = &test3_dev_remove, 51 .fun_online = &test3_fun_online, 52 .fun_offline = &test3_fun_offline, 45 53 }; 46 54 … … 50 58 }; 51 59 52 static int register_fun_and_add_to_class(ddf_dev_t *parent, 53 const char *base_name, size_t index, const char *class_name) 60 typedef struct { 61 ddf_dev_t *dev; 62 ddf_fun_t *fun[NUM_FUNCS]; 63 } test3_t; 64 65 static int register_fun_and_add_to_category(ddf_dev_t *parent, 66 const char *base_name, size_t index, const char *class_name, 67 ddf_fun_t **pfun) 54 68 { 55 69 ddf_fun_t *fun = NULL; … … 77 91 } 78 92 79 ddf_fun_add_to_c lass(fun, class_name);93 ddf_fun_add_to_category(fun, class_name); 80 94 81 95 ddf_msg(LVL_NOTE, "Registered exposed function `%s'.", fun_name); … … 88 102 } 89 103 104 *pfun = fun; 90 105 return rc; 106 } 107 108 static int fun_remove(ddf_fun_t *fun, const char *name) 109 { 110 int rc; 111 112 ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name); 113 rc = ddf_fun_offline(fun); 114 if (rc != EOK) { 115 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name); 116 return rc; 117 } 118 119 rc = ddf_fun_unbind(fun); 120 if (rc != EOK) { 121 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name); 122 return rc; 123 } 124 125 ddf_fun_destroy(fun); 126 return EOK; 91 127 } 92 128 … … 94 130 { 95 131 int rc = EOK; 132 test3_t *test3; 96 133 97 134 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 98 135 dev->name, (int) dev->handle); 99 136 137 test3 = ddf_dev_data_alloc(dev, sizeof(test3_t)); 138 if (test3 == NULL) { 139 ddf_msg(LVL_ERROR, "Failed allocating soft state."); 140 return ENOMEM; 141 } 142 100 143 size_t i; 101 for (i = 0; i < 20; i++) {102 rc = register_fun_and_add_to_c lass(dev,103 "test3_", i, "test3" );144 for (i = 0; i < NUM_FUNCS; i++) { 145 rc = register_fun_and_add_to_category(dev, 146 "test3_", i, "test3", &test3->fun[i]); 104 147 if (rc != EOK) { 105 148 break; … … 110 153 } 111 154 155 static int test3_dev_remove(ddf_dev_t *dev) 156 { 157 test3_t *test3 = (test3_t *)dev->driver_data; 158 char *fun_name; 159 int rc; 160 size_t i; 161 162 for (i = 0; i < NUM_FUNCS; i++) { 163 rc = asprintf(&fun_name, "test3_%zu", i); 164 if (rc < 0) { 165 ddf_msg(LVL_ERROR, "Failed to format string: %s", str_error(rc)); 166 return ENOMEM; 167 } 168 169 rc = fun_remove(test3->fun[i], fun_name); 170 if (rc != EOK) 171 return rc; 172 173 free(fun_name); 174 } 175 176 return EOK; 177 } 178 179 static int test3_fun_online(ddf_fun_t *fun) 180 { 181 ddf_msg(LVL_DEBUG, "test3_fun_online()"); 182 return ddf_fun_online(fun); 183 } 184 185 static int test3_fun_offline(ddf_fun_t *fun) 186 { 187 ddf_msg(LVL_DEBUG, "test3_fun_offline()"); 188 return ddf_fun_offline(fun); 189 } 190 191 112 192 int main(int argc, char *argv[]) 113 193 {
Note:
See TracChangeset
for help on using the changeset viewer.