diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2005-04-21 17:45:55 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2005-04-21 17:45:55 +0000 |
commit | 3f3df2e7884bcefd5338c81a452a4d0f308dbea2 (patch) | |
tree | ee34392051fc9f3fa80b00b8f5b2253b5981b0e8 | |
parent | 81f2ba2353e747873c0af3e406a1866db28050a9 (diff) |
Add a regression test for the extent subroutines; from NetBSD.
-rw-r--r-- | regress/sys/kern/Makefile | 4 | ||||
-rw-r--r-- | regress/sys/kern/extent/Makefile | 18 | ||||
-rw-r--r-- | regress/sys/kern/extent/extest.awk | 71 | ||||
-rw-r--r-- | regress/sys/kern/extent/extest.exp | 77 | ||||
-rw-r--r-- | regress/sys/kern/extent/tests | 101 |
5 files changed, 269 insertions, 2 deletions
diff --git a/regress/sys/kern/Makefile b/regress/sys/kern/Makefile index cd2a9f89134..d81fb047091 100644 --- a/regress/sys/kern/Makefile +++ b/regress/sys/kern/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.47 2004/08/05 02:59:49 art Exp $ +# $OpenBSD: Makefile,v 1.48 2005/04/21 17:45:52 miod Exp $ SUBDIR+= execve getrusage kqueue mmap mmap2 mmap3 dup2 minherit rlimit-file SUBDIR+= fcntl_dup dup2_self ptmget pread preadv exit wait mbuf pwrite pwritev SUBDIR+= syscall __syscall unfdpass accept nanosleep sysvmsg sysvsem SUBDIR+= sysvshm gettimeofday signal exec_self noexec signal-stress -SUBDIR+= rcvtimeo itimer +SUBDIR+= rcvtimeo itimer extent #SUBDIR+= mquery rfork install: diff --git a/regress/sys/kern/extent/Makefile b/regress/sys/kern/extent/Makefile new file mode 100644 index 00000000000..5be4d122f58 --- /dev/null +++ b/regress/sys/kern/extent/Makefile @@ -0,0 +1,18 @@ +# $OpenBSD: Makefile,v 1.1 2005/04/21 17:45:54 miod Exp $ +# $NetBSD: Makefile,v 1.5 2002/09/18 04:16:02 lukem Exp $ + +PROG= extest +SRCS= extest.c subr_extent.c +CPPFLAGS+= -D_EXTENT_TESTING -DDIAGNOSTIC +CLEANFILES+= extest.c extest.out + +.PATH: ${.CURDIR}/../../../../sys/kern + +regress: ${PROG} + ./${PROG} >extest.out + tail +5 ${.CURDIR}/extest.exp | diff - extest.out + +extest.c: extest.awk tests + awk -f ${.CURDIR}/extest.awk <${.CURDIR}/tests >extest.c + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/extent/extest.awk b/regress/sys/kern/extent/extest.awk new file mode 100644 index 00000000000..5c875d44133 --- /dev/null +++ b/regress/sys/kern/extent/extest.awk @@ -0,0 +1,71 @@ +# $OpenBSD: extest.awk,v 1.1 2005/04/21 17:45:54 miod Exp $ +# $NetBSD: extest.awk,v 1.6 2002/02/21 03:59:25 mrg Exp $ + +BEGIN { + first = 1; + + printf("#include <sys/types.h>\n") + printf("#include <sys/extent.h>\n\n") + printf("#include <stdio.h>\n") + printf("#include <stdlib.h>\n") + printf("#include <string.h>\n") + printf("int main(void) {\n") + printf("struct extent *ex; int error; long result;\n") +} + +END { + printf("exit (0);\n") + printf("}\n") +} + +$1 == "extent" { + if (first == 0) { + printf("extent_destroy(ex);\n") + } + + align = "EX_NOALIGN"; + boundary = "EX_NOBOUNDARY"; + + printf("printf(\"output for %s\\n\");\n", $2) + + if ($5 == "") { + flags = "0"; + } else { + flags = $5; + } + printf("ex = extent_create(\"%s\", %s, %s, 0, 0, 0, %s);\n", + $2, $3, $4, flags) + + first = 0; +} + +$1 == "align" { + align = $2; +} + +$1 == "boundary" { + boundary = $2; +} + +$1 == "alloc_region" { + printf("error = extent_alloc_region(ex, %s, %s, 0);\n", + $2, $3) + printf("if (error)\n\tprintf(\"error: %%s\\n\", strerror(error));\n") +} + +$1 == "alloc_subregion" { + printf("error = extent_alloc_subregion(ex, %s, %s, %s,\n", + $2, $3, $4) + printf("\t%s, 0, %s, 0, &result);\n", align, boundary) + printf("if (error)\n\tprintf(\"error: %%s\\n\", strerror(error));\n") + printf("else\n\tprintf(\"result: 0x%%lx\\n\", result);\n") +} + +$1 == "free" { + printf("error = extent_free(ex, %s, %s, 0);\n", $2, $3) + printf("if (error)\n\tprintf(\"error: %%s\\n\", strerror(error));\n") +} + +$1 == "print" { + printf("extent_print(ex);\n") +} diff --git a/regress/sys/kern/extent/extest.exp b/regress/sys/kern/extent/extest.exp new file mode 100644 index 00000000000..c8e0a8beb98 --- /dev/null +++ b/regress/sys/kern/extent/extest.exp @@ -0,0 +1,77 @@ +# $OpenBSD: extest.exp,v 1.1 2005/04/21 17:45:54 miod Exp $ +# $NetBSD: extest.exp,v 1.9 2005/03/15 18:27:23 bouyer Exp $ +# real output must start in line 5 + +output for test1 +result: 0x30 +extent `test1' (0x0 - 0x4f), flags = 0x0 + 0x0 - 0x4f +output for test2 +result: 0x20 +extent `test2' (0x0 - 0x2f), flags = 0x2 + 0x0 - 0xf + 0x20 - 0x2f +output for test3 +result: 0x20 +extent `test3' (0x0 - 0x3f), flags = 0x2 + 0x0 - 0x1f + 0x20 - 0x2f + 0x30 - 0x3f +output for test4 +result: 0xf0000000 +extent `test4' (0xf0000000 - 0xffffffff), flags = 0x0 + 0xf0000000 - 0xf0000000 + 0xf1000000 - 0xf1000000 +output for test5 +result: 0xf0000000 +extent `test5' (0xf0000000 - 0xffffffff), flags = 0x0 + 0xf0000000 - 0xf0000000 +output for test6 +result: 0x0 +result: 0x8 +result: 0xa +extent `test6' (0x0 - 0xb), flags = 0x0 + 0x0 - 0xb +output for test7 +result: 0x0 +result: 0x8 +extent `test7' (0x0 - 0xb), flags = 0x0 + 0x0 - 0x6 + 0x8 - 0xb +output for test8 +result: 0x0 +error: Resource temporarily unavailable +extent `test8' (0x0 - 0x4f), flags = 0x2 + 0x0 - 0xf + 0x30 - 0x3f +output for test9 +result: 0x0 +result: 0xd +result: 0x10 +extent `test9' (0x0 - 0x4f), flags = 0x0 + 0x0 - 0x3 + 0xd - 0xe + 0x10 - 0x17 +output for test10 +result: 0xc0010000 +result: 0xc0020000 +extent `test10' (0xc0002000 - 0xffffe000), flags = 0x0 + 0xc0010000 - 0xc0011fff + 0xc0020000 - 0xc0021fff +extent `test10' (0xc0002000 - 0xffffe000), flags = 0x0 + 0xc0010000 - 0xc0011fff +result: 0xc0022000 +extent `test10' (0xc0002000 - 0xffffe000), flags = 0x0 + 0xc0010000 - 0xc0011fff + 0xc0022000 - 0xc0031fff +output for test11 +result: 0x10 +result: 0x1e +result: 0x20 +error: Resource temporarily unavailable +result: 0x14 +extent `test11' (0x10 - 0x20), flags = 0x2 + 0x10 - 0x13 + 0x14 - 0x14 + 0x1e - 0x1f + 0x20 - 0x20 diff --git a/regress/sys/kern/extent/tests b/regress/sys/kern/extent/tests new file mode 100644 index 00000000000..057ef009a6f --- /dev/null +++ b/regress/sys/kern/extent/tests @@ -0,0 +1,101 @@ +# $OpenBSD: tests,v 1.1 2005/04/21 17:45:54 miod Exp $ +# $NetBSD: tests,v 1.9 2005/03/15 18:27:23 bouyer Exp $ + +#fill up an extent, should coalesce into one allocation +extent test1 0 0x4f +alloc_region 0x00 0x10 +alloc_region 0x20 0x10 +alloc_region 0x40 0x10 +alloc_region 0x10 0x10 +alloc_subregion 0 0x4f 0x10 +print + +#check whether subregion is obeyed (PR kern/7539) +extent test2 0 0x2f EX_NOCOALESCE +alloc_region 0x00 0x10 +alloc_subregion 0x20 0x30 0x10 +print + +#check overlap into subregion (fixed in 1.25) +extent test3 0 0x3f EX_NOCOALESCE +alloc_region 0x00 0x20 +alloc_region 0x30 0x10 +alloc_subregion 0x10 0x3f 0x10 +print + +#check overflow in boundary check, before an allocated region (fixed in 1.32) +extent test4 0xf0000000 0xffffffff +alloc_region 0xf1000000 0x1 +boundary 0x20000000 +alloc_subregion 0xf0000000 0xffffffff 0x1 +print + +#check overflow in boundary check, before the subregion end (fixed in 1.32) +extent test5 0xf0000000 0xffffffff +boundary 0x20000000 +alloc_subregion 0xf0000000 0xffffffff 0x1 +print + +#check allocation beyond last boundary line (to be fixed) +# last two allocations should succeed without boundary "fixups" +extent test6 0 11 +boundary 8 +alloc_subregion 0 11 8 +alloc_subregion 0 11 2 +alloc_subregion 0 11 2 +print + +#check allocation beyond last boundary line (to be fixed) +# last allocation should be bumped to the next boundary and exactly fit +# the remaining space +extent test7 0 11 +boundary 8 +alloc_subregion 0 11 7 +alloc_subregion 0 11 4 +print + +#don't allocate a region pasts the end of subregion (i.e., the second +#alloc_subregion should fail). subr_extent.c prior to rev. 1.43 allocates +#region starts from 0x10. +extent test8 0 0x4f EX_NOCOALESCE +alloc_region 0x30 0x10 +alloc_subregion 0 0xf 0x10 +alloc_subregion 0 0xf 0x10 +print + +#When allocating a region with a boundary constraint, check that we properly +#detect overlaps once the candidate region has been aligned. +#subr_extent.c prior 1.45 could corrupt the extent map in this situation +extent test9 0 0x4f +boundary 0 +alloc_subregion 0 0x10 4 +alloc_subregion 0xd 0x20 2 +boundary 8 +alloc_subregion 0 0x4f 8 +print + +#check that free works +extent test10 0xc0002000 0xffffe000 EX_BOUNDZERO +boundary 0x10000 +align 0x10000 +alloc_subregion 0xc0002000 0xffffe000 0x2000 +alloc_subregion 0xc0002000 0xffffe000 0x2000 +print +free 0xc0020000 0x2000 +print +alloc_subregion 0xc0002000 0xffffe000 0x10000 +print +#If we have something like that in the EX_NOCOALESCE case: +#extent `test11' (0x10 - 0x20), flags = 0x2 +# 0x10 - 0x13 +# 0x1e - 0x1f +# 0x20 - 0x20 +#then a new extent of size 1 could be allocated at 0x20. +# fixed in 1.51 +extent test11 0x10 0x20 EX_NOCOALESCE +alloc_subregion 0x10 0x13 0x4 +alloc_subregion 0x1e 0x1f 0x2 +alloc_subregion 0x20 0x20 0x1 +alloc_subregion 0x20 0x20 0x1 +alloc_subregion 0x10 0x20 0x1 +print |