Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F132546777
D6038.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D6038.diff
View Options
Index: head/sys/kern/subr_unit.c
===================================================================
--- head/sys/kern/subr_unit.c
+++ head/sys/kern/subr_unit.c
@@ -68,11 +68,11 @@
*/
#include <sys/types.h>
-#include <sys/bitstring.h>
#include <sys/_unrhdr.h>
#ifdef _KERNEL
+#include <sys/bitstring.h>
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
@@ -98,6 +98,11 @@
#else /* ...USERLAND */
+#include <bitstring.h>
+#include <err.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -880,9 +885,13 @@
#ifndef _KERNEL /* USERLAND test driver */
/*
- * Simple stochastic test driver for the above functions
+ * Simple stochastic test driver for the above functions. The code resides
+ * here so that it can access static functions and structures.
*/
+static bool verbose;
+#define VPRINTF(...) {if (verbose) printf(__VA_ARGS__);}
+
static void
print_unr(struct unrhdr *uh, struct unr *up)
{
@@ -933,7 +942,7 @@
int j;
if (a[i]) {
- printf("F %u\n", i);
+ VPRINTF("F %u\n", i);
free_unr(uh, i);
a[i] = 0;
} else {
@@ -941,7 +950,7 @@
j = alloc_unr(uh);
if (j != -1) {
a[j] = 1;
- printf("A %d\n", j);
+ VPRINTF("A %d\n", j);
}
no_alloc = 0;
}
@@ -954,40 +963,73 @@
j = alloc_unr_specific(uh, i);
if (j == -1) {
- printf("F %u\n", i);
+ VPRINTF("F %u\n", i);
a[i] = 0;
free_unr(uh, i);
} else {
a[i] = 1;
- printf("A %d\n", j);
+ VPRINTF("A %d\n", j);
}
}
-/* Number of unrs to test */
-#define NN 10000
+static void
+usage(char** argv)
+{
+ printf("%s [-h] [-r REPETITIONS] [-v]\n", argv[0]);
+}
int
-main(int argc __unused, const char **argv __unused)
+main(int argc, char **argv)
{
struct unrhdr *uh;
+ char *a;
+ long count = 10000; /* Number of unrs to test */
+ long reps = 1;
+ int ch;
u_int i, x, m, j;
- char a[NN];
+
+ verbose = false;
+
+ while ((ch = getopt(argc, argv, "hr:v")) != -1) {
+ switch (ch) {
+ case 'r':
+ errno = 0;
+ reps = strtol(optarg, NULL, 0);
+ if (errno == ERANGE || errno == EINVAL) {
+ usage(argv);
+ exit(2);
+ }
+
+ break;
+ case 'v':
+ verbose = true;
+ break;
+ case 'h':
+ default:
+ usage(argv);
+ exit(2);
+ }
+
+
+ }
setbuf(stdout, NULL);
- uh = new_unrhdr(0, NN - 1, NULL);
+ uh = new_unrhdr(0, count - 1, NULL);
print_unrhdr(uh);
- memset(a, 0, sizeof a);
+ a = calloc(count, sizeof(char));
+ if (a == NULL)
+ err(1, "calloc failed");
srandomdev();
- fprintf(stderr, "sizeof(struct unr) %zu\n", sizeof(struct unr));
- fprintf(stderr, "sizeof(struct unrb) %zu\n", sizeof(struct unrb));
- fprintf(stderr, "sizeof(struct unrhdr) %zu\n", sizeof(struct unrhdr));
- fprintf(stderr, "NBITS %d\n", NBITS);
+ printf("sizeof(struct unr) %zu\n", sizeof(struct unr));
+ printf("sizeof(struct unrb) %zu\n", sizeof(struct unrb));
+ printf("sizeof(struct unrhdr) %zu\n", sizeof(struct unrhdr));
+ printf("NBITS %d\n", NBITS);
x = 1;
- for (m = 0; m < NN * 100; m++) {
+ for (m = 0; m < count * reps; m++) {
j = random();
- i = (j >> 1) % NN;
+ i = (j >> 1) % count;
#if 0
if (a[i] && (j & 1))
continue;
@@ -997,19 +1039,22 @@
else
test_alloc_unr_specific(uh, i, a);
- if (1) /* XXX: change this for detailed debug printout */
+ if (verbose)
print_unrhdr(uh);
check_unrhdr(uh, __LINE__);
}
- for (i = 0; i < NN; i++) {
+ for (i = 0; i < count; i++) {
if (a[i]) {
- printf("C %u\n", i);
+ if (verbose) {
+ printf("C %u\n", i);
+ print_unrhdr(uh);
+ }
free_unr(uh, i);
- print_unrhdr(uh);
}
}
print_unrhdr(uh);
delete_unrhdr(uh);
+ free(a);
return (0);
}
#endif
Index: head/tests/sys/kern/Makefile
===================================================================
--- head/tests/sys/kern/Makefile
+++ head/tests/sys/kern/Makefile
@@ -4,12 +4,14 @@
FILESGROUPS= TESTS
TESTSPACKAGE= ${PACKAGE}
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/kernel
+.PATH: ${SRCTOP}/sys/kern
TESTSDIR= ${TESTSBASE}/sys/kern
ATF_TESTS_C+= kern_copyin
ATF_TESTS_C+= kern_descrip_test
ATF_TESTS_C+= ptrace_test
+PLAIN_TESTS_C+= subr_unit_test
ATF_TESTS_C+= unix_seqpacket_test
ATF_TESTS_C+= unix_passfd_test
TEST_METADATA.unix_seqpacket_test+= timeout="15"
@@ -23,6 +25,14 @@
CFLAGS.mqueue_test+= -I${SRCTOP}/tests
LIBADD.mqueue_test+= rt
+# subr_unit.c contains functions whose prototypes lie in headers that cannot be
+# included in userland. But as far as subr_unit_test goes, they're effectively
+# static. So it's ok to disable -Wmissing-prototypes for this program.
+CFLAGS.subr_unit.c+= -Wno-missing-prototypes
+# XXX: -Wno-sign-compare will be eliminated as part of D6004
+CFLAGS.subr_unit.c+= -Wno-sign-compare
+SRCS.subr_unit_test+= subr_unit.c
+
WARNS?= 5
TESTS_SUBDIRS+= acct
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 18, 9:14 PM (4 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
23893961
Default Alt Text
D6038.diff (4 KB)
Attached To
Mode
D6038: Automate the subr_unit test.
Attached
Detach File
Event Timeline
Log In to Comment