/* * Copyright (c) 2005 Topspin Communications. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * $Id: $ */ #include #include #include #include #include #include #include #include #include #include #include #define TEST_DEV_PATH "/dev/mltest" #define TEST_SLEEP_UTIME 50000 struct ioctl_arg { __u64 addr; __u64 size; }; enum { TEST_CMD_REGISTER = 1, TEST_CMD_UNREGISTER = 2, TEST_CMD_CHECK = 3 }; static int hold = 1; void sig_usr(int value) { hold = 0; } int main(int argc, char **argv) { struct ioctl_arg req; void *data; int param_c = 0; int size; int fd; int result; if (2 != argc || 0 > (size = atoi(argv[++param_c]))) { fprintf(stderr, "usage: %s \n", argv[0]); fprintf(stderr, " size - allocated region size in bytes.\n"); exit(1); } signal(SIGUSR1, sig_usr); data = malloc(size); if (!data) { fprintf(stderr, "Failed to allocated region of size <%d>\n", size); exit(1); } fd = open(TEST_DEV_PATH, O_RDWR); if (fd < 0) { fprintf(stderr, "Error <%d:%d> opening device <%s>\n", fd, errno, TEST_DEV_PATH); goto open_err; } req.addr = (unsigned long)data; req.size = size; result = ioctl(fd, TEST_CMD_REGISTER, &req); if (result) { fprintf(stderr, "Error <%d:%d> registering region\n", result, errno); goto ioctl_err; } fprintf(stdout, "Address <%016lx> registered, process <%d> waiting...\n", data, getpid()); while (hold) { usleep(TEST_SLEEP_UTIME); } fprintf(stdout, "Process continuing, checking address <%016lx>\n", data); result = ioctl(fd, TEST_CMD_CHECK, &req); if (result) { fprintf(stderr, "Error <%d:%d> checking region\n", result, errno); goto ioctl_err; } result = ioctl(fd, TEST_CMD_UNREGISTER, &req); if (result) { fprintf(stderr, "Error <%d:%d> unregistering region\n", result, errno); goto ioctl_err; } ioctl_err: close(fd); open_err: free(data); return 0; }