syncloop.c revision c7e4935f5b755b4bbeaec416f1ad24337aeac7a4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Synchronous loop-back test program
* For installation verification of synchronous lines and facilities
*/
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/ser_sync.h>
#include <libdlpi.h>
static void Usage(void);
static void quiet_period(void);
static void first_packet();
static void many_packets();
static unsigned int speed = 9600;
static int reccount = 100;
static int reclen = 100;
static int looptype = 0;
static int loopchange = 0;
static int clockchange = 0;
static int data = -1;
static int verbose = 0;
static char *yesno[] = {
"no",
"yes",
"silent",
0,
};
static char *txnames[] = {
"txc",
"rxc",
"baud",
"pll",
"sysclk",
"-txc",
0,
};
static char *rxnames[] = {
"rxc",
"txc",
"baud",
"pll",
"sysclk",
"-rxc",
0,
};
#define MAXPACKET 4096
int
{
char *portname;
char device[DLPI_LINKNAME_MAX];
char *devstr = "/dev/";
int devstrlen;
int retval;
argc--;
argv++;
switch (argv[0][1]) {
case 'c': /* rec count */
if (argc < 2)
Usage();
argc -= 2;
argv += 2;
break;
case 'd':
Usage();
argc -= 2;
argv += 2;
break;
case 'l': /* rec length */
if (argc < 2)
Usage();
argc -= 2;
argv += 2;
break;
case 's': /* line speed */
if (argc < 2)
Usage();
argc -= 2;
argv += 2;
break;
case 't': /* test type */
if (argc < 2)
Usage();
argc -= 2;
argv += 2;
break;
case 'v':
verbose = 1;
argc--;
argv++;
break;
}
if (argc != 1)
Usage();
"syncloop: invalid device name (too long) %s\n",
portname);
exit(1);
}
}
if (dfd < 0) {
exit(1);
}
while (*cp) /* find the end of the name */
cp++;
cp--;
"syncloop: %s missing minor device number\n", portname);
exit(1);
}
"syncloop: invalid device name (too long) %s\n",
portname);
exit(1);
}
exit(1);
}
exit(1);
}
(void) printf("[ Data device: %s | Control device: %s, ppa=%u ]\n",
perror("S_IOCGETMODE");
"for %s\n", portname);
exit(1);
}
(void) printf("Enter test type:\n");
(void) printf("1: Internal Test\n");
(void) printf(
" (internal data loop, internal clocking)\n");
(void) printf("2: Test using loopback plugs\n");
(void) printf(
" (external data loop, internal clocking)\n");
(void) printf("3: Test using local or remote modem loopback\n");
(void) printf(
" (external data loop, external clocking)\n");
(void) printf("4: Other, previously set, special mode\n");
}
switch (looptype) {
case 1:
clockchange++;
loopchange++;
break;
case 2:
clockchange++;
loopchange++;
break;
case 3:
clockchange++;
loopchange++;
break;
case 4:
goto no_params;
}
perror("S_IOCSETMODE");
"syncloop: can't set sync mode info for %s\n", portname);
exit(1);
}
/* report state */
perror("S_IOCGETMODE");
"for %s\n", portname);
exit(1);
}
(void) printf("speed=%d, loopback=%s, nrzi=%s, txc=%s, rxc=%s\n",
quiet_period();
first_packet();
many_packets();
return (0);
}
static void
Usage()
{
(void) printf("Usage: syncloop [ options ] portname\n");
(void) printf("Options: -c packet_count\n");
(void) printf(" -l packet_length\n");
(void) printf(" -s line_speed\n");
(void) printf(" -t test_type\n");
(void) printf(" -d hex_data_byte\n");
exit(1);
}
static int zero_time = 0;
static int short_time = 1000;
static int long_time = 4000;
static char bigbuf[4096];
static void
{
(void) printf("[ checking for quiet line ]\n");
}
(void) printf("packet received but none sent!\n");
(void) printf("quiesce other end before starting syncloop\n");
exit(1);
}
}
static void
{
int i, len;
int pollret;
for (i = 0; i < reclen; i++)
(void) printf("[ Trying first packet ]\n");
perror("S_IOCGETSTATS");
exit(1);
}
for (i = 0; i < 5; i++) {
"packet write failed, errno %d\n",
errno);
exit(1);
}
if (pollret == 0)
(void) printf("poll: nothing to read.\n");
if (pollret == 1) {
return; /* success */
else {
(void) printf("len %d should be %d\n",
if (verbose) {
(void) printf(" ");
(void) printf("\nshould be ");
(void) printf("\n");
}
}
}
}
(void) printf("Loopback has TOTALLY FAILED - ");
(void) printf("no packets returned after 5 attempts\n");
perror("S_IOCGETSTATS");
exit(1);
}
(void) printf(
"No packets transmitted - no transmit clock present\n");
exit(1);
}
static void
{
int baddata = 0;
int i, len;
int incount = 0;
long prev_sec = -1;
int pollret;
(void) printf("[ Trying many packets ]\n");
perror("S_IOCGETSTATS");
exit(1);
}
(void) gettimeofday(&start_time, 0);
i = 0;
while (i < reccount) {
}
if (pollret < 0)
perror("poll");
else {
(void) printf("len %d should be %d\n",
if (verbose) {
(void) printf(" ");
(void) printf("\nshould be ");
(void) printf("\n");
}
baddata++;
}
incount++;
(void) gettimeofday(&end_time, 0);
}
}
if (pollret < 0)
perror("poll");
if (pollret == 0)
(void) printf("poll: nothing to read or write.\n");
if (pollret == 1) {
i++;
(void) printf("OUTPUT HAS LOCKED UP!!!\n");
break;
}
}
}
}
if (verbose) {
(void) printf(" ");
(void) printf("\nshould be ");
(void) printf("\n");
}
baddata++;
}
incount++;
(void) gettimeofday(&end_time, 0);
}
if (baddata)
(void) printf("%d packets with wrong data received!\n",
baddata);
perror("S_IOCGETSTATS");
exit(1);
}
(void) printf("%d packets lost in outbound queueing\n",
(void) printf("%d packets lost in inbound queueing\n",
(void) printf("CRC errors Aborts Overruns Underruns ");
(void) printf(" In <-Drops-> Out\n%9d %9d %9d %9d %12d %12d\n",
if (secs) {
}
}
static void
{
char c, *hex = "0123456789ABCDEF";
int i;
for (i = 0; i < len; i++) {
c = *cp++;
}
}