Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new tests using named pipe tests #98

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions UnixBench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ TMPDIR = ./tmp
INCLDIR = /usr/include
LIBDIR = /lib
SCRIPTS = unixbench.logo multi.sh tst.sh index.base
SOURCES = arith.c big.c context1.c \
SOURCES = arith.c big.c context1.c context2.c \
dummy.c execl.c \
fstime.c hanoi.c \
pipe.c spawn.c \
syscall.c looper.c timeit.c time-polling.c \
dhry_1.c dhry_2.c dhry.h whets.c ubgears.c
dhry_1.c dhry_2.c dhry.h whets.c ubgears.c \
named_pipe.c
TESTS = sort.src cctest.c dc.dat large.txt

ifneq (,$(GRAPHIC_TESTS))
Expand All @@ -157,7 +158,8 @@ BINS = $(PROGDIR)/arithoh $(PROGDIR)/register $(PROGDIR)/short \
$(PROGDIR)/hanoi $(PROGDIR)/syscall $(PROGDIR)/context1 \
$(PROGDIR)/pipe $(PROGDIR)/spawn $(PROGDIR)/execl \
$(PROGDIR)/dhry2 $(PROGDIR)/dhry2reg $(PROGDIR)/looper \
$(PROGDIR)/fstime $(PROGDIR)/whetstone-double $(GRAPHIC_BINS)
$(PROGDIR)/fstime $(PROGDIR)/whetstone-double $(PROGDIR)/named_pipe \
$(PROGDIR)/context2 $(GRAPHIC_BINS)
## These compile only on some platforms...
# $(PROGDIR)/poll $(PROGDIR)/poll2 $(PROGDIR)/select

Expand Down Expand Up @@ -266,6 +268,8 @@ $(PROGDIR)/whetstone-double: LDFLAGS += -lm

$(PROGDIR)/pipe: $(SRCDIR)/pipe.c $(SRCDIR)/timeit.c

$(PROGDIR)/named_pipe: $(SRCDIR)/named_pipe.c $(SRCDIR)/timeit.c

$(PROGDIR)/execl: $(SRCDIR)/execl.c $(SRCDIR)/big.c

$(PROGDIR)/spawn: $(SRCDIR)/spawn.c $(SRCDIR)/timeit.c
Expand All @@ -278,6 +282,8 @@ $(PROGDIR)/syscall: $(SRCDIR)/syscall.c $(SRCDIR)/timeit.c

$(PROGDIR)/context1: $(SRCDIR)/context1.c $(SRCDIR)/timeit.c

$(PROGDIR)/context2: $(SRCDIR)/context2.c $(SRCDIR)/timeit.c

$(PROGDIR)/looper: $(SRCDIR)/looper.c $(SRCDIR)/timeit.c

