+// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000-2003 Silicon Graphics, Inc.
* All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
#define HANDLE int
#define INVALID_HANDLE -1
-#define OPEN(N,F) (open(N, F|O_CREAT|O_BINARY| \
- (D_flag ? O_DIRECT : 0), 0644))
+#define OPEN(N,F) (open(N, F|O_CREAT|O_BINARY, 0644))
#define SEEK(H, O) (lseek(H, O, SEEK_SET))
#define READ(H, B, L) (read(H, B, L))
#define WRITE(H, B, L) (write(H, B, L))
#define RAND() (rand())
#define SRAND(s) (srand(s))
-#define SLEEP(s) (sleep(s))
#define MIN(A,B) (((A)<(B))?(A):(B))
#define MAX(A,B) (((A)>(B))?(A):(B))
static char *filename = 0;
static int debug = 0;
static int server = 1;
-static int maxio = 8192;
-static int port = 7890;
+static int port = 0;
static int testnumber = -1;
static int saved_errno = 0;
static SOCKET s_fd = -1; /* listen socket */
static SOCKET c_fd = -1; /* IPC socket */
static HANDLE f_fd = INVALID_HANDLE; /* shared file */
-static char *buf; /* I/O buffer */
-static int D_flag = 0;
#define WRLOCK 0
#define RDLOCK 1
};
static int64_t tests[][6] =
- /* test # Action offset length expected server/client */
+ /* test # Action [offset|flags] length expected server/client */
{
/* Various simple tests exercising the list */
int offset = 0;
int togo = FILE_SIZE;
- if (D_flag) {
- ibuf = (char *)ALLOC_ALIGNED(INIT_BUFSZ);
- }
- else {
- ibuf = (char*)malloc(INIT_BUFSZ);
- }
+ ibuf = (char*)malloc(INIT_BUFSZ);
memset(ibuf, ':', INIT_BUFSZ);
SEEK(fd, 0L);
/*NOTREACHED*/
}
-#ifdef __sun
- if (D_flag) {
- directio(f_fd, DIRECTIO_ON);
- }
-#elif defined(__APPLE__)
- if (D_flag) {
- fcntl(f_fd, F_NOCACHE, 1);
- }
-#endif
return PASS;
}
if (do_open(O_RDWR) == FAIL)
exit(1);
- /*
- * +10 is slop for the iteration number if do_write() ... never
- * needed unless maxio is very small
- */
- if (D_flag) {
- if ((buf = (char *)ALLOC_ALIGNED(maxio + 10)) == NULL) {
- perror("aligned alloc buf");
- exit(1);
- /*NOTREACHED*/
- }
- } else {
- if ((buf = (char *)malloc(maxio + 10)) == NULL) {
- perror("malloc buf");
- exit(1);
- /*NOTREACHED*/
- }
- }
-
setbuf(stderr, NULL);
if (server) {
/*NOTREACHED*/
}
+ if (port == 0) {
+ socklen_t addr_len = sizeof(myAddr);
+
+ if (getsockname(s_fd, &myAddr, &addr_len)) {
+ perror("getsockname");
+ exit(1);
+ }
+
+ port = ntohs(myAddr.sin_port);
+ }
+
+ printf("server port: %d\n", port);
+ fflush(stdout);
+
c_fd = accept(s_fd, NULL, NULL);
if (c_fd == INVALID_SOCKET) {
perror("accept");
}
}
}
- if (debug > 1) {
- fprintf(stderr, "server sleeping ...\n");
- SLEEP(1);
- }
if(tests[index][TEST_NUM] != 0) {
if(last_test != tests[index][TEST_NUM]) {
test_count++;
if(server)
printf("%d tests run, %d failed\n", test_count, fail_count);
}
- if (buf) {
- if (D_flag)
- FREE_ALIGNED(buf);
- else
- free(buf);
- }
-
exit(fail_count);
/*NOTREACHED*/