Skip to content

Commit 36bc2f7

Browse files
committed
move multi open test to new t/multi directory
1 parent 4b39e94 commit 36bc2f7

File tree

2 files changed

+42
-25
lines changed

2 files changed

+42
-25
lines changed

t/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ libexec_PROGRAMS = \
5151
std/stdio-static.t \
5252
sys/sysio-gotcha.t \
5353
sys/sysio-static.t \
54+
multi/stdio-static.t \
5455
unifyfs_unmount.t
5556

5657

@@ -153,6 +154,12 @@ std_stdio_static_t_CPPFLAGS = $(test_cppflags)
153154
std_stdio_static_t_LDADD = $(test_static_ldadd)
154155
std_stdio_static_t_LDFLAGS = $(test_static_ldflags)
155156

157+
multi_stdio_static_t_SOURCES = multi/open_multi.c
158+
159+
multi_stdio_static_t_CPPFLAGS = $(test_cppflags)
160+
multi_stdio_static_t_LDADD = $(test_static_ldadd)
161+
multi_stdio_static_t_LDFLAGS = $(test_static_ldflags)
162+
156163
unifyfs_unmount_t_SOURCES = unifyfs_unmount.c
157164
unifyfs_unmount_t_CPPFLAGS = $(test_cppflags)
158165
unifyfs_unmount_t_LDADD = $(test_static_ldadd)

open_multi.c renamed to t/multi/open_multi.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3+
#include <string.h>
34
#include <sys/types.h>
45
#include <sys/stat.h>
56
#include <unistd.h>
67
#include <fcntl.h>
78
#include <errno.h>
89

10+
#include "t/lib/tap.h"
11+
#include "t/lib/testutil.h"
12+
913
#include "mpi.h"
1014
#include "unifyfs.h"
1115

16+
#define all_ok(condition, comm, ...) \
17+
do { \
18+
int input = (int) condition; \
19+
int output; \
20+
MPI_Allreduce(&input, &output, 1, MPI_INT, MPI_LAND, comm); \
21+
int rank; \
22+
MPI_Comm_rank(comm, &rank); \
23+
if (rank == 0) { \
24+
ok_at_loc(__FILE__, __LINE__, condition, __VA_ARGS__, NULL); \
25+
} \
26+
} while(0);
27+
1228
int mpi_sum(int val)
1329
{
1430
int sum;
@@ -37,7 +53,7 @@ int main(int argc, char* argv[])
3753
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
3854
MPI_Comm_size(MPI_COMM_WORLD, &ranks);
3955

40-
int ret = unifyfs_mount(mountpoint, rank, ranks, 0);
56+
unifyfs_mount(mountpoint, rank, ranks, 0);
4157

4258
char file[256];
4359
sprintf(file, "%s/testfile", mountpoint);
@@ -63,15 +79,13 @@ int main(int argc, char* argv[])
6379

6480
/* one rank should win */
6581
int sum = mpi_sum(success);
66-
if (sum != 1) {
67-
}
82+
all_ok(sum == 1, MPI_COMM_WORLD,
83+
"More than one process opened file in exclusive mode");
6884

6985
/* all others should get EEXIST */
7086
sum = mpi_sum(eexist);
71-
if (sum != (ranks - 1)) {
72-
}
73-
74-
MPI_Barrier(MPI_COMM_WORLD);
87+
all_ok(sum == (ranks - 1), MPI_COMM_WORLD,
88+
"All but one process should get EEXIST when opening file in exclusive mode");
7589

7690
/* all delete,
7791
* one rank should win, all others should get ENOENT */
@@ -87,15 +101,13 @@ int main(int argc, char* argv[])
87101

88102
/* one winner */
89103
sum = mpi_sum(success);
90-
if (sum != 1) {
91-
}
104+
all_ok(sum == 1, MPI_COMM_WORLD,
105+
"More than one process got success on unlink of the same file");
92106

93107
/* everyone else should get ENOENT */
94108
sum = mpi_sum(enoent);
95-
if (sum != (ranks - 1)) {
96-
}
97-
98-
MPI_Barrier(MPI_COMM_WORLD);
109+
all_ok(sum == (ranks - 1), MPI_COMM_WORLD,
110+
"All but one process should get ENOENT when unlinking the same file");
99111

100112
/* all create, this time not exclusive */
101113
errno = 0;
@@ -107,11 +119,8 @@ int main(int argc, char* argv[])
107119
}
108120

109121
/* all should succeed */
110-
sum = mpi_sum(success);
111-
if (sum != ranks) {
112-
}
113-
114-
MPI_Barrier(MPI_COMM_WORLD);
122+
all_ok(success, MPI_COMM_WORLD,
123+
"All processes should open file with O_CREAT and not O_EXCL");
115124

116125
/* open file for writing */
117126
errno = 0;
@@ -123,9 +132,8 @@ int main(int argc, char* argv[])
123132
}
124133

125134
/* all should succeeed */
126-
sum = mpi_sum(success);
127-
if (sum != ranks) {
128-
}
135+
all_ok(success, MPI_COMM_WORLD,
136+
"All processes should open file with O_CREAT for writing");
129137

130138
MPI_Barrier(MPI_COMM_WORLD);
131139

@@ -146,8 +154,9 @@ int main(int argc, char* argv[])
146154
if (rank == 0) {
147155
/* all ranks should have written some data */
148156
off_t size = getsize(file);
149-
if (size != bufsize * ranks) {
150-
}
157+
ok(size == bufsize * ranks,
158+
"File size %lu does not match expected size %lu",
159+
size, bufsize * ranks);
151160

152161
/* create file with truncate */
153162
fd = open(file, O_WRONLY | O_CREAT | O_TRUNC);
@@ -157,8 +166,9 @@ int main(int argc, char* argv[])
157166

158167
/* now file should be 0 length again */
159168
size = getsize(file);
160-
if (size != 0) {
161-
}
169+
ok(size == 0,
170+
"File size %lu does not match expected size %lu",
171+
size, 0);
162172
}
163173
MPI_Barrier(MPI_COMM_WORLD);
164174

0 commit comments

Comments
 (0)