-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlg-tree-test.patch
118 lines (116 loc) · 2.43 KB
/
lg-tree-test.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
diff --git a/src/tests/filesys/base/Make.tests b/src/tests/filesys/base/Make.tests
index e475222..a41b8de 100644
--- a/src/tests/filesys/base/Make.tests
+++ b/src/tests/filesys/base/Make.tests
@@ -1,7 +1,7 @@
# -*- makefile -*-
tests/filesys/base_TESTS = $(addprefix tests/filesys/base/,lg-create \
-lg-full lg-random lg-seq-block lg-seq-random sm-create sm-full \
+lg-full lg-random lg-seq-block lg-seq-random lg-tree sm-create sm-full \
sm-random sm-seq-block sm-seq-random syn-read syn-remove syn-write)
tests/filesys/base_PROGS = $(tests/filesys/base_TESTS) $(addprefix \
diff --git a/src/tests/filesys/base/lg-tree.c b/src/tests/filesys/base/lg-tree.c
new file mode 100644
index 0000000..36c6b4a
--- /dev/null
+++ b/src/tests/filesys/base/lg-tree.c
@@ -0,0 +1,82 @@
+/* Library function for creating a tree of directories. */
+
+#include <stdio.h>
+#include <syscall.h>
+#include "tests/main.h"
+#include "tests/lib.h"
+#include <random.h>
+
+#define MAX_PATHLEN 300
+
+char pathname[MAX_PATHLEN];
+int max_idx = 0;
+
+void test1 (void);
+void test2 (void);
+void test_mkdir (char *path);
+void test_open (char *path);
+
+void test_mkdir (char *path)
+{
+ if (mkdir(path) <= 0)
+ exit(-1);
+}
+
+void test_open (char *path)
+{
+ int fd;
+ if ((fd = open(path)) <=0)
+ exit(-1);
+
+ close(fd);
+}
+
+void
+test1 (void) {
+ int i;
+
+ for (i = 0; i*2+2 < MAX_PATHLEN; i++ ) {
+ pathname[i*2] = '/';
+ pathname[i*2+2] = '\0';
+
+ // Create directory
+ pathname[i*2+1] = 'a';
+ test_mkdir(pathname);
+
+ pathname[i*2+1] = 'b';
+ test_mkdir(pathname);
+
+ pathname[i*2+1] = 'c';
+ test_mkdir(pathname);
+ }
+
+ max_idx = i;
+
+ msg("Test 1 Done");
+}
+
+void
+test2 (void) {
+ unsigned long r;
+ char tmp; int i;
+
+ for (i = 0; i < 100; i++) {
+ r = random_ulong() % max_idx;
+
+ tmp = pathname[r*2+2];
+ pathname[r*2+2] = '\0';
+
+ //msg("%s\n", pathname);
+ test_open(pathname);
+
+ pathname[r*2+2] = tmp;
+ }
+ msg("Test 2 Done");
+}
+
+void
+test_main (void)
+{
+ test1 ();
+ test2 ();
+}
diff --git a/src/tests/filesys/base/lg-tree.ck b/src/tests/filesys/base/lg-tree.ck
new file mode 100644
index 0000000..7d9ed80
--- /dev/null
+++ b/src/tests/filesys/base/lg-tree.ck
@@ -0,0 +1,11 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
+(lg-tree) begin
+(lg-tree) Test 1 Done
+(lg-tree) Test 2 Done
+(lg-tree) end
+EOF
+pass;