xref: /openbsd-src/regress/sys/kern/extent/extest.awk (revision e2edd5f0662c4abe8ab1c203497095eb8f343bcd)
1# $OpenBSD: extest.awk,v 1.3 2019/09/11 12:30:34 kettenis Exp $
2# $NetBSD: extest.awk,v 1.6 2002/02/21 03:59:25 mrg Exp $
3
4BEGIN {
5	first = 1;
6
7	printf("#include <sys/types.h>\n")
8	printf("#include <sys/extent.h>\n\n")
9	printf("#include <stdio.h>\n")
10	printf("#include <stdlib.h>\n")
11	printf("#include <string.h>\n")
12	printf("int main(void) {\n")
13	printf("struct extent *ex; int error; long result;\n")
14}
15
16END {
17	printf("exit (0);\n")
18	printf("}\n")
19}
20
21$1 == "extent" {
22	if (first == 0) {
23		printf("extent_destroy(ex);\n")
24	}
25
26	align = "EX_NOALIGN";
27	boundary = "EX_NOBOUNDARY";
28
29	printf("printf(\"output for %s\\n\");\n", $2)
30
31	if ($5 == "") {
32		flags = "0";
33	} else {
34		flags = $5;
35	}
36	printf("ex = extent_create(\"%s\", %s, %s, 0, 0, 0, %s);\n",
37	       $2, $3, $4, flags)
38
39	first = 0;
40}
41
42$1 == "align" {
43	align = $2;
44}
45
46$1 == "boundary" {
47	boundary = $2;
48}
49
50$1 == "alloc_region" {
51	if ($4 == "") {
52		flags = "0";
53	} else {
54		flags = $4;
55	}
56	printf("error = extent_alloc_region(ex, %s, %s, %s);\n",
57	       $2, $3, flags)
58	printf("if (error)\n\tprintf(\"error: %%s\\n\", strerror(error));\n")
59}
60
61$1 == "alloc_subregion" {
62	printf("error = extent_alloc_subregion(ex, %s, %s, %s,\n",
63	       $2, $3, $4)
64	printf("\t%s, 0, %s, 0, &result);\n", align, boundary)
65	printf("if (error)\n\tprintf(\"error: %%s\\n\", strerror(error));\n")
66	printf("else\n\tprintf(\"result: 0x%%lx\\n\", result);\n")
67}
68
69$1 == "free" {
70	if ($4 == "") {
71		flags = "0";
72	} else {
73		flags = $4;
74	}
75	printf("error = extent_free(ex, %s, %s, %s);\n", $2, $3, flags)
76	printf("if (error)\n\tprintf(\"error: %%s\\n\", strerror(error));\n")
77}
78
79$1 == "print" {
80	printf("extent_print(ex);\n")
81}
82