Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153357720
D6038.id15506.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.id15506.diff
View Options
Index: sys/kern/subr_unit.c
===================================================================
--- sys/kern/subr_unit.c
+++ 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,10 @@
#else /* ...USERLAND */
+#include <bitstring.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -880,7 +884,9 @@
#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 rather than in tests/sys/kern so that it can access static functions
+ * and structures.
*/
static void
@@ -928,12 +934,13 @@
}
static void
-test_alloc_unr(struct unrhdr *uh, u_int i, char a[])
+test_alloc_unr(struct unrhdr *uh, u_int i, char a[], bool verbose)
{
int j;
if (a[i]) {
- printf("F %u\n", i);
+ if (verbose)
+ printf("F %u\n", i);
free_unr(uh, i);
a[i] = 0;
} else {
@@ -941,75 +948,110 @@
j = alloc_unr(uh);
if (j != -1) {
a[j] = 1;
- printf("A %d\n", j);
+ if (verbose)
+ printf("A %d\n", j);
}
no_alloc = 0;
}
}
static void
-test_alloc_unr_specific(struct unrhdr *uh, u_int i, char a[])
+test_alloc_unr_specific(struct unrhdr *uh, u_int i, char a[], bool verbose)
{
int j;
j = alloc_unr_specific(uh, i);
if (j == -1) {
- printf("F %u\n", i);
+ if (verbose)
+ printf("F %u\n", i);
a[i] = 0;
free_unr(uh, i);
} else {
a[i] = 1;
- printf("A %d\n", j);
+ if (verbose)
+ printf("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;
+ int ch;
+ bool verbose = false;
+ long count = 10000; /* Number of unrs to test */
+ long reps = 1;
u_int i, x, m, j;
- char a[NN];
+ char *a;
+
+ while ((ch = getopt(argc, argv, "hr:v")) != -1) {
+ switch (ch) {
+ case 'r':
+ 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));
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;
#endif
if ((random() & 1) != 0)
- test_alloc_unr(uh, i, a);
+ test_alloc_unr(uh, i, a, verbose);
else
- test_alloc_unr_specific(uh, i, a);
+ test_alloc_unr_specific(uh, i, a, verbose);
- 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: tests/sys/kern/Makefile
===================================================================
--- tests/sys/kern/Makefile
+++ 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
Tue, Apr 21, 4:47 PM (9 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31902097
Default Alt Text
D6038.id15506.diff (4 KB)
Attached To
Mode
D6038: Automate the subr_unit test.
Attached
Detach File
Event Timeline
Log In to Comment