1/*-
2 * Public Domain 2014-2018 MongoDB, Inc.
3 * Public Domain 2008-2014 WiredTiger, Inc.
4 *
5 * This is free and unencumbered software released into the public domain.
6 *
7 * Anyone is free to copy, modify, publish, use, compile, sell, or
8 * distribute this software, either in source code form or as a compiled
9 * binary, for any purpose, commercial or non-commercial, and by any
10 * means.
11 *
12 * In jurisdictions that recognize copyright laws, the author or authors
13 * of this software dedicate any and all copyright interest in the
14 * software to the public domain. We make this dedication for the benefit
15 * of the public at large and to the detriment of our heirs and
16 * successors. We intend this dedication to be an overt act of
17 * relinquishment in perpetuity of all present and future rights to this
18 * software under copyright law.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29/*
30 * base.run
31 * Command line syscall test runner
32 */
33#ifdef __linux__
34SYSTEM("Linux");
35#define OPEN_EXISTING(name, flags)		OPEN(name, flags)
36#else /* __linux__ */
37SYSTEM("Darwin");
38#define O_NOATIME 0
39#define OPEN_EXISTING(name, flags)		OPEN(name, flags, 0)
40#endif /* __linux__ */
41
42#ifdef HAVE_FTRUNCATE
43#ifdef __linux__
44#define FTRUNCATE(fd, len)			ftruncate(fd, len)
45#else
46#define FTRUNCATE(fd, len)			ftruncate(fd, len, len)
47#endif
48#else
49#define FTRUNCATE(fd, len)			/* do nothing */
50#endif
51
52#ifdef WT_USE_OPENAT
53#define OPEN(...)				openat(AT_FDCWD, __VA_ARGS__)
54#else
55#define OPEN(...)				open(__VA_ARGS__)
56#endif
57
58TRACE("close,fdatasync,fsync,ftruncate,open,openat,pwrite64,rename");
59RUN("");
60...
61OUTPUT("--------------wiredtiger_open");
62// lock == 3
63lock = OPEN("./WiredTiger.lock", O_RDWR|O_CREAT|O_CLOEXEC, 0666);
64pwrite64(lock, "WiredTiger lock file\n", 0x15, 0x0);
65fd = OPEN("./WiredTiger", O_RDWR|O_CREAT|O_CLOEXEC, 0666);
66pwrite64(fd, "WiredTiger\nWiredTiger"..., ...);
67#ifdef __linux__
68fdatasync(fd);
69#endif /* __linux__ */
70close(fd);
71
72...  // On Linux, there are calls to open and read "/proc/meminfo" here.
73
74fd = OPEN("./WiredTiger.basecfg.set", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0666);
75pwrite64(fd, "# Do not modify this file."..., ...);
76#ifdef __linux__
77fdatasync(fd);
78#endif /* __linux__ */
79close(fd);
80rename("./WiredTiger.basecfg.set", "./WiredTiger.basecfg");
81
82#ifdef __linux__
83dir = OPEN("./", O_RDONLY);
84fdatasync(dir);
85close(dir);
86#endif
87
88fd = OPEN("./WiredTiger.wt", O_RDWR|O_CREAT|O_EXCL|O_NOATIME|O_CLOEXEC, 0666);
89
90#ifdef __linux__
91dir = OPEN("./", O_RDONLY);
92fdatasync(dir);
93close(dir);
94#endif /* __linux__ */
95
96pwrite64(fd, ""..., 0x1000, 0x0);
97#ifdef __linux__
98fdatasync(fd);
99#endif /* __linux__ */
100close(fd);
101
102wt = OPEN_EXISTING("./WiredTiger.wt\0", O_RDWR|O_NOATIME|O_CLOEXEC);
103FTRUNCATE(wt, 0x1000);
104
105fd = OPEN("./WiredTiger.turtle.set\0", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0666);
106pwrite64(fd, "WiredTiger version string\nWiredTiger"..., ...);
107#ifdef __linux__
108fdatasync(fd);
109#endif /* __linux__ */
110close(fd);
111rename("./WiredTiger.turtle.set", "./WiredTiger.turtle");
112
113...  // There is a second open of turtle here, is it important?
114
115fd = OPEN("./WiredTigerLAS.wt", O_RDWR|O_CREAT|O_EXCL|O_NOATIME|O_CLOEXEC, 0666);
116
117#ifdef __linux__
118dir = OPEN("./", O_RDONLY);
119fdatasync(dir);
120close(dir);
121#endif /* __linux__ */
122
123pwrite64(fd, ""..., 0x1000, 0x0);
124
125#ifdef __linux__
126fdatasync(fd);
127#endif /* __linux__ */
128
129close(fd);
130fd = OPEN_EXISTING("./WiredTigerLAS.wt", O_RDWR|O_NOATIME|O_CLOEXEC);
131FTRUNCATE(fd, 0x1000);
132fd = OPEN_EXISTING("./WiredTiger.turtle", O_RDWR|O_CLOEXEC);
133close(fd);
134pwrite64(wt, ""..., 0x1000, 0x1000);
135pwrite64(wt, ""..., 0x1000, 0x2000);
136pwrite64(wt, ""..., 0x1000, 0x3000);
137#ifdef __linux__
138fdatasync(wt);
139#endif /* __linux__ */
140fd = OPEN("./WiredTiger.turtle.set", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0666);
141pwrite64(fd, "WiredTiger version string\nWiredTiger"..., ...);
142#ifdef __linux__
143fdatasync(fd);
144#endif /* __linux__ */
145close(fd);
146rename("./WiredTiger.turtle.set", "./WiredTiger.turtle");
147#ifdef __linux__
148dir = OPEN("./", O_RDONLY);
149fdatasync(dir);
150close(dir);
151fdatasync(wt);
152#endif /* __linux__ */
153
154OUTPUT("--------------open_session");
155OUTPUT("--------------create");
156
157hello = OPEN("./hello.wt", O_RDWR|O_CREAT|O_EXCL|O_NOATIME|O_CLOEXEC, 0666);
158#ifdef __linux__
159dir = OPEN("./", O_RDONLY);
160fdatasync(dir);
161close(dir);
162#endif /* __linux__ */
163pwrite64(hello, "A\330\001"..., 0x1000, 0x0);
164#ifdef __linux__
165fdatasync(hello);
166#endif /* __linux__ */
167close(hello);
168hello = OPEN_EXISTING("./hello.wt", O_RDWR|O_NOATIME|O_CLOEXEC);
169FTRUNCATE(hello, 0x1000);
170turtle = OPEN_EXISTING("./WiredTiger.turtle", O_RDWR|O_CLOEXEC);
171close(turtle);
172...  // more changes to turtle
173OUTPUT("--------------rename");
174#ifdef __linux__
175FTRUNCATE(hello, 0x1000);
176#endif /* __linux__ */
177close(hello);
178rename("./hello.wt", "./world.wt");
179// Changes to turtle, more writes to wt.
180turtle = OPEN_EXISTING("./WiredTiger.turtle", O_RDWR|O_CLOEXEC);
181close(turtle);
182...
183OUTPUT("--------------drop");
184...
185OUTPUT("--------------WT_CONNECTION::close");
186...
187