| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved. | 
 | 2 |  * | 
 | 3 |  * This program is free software; you can redistribute it and/or modify | 
 | 4 |  * it under the terms of the GNU General Public License version 2 and | 
 | 5 |  * only version 2 as published by the Free Software Foundation. | 
 | 6 |  * | 
 | 7 |  * This program is distributed in the hope that it will be useful, | 
 | 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 9 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 10 |  * GNU General Public License for more details. | 
 | 11 |  * | 
 | 12 |  */ | 
 | 13 | /* | 
 | 14 |  * DAL remote test device test suite. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #include <linux/kernel.h> | 
 | 18 | #include <linux/module.h> | 
 | 19 | #include <linux/errno.h> | 
 | 20 | #include <linux/string.h> | 
 | 21 | #include <linux/debugfs.h> | 
 | 22 |  | 
 | 23 | #include "dal_remotetest.h" | 
 | 24 |  | 
 | 25 | #define BYTEBUF_LEN 64 | 
 | 26 |  | 
 | 27 | #define rpc_error(num)							\ | 
 | 28 | 	do {								\ | 
 | 29 | 		errmask |= (1 << num);					\ | 
 | 30 | 		printk(KERN_INFO "%s: remote_unittest_%d failed (%d)\n", \ | 
 | 31 | 		       __func__, num, ret);				\ | 
 | 32 | 	} while (0) | 
 | 33 |  | 
 | 34 | #define verify_error(num, field)					\ | 
 | 35 | 	do {								\ | 
 | 36 | 		errmask |= (1 << num);					\ | 
 | 37 | 		printk(KERN_INFO "%s: remote_unittest_%d failed (%s)\n", \ | 
 | 38 | 		       __func__, num, field);				\ | 
 | 39 | 	} while (0) | 
 | 40 |  | 
 | 41 |  | 
 | 42 | static struct dentry *debugfs_dir_entry; | 
 | 43 | static struct dentry *debugfs_modem_entry; | 
 | 44 | static struct dentry *debugfs_dsp_entry; | 
 | 45 |  | 
 | 46 | static uint8_t in_bytebuf[BYTEBUF_LEN]; | 
 | 47 | static uint8_t out_bytebuf[BYTEBUF_LEN]; | 
 | 48 | static uint8_t out_bytebuf2[BYTEBUF_LEN]; | 
 | 49 | static struct remote_test_data in_data; | 
 | 50 | static struct remote_test_data out_data; | 
 | 51 | static int block_until_cb = 1; | 
 | 52 |  | 
 | 53 | static void init_data(struct remote_test_data *data) | 
 | 54 | { | 
 | 55 | 	int i; | 
 | 56 | 	data->regular_event = REMOTE_UNITTEST_INPUT_HANDLE; | 
 | 57 | 	data->payload_event = REMOTE_UNITTEST_INPUT_HANDLE; | 
 | 58 | 	for (i = 0; i < 32; i++) | 
 | 59 | 		data->test[i] = i; | 
 | 60 | } | 
 | 61 |  | 
 | 62 | static int verify_data(struct remote_test_data *data) | 
 | 63 | { | 
 | 64 | 	int i; | 
 | 65 | 	if (data->regular_event != REMOTE_UNITTEST_INPUT_HANDLE || | 
 | 66 | 	    data->payload_event != REMOTE_UNITTEST_INPUT_HANDLE) | 
 | 67 | 		return -1; | 
 | 68 | 	for (i = 0; i < 32; i++) | 
 | 69 | 		if (data->test[i] != i) | 
 | 70 | 			return -1; | 
 | 71 |  | 
 | 72 | 	return 0; | 
 | 73 | } | 
 | 74 |  | 
 | 75 | static int verify_uint32_buffer(uint32_t *buf) | 
 | 76 | { | 
 | 77 | 	int i; | 
 | 78 | 	for (i = 0; i < 32; i++) | 
 | 79 | 		if (buf[i] != i) | 
 | 80 | 			return -1; | 
 | 81 |  | 
 | 82 | 	return 0; | 
 | 83 | } | 
 | 84 |  | 
 | 85 | static void init_bytebuf(uint8_t *bytebuf) | 
 | 86 | { | 
 | 87 | 	int i; | 
 | 88 | 	for (i = 0; i < BYTEBUF_LEN; i++) | 
 | 89 | 		bytebuf[i] = i & 0xff; | 
 | 90 | } | 
 | 91 |  | 
 | 92 | static int verify_bytebuf(uint8_t *bytebuf) | 
 | 93 | { | 
 | 94 | 	int i; | 
 | 95 | 	for (i = 0; i < BYTEBUF_LEN; i++) | 
 | 96 | 		if (bytebuf[i] != (i & 0xff)) | 
 | 97 | 			return -1; | 
 | 98 |  | 
 | 99 | 	return 0; | 
 | 100 | } | 
 | 101 |  | 
 | 102 | static void test_cb(void *context, uint32_t param, void *data, uint32_t len) | 
 | 103 | { | 
 | 104 | 	block_until_cb = 0; | 
 | 105 | } | 
 | 106 |  | 
 | 107 | static int remotetest_exec(int dest, u64 *val) | 
 | 108 | { | 
 | 109 | 	void *dev_handle; | 
 | 110 | 	void *event_handles[3]; | 
 | 111 | 	void *cb_handle; | 
 | 112 | 	int ret; | 
 | 113 | 	u64 errmask = 0; | 
 | 114 | 	uint32_t ouint; | 
 | 115 | 	uint32_t oalen; | 
 | 116 |  | 
 | 117 | 	/* test daldevice_attach */ | 
 | 118 | 	ret = daldevice_attach(REMOTE_UNITTEST_DEVICEID, NULL, | 
 | 119 | 			       dest, &dev_handle); | 
 | 120 | 	if (ret) { | 
 | 121 | 		printk(KERN_INFO "%s: failed to attach (%d)\n", __func__, ret); | 
 | 122 | 		*val = 0xffffffff; | 
 | 123 | 		return 0; | 
 | 124 | 	} | 
 | 125 |  | 
 | 126 | 	/* test remote_unittest_0 */ | 
 | 127 | 	ret = remote_unittest_0(dev_handle, REMOTE_UNITTEST_INARG_1); | 
 | 128 | 	if (ret) | 
 | 129 | 		rpc_error(0); | 
 | 130 |  | 
 | 131 | 	/* test remote_unittest_1 */ | 
 | 132 | 	ret = remote_unittest_1(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 133 | 				REMOTE_UNITTEST_INARG_2); | 
 | 134 | 	if (ret) | 
 | 135 | 		rpc_error(1); | 
 | 136 |  | 
 | 137 | 	/* test remote_unittest_2 */ | 
 | 138 | 	ouint = 0; | 
 | 139 | 	ret = remote_unittest_2(dev_handle, REMOTE_UNITTEST_INARG_1, &ouint); | 
 | 140 | 	if (ret) | 
 | 141 | 		rpc_error(2); | 
 | 142 | 	else if (ouint != REMOTE_UNITTEST_OUTARG_1) | 
 | 143 | 		verify_error(2, "ouint"); | 
 | 144 |  | 
 | 145 | 	/* test remote_unittest_3 */ | 
 | 146 | 	ret = remote_unittest_3(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 147 | 				REMOTE_UNITTEST_INARG_2, | 
 | 148 | 				REMOTE_UNITTEST_INARG_3); | 
 | 149 | 	if (ret) | 
 | 150 | 		rpc_error(3); | 
 | 151 |  | 
 | 152 | 	/* test remote_unittest_4 */ | 
 | 153 | 	ouint = 0; | 
 | 154 | 	ret = remote_unittest_4(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 155 | 				REMOTE_UNITTEST_INARG_2, &ouint); | 
 | 156 | 	if (ret) | 
 | 157 | 		rpc_error(4); | 
 | 158 | 	else if (ouint != REMOTE_UNITTEST_OUTARG_1) | 
 | 159 | 		verify_error(4, "ouint"); | 
 | 160 |  | 
 | 161 | 	/* test remote_unittest_5 */ | 
 | 162 | 	init_data(&in_data); | 
 | 163 | 	ret = remote_unittest_5(dev_handle, &in_data, sizeof(in_data)); | 
 | 164 | 	if (ret) | 
 | 165 | 		rpc_error(5); | 
 | 166 |  | 
 | 167 | 	/* test remote_unittest_6 */ | 
 | 168 | 	init_data(&in_data); | 
 | 169 | 	ret = remote_unittest_6(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 170 | 				&in_data.test, sizeof(in_data.test)); | 
 | 171 | 	if (ret) | 
 | 172 | 		rpc_error(6); | 
 | 173 |  | 
 | 174 | 	/* test remote_unittest_7 */ | 
 | 175 | 	init_data(&in_data); | 
 | 176 | 	memset(&out_data, 0, sizeof(out_data)); | 
 | 177 | 	ret = remote_unittest_7(dev_handle, &in_data, sizeof(in_data), | 
 | 178 | 				&out_data.test, sizeof(out_data.test), | 
 | 179 | 				&oalen); | 
 | 180 | 	if (ret) | 
 | 181 | 		rpc_error(7); | 
 | 182 | 	else if (oalen != sizeof(out_data.test)) | 
 | 183 | 		verify_error(7, "oalen"); | 
 | 184 | 	else if (verify_uint32_buffer(out_data.test)) | 
 | 185 | 		verify_error(7, "obuf"); | 
 | 186 |  | 
 | 187 | 	/* test remote_unittest_8 */ | 
 | 188 | 	init_bytebuf(in_bytebuf); | 
 | 189 | 	memset(&out_data, 0, sizeof(out_data)); | 
 | 190 | 	ret = remote_unittest_8(dev_handle, in_bytebuf, sizeof(in_bytebuf), | 
 | 191 | 				&out_data, sizeof(out_data)); | 
 | 192 | 	if (ret) | 
 | 193 | 		rpc_error(8); | 
 | 194 | 	else if (verify_data(&out_data)) | 
 | 195 | 		verify_error(8, "obuf"); | 
 | 196 |  | 
 | 197 | 	/* test remote_unittest_9 */ | 
 | 198 | 	memset(&out_bytebuf, 0, sizeof(out_bytebuf)); | 
 | 199 | 	ret = remote_unittest_9(dev_handle, out_bytebuf, sizeof(out_bytebuf)); | 
 | 200 | 	if (ret) | 
 | 201 | 		rpc_error(9); | 
 | 202 | 	else if (verify_bytebuf(out_bytebuf)) | 
 | 203 | 		verify_error(9, "obuf"); | 
 | 204 |  | 
 | 205 | 	/* test remote_unittest_10 */ | 
 | 206 | 	init_bytebuf(in_bytebuf); | 
 | 207 | 	memset(&out_bytebuf, 0, sizeof(out_bytebuf)); | 
 | 208 | 	ret = remote_unittest_10(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 209 | 				 in_bytebuf, sizeof(in_bytebuf), | 
 | 210 | 				 out_bytebuf, sizeof(out_bytebuf), &oalen); | 
 | 211 | 	if (ret) | 
 | 212 | 		rpc_error(10); | 
 | 213 | 	else if (oalen != sizeof(out_bytebuf)) | 
 | 214 | 		verify_error(10, "oalen"); | 
 | 215 | 	else if (verify_bytebuf(out_bytebuf)) | 
 | 216 | 		verify_error(10, "obuf"); | 
 | 217 |  | 
 | 218 | 	/* test remote_unittest_11 */ | 
 | 219 | 	memset(&out_bytebuf, 0, sizeof(out_bytebuf)); | 
 | 220 | 	ret = remote_unittest_11(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 221 | 				 out_bytebuf, sizeof(out_bytebuf)); | 
 | 222 | 	if (ret) | 
 | 223 | 		rpc_error(11); | 
 | 224 | 	else if (verify_bytebuf(out_bytebuf)) | 
 | 225 | 		verify_error(11, "obuf"); | 
 | 226 |  | 
 | 227 | 	/* test remote_unittest_12 */ | 
 | 228 | 	memset(&out_bytebuf, 0, sizeof(out_bytebuf)); | 
 | 229 | 	ret = remote_unittest_12(dev_handle, REMOTE_UNITTEST_INARG_1, | 
 | 230 | 				 out_bytebuf, sizeof(out_bytebuf), &oalen); | 
 | 231 | 	if (ret) | 
 | 232 | 		rpc_error(12); | 
 | 233 | 	else if (oalen != sizeof(out_bytebuf)) | 
 | 234 | 		verify_error(12, "oalen"); | 
 | 235 | 	else if (verify_bytebuf(out_bytebuf)) | 
 | 236 | 		verify_error(12, "obuf"); | 
 | 237 |  | 
 | 238 | 	/* test remote_unittest_13 */ | 
 | 239 | 	init_data(&in_data); | 
 | 240 | 	memset(&out_data, 0, sizeof(out_data)); | 
 | 241 | 	ret = remote_unittest_13(dev_handle, in_data.test, sizeof(in_data.test), | 
 | 242 | 				 &in_data, sizeof(in_data), | 
 | 243 | 				 &out_data, sizeof(out_data)); | 
 | 244 | 	if (ret) | 
 | 245 | 		rpc_error(13); | 
 | 246 | 	else if (verify_data(&out_data)) | 
 | 247 | 		verify_error(13, "obuf"); | 
 | 248 |  | 
 | 249 | 	/* test remote_unittest_14 */ | 
 | 250 | 	init_data(&in_data); | 
 | 251 | 	memset(out_bytebuf, 0, sizeof(out_bytebuf)); | 
 | 252 | 	memset(out_bytebuf2, 0, sizeof(out_bytebuf2)); | 
 | 253 | 	ret = remote_unittest_14(dev_handle, | 
 | 254 | 				 in_data.test, sizeof(in_data.test), | 
 | 255 | 				 out_bytebuf, sizeof(out_bytebuf), | 
 | 256 | 				 out_bytebuf2, sizeof(out_bytebuf2), &oalen); | 
 | 257 | 	if (ret) | 
 | 258 | 		rpc_error(14); | 
 | 259 | 	else if (verify_bytebuf(out_bytebuf)) | 
 | 260 | 		verify_error(14, "obuf"); | 
 | 261 | 	else if (oalen != sizeof(out_bytebuf2)) | 
 | 262 | 		verify_error(14, "oalen"); | 
 | 263 | 	else if (verify_bytebuf(out_bytebuf2)) | 
 | 264 | 		verify_error(14, "obuf2"); | 
 | 265 |  | 
 | 266 | 	/* test remote_unittest_15 */ | 
 | 267 | 	init_data(&in_data); | 
 | 268 | 	memset(out_bytebuf, 0, sizeof(out_bytebuf)); | 
 | 269 | 	memset(&out_data, 0, sizeof(out_data)); | 
 | 270 | 	ret = remote_unittest_15(dev_handle, | 
 | 271 | 				 in_data.test, sizeof(in_data.test), | 
 | 272 | 				 &in_data, sizeof(in_data), | 
 | 273 | 				 &out_data, sizeof(out_data), &oalen, | 
 | 274 | 				 out_bytebuf, sizeof(out_bytebuf)); | 
 | 275 | 	if (ret) | 
 | 276 | 		rpc_error(15); | 
 | 277 | 	else if (oalen != sizeof(out_data)) | 
 | 278 | 		verify_error(15, "oalen"); | 
 | 279 | 	else if (verify_bytebuf(out_bytebuf)) | 
 | 280 | 		verify_error(15, "obuf"); | 
 | 281 | 	else if (verify_data(&out_data)) | 
 | 282 | 		verify_error(15, "obuf2"); | 
 | 283 |  | 
 | 284 | 	/* test setting up asynch events */ | 
 | 285 | 	event_handles[0] = dalrpc_alloc_event(dev_handle); | 
 | 286 | 	event_handles[1] = dalrpc_alloc_event(dev_handle); | 
 | 287 | 	event_handles[2] = dalrpc_alloc_event(dev_handle); | 
 | 288 | 	cb_handle = dalrpc_alloc_cb(dev_handle, test_cb, &out_data); | 
 | 289 | 	in_data.regular_event = (uint32_t)event_handles[2]; | 
 | 290 | 	in_data.payload_event = (uint32_t)cb_handle; | 
 | 291 | 	ret = remote_unittest_eventcfg(dev_handle, &in_data, sizeof(in_data)); | 
 | 292 | 	if (ret) { | 
 | 293 | 		errmask |= (1 << 16); | 
 | 294 | 		printk(KERN_INFO "%s: failed to configure asynch (%d)\n", | 
 | 295 | 		       __func__, ret); | 
 | 296 | 	} | 
 | 297 |  | 
 | 298 | 	/* test event */ | 
 | 299 | 	ret = remote_unittest_eventtrig(dev_handle, | 
 | 300 | 					REMOTE_UNITTEST_REGULAR_EVENT); | 
 | 301 | 	if (ret) { | 
 | 302 | 		errmask |= (1 << 17); | 
 | 303 | 		printk(KERN_INFO "%s: failed to trigger event (%d)\n", | 
 | 304 | 		       __func__, ret); | 
 | 305 | 	} | 
 | 306 | 	ret = dalrpc_event_wait(event_handles[2], 1000); | 
 | 307 | 	if (ret) { | 
 | 308 | 		errmask |= (1 << 18); | 
 | 309 | 		printk(KERN_INFO "%s: failed to receive event (%d)\n", | 
 | 310 | 		       __func__, ret); | 
 | 311 | 	} | 
 | 312 |  | 
 | 313 | 	/* test event again */ | 
 | 314 | 	ret = remote_unittest_eventtrig(dev_handle, | 
 | 315 | 					REMOTE_UNITTEST_REGULAR_EVENT); | 
 | 316 | 	if (ret) { | 
 | 317 | 		errmask |= (1 << 19); | 
 | 318 | 		printk(KERN_INFO "%s: failed to trigger event (%d)\n", | 
 | 319 | 		       __func__, ret); | 
 | 320 | 	} | 
 | 321 | 	ret = dalrpc_event_wait_multiple(3, event_handles, 1000); | 
 | 322 | 	if (ret != 2) { | 
 | 323 | 		errmask |= (1 << 20); | 
 | 324 | 		printk(KERN_INFO "%s: failed to receive event (%d)\n", | 
 | 325 | 		       __func__, ret); | 
 | 326 | 	} | 
 | 327 |  | 
 | 328 | 	/* test callback */ | 
 | 329 | 	ret = remote_unittest_eventtrig(dev_handle, | 
 | 330 | 					REMOTE_UNITTEST_CALLBACK_EVENT); | 
 | 331 | 	if (ret) { | 
 | 332 | 		errmask |= (1 << 21); | 
 | 333 | 		printk(KERN_INFO "%s: failed to trigger callback (%d)\n", | 
 | 334 | 		       __func__, ret); | 
 | 335 | 	} else | 
 | 336 | 		while (block_until_cb) | 
 | 337 | 			; | 
 | 338 |  | 
 | 339 | 	dalrpc_dealloc_cb(dev_handle, cb_handle); | 
 | 340 | 	dalrpc_dealloc_event(dev_handle, event_handles[0]); | 
 | 341 | 	dalrpc_dealloc_event(dev_handle, event_handles[1]); | 
 | 342 | 	dalrpc_dealloc_event(dev_handle, event_handles[2]); | 
 | 343 |  | 
 | 344 | 	/* test daldevice_detach */ | 
 | 345 | 	ret = daldevice_detach(dev_handle); | 
 | 346 | 	if (ret) { | 
 | 347 | 		errmask |= (1 << 22); | 
 | 348 | 		printk(KERN_INFO "%s: failed to detach (%d)\n", __func__, ret); | 
 | 349 | 	} | 
 | 350 |  | 
 | 351 | 	printk(KERN_INFO "%s: remote_unittest complete\n", __func__); | 
 | 352 |  | 
 | 353 | 	*val = errmask; | 
 | 354 | 	return 0; | 
 | 355 | } | 
 | 356 |  | 
 | 357 | static int remotetest_modem_exec(void *data, u64 *val) | 
 | 358 | { | 
 | 359 | 	return remotetest_exec(DALRPC_DEST_MODEM, val); | 
 | 360 | } | 
 | 361 |  | 
 | 362 | static int remotetest_dsp_exec(void *data, u64 *val) | 
 | 363 | { | 
 | 364 | 	return remotetest_exec(DALRPC_DEST_QDSP, val); | 
 | 365 | } | 
 | 366 |  | 
 | 367 | DEFINE_SIMPLE_ATTRIBUTE(dal_modemtest_fops, remotetest_modem_exec, | 
 | 368 | 			NULL, "%llu\n"); | 
 | 369 | DEFINE_SIMPLE_ATTRIBUTE(dal_dsptest_fops, remotetest_dsp_exec, | 
 | 370 | 			NULL, "%llu\n"); | 
 | 371 |  | 
 | 372 | static int __init remotetest_init(void) | 
 | 373 | { | 
 | 374 | 	debugfs_dir_entry = debugfs_create_dir("dal", 0); | 
 | 375 | 	if (IS_ERR(debugfs_dir_entry)) | 
 | 376 | 		return PTR_ERR(debugfs_dir_entry); | 
 | 377 |  | 
 | 378 | 	debugfs_modem_entry = debugfs_create_file("modem_test", 0444, | 
 | 379 | 						  debugfs_dir_entry, | 
 | 380 | 						  NULL, &dal_modemtest_fops); | 
 | 381 | 	if (IS_ERR(debugfs_modem_entry)) { | 
 | 382 | 		debugfs_remove(debugfs_dir_entry); | 
 | 383 | 		return PTR_ERR(debugfs_modem_entry); | 
 | 384 | 	} | 
 | 385 |  | 
 | 386 | 	debugfs_dsp_entry = debugfs_create_file("dsp_test", 0444, | 
 | 387 | 					    debugfs_dir_entry, | 
 | 388 | 					    NULL, &dal_dsptest_fops); | 
 | 389 | 	if (IS_ERR(debugfs_dsp_entry)) { | 
 | 390 | 		debugfs_remove(debugfs_modem_entry); | 
 | 391 | 		debugfs_remove(debugfs_dir_entry); | 
 | 392 | 		return PTR_ERR(debugfs_dsp_entry); | 
 | 393 | 	} | 
 | 394 |  | 
 | 395 | 	return 0; | 
 | 396 | } | 
 | 397 |  | 
 | 398 | static void __exit remotetest_exit(void) | 
 | 399 | { | 
 | 400 | 	debugfs_remove(debugfs_modem_entry); | 
 | 401 | 	debugfs_remove(debugfs_dsp_entry); | 
 | 402 | 	debugfs_remove(debugfs_dir_entry); | 
 | 403 | } | 
 | 404 |  | 
 | 405 | MODULE_LICENSE("GPL v2"); | 
 | 406 | MODULE_DESCRIPTION("Test for DAL RPC"); | 
 | 407 | MODULE_VERSION("1.0"); | 
 | 408 |  | 
 | 409 | module_init(remotetest_init); | 
 | 410 | module_exit(remotetest_exit); |