diff options
| author | Len Brown <len.brown@intel.com> | 2012-06-04 00:35:19 -0400 |
|---|---|---|
| committer | Len Brown <len.brown@intel.com> | 2012-06-04 00:35:19 -0400 |
| commit | 7e1bd6e38b1f30860ce25a014c6d6adfb0079f4a (patch) | |
| tree | 65c5898ba93007d4399150c7a127a670bcfbc30d /tools/testing/selftests/mqueue | |
| parent | 301f33fbcf4ced53b3de114846ecece5d6aafeeb (diff) | |
| parent | f8f5701bdaf9134b1f90e5044a82c66324d2073f (diff) | |
Merge branch 'upstream' into bugfix-video
Update bugfix-video branch to 2.5-rc1
so I don't have to again resolve the
conflict in these patches vs. upstream.
Conflicts:
drivers/gpu/drm/gma500/psb_drv.c
text conflict: add comment vs delete neighboring line
keep just this:
/* igd_opregion_init(&dev_priv->opregion_dev); */
/* acpi_video_register(); */
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/testing/selftests/mqueue')
| -rw-r--r-- | tools/testing/selftests/mqueue/.gitignore | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/mqueue/Makefile | 10 | ||||
| -rw-r--r-- | tools/testing/selftests/mqueue/mq_open_tests.c | 492 | ||||
| -rw-r--r-- | tools/testing/selftests/mqueue/mq_perf_tests.c | 741 |
4 files changed, 1245 insertions, 0 deletions
diff --git a/tools/testing/selftests/mqueue/.gitignore b/tools/testing/selftests/mqueue/.gitignore new file mode 100644 index 000000000000..d8d42377205a --- /dev/null +++ b/tools/testing/selftests/mqueue/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | mq_open_tests | ||
| 2 | mq_perf_tests | ||
diff --git a/tools/testing/selftests/mqueue/Makefile b/tools/testing/selftests/mqueue/Makefile new file mode 100644 index 000000000000..54c0aad2b47c --- /dev/null +++ b/tools/testing/selftests/mqueue/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | all: | ||
| 2 | gcc -O2 -lrt mq_open_tests.c -o mq_open_tests | ||
| 3 | gcc -O2 -lrt -lpthread -lpopt -o mq_perf_tests mq_perf_tests.c | ||
| 4 | |||
| 5 | run_tests: | ||
| 6 | ./mq_open_tests /test1 | ||
| 7 | ./mq_perf_tests | ||
| 8 | |||
| 9 | clean: | ||
| 10 | rm -f mq_open_tests mq_perf_tests | ||
diff --git a/tools/testing/selftests/mqueue/mq_open_tests.c b/tools/testing/selftests/mqueue/mq_open_tests.c new file mode 100644 index 000000000000..711cc2923047 --- /dev/null +++ b/tools/testing/selftests/mqueue/mq_open_tests.c | |||
| @@ -0,0 +1,492 @@ | |||
| 1 | /* | ||
| 2 | * This application is Copyright 2012 Red Hat, Inc. | ||
| 3 | * Doug Ledford <dledford@redhat.com> | ||
| 4 | * | ||
| 5 | * mq_open_tests is free software: you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation, version 3. | ||
| 8 | * | ||
| 9 | * mq_open_tests is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * For the full text of the license, see <http://www.gnu.org/licenses/>. | ||
| 15 | * | ||
| 16 | * mq_open_tests.c | ||
| 17 | * Tests the various situations that should either succeed or fail to | ||
| 18 | * open a posix message queue and then reports whether or not they | ||
| 19 | * did as they were supposed to. | ||
| 20 | * | ||
| 21 | */ | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | #include <fcntl.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <limits.h> | ||
| 28 | #include <errno.h> | ||
| 29 | #include <sys/types.h> | ||
| 30 | #include <sys/time.h> | ||
| 31 | #include <sys/resource.h> | ||
| 32 | #include <sys/stat.h> | ||
| 33 | #include <mqueue.h> | ||
| 34 | |||
| 35 | static char *usage = | ||
| 36 | "Usage:\n" | ||
| 37 | " %s path\n" | ||
| 38 | "\n" | ||
| 39 | " path Path name of the message queue to create\n" | ||
| 40 | "\n" | ||
| 41 | " Note: this program must be run as root in order to enable all tests\n" | ||
| 42 | "\n"; | ||
| 43 | |||
| 44 | char *DEF_MSGS = "/proc/sys/fs/mqueue/msg_default"; | ||
| 45 | char *DEF_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_default"; | ||
| 46 | char *MAX_MSGS = "/proc/sys/fs/mqueue/msg_max"; | ||
| 47 | char *MAX_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_max"; | ||
| 48 | |||
| 49 | int default_settings; | ||
| 50 | struct rlimit saved_limits, cur_limits; | ||
| 51 | int saved_def_msgs, saved_def_msgsize, saved_max_msgs, saved_max_msgsize; | ||
| 52 | int cur_def_msgs, cur_def_msgsize, cur_max_msgs, cur_max_msgsize; | ||
| 53 | FILE *def_msgs, *def_msgsize, *max_msgs, *max_msgsize; | ||
| 54 | char *queue_path; | ||
| 55 | mqd_t queue = -1; | ||
| 56 | |||
| 57 | static inline void __set(FILE *stream, int value, char *err_msg); | ||
| 58 | void shutdown(int exit_val, char *err_cause, int line_no); | ||
| 59 | static inline int get(FILE *stream); | ||
| 60 | static inline void set(FILE *stream, int value); | ||
| 61 | static inline void getr(int type, struct rlimit *rlim); | ||
| 62 | static inline void setr(int type, struct rlimit *rlim); | ||
| 63 | void validate_current_settings(); | ||
| 64 | static inline void test_queue(struct mq_attr *attr, struct mq_attr *result); | ||
| 65 | static inline int test_queue_fail(struct mq_attr *attr, struct mq_attr *result); | ||
| 66 | |||
| 67 | static inline void __set(FILE *stream, int value, char *err_msg) | ||
| 68 | { | ||
| 69 | rewind(stream); | ||
| 70 | if (fprintf(stream, "%d", value) < 0) | ||
| 71 | perror(err_msg); | ||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | void shutdown(int exit_val, char *err_cause, int line_no) | ||
| 76 | { | ||
| 77 | static int in_shutdown = 0; | ||
| 78 | |||
| 79 | /* In case we get called recursively by a set() call below */ | ||
| 80 | if (in_shutdown++) | ||
| 81 | return; | ||
| 82 | |||
| 83 | seteuid(0); | ||
| 84 | |||
| 85 | if (queue != -1) | ||
| 86 | if (mq_close(queue)) | ||
| 87 | perror("mq_close() during shutdown"); | ||
| 88 | if (queue_path) | ||
| 89 | /* | ||
| 90 | * Be silent if this fails, if we cleaned up already it's | ||
| 91 | * expected to fail | ||
| 92 | */ | ||
| 93 | mq_unlink(queue_path); | ||
| 94 | if (default_settings) { | ||
| 95 | if (saved_def_msgs) | ||
| 96 | __set(def_msgs, saved_def_msgs, | ||
| 97 | "failed to restore saved_def_msgs"); | ||
| 98 | if (saved_def_msgsize) | ||
| 99 | __set(def_msgsize, saved_def_msgsize, | ||
| 100 | "failed to restore saved_def_msgsize"); | ||
| 101 | } | ||
| 102 | if (saved_max_msgs) | ||
| 103 | __set(max_msgs, saved_max_msgs, | ||
| 104 | "failed to restore saved_max_msgs"); | ||
| 105 | if (saved_max_msgsize) | ||
| 106 | __set(max_msgsize, saved_max_msgsize, | ||
| 107 | "failed to restore saved_max_msgsize"); | ||
| 108 | if (exit_val) | ||
| 109 | error(exit_val, errno, "%s at %d", err_cause, line_no); | ||
| 110 | exit(0); | ||
| 111 | } | ||
| 112 | |||
| 113 | static inline int get(FILE *stream) | ||
| 114 | { | ||
| 115 | int value; | ||
| 116 | rewind(stream); | ||
| 117 | if (fscanf(stream, "%d", &value) != 1) | ||
| 118 | shutdown(4, "Error reading /proc entry", __LINE__ - 1); | ||
| 119 | return value; | ||
| 120 | } | ||
| 121 | |||
| 122 | static inline void set(FILE *stream, int value) | ||
| 123 | { | ||
| 124 | int new_value; | ||
| 125 | |||
| 126 | rewind(stream); | ||
| 127 | if (fprintf(stream, "%d", value) < 0) | ||
| 128 | return shutdown(5, "Failed writing to /proc file", | ||
| 129 | __LINE__ - 1); | ||
| 130 | new_value = get(stream); | ||
| 131 | if (new_value != value) | ||
| 132 | return shutdown(5, "We didn't get what we wrote to /proc back", | ||
| 133 | __LINE__ - 1); | ||
| 134 | } | ||
| 135 | |||
| 136 | static inline void getr(int type, struct rlimit *rlim) | ||
| 137 | { | ||
| 138 | if (getrlimit(type, rlim)) | ||
| 139 | shutdown(6, "getrlimit()", __LINE__ - 1); | ||
| 140 | } | ||
| 141 | |||
| 142 | static inline void setr(int type, struct rlimit *rlim) | ||
| 143 | { | ||
| 144 | if (setrlimit(type, rlim)) | ||
| 145 | shutdown(7, "setrlimit()", __LINE__ - 1); | ||
| 146 | } | ||
| 147 | |||
| 148 | void validate_current_settings() | ||
| 149 | { | ||
| 150 | int rlim_needed; | ||
| 151 | |||
| 152 | if (cur_limits.rlim_cur < 4096) { | ||
| 153 | printf("Current rlimit value for POSIX message queue bytes is " | ||
| 154 | "unreasonably low,\nincreasing.\n\n"); | ||
| 155 | cur_limits.rlim_cur = 8192; | ||
| 156 | cur_limits.rlim_max = 16384; | ||
| 157 | setr(RLIMIT_MSGQUEUE, &cur_limits); | ||
| 158 | } | ||
