diff options
Diffstat (limited to '')
41 files changed, 0 insertions, 4317 deletions
diff --git a/tests/.libs/bandwidth-client b/tests/.libs/bandwidth-client Binary files differdeleted file mode 100755 index 4d82059..0000000 --- a/tests/.libs/bandwidth-client +++ /dev/null diff --git a/tests/.libs/bandwidth-server-many-up b/tests/.libs/bandwidth-server-many-up Binary files differdeleted file mode 100755 index 9f3e0b5..0000000 --- a/tests/.libs/bandwidth-server-many-up +++ /dev/null diff --git a/tests/.libs/bandwidth-server-one b/tests/.libs/bandwidth-server-one Binary files differdeleted file mode 100755 index f14a514..0000000 --- a/tests/.libs/bandwidth-server-one +++ /dev/null diff --git a/tests/.libs/lt-random-test-client b/tests/.libs/lt-random-test-client Binary files differdeleted file mode 100755 index 168d3c4..0000000 --- a/tests/.libs/lt-random-test-client +++ /dev/null diff --git a/tests/.libs/lt-unit-test-client b/tests/.libs/lt-unit-test-client Binary files differdeleted file mode 100755 index 72c8ca1..0000000 --- a/tests/.libs/lt-unit-test-client +++ /dev/null diff --git a/tests/.libs/lt-unit-test-server b/tests/.libs/lt-unit-test-server Binary files differdeleted file mode 100755 index 4a6d570..0000000 --- a/tests/.libs/lt-unit-test-server +++ /dev/null diff --git a/tests/.libs/lt-version b/tests/.libs/lt-version Binary files differdeleted file mode 100755 index 7b81ff1..0000000 --- a/tests/.libs/lt-version +++ /dev/null diff --git a/tests/.libs/random-test-client b/tests/.libs/random-test-client Binary files differdeleted file mode 100755 index 17d9c36..0000000 --- a/tests/.libs/random-test-client +++ /dev/null diff --git a/tests/.libs/random-test-server b/tests/.libs/random-test-server Binary files differdeleted file mode 100755 index d0d9010..0000000 --- a/tests/.libs/random-test-server +++ /dev/null diff --git a/tests/.libs/unit-test-client b/tests/.libs/unit-test-client Binary files differdeleted file mode 100755 index 4920d69..0000000 --- a/tests/.libs/unit-test-client +++ /dev/null diff --git a/tests/.libs/unit-test-server b/tests/.libs/unit-test-server Binary files differdeleted file mode 100755 index 6a426ab..0000000 --- a/tests/.libs/unit-test-server +++ /dev/null diff --git a/tests/.libs/version b/tests/.libs/version Binary files differdeleted file mode 100755 index c88ec66..0000000 --- a/tests/.libs/version +++ /dev/null diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 88d829e..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,585 +0,0 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. -# tests/Makefile. Generated from Makefile.in by configure. - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, -# Inc. -# This Makefile.in is free software; the Free Software Foundation -# giv /* $Id: MatrixOrbital.c,v 1.22 2001/04/27 05:04:57 reinelt Exp $
*
* driver for Matrix Orbital serial display modules
*
* Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
*
* 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; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will 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 to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Log: MatrixOrbital.c,v $
* Revision 1.22 2001/04/27 05:04:57 reinelt
*
* replaced OPEN_MAX with sysconf()
* replaced mktemp() with mkstemp()
* unlock serial port if open() fails
*
* Revision 1.21 2001/02/14 07:40:16 reinelt
*
* first (incomplete) GPO implementation
*
* Revision 1.20 2001/02/13 09:00:13 reinelt
*
* prepared framework for GPO's (general purpose outputs)
*
* Revision 1.19 2000/08/10 09:44:09 reinelt
*
* new debugging scheme: error(), info(), debug()
* uses syslog if in daemon mode
*
* Revision 1.18 2000/08/09 09:50:29 reinelt
*
* opened 0.98 development
* removed driver-specific signal-handlers
* added 'quit'-function to driver structure
* added global signal-handler
*
* Revision 1.17 2000/04/15 11:13:54 reinelt
*
* added '-d' (debugging) switch
* added several debugging messages
* removed config entry 'Delay' for HD44780 driver
* delay loop for HD44780 will be calibrated automatically
*
* Revision 1.16 2000/04/13 06:09:52 reinelt
*
* added BogoMips() to system.c (not used by now, maybe sometimes we can
* calibrate our delay loop with this value)
*
* added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully
* no compiler will optimize away the delay loop!
*
* Revision 1.15 2000/04/12 08:05:45 reinelt
*
* first version of the HD44780 driver
*
* Revision 1.14 2000/04/10 04:40:53 reinelt
*
* minor changes and cleanups
*
* Revision 1.13 2000/04/07 05:42:20 reinelt
*
* UUCP style lockfiles for the serial port
*
* Revision 1.12 2000/03/26 18:46:28 reinelt
*
* bug in pixmap.c that leaded to empty bars fixed
* name conflicts with X11 resolved
*
* Revision 1.11 2000/03/25 05:50:43 reinelt
*
* memory leak in Raster_flush closed
* driver family logic changed
*
* Revision 1.10 2000/03/23 07:24:48 reinelt
*
* PPM driver up and running (but slow!)
*
* Revision 1.9 2000/03/22 07:33:50 reinelt
*
* FAQ added
* new modules 'processor.c' contains all data processing
*
* Revision 1.8 2000/03/19 08:41:28 reinelt
*
* documentation available! README, README.MatrixOrbital, README.Drivers
* added Skeleton.c as a starting point for new drivers
*
* Revision 1.7 2000/03/18 08:07:04 reinelt
*
* vertical bars implemented
* bar compaction improved
* memory information implemented
*
* Revision 1.6 2000/03/17 09:21:42 reinelt
*
* various memory statistics added
*
* Revision 1.5 2000/03/13 15:58:24 reinelt
*
* release 0.9
* moved row parsing to parser.c
* all basic work finished
*
* Revision 1.4 2000/03/10 17:36:02 reinelt
*
* first unstable but running release
*
*/
/*
*
* exported fuctions:
*
* struct LCD MatrixOrbital[]
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include "debug.h"
#include "cfg.h"
#include "lock.h"
#include "display.h"
#define XRES 5
#define YRES 8
#define CHARS 8
#define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 )
typedef struct {
int len1;
int len2;
int type;
int segment;
} BAR;
typedef struct {
int len1;
int len2;
int type;
int used;
int ascii;
} SEGMENT;
static LCD Lcd;
static char *Port=NULL;
static speed_t Speed;
static int Device=-1;
static char Txt[4][40];
static BAR Bar[4][40];
static int GPO;
static int nSegment=2;
static SEGMENT Segment[128] = {{ len1:0, len2:0, type:255, used:0, ascii:32 },
{ len1:255, len2:255, type:255, used:0, ascii:255 }};
static int MO_open (void)
{
int fd;
pid_t pid;
struct termios portset;
if ((pid=lock_port(Port))!=0) {
if (pid==-1)
error ("MatrixOrbital: port %s could not be locked", Port);
else
error ("MatrixOrbital: port %s is locked by process %d", Port, pid);
return -1;
}
fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd==-1) {
error ("MatrixOrbital: open(%s) failed: %s", Port, strerror(errno));
unlock_port(Port);
return -1;
}
if (tcgetattr(fd, &portset)==-1) {
error ("MatrixOrbital: tcgetattr(%s) failed: %s", Port, strerror(errno));
unlock_port(Port);
return -1;
}
cfmakeraw(&portset);
cfsetospeed(&portset, Speed);
if (tcsetattr(fd, TCSANOW, &portset)==-1) {
error ("MatrixOrbital: tcsetattr(%s) failed: %s", Port, strerror(errno));
unlock_port(Port);
return -1;
}
return fd;
}
static void MO_write (char *string, int len)
{
if (Device==-1) return;
if (write (Device, string, len)==-1) {
if (errno==EAGAIN) {
usleep(1000);
if (write (Device, string, len)>=0) return;
}
error ("MatrixOrbital: write(%s) failed: %s", Port, strerror(errno));
}
}
static int MO_contrast (void)
{
char buffer[4];
int contrast;
contrast=atoi(cfg_get("Contrast")?:"160");
snprintf (buffer, 4, "\376P%c", contrast);
MO_write (buffer, 3);
return 0;
}
static void MO_process_bars (void)
{
int row, col;
int i, j;
for (i=2; i<nSegment && Segment[i].used; i++);
for (j=i+1; j<nSegment; j++) {
if (Segment[j].used)
Segment[i++]=Segment[j];
}
nSegment=i;
for (row=0; row<Lcd.rows; row++) {
for (col=0; col<Lcd.cols; col++) {
if (Bar[row][col].type==0) continue;
for (i=0; i<nSegment; i++) {
if (Segment[i].type & Bar[row][col].type &&
Segment[i].len1== Bar[row][col].len1 &&
Segment[i].len2== Bar[row][col].len2) break;
}
if (i==nSegment) {
nSegment++;
Segment[i].len1=Bar[row][col].len1;
Segment[i].len2=Bar[row][col].len2;
Segment[i].type=Bar[row][col].type;
Segment[i].used=0;
Segment[i].ascii=-1;
}
Bar[row][col].segment=i;
}
}
}
static int MO_segment_diff (int i, int j)
{
int RES;
int i1, i2, j1, j2;
if (i==j) return 65535;
if (!(Segment[i].type & Segment[j].type)) return 65535;
if (Segment[i].len1==0 && Segment[j].len1!=0) return 65535;
if (Segment[i].len2==0 && Segment[j].len2!=0) return 65535;
RES=Segment[i].type & BAR_H ? XRES:YRES;
if (Segment[i].len1>=RES && Segment[j].len1<RES) return 65535;
if (Segment[i].len2>=RES && Segment[j].len2<RES) return 65535;
if (Segment[i].len1==Segment[i].len2 && Segment[j].len1!=Segment[j].len2) return 65535;
i1=Segment[i].len1; if (i1>RES) i1=RES;
i2=Segment[i].len2; if (i2>RES) i2=RES;
j1=Segment[j].len1; if (j1>RES) i1=RES;
j2=Segment[j].len2; if (j2>RES) i2=RES;
return (i1-i2)*(i1-i2)+(j1-j2)*(j1-j2);
}
static void MO_compact_bars (void)
{
int i, j, r, c, min;
int pack_i, pack_j;
int pass1=1;
int deviation[nSegment][nSegment];
if (nSegment>CHARS+2) {
for (i=2; i<nSegment; i++) {
for (j=0; j<nSegment; j++) {
deviation[i][j]=MO_segment_diff(i,j);
}
}
while (nSegment>CHARS+2) {
min=65535;
pack_i=-1;
pack_j=-1;
for (i=2; i<nSegment; i++) {
if (pass1 && Segment[i].used) continue;
for (j=0; j<nSegment; j++) {
if (deviation[i][j]<min) {
min=deviation[i][j];
pack_i=i;
pack_j=j;
}
}
}
if (pack_i==-1) {
if (pass1) {
pass1=0;
continue;
} else {
error ("MatrixOrbital: unable to compact bar characters");
nSegment=CHARS;
break;
}
}
nSegment--;
Segment[pack_i]=Segment[nSegment];
for (i=0; i<nSegment; i++) {
deviation[pack_i][i]=deviation[nSegment][i];
deviation[i][pack_i]=deviation[i][nSegment];
}
for (r=0; r<Lcd.rows; r++) {
for (c=0; c<Lcd.cols; c++) {
if (Bar[r][c].segment==pack_i)
Bar[r][c].segment=pack_j;
if (Bar[r][c].segment==nSegment)
Bar[r][c].segment=pack_i;
}
}
}
}
}
static void MO_define_chars (void)
{
int c, i, j;
char buffer[12]="\376N";
for (i=2; i<nSegment; i++) {
if (Segment[i].used) continue;
if (Segment[i].ascii!=-1) continue;
for (c=0; c<CHARS; c++) {
for (j=2; j<nSegment; j++) {
if (Segment[j].ascii==c) break;
}
if (j==nSegment) break;
}
Segment[i].ascii=c;
buffer[2]=c;
switch (Segment[i].type) {
case BAR_L:
for (j=0; j<4; j++) {
char Pixel[] = { 0, 1, 3, 7, 15, 31 };
buffer[j+3]=Pixel[Segment[i].len1];
buffer[j+7]=Pixel[Segment[i].len2];
}
break;
case BAR_R:
for (j=0; j<4; j++) {
char Pixel[] = { 0, 16, 24, 28, 30, 31 };
buffer[j+3]=Pixel[Segment[i].len1];
buffer[j+7]=Pixel[Segment[i].len2];
}
break;
case BAR_U:
for (j=0; j<Segment[i].len1; j++) {
buffer[10-j]=31;
}
for (; j<YRES; j++) {
buffer[10-j]=0;
}
break;
case BAR_D:
for (j=0; j<Segment[i].len1; j++) {
buffer[j+3]=31;
}
for (; j<YRES; j++) {
buffer[j+3]=0;
}
break;
}
MO_write (buffer, 11);
}
}
int MO_clear (void)
{
int row, col;
for (row=0; row<Lcd.rows; row++) {
for (col=0; col<Lcd.cols; col++) {
Txt[row][col]='\t';
Bar[row][col].len1=-1;
Bar[row][col].len2=-1;
Bar[row][col].type=0;
Bar[row][col].segment=-1;
}
}
MO_write ("\014", 1); // Clear Screen
MO_write ("\376V", 2); // GPO off
GPO=0;
return 0;
}
int MO_init (LCD *Self)
{
char *port;
char *speed;
Lcd=*Self;
if (Port) {
free (Port);
Port=NULL;
}
port=cfg_get ("Port");
if (port==NULL || *port=='\0') {
error ("MatrixOrbital: no 'Port' entry in %s", cfg_file());
return -1;
}
Port=strdup(port);
speed=cfg_get("Speed")?:"19200";
switch (atoi(speed)) {
case 1200:
Speed=B1200;
break;
case 2400:
Speed=B2400;
break;
case 9600:
Speed=B9600;
break;
case 19200:
Speed=B19200;
break;
default:
error ("MatrixOrbital: unsupported speed '%s' in %s", speed, cfg_file());
return -1;
}
debug ("using port %s at %d baud", Port, atoi(speed));
Device=MO_open();
if (Device==-1) return -1;
MO_clear();
MO_contrast();
MO_write ("\376B", 3); // backlight on
MO_write ("\376K", 2); // cursor off
MO_write ("\376T", 2); // blink off
MO_write ("\376D", 2); // line wrapping off
MO_write ("\376R", 2); // auto scroll off
return 0;
}
int MO_put (int row, int col, char *text)
{
char *p=&Txt[row][col];
char *t=text;
while (*t && col++<=Lcd.cols) {
*p++=*t++;
}
return 0;
}
int MO_bar (int type, int row, int col, int max, int len1, int len2)
{
int rev=0;
if (len1<1) len1=1;
else if (len1>max) len1=max;
if (len2<1) len2=1;
else if (len2>max) len2=max;
switch (type) {
case BAR_L:
len1=max-len1;
len2=max-len2;
rev=1;
case BAR_R:
while (max>0 && col<=Lcd.cols) {
Bar[row][col].type=type;
Bar[row][col].segment=-1;
if (len1>=XRES) {
Bar[row][col].len1=rev?0:XRES;
len1-=XRES;
} else {
Bar[row][col].len1=rev?XRES-len1:len1;
len1=0;
}
if (len2>=XRES) {
Bar[row][col].len2=rev?0:XRES;
len2-=XRES;
} else {
Bar[row][col].len2=rev?XRES-len2:len2;
len2=0;
}
max-=XRES;
col++;
}
break;
case BAR_U:
len1=max-len1;
len2=max-len2;
rev=1;
case BAR_D:
while (max>0 && row<=Lcd.rows) {
Bar[row][col].type=type;
Bar[row][col].segment=-1;
if (len1>=YRES) {
Bar[row][col].len1=rev?0:YRES;
len1-=YRES;
} else {
Bar[row][col].len1=rev?YRES-len1:len1;
len1=0;
}
if (len2>=YRES) {
Bar[row][col].len2=rev?0:YRES;
len2-=YRES;
} else {
Bar[row][col].len2=rev?YRES-len2:len2;
len2=0;
}
max-=YRES;
row++;
}
break;
}
return 0;
}
int MO_gpo (int num, int val)
{
if (num>=Lcd.gpos)
return -1;
if (val) {
GPO |= 1<<num; // set bit
} else {
GPO &= ~(1<<num); // clear bit
}
return 0;
}
int MO_flush (void)
{
char buffer[256]="\376G";
char *p;
int s, row, col;
MO_process_bars();
MO_compact_bars();
MO_define_chars();
for (s=0; s<nSegment; s++) {
Segment[s].used=0;
}
for (row=0; row<Lcd.rows; row++) {
buffer[3]=row+1;
for (col=0; col<Lcd.cols; col++) {
s=Bar[row][col].segment;
if (s!=-1) {
Segment[s].used=1;
Txt[row][col]=Segment[s].ascii;
}
}
for (col=0; col<Lcd.cols; col++) {
if (Txt[row][col]=='\t') continue;
buffer[2]=col+1;
for (p=buffer+4; col<Lcd.cols; col++, p++) {
if (Txt[row][col]=='\t') break;
*p=Txt[row][col];
}
MO_write (buffer, p-buffer);
}
}
if (GPO & 1) {
MO_write ("\376W", 2); // GPO on
} else {
MO_write ("\376V", 2); // GPO off
}
return 0;
}
int MO_quit (void)
{
debug ("closing port %s", Port);
close (Device);
unlock_port(Port);
return (0);
}
LCD MatrixOrbital[] = {
{ "LCD0821",2, 8,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit },
{ "LCD1621",2,16,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit },
{ "LCD2021",2,20,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit },
{ "LCD2041",4,20,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit },
{ "LCD4021",2,40,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit },
{ NULL }
};
- printf("Transfert rate in points/seconds:\n"); - printf("* %d registers/s\n", rate); - printf("\n"); - - bytes = n_loop * nb_points * sizeof(uint16_t); - rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); - printf("Values:\n"); - printf("* %d x %d values\n", n_loop, nb_points); - printf("* %.3f ms for %d bytes\n", elapsed, bytes); - printf("* %d KiB/s\n", rate); - printf("\n"); - - /* TCP:Query and reponse header and values */ - bytes = 12 + 9 + (nb_points * sizeof(uint16_t)); - printf("Values and TCP Modbus overhead:\n"); - printf("* %d x %d bytes\n", n_loop, bytes); - bytes = n_loop * bytes; - rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); - printf("* %.3f ms for %d bytes\n", elapsed, bytes); - printf("* %d KiB/s\n", rate); - printf("\n\n"); - - printf("READ AND WRITE REGISTERS\n\n"); - - nb_points = MODBUS_MAX_RW_WRITE_REGISTERS; - start = gettime_ms(); - for (i=0; i<n_loop; i++) { - rc = modbus_write_and_read_registers(ctx, - 0, nb_points, tab_reg, - 0, nb_points, tab_reg); - if (rc == -1) { - fprintf(stderr, "%s\n", modbus_strerror(errno)); - return -1; - } - } - end = gettime_ms(); - elapsed = end - start; - - rate = (n_loop * nb_points) * G_MSEC_PER_SEC / (end - start); - printf("Transfert rate in points/seconds:\n"); - printf("* %d registers/s\n", rate); - printf("\n"); - - bytes = n_loop * nb_points * sizeof(uint16_t); - rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); - printf("Values:\n"); - printf("* %d x %d values\n", n_loop, nb_points); - printf("* %.3f ms for %d bytes\n", elapsed, bytes); - printf("* %d KiB/s\n", rate); - printf("\n"); - - /* TCP:Query and reponse header and values */ - bytes = 12 + 9 + (nb_points * sizeof(uint16_t)); - printf("Values and TCP Modbus overhead:\n"); - printf("* %d x %d bytes\n", n_loop, bytes); - bytes = n_loop * bytes; - rate = bytes / 1024 * G_MSEC_PER_SEC / (end - start); - printf("* %.3f ms for %d bytes\n", elapsed, bytes); - printf("* %d KiB/s\n", rate); - printf("\n"); - - /* Free the memory */ - free(tab_bit); - free(tab_reg); - - /* Close the connection */ - modbus_close(ctx); - modbus_free(ctx); - - return 0; -} diff --git a/tests/bandwidth-client.o b/tests/bandwidth-client.o Binary files differdeleted file mode 100644 index 9ff6b23..0000000 --- a/tests/bandwidth-client.o +++ /dev/null diff --git a/tests/bandwidth-server-many-up b/tests/bandwidth-server-many-up deleted file mode 100755 index 85a88ea..0000000 --- a/tests/bandwidth-server-many-up +++ /dev/null @@ -1,225 +0,0 @@ -#! /bin/bash - -# bandwidth-server-many-up - temporary wrapper script for .libs/bandwidth-server-many-up -# Generated by libtool (GNU libtool) 2.4 Debian-2.4-3 -# -# The bandwidth-server-many-up program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -sed_quote_subst='s/\([`"$\\]\)/\\\1/g' - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command="(cd /home/jmccrohan/bin/libmodbus/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11; export PATH; gcc -g -O2 -g -O2 -Wall -Werror -o \$progdir/\$file bandwidth-server-many-up.o ../src/.libs/libmodbus.so -Wl,-rpath -Wl,/home/jmccrohan/bin/libmodbus/src/.libs)" - -# This environment variable determines our operation mode. -if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then - # install mode needs the following variables: - generated_by_libtool_version='2.4' - notinst_deplibs=' ../src/libmodbus.la' -else - # When we are sourced in execute mode, $file and $ECHO are already set. - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - file="$0" - -# A function that is used when there is no print builtin or printf. -func_fallback_echo () -{ - eval 'cat <<_LTECHO_EOF -$1 -_LTECHO_EOF' -} - ECHO="printf %s\\n" - fi - -# Very basic option parsing. These options are (a) specific to -# the libtool wrapper, (b) are identical between the wrapper -# /script/ and the wrapper /executable/ which is used only on -# windows platforms, and (c) all begin with the string --lt- -# (application programs are unlikely to have options which match -# this pattern). -# -# There are only two supported options: --lt-debug and -# --lt-dump-script. There is, deliberately, no --lt-help. -# -# The first argument to this parsing function should be the -# script's ../libtool value, followed by no. -lt_option_debug= -func_parse_lt_options () -{ - lt_script_arg0=$0 - shift - for lt_opt - do - case "$lt_opt" in - --lt-debug) lt_option_debug=1 ;; - --lt-dump-script) - lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` - test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. - lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` - cat "$lt_dump_D/$lt_dump_F" - exit 0 - ;; - --lt-*) - $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 - exit 1 - ;; - esac - done - - # Print the debug banner immediately: - if test -n "$lt_option_debug"; then - echo "bandwidth-server-many-up:bandwidth-server-many-up:${LINENO}: libtool wrapper (GNU libtool) 2.4 Debian-2.4-3" 1>&2 - fi -} - -# Used when --lt-debug. Prints its arguments to stdout -# (redirection is the responsibility of the caller) -func_lt_dump_args () -{ - lt_dump_args_N=1; - for lt_arg - do - $ECHO "bandwidth-server-many-up:bandwidth-server-many-up:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" - lt_dump_args_N=`expr $lt_dump_args_N + 1` - done -} - -# Core function for launching the target application -func_exec_program_core () -{ - - if test -n "$lt_option_debug"; then - $ECHO "bandwidth-server-many-up:bandwidth-server-many-up:${LINENO}: newargv[0]: $progdir/$program" 1>&2 - func_lt_dump_args ${1+"$@"} 1>&2 - fi - exec "$progdir/$program" ${1+"$@"} - - $ECHO "$0: cannot exec $program $*" 1>&2 - exit 1 -} - -# A function to encapsulate launching the target application -# Strips options in the --lt-* namespace from $@ and -# launches target application with the remaining arguments. -func_exec_program () -{ - for lt_wr_arg - do - case $lt_wr_arg in - --lt-*) ;; - *) set x "$@" "$lt_wr_arg"; shift;; - esac - shift - done - func_exec_program_core ${1+"$@"} -} - - # Parse options - func_parse_lt_options "$0" ${1+"$@"} - - # Find the directory that this script lives in. - thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - test "x$thisdir" = "x$file" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` - while test -n "$file"; do - destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - - # If there was a directory component, then change thisdir. - if test "x$destdir" != "x$file"; then - case "$destdir" in - [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; - *) thisdir="$thisdir/$destdir" ;; - esac - fi - - file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` - file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` - done - - # Usually 'no', except on cygwin/mingw when embedded into - # the cwrapper. - WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no - if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then - # special case for '.' - if test "$thisdir" = "."; then - thisdir=`pwd` - fi - # remove .libs from thisdir - case "$thisdir" in - *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; - .libs ) thisdir=. ;; - esac - fi - - # Try to get the absolute directory name. - absdir=`cd "$thisdir" && pwd` - test -n "$absdir" && thisdir="$absdir" - - program=lt-'bandwidth-server-many-up' - progdir="$thisdir/.libs" - - if test ! -f "$progdir/$program" || - { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ - test "X$file" != "X$progdir/$program"; }; then - - file="$$-$program" - - if test ! -d "$progdir"; then - mkdir "$progdir" - else - rm -f "$progdir/$file" - fi - - # relink executable if necessary - if test -n "$relink_command"; then - if relink_command_output=`eval $relink_command 2>&1`; then : - else - printf %s\n "$relink_command_output" >&2 - rm -f "$progdir/$file" - exit 1 - fi - fi - - mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || - { rm -f "$progdir/$program"; - mv -f "$progdir/$file" "$progdir/$program"; } - rm -f "$progdir/$file" - fi - - if test -f "$progdir/$program"; then - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - # Run the actual program with our arguments. - func_exec_program ${1+"$@"} - fi - else - # The program doesn't exist. - $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 - $ECHO "This script is just a wrapper for $program." 1>&2 - $ECHO "See the libtool documentation for more information." 1>&2 - exit 1 - fi -fi diff --git a/tests/bandwidth-server-many-up.c b/tests/bandwidth-server-many-up.c deleted file mode 100644 index 02968c1..0000000 --- a/tests/bandwidth-server-many-up.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © 2009-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#include <signal.h> - -#include <modbus.h> - -#if defined(_WIN32) -#include <ws2tcpip.h> -#else -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#endif - -#define NB_CONNECTION 5 - -modbus_t *ctx = NULL; -int server_socket; -modbus_mapping_t *mb_mapping; - -static void close_sigint(int dummy) -{ - close(server_socket); - modbus_free(ctx); - modbus_mapping_free(mb_mapping); - - exit(dummy); -} - -int main(void) -{ - int master_socket; - int rc; - fd_set refset; - fd_set rdset; - - /* Maximum file descriptor number */ - int fdmax; - - ctx = modbus_new_tcp("127.0.0.1", 1502); - - mb_mapping = modbus_mapping_new(MODBUS_MAX_READ_BITS, 0, - MODBUS_MAX_READ_REGISTERS, 0); - if (mb_mapping == NULL) { - fprintf(stderr, "Failed to allocate the mapping: %s\n", - modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - - server_socket = modbus_tcp_listen(ctx, NB_CONNECTION); - - signal(SIGINT, close_sigint); - - /* Clear the reference set of socket */ - FD_ZERO(&refset); - /* Add the server socket */ - FD_SET(server_socket, &refset); - - /* Keep track of the max file descriptor */ - fdmax = server_socket; - - for (;;) { - rdset = refset; - if (select(fdmax+1, &rdset, NULL, NULL, NULL) == -1) { - perror("Server select() failure."); - close_sigint(1); - } - - /* Run through the existing connections looking for data to be - * read */ - for (master_socket = 0; master_socket <= fdmax; master_socket++) { - - if (FD_ISSET(master_socket, &rdset)) { - if (master_socket == server_socket) { - /* A client is asking a new connection */ - socklen_t addrlen; - struct sockaddr_in clientaddr; - int newfd; - - /* Handle new connections */ - addrlen = sizeof(clientaddr); - memset(&clientaddr, 0, sizeof(clientaddr)); - newfd = accept(server_socket, (struct sockaddr *)&clientaddr, &addrlen); - if (newfd == -1) { - perror("Server accept() error"); - } else { - FD_SET(newfd, &refset); - - if (newfd > fdmax) { - /* Keep track of the maximum */ - fdmax = newfd; - } - printf("New connection from %s:%d on socket %d\n", - inet_ntoa(clientaddr.sin_addr), clientaddr.sin_port, newfd); - } - } else { - /* An already connected master has sent a new query */ - uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH]; - - modbus_set_socket(ctx, master_socket); - rc = modbus_receive(ctx, query); - if (rc != -1) { - modbus_reply(ctx, query, rc, mb_mapping); - } else { - /* Connection closed by the client, end of server */ - printf("Connection closed on socket %d\n", master_socket); - close(master_socket); - - /* Remove from reference set */ - FD_CLR(master_socket, &refset); - - if (master_socket == fdmax) { - fdmax--; - } - } - } - } - } - } - - return 0; -} diff --git a/tests/bandwidth-server-many-up.o b/tests/bandwidth-server-many-up.o Binary files differdeleted file mode 100644 index 0b6254d..0000000 --- a/tests/bandwidth-server-many-up.o +++ /dev/null diff --git a/tests/bandwidth-server-one b/tests/bandwidth-server-one deleted file mode 100755 index 4aa0039..0000000 --- a/tests/bandwidth-server-one +++ /dev/null @@ -1,225 +0,0 @@ -#! /bin/bash - -# bandwidth-server-one - temporary wrapper script for .libs/bandwidth-server-one -# Generated by libtool (GNU libtool) 2.4 Debian-2.4-3 -# -# The bandwidth-server-one program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -sed_quote_subst='s/\([`"$\\]\)/\\\1/g' - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command="(cd /home/jmccrohan/bin/libmodbus/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11; export PATH; gcc -g -O2 -g -O2 -Wall -Werror -o \$progdir/\$file bandwidth-server-one.o ../src/.libs/libmodbus.so -Wl,-rpath -Wl,/home/jmccrohan/bin/libmodbus/src/.libs)" - -# This environment variable determines our operation mode. -if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then - # install mode needs the following variables: - generated_by_libtool_version='2.4' - notinst_deplibs=' ../src/libmodbus.la' -else - # When we are sourced in execute mode, $file and $ECHO are already set. - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - file="$0" - -# A function that is used when there is no print builtin or printf. -func_fallback_echo () -{ - eval 'cat <<_LTECHO_EOF -$1 -_LTECHO_EOF' -} - ECHO="printf %s\\n" - fi - -# Very basic option parsing. These options are (a) specific to -# the libtool wrapper, (b) are identical between the wrapper -# /script/ and the wrapper /executable/ which is used only on -# windows platforms, and (c) all begin with the string --lt- -# (application programs are unlikely to have options which match -# this pattern). -# -# There are only two supported options: --lt-debug and -# --lt-dump-script. There is, deliberately, no --lt-help. -# -# The first argument to this parsing function should be the -# script's ../libtool value, followed by no. -lt_option_debug= -func_parse_lt_options () -{ - lt_script_arg0=$0 - shift - for lt_opt - do - case "$lt_opt" in - --lt-debug) lt_option_debug=1 ;; - --lt-dump-script) - lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` - test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. - lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` - cat "$lt_dump_D/$lt_dump_F" - exit 0 - ;; - --lt-*) - $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 - exit 1 - ;; - esac - done - - # Print the debug banner immediately: - if test -n "$lt_option_debug"; then - echo "bandwidth-server-one:bandwidth-server-one:${LINENO}: libtool wrapper (GNU libtool) 2.4 Debian-2.4-3" 1>&2 - fi -} - -# Used when --lt-debug. Prints its arguments to stdout -# (redirection is the responsibility of the caller) -func_lt_dump_args () -{ - lt_dump_args_N=1; - for lt_arg - do - $ECHO "bandwidth-server-one:bandwidth-server-one:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" - lt_dump_args_N=`expr $lt_dump_args_N + 1` - done -} - -# Core function for launching the target application -func_exec_program_core () -{ - - if test -n "$lt_option_debug"; then - $ECHO "bandwidth-server-one:bandwidth-server-one:${LINENO}: newargv[0]: $progdir/$program" 1>&2 - func_lt_dump_args ${1+"$@"} 1>&2 - fi - exec "$progdir/$program" ${1+"$@"} - - $ECHO "$0: cannot exec $program $*" 1>&2 - exit 1 -} - -# A function to encapsulate launching the target application -# Strips options in the --lt-* namespace from $@ and -# launches target application with the remaining arguments. -func_exec_program () -{ - for lt_wr_arg - do - case $lt_wr_arg in - --lt-*) ;; - *) set x "$@" "$lt_wr_arg"; shift;; - esac - shift - done - func_exec_program_core ${1+"$@"} -} - - # Parse options - func_parse_lt_options "$0" ${1+"$@"} - - # Find the directory that this script lives in. - thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - test "x$thisdir" = "x$file" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` - while test -n "$file"; do - destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - - # If there was a directory component, then change thisdir. - if test "x$destdir" != "x$file"; then - case "$destdir" in - [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; - *) thisdir="$thisdir/$destdir" ;; - esac - fi - - file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` - file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` - done - - # Usually 'no', except on cygwin/mingw when embedded into - # the cwrapper. - WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no - if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then - # special case for '.' - if test "$thisdir" = "."; then - thisdir=`pwd` - fi - # remove .libs from thisdir - case "$thisdir" in - *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; - .libs ) thisdir=. ;; - esac - fi - - # Try to get the absolute directory name. - absdir=`cd "$thisdir" && pwd` - test -n "$absdir" && thisdir="$absdir" - - program=lt-'bandwidth-server-one' - progdir="$thisdir/.libs" - - if test ! -f "$progdir/$program" || - { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ - test "X$file" != "X$progdir/$program"; }; then - - file="$$-$program" - - if test ! -d "$progdir"; then - mkdir "$progdir" - else - rm -f "$progdir/$file" - fi - - # relink executable if necessary - if test -n "$relink_command"; then - if relink_command_output=`eval $relink_command 2>&1`; then : - else - printf %s\n "$relink_command_output" >&2 - rm -f "$progdir/$file" - exit 1 - fi - fi - - mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || - { rm -f "$progdir/$program"; - mv -f "$progdir/$file" "$progdir/$program"; } - rm -f "$progdir/$file" - fi - - if test -f "$progdir/$program"; then - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - # Run the actual program with our arguments. - func_exec_program ${1+"$@"} - fi - else - # The program doesn't exist. - $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 - $ECHO "This script is just a wrapper for $program." 1>&2 - $ECHO "See the libtool documentation for more information." 1>&2 - exit 1 - fi -fi diff --git a/tests/bandwidth-server-one.c b/tests/bandwidth-server-one.c deleted file mode 100644 index e15fb69..0000000 --- a/tests/bandwidth-server-one.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -#include <modbus.h> - -enum { - TCP, - RTU -}; - -int main(int argc, char *argv[]) -{ - int socket; - modbus_t *ctx; - modbus_mapping_t *mb_mapping; - int rc; - int use_backend; - - /* TCP */ - if (argc > 1) { - if (strcmp(argv[1], "tcp") == 0) { - use_backend = TCP; - } else if (strcmp(argv[1], "rtu") == 0) { - use_backend = RTU; - } else { - printf("Usage:\n %s [tcp|rtu] - Modbus client to measure data bandwith\n\n", argv[0]); - exit(1); - } - } else { - /* By default */ - use_backend = TCP; - } - - if (use_backend == TCP) { - ctx = modbus_new_tcp("127.0.0.1", 1502); - socket = modbus_tcp_listen(ctx, 1); - modbus_tcp_accept(ctx, &socket); - - } else { - ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1); - modbus_set_slave(ctx, 1); - modbus_connect(ctx); - } - - mb_mapping = modbus_mapping_new(MODBUS_MAX_READ_BITS, 0, - MODBUS_MAX_READ_REGISTERS, 0); - if (mb_mapping == NULL) { - fprintf(stderr, "Failed to allocate the mapping: %s\n", - modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - - for(;;) { - uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH]; - - rc = modbus_receive(ctx, query); - if (rc >= 0) { - modbus_reply(ctx, query, rc, mb_mapping); - } else { - /* Connection closed by the client or server */ - break; - } - } - - printf("Quit the loop: %s\n", modbus_strerror(errno)); - - modbus_mapping_free(mb_mapping); - close(socket); - modbus_free(ctx); - - return 0; -} diff --git a/tests/bandwidth-server-one.o b/tests/bandwidth-server-one.o Binary files differdeleted file mode 100644 index 016e927..0000000 --- a/tests/bandwidth-server-one.o +++ /dev/null diff --git a/tests/random-test-client b/tests/random-test-client Binary files differdeleted file mode 100755 index d6291ee..0000000 --- a/tests/random-test-client +++ /dev/null diff --git a/tests/random-test-client.c b/tests/random-test-client.c deleted file mode 100644 index 593867c..0000000 --- a/tests/random-test-client.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright © 2001-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -#include <modbus.h> - -/* The goal of this program is to check all major functions of - libmodbus: - - write_coil - - read_bits - - write_coils - - write_register - - read_registers - - write_registers - - read_registers - - All these functions are called with random values on a address - range defined by the following defines. -*/ -#define LOOP 1 -#define SERVER_ID 17 -#define ADDRESS_START 0 -#define ADDRESS_END 99 - -/* At each loop, the program works in the range ADDRESS_START to - * ADDRESS_END then ADDRESS_START + 1 to ADDRESS_END and so on. - */ -int main(void) -{ - modbus_t *ctx; - int rc; - int nb_fail; - int nb_loop; - int addr; - int nb; - uint8_t *tab_rq_bits; - uint8_t *tab_rp_bits; - uint16_t *tab_rq_registers; - uint16_t *tab_rw_rq_registers; - uint16_t *tab_rp_registers; - - /* RTU */ -/* - ctx = modbus_new_rtu("/dev/ttyUSB0", 19200, 'N', 8, 1); - modbus_set_slave(ctx, SERVER_ID); -*/ - - /* TCP */ - ctx = modbus_new_tcp("127.0.0.1", 1502); - modbus_set_debug(ctx, TRUE); - - if (modbus_connect(ctx) == -1) { - fprintf(stderr, "Connection failed: %s\n", - modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - - /* Allocate and initialize the different memory spaces */ - nb = ADDRESS_END - ADDRESS_START; - - tab_rq_bits = (uint8_t *) malloc(nb * sizeof(uint8_t)); - memset(tab_rq_bits, 0, nb * sizeof(uint8_t)); - - tab_rp_bits = (uint8_t *) malloc(nb * sizeof(uint8_t)); - memset(tab_rp_bits, 0, nb * sizeof(uint8_t)); - - tab_rq_registers = (uint16_t *) malloc(nb * sizeof(uint16_t)); - memset(tab_rq_registers, 0, nb * sizeof(uint16_t)); - - tab_rp_registers = (uint16_t *) malloc(nb * sizeof(uint16_t)); - memset(tab_rp_registers, 0, nb * sizeof(uint16_t)); - - tab_rw_rq_registers = (uint16_t *) malloc(nb * sizeof(uint16_t)); - memset(tab_rw_rq_registers, 0, nb * sizeof(uint16_t)); - - nb_loop = nb_fail = 0; - while (nb_loop++ < LOOP) { - for (addr = ADDRESS_START; addr <= ADDRESS_END; addr++) { - int i; - - /* Random numbers (short) */ - for (i=0; i<nb; i++) { - tab_rq_registers[i] = (uint16_t) (65535.0*rand() / (RAND_MAX + 1.0)); - tab_rw_rq_registers[i] = ~tab_rq_registers[i]; - tab_rq_bits[i] = tab_rq_registers[i] % 2; - } - nb = ADDRESS_END - addr; - - /* WRITE BIT */ - rc = modbus_write_bit(ctx, addr, tab_rq_bits[0]); - if (rc != 1) { - printf("ERROR modbus_write_bit (%d)\n", rc); - printf("Address = %d, value = %d\n", addr, tab_rq_bits[0]); - nb_fail++; - } else { - rc = modbus_read_bits(ctx, addr, 1, tab_rp_bits); - if (rc != 1 || tab_rq_bits[0] != tab_rp_bits[0]) { - printf("ERROR modbus_read_bits single (%d)\n", rc); - printf("address = %d\n", addr); - nb_fail++; - } - } - - /* MULTIPLE BITS */ - rc = modbus_write_bits(ctx, addr, nb, tab_rq_bits); - if (rc != nb) { - printf("ERROR modbus_write_bits (%d)\n", rc); - printf("Address = %d, nb = %d\n", addr, nb); - nb_fail++; - } else { - rc = modbus_read_bits(ctx, addr, nb, tab_rp_bits); - if (rc != nb) { - printf("ERROR modbus_read_bits\n"); - printf("Address = %d, nb = %d\n", addr, nb); - nb_fail++; - } else { - for (i=0; i<nb; i++) { - if (tab_rp_bits[i] != tab_rq_bits[i]) { - printf("ERROR modbus_read_bits\n"); - printf("Address = %d, value %d (0x%X) != %d (0x%X)\n", - addr, tab_rq_bits[i], tab_rq_bits[i], - tab_rp_bits[i], tab_rp_bits[i]); - nb_fail++; - } - } - } - } - - /* SINGLE REGISTER */ - rc = modbus_write_register(ctx, addr, tab_rq_registers[0]); - if (rc != 1) { - printf("ERROR modbus_write_register (%d)\n", rc); - printf("Address = %d, value = %d (0x%X)\n", - addr, tab_rq_registers[0], tab_rq_registers[0]); - nb_fail++; - } else { - rc = modbus_read_registers(ctx, addr, 1, tab_rp_registers); - if (rc != 1) { - printf("ERROR modbus_read_registers single (%d)\n", rc); - printf("Address = %d\n", addr); - nb_fail++; - } else { - if (tab_rq_registers[0] != tab_rp_registers[0]) { - printf("ERROR modbus_read_registers single\n"); - printf("Address = %d, value = %d (0x%X) != %d (0x%X)\n", - addr, tab_rq_registers[0], tab_rq_registers[0], - tab_rp_registers[0], tab_rp_registers[0]); - nb_fail++; - } - } - } - - /* MULTIPLE REGISTERS */ - rc = modbus_write_registers(ctx, addr, nb, tab_rq_registers); - if (rc != nb) { - printf("ERROR modbus_write_registers (%d)\n", rc); - printf("Address = %d, nb = %d\n", addr, nb); - nb_fail++; - } else { - rc = modbus_read_registers(ctx, addr, nb, tab_rp_registers); - if (rc != nb) { - printf("ERROR modbus_read_registers (%d)\n", rc); - printf("Address = %d, nb = %d\n", addr, nb); - nb_fail++; - } else { - for (i=0; i<nb; i++) { - if (tab_rq_registers[i] != tab_rp_registers[i]) { - printf("ERROR modbus_read_registers\n"); - printf("Address = %d, value %d (0x%X) != %d (0x%X)\n", - addr, tab_rq_registers[i], tab_rq_registers[i], - tab_rp_registers[i], tab_rp_registers[i]); - nb_fail++; - } - } - } - } - /* R/W MULTIPLE REGISTERS */ - rc = modbus_write_and_read_registers(ctx, - addr, nb, tab_rw_rq_registers, - addr, nb, tab_rp_registers); - if (rc != nb) { - printf("ERROR modbus_read_and_write_registers (%d)\n", rc); - printf("Address = %d, nb = %d\n", addr, nb); - nb_fail++; - } else { - for (i=0; i<nb; i++) { - if (tab_rp_registers[i] != tab_rw_rq_registers[i]) { - printf("ERROR modbus_read_and_write_registers READ\n"); - printf("Address = %d, value %d (0x%X) != %d (0x%X)\n", - addr, tab_rp_registers[i], tab_rw_rq_registers[i], - tab_rp_registers[i], tab_rw_rq_registers[i]); - nb_fail++; - } - } - - rc = modbus_read_registers(ctx, addr, nb, tab_rp_registers); - if (rc != nb) { - printf("ERROR modbus_read_registers (%d)\n", rc); - printf("Address = %d, nb = %d\n", addr, nb); - nb_fail++; - } else { - for (i=0; i<nb; i++) { - if (tab_rw_rq_registers[i] != tab_rp_registers[i]) { - printf("ERROR modbus_read_and_write_registers WRITE\n"); - printf("Address = %d, value %d (0x%X) != %d (0x%X)\n", - addr, tab_rw_rq_registers[i], tab_rw_rq_registers[i], - tab_rp_registers[i], tab_rp_registers[i]); - nb_fail++; - } - } - } - } - } - - printf("Test: "); - if (nb_fail) - printf("%d FAILS\n", nb_fail); - else - printf("SUCCESS\n"); - } - - /* Free the memory */ - free(tab_rq_bits); - free(tab_rp_bits); - free(tab_rq_registers); - free(tab_rp_registers); - - /* Close the connection */ - modbus_close(ctx); - modbus_free(ctx); - - return 0; -} diff --git a/tests/random-test-client.o b/tests/random-test-client.o Binary files differdeleted file mode 100644 index b9ddf6f..0000000 --- a/tests/random-test-client.o +++ /dev/null diff --git a/tests/random-test-server b/tests/random-test-server Binary files differdeleted file mode 100755 index 5beca61..0000000 --- a/tests/random-test-server +++ /dev/null diff --git a/tests/random-test-server.c b/tests/random-test-server.c deleted file mode 100644 index 9569fe4..0000000 --- a/tests/random-test-server.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> - -#include <modbus.h> - -int main(void) -{ - int socket; - modbus_t *ctx; - modbus_mapping_t *mb_mapping; - - ctx = modbus_new_tcp("127.0.0.1", 1502); - /* modbus_set_debug(ctx, TRUE); */ - - mb_mapping = modbus_mapping_new(500, 500, 500, 500); - if (mb_mapping == NULL) { - fprintf(stderr, "Failed to allocate the mapping: %s\n", - modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - - socket = modbus_tcp_listen(ctx, 1); - modbus_tcp_accept(ctx, &socket); - - for (;;) { - uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH]; - int rc; - - rc = modbus_receive(ctx, query); - if (rc != -1) { - /* rc is the query size */ - modbus_reply(ctx, query, rc, mb_mapping); - } else { - /* Connection closed by the client or error */ - break; - } - } - - printf("Quit the loop: %s\n", modbus_strerror(errno)); - - modbus_mapping_free(mb_mapping); - modbus_close(ctx); - modbus_free(ctx); - - return 0; -} diff --git a/tests/random-test-server.o b/tests/random-test-server.o Binary files differdeleted file mode 100644 index 7ea92e9..0000000 --- a/tests/random-test-server.o +++ /dev/null diff --git a/tests/unit-test-client b/tests/unit-test-client deleted file mode 100755 index 4e2b561..0000000 --- a/tests/unit-test-client +++ /dev/null @@ -1,225 +0,0 @@ -#! /bin/bash - -# unit-test-client - temporary wrapper script for .libs/unit-test-client -# Generated by libtool (GNU libtool) 2.4 Debian-2.4-3 -# -# The unit-test-client program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -sed_quote_subst='s/\([`"$\\]\)/\\\1/g' - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command="(cd /home/jmccrohan/bin/libmodbus/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11; export PATH; gcc -g -O2 -g -O2 -Wall -Werror -o \$progdir/\$file unit-test-client.o ../src/.libs/libmodbus.so -Wl,-rpath -Wl,/home/jmccrohan/bin/libmodbus/src/.libs)" - -# This environment variable determines our operation mode. -if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then - # install mode needs the following variables: - generated_by_libtool_version='2.4' - notinst_deplibs=' ../src/libmodbus.la' -else - # When we are sourced in execute mode, $file and $ECHO are already set. - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - file="$0" - -# A function that is used when there is no print builtin or printf. -func_fallback_echo () -{ - eval 'cat <<_LTECHO_EOF -$1 -_LTECHO_EOF' -} - ECHO="printf %s\\n" - fi - -# Very basic option parsing. These options are (a) specific to -# the libtool wrapper, (b) are identical between the wrapper -# /script/ and the wrapper /executable/ which is used only on -# windows platforms, and (c) all begin with the string --lt- -# (application programs are unlikely to have options which match -# this pattern). -# -# There are only two supported options: --lt-debug and -# --lt-dump-script. There is, deliberately, no --lt-help. -# -# The first argument to this parsing function should be the -# script's ../libtool value, followed by no. -lt_option_debug= -func_parse_lt_options () -{ - lt_script_arg0=$0 - shift - for lt_opt - do - case "$lt_opt" in - --lt-debug) lt_option_debug=1 ;; - --lt-dump-script) - lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` - test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. - lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` - cat "$lt_dump_D/$lt_dump_F" - exit 0 - ;; - --lt-*) - $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 - exit 1 - ;; - esac - done - - # Print the debug banner immediately: - if test -n "$lt_option_debug"; then - echo "unit-test-client:unit-test-client:${LINENO}: libtool wrapper (GNU libtool) 2.4 Debian-2.4-3" 1>&2 - fi -} - -# Used when --lt-debug. Prints its arguments to stdout -# (redirection is the responsibility of the caller) -func_lt_dump_args () -{ - lt_dump_args_N=1; - for lt_arg - do - $ECHO "unit-test-client:unit-test-client:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" - lt_dump_args_N=`expr $lt_dump_args_N + 1` - done -} - -# Core function for launching the target application -func_exec_program_core () -{ - - if test -n "$lt_option_debug"; then - $ECHO "unit-test-client:unit-test-client:${LINENO}: newargv[0]: $progdir/$program" 1>&2 - func_lt_dump_args ${1+"$@"} 1>&2 - fi - exec "$progdir/$program" ${1+"$@"} - - $ECHO "$0: cannot exec $program $*" 1>&2 - exit 1 -} - -# A function to encapsulate launching the target application -# Strips options in the --lt-* namespace from $@ and -# launches target application with the remaining arguments. -func_exec_program () -{ - for lt_wr_arg - do - case $lt_wr_arg in - --lt-*) ;; - *) set x "$@" "$lt_wr_arg"; shift;; - esac - shift - done - func_exec_program_core ${1+"$@"} -} - - # Parse options - func_parse_lt_options "$0" ${1+"$@"} - - # Find the directory that this script lives in. - thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - test "x$thisdir" = "x$file" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` - while test -n "$file"; do - destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - - # If there was a directory component, then change thisdir. - if test "x$destdir" != "x$file"; then - case "$destdir" in - [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; - *) thisdir="$thisdir/$destdir" ;; - esac - fi - - file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` - file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` - done - - # Usually 'no', except on cygwin/mingw when embedded into - # the cwrapper. - WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no - if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then - # special case for '.' - if test "$thisdir" = "."; then - thisdir=`pwd` - fi - # remove .libs from thisdir - case "$thisdir" in - *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; - .libs ) thisdir=. ;; - esac - fi - - # Try to get the absolute directory name. - absdir=`cd "$thisdir" && pwd` - test -n "$absdir" && thisdir="$absdir" - - program=lt-'unit-test-client' - progdir="$thisdir/.libs" - - if test ! -f "$progdir/$program" || - { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ - test "X$file" != "X$progdir/$program"; }; then - - file="$$-$program" - - if test ! -d "$progdir"; then - mkdir "$progdir" - else - rm -f "$progdir/$file" - fi - - # relink executable if necessary - if test -n "$relink_command"; then - if relink_command_output=`eval $relink_command 2>&1`; then : - else - printf %s\n "$relink_command_output" >&2 - rm -f "$progdir/$file" - exit 1 - fi - fi - - mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || - { rm -f "$progdir/$program"; - mv -f "$progdir/$file" "$progdir/$program"; } - rm -f "$progdir/$file" - fi - - if test -f "$progdir/$program"; then - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - # Run the actual program with our arguments. - func_exec_program ${1+"$@"} - fi - else - # The program doesn't exist. - $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 - $ECHO "This script is just a wrapper for $program." 1>&2 - $ECHO "See the libtool documentation for more information." 1>&2 - exit 1 - fi -fi diff --git a/tests/unit-test-client.c b/tests/unit-test-client.c deleted file mode 100644 index 533e6a7..0000000 --- a/tests/unit-test-client.c +++ /dev/null @@ -1,690 +0,0 @@ -/* - * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#include <modbus.h> - -#include "unit-test.h" - -enum { - TCP, - TCP_PI, - RTU -}; - -int main(int argc, char *argv[]) -{ - uint8_t *tab_rp_bits; - uint16_t *tab_rp_registers; - uint16_t *tab_rp_registers_bad; - modbus_t *ctx; - int i; - uint8_t value; - int nb_points; - int rc; - float real; - struct timeval old_response_timeout; - struct timeval response_timeout; - int use_backend; - - if (argc > 1) { - if (strcmp(argv[1], "tcp") == 0) { - use_backend = TCP; - } else if (strcmp(argv[1], "tcppi") == 0) { - use_backend = TCP_PI; - } else if (strcmp(argv[1], "rtu") == 0) { - use_backend = RTU; - } else { - printf("Usage:\n %s [tcp|tcppi|rtu] - Modbus client for unit testing\n\n", argv[0]); - exit(1); - } - } else { - /* By default */ - use_backend = TCP; - } - - if (use_backend == TCP) { - ctx = modbus_new_tcp("127.0.0.1", 1502); - } else if (use_backend == TCP_PI) { - ctx = modbus_new_tcp_pi("::1", "1502"); - } else { - ctx = modbus_new_rtu("/dev/ttyUSB1", 115200, 'N', 8, 1); - } - if (ctx == NULL) { - fprintf(stderr, "Unable to allocate libmodbus context\n"); - return -1; - } - modbus_set_debug(ctx, TRUE); - modbus_set_error_recovery(ctx, - MODBUS_ERROR_RECOVERY_LINK | - MODBUS_ERROR_RECOVERY_PROTOCOL); - - if (use_backend == RTU) { - modbus_set_slave(ctx, SERVER_ID); - } - - if (modbus_connect(ctx) == -1) { - fprintf(stderr, "Connection failed: %s\n", - modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - - /* Allocate and initialize the memory to store the bits */ - nb_points = (UT_BITS_NB > UT_INPUT_BITS_NB) ? UT_BITS_NB : UT_INPUT_BITS_NB; - tab_rp_bits = (uint8_t *) malloc(nb_points * sizeof(uint8_t)); - memset(tab_rp_bits, 0, nb_points * sizeof(uint8_t)); - - /* Allocate and initialize the memory to store the registers */ - nb_points = (UT_REGISTERS_NB > UT_INPUT_REGISTERS_NB) ? - UT_REGISTERS_NB : UT_INPUT_REGISTERS_NB; - tab_rp_registers = (uint16_t *) malloc(nb_points * sizeof(uint16_t)); - memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); - - printf("** UNIT TESTING **\n"); - - printf("\nTEST WRITE/READ:\n"); - - /** COIL BITS **/ - - /* Single */ - rc = modbus_write_bit(ctx, UT_BITS_ADDRESS, ON); - printf("1/2 modbus_write_bit: "); - if (rc == 1) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, 1, tab_rp_bits); - printf("2/2 modbus_read_bits: "); - if (rc != 1) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - - if (tab_rp_bits[0] != ON) { - printf("FAILED (%0X = != %0X)\n", tab_rp_bits[0], ON); - goto close; - } - printf("OK\n"); - /* End single */ - - /* Multiple bits */ - { - uint8_t tab_value[UT_BITS_NB]; - - modbus_set_bits_from_bytes(tab_value, 0, UT_BITS_NB, UT_BITS_TAB); - rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, - UT_BITS_NB, tab_value); - printf("1/2 modbus_write_bits: "); - if (rc == UT_BITS_NB) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - } - - rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, UT_BITS_NB, tab_rp_bits); - printf("2/2 modbus_read_bits: "); - if (rc != UT_BITS_NB) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - - i = 0; - nb_points = UT_BITS_NB; - while (nb_points > 0) { - int nb_bits = (nb_points > 8) ? 8 : nb_points; - - value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); - if (value != UT_BITS_TAB[i]) { - printf("FAILED (%0X != %0X)\n", value, UT_BITS_TAB[i]); - goto close; - } - - nb_points -= nb_bits; - i++; - } - printf("OK\n"); - /* End of multiple bits */ - - /** DISCRETE INPUTS **/ - rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, - UT_INPUT_BITS_NB, tab_rp_bits); - printf("1/1 modbus_read_input_bits: "); - - if (rc != UT_INPUT_BITS_NB) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - - i = 0; - nb_points = UT_INPUT_BITS_NB; - while (nb_points > 0) { - int nb_bits = (nb_points > 8) ? 8 : nb_points; - - value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); - if (value != UT_INPUT_BITS_TAB[i]) { - printf("FAILED (%0X != %0X)\n", value, UT_INPUT_BITS_TAB[i]); - goto close; - } - - nb_points -= nb_bits; - i++; - } - printf("OK\n"); - - /** HOLDING REGISTERS **/ - - /* Single register */ - rc = modbus_write_register(ctx, UT_REGISTERS_ADDRESS, 0x1234); - printf("1/2 modbus_write_register: "); - if (rc == 1) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - 1, tab_rp_registers); - printf("2/2 modbus_read_registers: "); - if (rc != 1) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - - if (tab_rp_registers[0] != 0x1234) { - printf("FAILED (%0X != %0X)\n", - tab_rp_registers[0], 0x1234); - goto close; - } - printf("OK\n"); - /* End of single register */ - - /* Many registers */ - rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB, UT_REGISTERS_TAB); - printf("1/5 modbus_write_registers: "); - if (rc == UT_REGISTERS_NB) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB, tab_rp_registers); - printf("2/5 modbus_read_registers: "); - if (rc != UT_REGISTERS_NB) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - - for (i=0; i < UT_REGISTERS_NB; i++) { - if (tab_rp_registers[i] != UT_REGISTERS_TAB[i]) { - printf("FAILED (%0X != %0X)\n", - tab_rp_registers[i], - UT_REGISTERS_TAB[i]); - goto close; - } - } - printf("OK\n"); - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - 0, tab_rp_registers); - printf("3/5 modbus_read_registers (0): "); - if (rc != 0) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - printf("OK\n"); - - nb_points = (UT_REGISTERS_NB > - UT_INPUT_REGISTERS_NB) ? - UT_REGISTERS_NB : UT_INPUT_REGISTERS_NB; - memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); - - /* Write registers to zero from tab_rp_registers and store read registers - into tab_rp_registers. So the read registers must set to 0, except the - first one because there is an offset of 1 register on write. */ - rc = modbus_write_and_read_registers(ctx, - UT_REGISTERS_ADDRESS + 1, UT_REGISTERS_NB - 1, - tab_rp_registers, - UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB, - tab_rp_registers); - printf("4/5 modbus_write_and_read_registers: "); - if (rc != UT_REGISTERS_NB) { - printf("FAILED (nb points %d != %d)\n", rc, UT_REGISTERS_NB); - goto close; - } - - if (tab_rp_registers[0] != UT_REGISTERS_TAB[0]) { - printf("FAILED (%0X != %0X)\n", - tab_rp_registers[0], UT_REGISTERS_TAB[0]); - } - - for (i=1; i < UT_REGISTERS_NB; i++) { - if (tab_rp_registers[i] != 0) { - printf("FAILED (%0X != %0X)\n", - tab_rp_registers[i], 0); - goto close; - } - } - printf("OK\n"); - - /* End of many registers */ - - - /** INPUT REGISTERS **/ - rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, - UT_INPUT_REGISTERS_NB, - tab_rp_registers); - printf("1/1 modbus_read_input_registers: "); - if (rc != UT_INPUT_REGISTERS_NB) { - printf("FAILED (nb points %d)\n", rc); - goto close; - } - - for (i=0; i < UT_INPUT_REGISTERS_NB; i++) { - if (tab_rp_registers[i] != UT_INPUT_REGISTERS_TAB[i]) { - printf("FAILED (%0X != %0X)\n", - tab_rp_registers[i], UT_INPUT_REGISTERS_TAB[i]); - goto close; - } - } - printf("OK\n"); - - printf("\nTEST FLOATS\n"); - /** FLOAT **/ - printf("1/2 Set float: "); - modbus_set_float(UT_REAL, tab_rp_registers); - if (tab_rp_registers[1] == (UT_IREAL >> 16) && - tab_rp_registers[0] == (UT_IREAL & 0xFFFF)) { - printf("OK\n"); - } else { - printf("FAILED (%x != %x)\n", - *((uint32_t *)tab_rp_registers), UT_IREAL); - goto close; - } - - printf("2/2 Get float: "); - real = modbus_get_float(tab_rp_registers); - if (real == UT_REAL) { - printf("OK\n"); - } else { - printf("FAILED (%f != %f)\n", real, UT_REAL); - goto close; - } - - printf("\nAt this point, error messages doesn't mean the test has failed\n"); - - /** ILLEGAL DATA ADDRESS **/ - printf("\nTEST ILLEGAL DATA ADDRESS:\n"); - - /* The mapping begins at 0 and ends at address + nb_points so - * the addresses are not valid. */ - - rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, - UT_BITS_NB + 1, tab_rp_bits); - printf("* modbus_read_bits: "); - if (rc == -1 && errno == EMBXILADD) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, - UT_INPUT_BITS_NB + 1, tab_rp_bits); - printf("* modbus_read_input_bits: "); - if (rc == -1 && errno == EMBXILADD) - printf("OK\n"); - else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB + 1, tab_rp_registers); - printf("* modbus_read_registers: "); - if (rc == -1 && errno == EMBXILADD) - printf("OK\n"); - else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, - UT_INPUT_REGISTERS_NB + 1, - tab_rp_registers); - printf("* modbus_read_input_registers: "); - if (rc == -1 && errno == EMBXILADD) - printf("OK\n"); - else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_write_bit(ctx, UT_BITS_ADDRESS + UT_BITS_NB, ON); - printf("* modbus_write_bit: "); - if (rc == -1 && errno == EMBXILADD) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_write_bits(ctx, UT_BITS_ADDRESS + UT_BITS_NB, - UT_BITS_NB, tab_rp_bits); - printf("* modbus_write_coils: "); - if (rc == -1 && errno == EMBXILADD) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS + UT_REGISTERS_NB, - UT_REGISTERS_NB, tab_rp_registers); - printf("* modbus_write_registers: "); - if (rc == -1 && errno == EMBXILADD) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - - /** TOO MANY DATA **/ - printf("\nTEST TOO MANY DATA ERROR:\n"); - - rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, - MODBUS_MAX_READ_BITS + 1, tab_rp_bits); - printf("* modbus_read_bits: "); - if (rc == -1 && errno == EMBMDATA) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, - MODBUS_MAX_READ_BITS + 1, tab_rp_bits); - printf("* modbus_read_input_bits: "); - if (rc == -1 && errno == EMBMDATA) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - MODBUS_MAX_READ_REGISTERS + 1, - tab_rp_registers); - printf("* modbus_read_registers: "); - if (rc == -1 && errno == EMBMDATA) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, - MODBUS_MAX_READ_REGISTERS + 1, - tab_rp_registers); - printf("* modbus_read_input_registers: "); - if (rc == -1 && errno == EMBMDATA) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, - MODBUS_MAX_WRITE_BITS + 1, tab_rp_bits); - printf("* modbus_write_bits: "); - if (rc == -1 && errno == EMBMDATA) { - printf("OK\n"); - } else { - goto close; - printf("FAILED\n"); - } - - rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS, - MODBUS_MAX_WRITE_REGISTERS + 1, - tab_rp_registers); - printf("* modbus_write_registers: "); - if (rc == -1 && errno == EMBMDATA) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - /** SLAVE REPLY **/ - printf("\nTEST SLAVE REPLY:\n"); - modbus_set_slave(ctx, INVALID_SERVER_ID); - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB, tab_rp_registers); - if (use_backend == RTU) { - const int RAW_REQ_LENGTH = 6; - uint8_t raw_req[] = { INVALID_SERVER_ID, 0x03, 0x00, 0x01, 0xFF, 0xFF }; - uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH]; - - /* No response in RTU mode */ - printf("1/4-A No response from slave %d: ", INVALID_SERVER_ID); - - if (rc == -1 && errno == ETIMEDOUT) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - /* Send an invalid query with a wrong slave ID */ - modbus_send_raw_request(ctx, raw_req, - RAW_REQ_LENGTH * sizeof(uint8_t)); - rc = modbus_receive_confirmation(ctx, rsp); - - printf("1/4-B No response from slave %d with invalid request: ", - INVALID_SERVER_ID); - - if (rc == -1 && errno == ETIMEDOUT) { - printf("OK\n"); - } else { - printf("FAILED (%d)\n", rc); - goto close; - } - - } else { - /* Response in TCP mode */ - printf("1/4 Response from slave %d: ", 18); - - if (rc == UT_REGISTERS_NB) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - } - - rc = modbus_set_slave(ctx, MODBUS_BROADCAST_ADDRESS); - if (rc == -1) { - printf("Invalid broacast address\n"); - goto close; - } - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB, tab_rp_registers); - printf("2/4 Reply after a broadcast query: "); - if (rc == UT_REGISTERS_NB) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - /* Restore slave */ - if (use_backend == RTU) { - modbus_set_slave(ctx, SERVER_ID); - } else { - modbus_set_slave(ctx, MODBUS_TCP_SLAVE); - } - - printf("3/4 Report slave ID: \n"); - /* tab_rp_bits is used to store bytes */ - rc = modbus_report_slave_id(ctx, tab_rp_bits); - if (rc == -1) { - printf("FAILED\n"); - goto close; - } - - /* Slave ID is an arbitraty number for libmodbus */ - if (rc > 0) { - printf("OK Slave ID is %d\n", tab_rp_bits[0]); - } else { - printf("FAILED\n"); - goto close; - } - - /* Run status indicator */ - if (rc > 1 && tab_rp_bits[1] == 0xFF) { - printf("OK Run Status Indicator is %s\n", tab_rp_bits[1] ? "ON" : "OFF"); - } else { - printf("FAILED\n"); - goto close; - } - - /* Print additional data as string */ - if (rc > 2) { - printf("Additional data: "); - for (i=2; i < rc; i++) { - printf("%c", tab_rp_bits[i]); - } - printf("\n"); - } - - /* Save original timeout */ - modbus_get_response_timeout(ctx, &old_response_timeout); - - /* Define a new and too short timeout */ - response_timeout.tv_sec = 0; - response_timeout.tv_usec = 0; - modbus_set_response_timeout(ctx, &response_timeout); - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB, tab_rp_registers); - printf("4/4 Too short timeout: "); - if (rc == -1 && errno == ETIMEDOUT) { - printf("OK\n"); - } else { - printf("FAILED (can fail on slow systems or Windows)\n"); - } - - /* Restore original timeout */ - modbus_set_response_timeout(ctx, &old_response_timeout); - - /* A wait and flush operation is done by the error recovery code of - * libmodbus */ - - /** BAD RESPONSE **/ - printf("\nTEST BAD RESPONSE ERROR:\n"); - - /* Allocate only the required space */ - tab_rp_registers_bad = (uint16_t *) malloc( - UT_REGISTERS_NB_SPECIAL * sizeof(uint16_t)); - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, - UT_REGISTERS_NB_SPECIAL, tab_rp_registers_bad); - printf("* modbus_read_registers: "); - if (rc == -1 && errno == EMBBADDATA) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - free(tab_rp_registers_bad); - - /** MANUAL EXCEPTION **/ - printf("\nTEST MANUAL EXCEPTION:\n"); - - rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS_SPECIAL, - UT_REGISTERS_NB, tab_rp_registers); - printf("* modbus_read_registers at special address: "); - if (rc == -1 && errno == EMBXSBUSY) { - printf("OK\n"); - } else { - printf("FAILED\n"); - goto close; - } - - /** RAW REQUEST */ - printf("\nTEST RAW REQUEST:\n"); - { - const int RAW_REQ_LENGTH = 6; - uint8_t raw_req[] = { (use_backend == RTU) ? SERVER_ID : 0xFF, - 0x03, 0x00, 0x01, 0x0, 0x05 }; - int req_length; - uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH]; - - req_length = modbus_send_raw_request(ctx, raw_req, - RAW_REQ_LENGTH * sizeof(uint8_t)); - - printf("* modbus_send_raw_request: "); - if ((use_backend == RTU && req_length == (RAW_REQ_LENGTH + 2)) || - ((use_backend == TCP || use_backend == TCP_PI) && - req_length == (RAW_REQ_LENGTH + 6))) { - printf("OK\n"); - } else { - printf("FAILED (%d)\n", req_length); - goto close; - } - - printf("* modbus_receive_confirmation: "); - rc = modbus_receive_confirmation(ctx, rsp); - if ((use_backend == RTU && rc == 15) || - ((use_backend == TCP || use_backend == TCP_PI) && - rc == 19)) { - printf("OK\n"); - } else { - printf("FAILED (%d)\n", rc); - goto close; - } - } - - printf("\nALL TESTS PASS WITH SUCCESS.\n"); - -close: - /* Free the memory */ - free(tab_rp_bits); - free(tab_rp_registers); - - /* Close the connection */ - modbus_close(ctx); - modbus_free(ctx); - - return 0; -} diff --git a/tests/unit-test-client.o b/tests/unit-test-client.o Binary files differdeleted file mode 100644 index 8358604..0000000 --- a/tests/unit-test-client.o +++ /dev/null diff --git a/tests/unit-test-server b/tests/unit-test-server deleted file mode 100755 index a8d1c0e..0000000 --- a/tests/unit-test-server +++ /dev/null @@ -1,225 +0,0 @@ -#! /bin/bash - -# unit-test-server - temporary wrapper script for .libs/unit-test-server -# Generated by libtool (GNU libtool) 2.4 Debian-2.4-3 -# -# The unit-test-server program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -sed_quote_subst='s/\([`"$\\]\)/\\\1/g' - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command="(cd /home/jmccrohan/bin/libmodbus/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11; export PATH; gcc -g -O2 -g -O2 -Wall -Werror -o \$progdir/\$file unit-test-server.o ../src/.libs/libmodbus.so -Wl,-rpath -Wl,/home/jmccrohan/bin/libmodbus/src/.libs)" - -# This environment variable determines our operation mode. -if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then - # install mode needs the following variables: - generated_by_libtool_version='2.4' - notinst_deplibs=' ../src/libmodbus.la' -else - # When we are sourced in execute mode, $file and $ECHO are already set. - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - file="$0" - -# A function that is used when there is no print builtin or printf. -func_fallback_echo () -{ - eval 'cat <<_LTECHO_EOF -$1 -_LTECHO_EOF' -} - ECHO="printf %s\\n" - fi - -# Very basic option parsing. These options are (a) specific to -# the libtool wrapper, (b) are identical between the wrapper -# /script/ and the wrapper /executable/ which is used only on -# windows platforms, and (c) all begin with the string --lt- -# (application programs are unlikely to have options which match -# this pattern). -# -# There are only two supported options: --lt-debug and -# --lt-dump-script. There is, deliberately, no --lt-help. -# -# The first argument to this parsing function should be the -# script's ../libtool value, followed by no. -lt_option_debug= -func_parse_lt_options () -{ - lt_script_arg0=$0 - shift - for lt_opt - do - case "$lt_opt" in - --lt-debug) lt_option_debug=1 ;; - --lt-dump-script) - lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` - test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. - lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` - cat "$lt_dump_D/$lt_dump_F" - exit 0 - ;; - --lt-*) - $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 - exit 1 - ;; - esac - done - - # Print the debug banner immediately: - if test -n "$lt_option_debug"; then - echo "unit-test-server:unit-test-server:${LINENO}: libtool wrapper (GNU libtool) 2.4 Debian-2.4-3" 1>&2 - fi -} - -# Used when --lt-debug. Prints its arguments to stdout -# (redirection is the responsibility of the caller) -func_lt_dump_args () -{ - lt_dump_args_N=1; - for lt_arg - do - $ECHO "unit-test-server:unit-test-server:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" - lt_dump_args_N=`expr $lt_dump_args_N + 1` - done -} - -# Core function for launching the target application -func_exec_program_core () -{ - - if test -n "$lt_option_debug"; then - $ECHO "unit-test-server:unit-test-server:${LINENO}: newargv[0]: $progdir/$program" 1>&2 - func_lt_dump_args ${1+"$@"} 1>&2 - fi - exec "$progdir/$program" ${1+"$@"} - - $ECHO "$0: cannot exec $program $*" 1>&2 - exit 1 -} - -# A function to encapsulate launching the target application -# Strips options in the --lt-* namespace from $@ and -# launches target application with the remaining arguments. -func_exec_program () -{ - for lt_wr_arg - do - case $lt_wr_arg in - --lt-*) ;; - *) set x "$@" "$lt_wr_arg"; shift;; - esac - shift - done - func_exec_program_core ${1+"$@"} -} - - # Parse options - func_parse_lt_options "$0" ${1+"$@"} - - # Find the directory that this script lives in. - thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - test "x$thisdir" = "x$file" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` - while test -n "$file"; do - destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - - # If there was a directory component, then change thisdir. - if test "x$destdir" != "x$file"; then - case "$destdir" in - [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; - *) thisdir="$thisdir/$destdir" ;; - esac - fi - - file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` - file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` - done - - # Usually 'no', except on cygwin/mingw when embedded into - # the cwrapper. - WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no - if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then - # special case for '.' - if test "$thisdir" = "."; then - thisdir=`pwd` - fi - # remove .libs from thisdir - case "$thisdir" in - *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; - .libs ) thisdir=. ;; - esac - fi - - # Try to get the absolute directory name. - absdir=`cd "$thisdir" && pwd` - test -n "$absdir" && thisdir="$absdir" - - program=lt-'unit-test-server' - progdir="$thisdir/.libs" - - if test ! -f "$progdir/$program" || - { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ - test "X$file" != "X$progdir/$program"; }; then - - file="$$-$program" - - if test ! -d "$progdir"; then - mkdir "$progdir" - else - rm -f "$progdir/$file" - fi - - # relink executable if necessary - if test -n "$relink_command"; then - if relink_command_output=`eval $relink_command 2>&1`; then : - else - printf %s\n "$relink_command_output" >&2 - rm -f "$progdir/$file" - exit 1 - fi - fi - - mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || - { rm -f "$progdir/$program"; - mv -f "$progdir/$file" "$progdir/$program"; } - rm -f "$progdir/$file" - fi - - if test -f "$progdir/$program"; then - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - # Run the actual program with our arguments. - func_exec_program ${1+"$@"} - fi - else - # The program doesn't exist. - $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 - $ECHO "This script is just a wrapper for $program." 1>&2 - $ECHO "See the libtool documentation for more information." 1>&2 - exit 1 - fi -fi diff --git a/tests/unit-test-server.c b/tests/unit-test-server.c deleted file mode 100644 index 9a986c5..0000000 --- a/tests/unit-test-server.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#include <modbus.h> - -#include "unit-test.h" - -enum { - TCP, - TCP_PI, - RTU -}; - -int main(int argc, char*argv[]) -{ - int socket; - modbus_t *ctx; - modbus_mapping_t *mb_mapping; - int rc; - int i; - int use_backend; - uint8_t *query; - int header_length; - - if (argc > 1) { - if (strcmp(argv[1], "tcp") == 0) { - use_backend = TCP; - } else if (strcmp(argv[1], "tcppi") == 0) { - use_backend = TCP_PI; - } else if (strcmp(argv[1], "rtu") == 0) { - use_backend = RTU; - } else { - printf("Usage:\n %s [tcp|tcppi|rtu] - Modbus server for unit testing\n\n", argv[0]); - return -1; - } - } else { - /* By default */ - use_backend = TCP; - } - - if (use_backend == TCP) { - ctx = modbus_new_tcp("127.0.0.1", 1502); - query = malloc(MODBUS_TCP_MAX_ADU_LENGTH); - } else if (use_backend == TCP_PI) { - ctx = modbus_new_tcp_pi("::0", "1502"); - query = malloc(MODBUS_TCP_MAX_ADU_LENGTH); - } else { - ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1); - modbus_set_slave(ctx, SERVER_ID); - query = malloc(MODBUS_RTU_MAX_ADU_LENGTH); - } - header_length = modbus_get_header_length(ctx); - - modbus_set_debug(ctx, TRUE); - - mb_mapping = modbus_mapping_new( - UT_BITS_ADDRESS + UT_BITS_NB, - UT_INPUT_BITS_ADDRESS + UT_INPUT_BITS_NB, - UT_REGISTERS_ADDRESS + UT_REGISTERS_NB, - UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB); - if (mb_mapping == NULL) { - fprintf(stderr, "Failed to allocate the mapping: %s\n", - modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - - /* Examples from PI_MODBUS_300.pdf. - Only the read-only input values are assigned. */ - - /** INPUT STATUS **/ - modbus_set_bits_from_bytes(mb_mapping->tab_input_bits, - UT_INPUT_BITS_ADDRESS, UT_INPUT_BITS_NB, - UT_INPUT_BITS_TAB); - - /** INPUT REGISTERS **/ - for (i=0; i < UT_INPUT_REGISTERS_NB; i++) { - mb_mapping->tab_input_registers[UT_INPUT_REGISTERS_ADDRESS+i] = - UT_INPUT_REGISTERS_TAB[i];; - } - - if (use_backend == TCP) { - socket = modbus_tcp_listen(ctx, 1); - modbus_tcp_accept(ctx, &socket); - } else if (use_backend == TCP_PI) { - socket = modbus_tcp_pi_listen(ctx, 1); - modbus_tcp_pi_accept(ctx, &socket); - } else { - rc = modbus_connect(ctx); - if (rc == -1) { - fprintf(stderr, "Unable to connect %s\n", modbus_strerror(errno)); - modbus_free(ctx); - return -1; - } - } - - for (;;) { - rc = modbus_receive(ctx, query); - if (rc == -1) { - /* Connection closed by the client or error */ - break; - } - - /* Read holding registers */ - if (query[header_length] == 0x03) { - if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 3) - == UT_REGISTERS_NB_SPECIAL) { - printf("Set an incorrect number of values\n"); - MODBUS_SET_INT16_TO_INT8(query, header_length + 3, - UT_REGISTERS_NB_SPECIAL - 1); - } else if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 1) - == UT_REGISTERS_ADDRESS_SPECIAL) { - printf("Reply to this special register address by an exception\n"); - modbus_reply_exception(ctx, query, - MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY); - continue; - } - } - - rc = modbus_reply(ctx, query, rc, mb_mapping); - if (rc == -1) { - break; - } - } - - printf("Quit the loop: %s\n", modbus_strerror(errno)); - - if (use_backend == TCP) { - close(socket); - } - modbus_mapping_free(mb_mapping); - free(query); - modbus_free(ctx); - - return 0; -} diff --git a/tests/unit-test-server.o b/tests/unit-test-server.o Binary files differdeleted file mode 100644 index 7d3a2de..0000000 --- a/tests/unit-test-server.o +++ /dev/null diff --git a/tests/unit-test.h b/tests/unit-test.h deleted file mode 100644 index 78575c1..0000000 --- a/tests/unit-test.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _UNIT_TEST_H_ -#define _UNIT_TEST_H_ - -#include <config.h> - -#ifdef HAVE_INTTYPES_H -#include <inttypes.h> -#endif -#ifdef HAVE_STDINT_H -# ifndef _MSC_VER -# include <stdint.h> -# else -# include "stdint.h" -# endif -#endif - -#define SERVER_ID 17 -#define INVALID_SERVER_ID 18 - -const uint16_t UT_BITS_ADDRESS = 0x13; -const uint16_t UT_BITS_NB = 0x25; -const uint8_t UT_BITS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; - -const uint16_t UT_INPUT_BITS_ADDRESS = 0xC4; -const uint16_t UT_INPUT_BITS_NB = 0x16; -const uint8_t UT_INPUT_BITS_TAB[] = { 0xAC, 0xDB, 0x35 }; - -const uint16_t UT_REGISTERS_ADDRESS = 0x6B; -/* Raise a manual exception when this adress is used for the first byte */ -const uint16_t UT_REGISTERS_ADDRESS_SPECIAL = 0x6C; -const uint16_t UT_REGISTERS_NB = 0x3; -const uint16_t UT_REGISTERS_TAB[] = { 0x022B, 0x0001, 0x0064 }; -/* If the following value is used, a bad response is sent. - It's better to test with a lower value than - UT_REGISTERS_NB_POINTS to try to raise a segfault. */ -const uint16_t UT_REGISTERS_NB_SPECIAL = 0x2; - -const uint16_t UT_INPUT_REGISTERS_ADDRESS = 0x08; -const uint16_t UT_INPUT_REGISTERS_NB = 0x1; -const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A }; - -const float UT_REAL = 916.540649; -const uint32_t UT_IREAL = 0x4465229a; - -#endif /* _UNIT_TEST_H_ */ diff --git a/tests/version b/tests/version deleted file mode 100755 index 7fa8075..0000000 --- a/tests/version +++ /dev/null @@ -1,225 +0,0 @@ -#! /bin/bash - -# version - temporary wrapper script for .libs/version -# Generated by libtool (GNU libtool) 2.4 Debian-2.4-3 -# -# The version program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -sed_quote_subst='s/\([`"$\\]\)/\\\1/g' - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command="(cd /home/jmccrohan/bin/libmodbus/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11; export PATH; gcc -g -O2 -g -O2 -Wall -Werror -o \$progdir/\$file version.o ../src/.libs/libmodbus.so -Wl,-rpath -Wl,/home/jmccrohan/bin/libmodbus/src/.libs)" - -# This environment variable determines our operation mode. -if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then - # install mode needs the following variables: - generated_by_libtool_version='2.4' - notinst_deplibs=' ../src/libmodbus.la' -else - # When we are sourced in execute mode, $file and $ECHO are already set. - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - file="$0" - -# A function that is used when there is no print builtin or printf. -func_fallback_echo () -{ - eval 'cat <<_LTECHO_EOF -$1 -_LTECHO_EOF' -} - ECHO="printf %s\\n" - fi - -# Very basic option parsing. These options are (a) specific to -# the libtool wrapper, (b) are identical between the wrapper -# /script/ and the wrapper /executable/ which is used only on -# windows platforms, and (c) all begin with the string --lt- -# (application programs are unlikely to have options which match -# this pattern). -# -# There are only two supported options: --lt-debug and -# --lt-dump-script. There is, deliberately, no --lt-help. -# -# The first argument to this parsing function should be the -# script's ../libtool value, followed by no. -lt_option_debug= -func_parse_lt_options () -{ - lt_script_arg0=$0 - shift - for lt_opt - do - case "$lt_opt" in - --lt-debug) lt_option_debug=1 ;; - --lt-dump-script) - lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` - test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. - lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` - cat "$lt_dump_D/$lt_dump_F" - exit 0 - ;; - --lt-*) - $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 - exit 1 - ;; - esac - done - - # Print the debug banner immediately: - if test -n "$lt_option_debug"; then - echo "version:version:${LINENO}: libtool wrapper (GNU libtool) 2.4 Debian-2.4-3" 1>&2 - fi -} - -# Used when --lt-debug. Prints its arguments to stdout -# (redirection is the responsibility of the caller) -func_lt_dump_args () -{ - lt_dump_args_N=1; - for lt_arg - do - $ECHO "version:version:${LINENO}: newargv[$lt_dump_args_N]: $lt_arg" - lt_dump_args_N=`expr $lt_dump_args_N + 1` - done -} - -# Core function for launching the target application -func_exec_program_core () -{ - - if test -n "$lt_option_debug"; then - $ECHO "version:version:${LINENO}: newargv[0]: $progdir/$program" 1>&2 - func_lt_dump_args ${1+"$@"} 1>&2 - fi - exec "$progdir/$program" ${1+"$@"} - - $ECHO "$0: cannot exec $program $*" 1>&2 - exit 1 -} - -# A function to encapsulate launching the target application -# Strips options in the --lt-* namespace from $@ and -# launches target application with the remaining arguments. -func_exec_program () -{ - for lt_wr_arg - do - case $lt_wr_arg in - --lt-*) ;; - *) set x "$@" "$lt_wr_arg"; shift;; - esac - shift - done - func_exec_program_core ${1+"$@"} -} - - # Parse options - func_parse_lt_options "$0" ${1+"$@"} - - # Find the directory that this script lives in. - thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - test "x$thisdir" = "x$file" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` - while test -n "$file"; do - destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` - - # If there was a directory component, then change thisdir. - if test "x$destdir" != "x$file"; then - case "$destdir" in - [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; - *) thisdir="$thisdir/$destdir" ;; - esac - fi - - file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` - file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` - done - - # Usually 'no', except on cygwin/mingw when embedded into - # the cwrapper. - WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no - if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then - # special case for '.' - if test "$thisdir" = "."; then - thisdir=`pwd` - fi - # remove .libs from thisdir - case "$thisdir" in - *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; - .libs ) thisdir=. ;; - esac - fi - - # Try to get the absolute directory name. - absdir=`cd "$thisdir" && pwd` - test -n "$absdir" && thisdir="$absdir" - - program=lt-'version' - progdir="$thisdir/.libs" - - if test ! -f "$progdir/$program" || - { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ - test "X$file" != "X$progdir/$program"; }; then - - file="$$-$program" - - if test ! -d "$progdir"; then - mkdir "$progdir" - else - rm -f "$progdir/$file" - fi - - # relink executable if necessary - if test -n "$relink_command"; then - if relink_command_output=`eval $relink_command 2>&1`; then : - else - printf %s\n "$relink_command_output" >&2 - rm -f "$progdir/$file" - exit 1 - fi - fi - - mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || - { rm -f "$progdir/$program"; - mv -f "$progdir/$file" "$progdir/$program"; } - rm -f "$progdir/$file" - fi - - if test -f "$progdir/$program"; then - if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then - # Run the actual program with our arguments. - func_exec_program ${1+"$@"} - fi - else - # The program doesn't exist. - $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 - $ECHO "This script is just a wrapper for $program." 1>&2 - $ECHO "See the libtool documentation for more information." 1>&2 - exit 1 - fi -fi diff --git a/tests/version.c b/tests/version.c deleted file mode 100644 index e0fc569..0000000 --- a/tests/version.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2010 Stéphane Raimbault <stephane.raimbault@gmail.com> - * - * 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; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <modbus.h> - -int main(void) -{ - printf("Compiled with libmodbus version %s\n", LIBMODBUS_VERSION_STRING); - printf("Linked with libmodbus version %d.%d.%d\n", - libmodbus_version_major, libmodbus_version_minor, libmodbus_version_micro); - - if (LIBMODBUS_VERSION_CHECK(2, 1, 0)) { - printf("The functions to read/write float values are available (2.1.0).\n"); - } - - if (LIBMODBUS_VERSION_CHECK(2, 1, 1)) { - printf("Oh gosh, brand new API (2.1.1)!\n"); - } - - return 0; -} diff --git a/tests/version.o b/tests/version.o Binary files differdeleted file mode 100644 index fa29586..0000000 --- a/tests/version.o +++ /dev/null |