Skip to content

Commit 090a7f4

Browse files
authored
Merge pull request #4180 from jsquyres/pr/v3.0.x/fix-opal-nfs-test
v3.0.x: fix opal NFS test
2 parents ba397f3 + b845f0b commit 090a7f4

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

test/util/opal_path_nfs.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2010 Oak Ridge National Laboratory.
1414
* All rights reserved.
15-
* Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved.
15+
* Copyright (c) 2010-2017 Cisco Systems, Inc. All rights reserved
1616
* Copyright (c) 2010 IBM Corporation. All rights reserved.
1717
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
1818
* reserved.
@@ -132,7 +132,6 @@ void test(char* file, bool expect)
132132

133133
void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
134134
{
135-
#define MAX_DIR 256
136135
#define SIZE 1024
137136
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
138137
int rc;
@@ -150,13 +149,31 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
150149
**dirs = NULL;
151150
*nfs = NULL;
152151
}
153-
dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char**));
154-
nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool));
155152

153+
/* First, count how many mount points there are. Previous
154+
versions of this test tried to have a (large) constant-sized
155+
array for the mount points, but periodically it would break
156+
because we would run this test on a system with a larger number
157+
of mount points than the array. So just count and make sure to
158+
have an array large enough. */
156159
file = fopen("opal_path_nfs.out", "r");
160+
int count = 0;
161+
while (NULL != fgets (buffer, SIZE, file)) {
162+
++count;
163+
}
164+
printf("Found %d mounts\n", count);
165+
166+
// Add one more so we can have a NULL entry at the end
167+
++count;
168+
169+
dirs_tmp = (char**) calloc (count, sizeof(char*));
170+
nfs_tmp = (bool*) calloc (count, sizeof(bool));
171+
157172
i = 0;
158173
rc = 4711;
159-
while (NULL != fgets (buffer, SIZE, file)) {
174+
rewind(file);
175+
// i should never be more than count, but be safe anyway.
176+
while (i < count && NULL != fgets (buffer, SIZE, file)) {
160177
int mount_known;
161178
char fs[MAXNAMLEN];
162179

0 commit comments

Comments
 (0)