From e44c028c15f596875449eed8885824add58e6865 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sat, 24 Aug 2002 21:23:58 +0000 Subject: Simple shared memory test --- test/misc/Makefile | 14 +++++++++++++- test/misc/sem.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 test/misc/sem.c diff --git a/test/misc/Makefile b/test/misc/Makefile index 60476890f..ae49a865a 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -19,7 +19,7 @@ TESTDIR=../ include $(TESTDIR)/Rules.mak -TARGETS=outb +TARGETS=sem outb all: $(TARGETS) outb: outb.c ../testsuite.h Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) @@ -32,6 +32,18 @@ outb: outb.c ../testsuite.h Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC $(STRIPTOOL) -x -R .note -R .comment $@ ./$@ -@ echo " " + +sem: sem.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs uClibc: " + -@ echo " " + $(CC) $(CFLAGS) -c $< -o $@.o + $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + $(STRIPTOOL) -x -R .note -R .comment $@ + -./$@ + -@ echo " " + clean: rm -f *.[oa] *~ core $(TARGETS) diff --git a/test/misc/sem.c b/test/misc/sem.c new file mode 100644 index 000000000..7606fd180 --- /dev/null +++ b/test/misc/sem.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +int main(void) +{ + int k, r; + union semun { + int val; + struct semid_ds *buf; + unsigned short int *array; + struct seminfo *__buf; + } sd; + struct semid_ds sd_buf; + + k = semget(IPC_PRIVATE, 10, IPC_CREAT | 0666 ); + printf("%d\n", k); + + if (k < 0) { + printf("semget failed: %m\n"); + return 1; + } + + sd.buf = &sd_buf; + r = semctl(k, 0, IPC_STAT, sd); + printf("%d\n", r); + + if (r < 0) { + printf("semctl IPC_STAT failed: %m\n"); + return 1; + } + + printf("sem_nsems = %lu\n", sd_buf.sem_nsems); + if (sd_buf.sem_nsems != 10) { + printf("failed: incorrect sem_nsems!\n"); + return 1; + } + + printf("succeeded\n"); + + return 0; +} -- cgit v1.2.3