$(PROGDIR)/ubgears: $(SRCDIR)/ubgears.c
Expand Down
16 changes: 15 additions & 1 deletion UnixBench/Run
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ my $fs = [

my $oldsystem = [
"execl", "fstime", "fsbuffer", "fsdisk", "pipe", "context1", "spawn",
"syscall"
"syscall", "named_pipe", "context2"
];

my $system = [
Expand All @@ -149,7 +149,9 @@ my $testList = {
"whetstone-double" => undef,
"syscall" => undef,
"pipe" => undef,
"named_pipe" => undef,
"context1" => undef,
"context2" => undef,
"spawn" => undef,
"execl" => undef,
"fstime-w" => undef,
Expand Down Expand Up @@ -256,12 +258,24 @@ my $testParams = {
"repeat" => 'long',
"options" => "10",
},
"context2" => {
"logmsg" => "Named Pipe-based Context Switching",
"cat" => 'system',
"repeat" => 'long',
"options" => "10",
},
"pipe" => {
"logmsg" => "Pipe Throughput",
"cat" => 'system',
"repeat" => 'long',
"options" => "10",
},
"named_pipe" => {
"logmsg" => "Named Pipe Throughput",
"cat" => 'system',
"repeat" => 'long',
"options" => "10",
},
"spawn" => {
"logmsg" => "Process Creation",
"cat" => 'system',
Expand Down
160 changes: 160 additions & 0 deletions UnixBench/src/context2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*******************************************************************************
* The BYTE UNIX Benchmarks - Release 3
* Module: context2.c SID: 0.1 8/06/24 11:11:11
*
*******************************************************************************
* Bug reports, patches, comments, suggestions should be sent to:
*
* Ben Smith, Rick Grehan or Tom Yager
* [email protected] [email protected] [email protected]
*
*******************************************************************************
*
******************************************************************************/
char SCCSid[] = "@(#) @(#)context2.c:0.1 -- 8/06/24 11:11:11";
/*
* Context switching via synchronized named pipe i/o
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <signal.h>
#include "timeit.c"

unsigned long iter;
char fifo1_name[] = "/tmp/test_fifo1XXXXXX";
char fifo2_name[] = "/tmp/test_fifo2XXXXXX";

void report()
{
fprintf(stderr, "COUNT|%lu|1|lps\n", iter);

// Clean up
unlink(fifo1_name);
unlink(fifo2_name);

exit(0);
}

int main(int argc, char *argv[])
{
int duration;
unsigned long check;
int fd1_read, fd1_write, fd2_read, fd2_write;
ssize_t ret;

if (argc != 2) {
fprintf(stderr, "Usage: context duration\n");
exit(1);
}

duration = atoi(argv[1]);

// Generate unique FIFO names
if (mkstemp(fifo1_name) == -1) {
perror("mkstemp");
exit(1);
}
if (mkstemp(fifo2_name) == -1) {
perror("mkstemp");
exit(1);
}

// Remove the generated files and create named pipes (FIFOs) with the same names
unlink(fifo1_name);
unlink(fifo2_name);
if (mkfifo(fifo1_name, 0666) == -1) {
perror("mkfifo1");
exit(1);
}
if (mkfifo(fifo2_name, 0666) == -1) {
perror("mkfifo2");
exit(1);
}

/* set up alarm call */
iter = 0;
wake_me(duration, report);
signal(SIGPIPE, SIG_IGN);

if (fork()) { /* parent process */
/* initiator, write to fifo1 & read from fifo2 */
fd1_write = open(fifo1_name, O_WRONLY);
fd2_read = open(fifo2_name, O_RDONLY);
if (fd1_write == -1 || fd2_read == -1) {
perror("open parent");
exit(1);
}

while (1) {
if ((ret = write(fd1_write, (char *)&iter, sizeof(iter))) != sizeof(iter)) {
if ((ret == -1) && (errno == EPIPE)) {
alarm(0);
report(); /* does not return */
}
if ((ret == -1) && (errno != 0) && (errno != EINTR))
perror("initiator write failed");
exit(1);
}
if ((ret = read(fd2_read, (char *)&check, sizeof(check))) != sizeof(check)) {
if ((ret == 0)) { /* end-of-stream */
alarm(0);
report(); /* does not return */
}
if ((ret == -1) && (errno != 0) && (errno != EINTR))
perror("initiator read failed");
exit(1);
}
if (check != iter) {
fprintf(stderr, "Initiator sync error: expect %lu, got %lu\n",
iter, check);
exit(2);
}
iter++;
}
}
else { /* child process */
/* target, read from fifo1 & write to fifo2 */
fd1_read = open(fifo1_name, O_RDONLY);
fd2_write = open(fifo2_name, O_WRONLY);
if (fd1_read == -1 || fd2_write == -1) {
perror("open child");
exit(1);
}

while (1) {
if ((ret = read(fd1_read, (char *)&check, sizeof(check))) != sizeof(check)) {
if ((ret == 0)) { /* end-of-stream */
alarm(0);
report(); /* does not return */
}
if ((ret == -1) && (errno != 0) && (errno != EINTR))
perror("target read failed");
exit(1);
}
if (check != iter) {
fprintf(stderr, "Target sync error: expect %lu, got %lu\n",
iter, check);
exit(2);
}
if ((ret = write(fd2_write, (char *)&iter, sizeof(iter))) != sizeof(iter)) {
if ((ret == -1) && (errno == EPIPE)) {
alarm(0);
report(); /* does not return */
}
if ((ret == -1) && (errno != 0) && (errno != EINTR))
perror("target write failed");
exit(1);
}
iter++;
}
}

}

95 changes: 95 additions & 0 deletions UnixBench/src/named_pipe.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* The BYTE UNIX Benchmarks - Release 3
* Module: named_pipe.c SID: 0.1 -- 8/06/24 11:11:11
*
*******************************************************************************
* Bug reports, patches, comments, suggestions should be sent to:
*
* Ben Smith, Rick Grehan or Tom Yager
* [email protected] [email protected] [email protected]
*
*******************************************************************************
* Modification Log:
*
******************************************************************************/
char SCCSid[] = "@(#) @(#)named_pipe.c:0.1 -- 8/06/24 11:11:11";
/*
* named_pipe -- test single process named pipe throughput (no context switching)
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include "timeit.c"

unsigned long iter;
char fifo_name[] = "/tmp/test_fifoXXXXXX";

void report()
{
fprintf(stderr,"COUNT|%ld|1|lps\n", iter);

// Clean up
unlink(fifo_name);

exit(0);
}

int main(int argc, char *argv[])
{
char buf[512];
int fd_read, fd_write, duration;

if (argc != 2) {
fprintf(stderr,"Usage: %s duration\n", argv[0]);
exit(1);
}

duration = atoi(argv[1]);

// Generate a unique FIFO name
if (mkstemp(fifo_name) == -1) {
perror("mkstemp");
exit(1);
}

// Remove the generated file and create a named pipe (FIFO) with the same name
unlink(fifo_name);
if (mkfifo(fifo_name, 0666) == -1) {
perror("mkfifo");
exit(1);
}

// Open the FIFO for reading and writing
fd_read = open(fifo_name, O_RDONLY | O_NONBLOCK);
if (fd_read == -1) {
perror("open for read");
exit(1);
}

fd_write = open(fifo_name, O_WRONLY | O_NONBLOCK);
if (fd_write == -1) {
perror("open for write");
exit(1);
}

wake_me(duration, report);
iter = 0;

while (1) {
if (write(fd_write, buf, sizeof(buf)) != sizeof(buf)) {
if ((errno != EINTR) && (errno != 0))
fprintf(stderr,"write failed, error %d\n", errno);
}
if (read(fd_read, buf, sizeof(buf)) != sizeof(buf)) {
if ((errno != EINTR) && (errno != 0))
fprintf(stderr,"read failed, error %d\n", errno);
}
iter++;
}
}