Merge branch 'brian'
authorBrian Norris <banorris@uci.edu>
Thu, 2 Aug 2012 23:55:58 +0000 (16:55 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 2 Aug 2012 23:55:58 +0000 (16:55 -0700)
DEBUGGINGNOTES.txt
Makefile
common.mk [new file with mode: 0644]
run.sh
test/Makefile [new file with mode: 0644]
test/userprog.c [new file with mode: 0644]
userprog.c [deleted file]

index 1a114f1..70cbba6 100644 (file)
@@ -1,3 +1,6 @@
 To run inside MacOS under gdb you need:
 set dont-handle-bad-access 1
 handle SIGBUS nostop noprint
+
+To run in Linux under gdb, use:
+handle SIGSEGV nostop noprint
index 4526ed7..c2d7072 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,4 @@
-CC=gcc
-CXX=g++
-
-BIN=model
-LIB_NAME=model
-LIB_SO=lib$(LIB_NAME).so
-
-USER_O=userprog.o
-USER_H=libthreads.h
+include common.mk
 
 MODEL_CC=libthreads.cc schedule.cc model.cc threads.cc librace.cc action.cc nodestack.cc clockvector.cc main.cc snapshot-interface.cc cyclegraph.cc datarace.cc impatomic.cc cmodelint.cc promise.cc
 MODEL_O=libthreads.o schedule.o model.o threads.o librace.o action.o nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o datarace.o impatomic.o cmodelint.o promise.o
@@ -16,11 +8,13 @@ SHMEM_CC=snapshot.cc malloc.c mymemory.cc
 SHMEM_O=snapshot.o malloc.o mymemory.o
 SHMEM_H=snapshot.h snapshotimp.h mymemory.h
 
-CPPFLAGS=-Wall -g -O0 -Iinclude -I.
+CPPFLAGS += -Iinclude -I.
 LDFLAGS=-ldl -lrt
 SHARED=-shared
 
-all: $(BIN)
+TESTS=test
+
+all: $(LIB_SO) tests
 
 debug: CPPFLAGS += -DCONFIG_DEBUG
 debug: all
@@ -33,11 +27,6 @@ mac: all
 docs: *.c *.cc *.h
        doxygen
 
-$(BIN): $(USER_O) $(LIB_SO)
-       $(CXX) -o $(BIN) $(USER_O) -L. -l$(LIB_NAME)
-
-# note: implicit rule for generating $(USER_O) (i.e., userprog.c -> userprog.o)
-
 $(LIB_SO): $(MODEL_O) $(MODEL_H) $(SHMEM_O) $(SHMEM_H)
        $(CXX) $(SHARED) -o $(LIB_SO) $(MODEL_O) $(SHMEM_O) $(LDFLAGS)
 
@@ -54,10 +43,14 @@ snapshot.o: mymemory.h snapshot.h snapshotimp.h snapshot.cc
        $(CXX) -fPIC -c $< $(CPPFLAGS)
 
 clean:
-       rm -f $(BIN) *.o *.so
+       rm -f *.o *.so
+       $(MAKE) -C $(TESTS) clean
 
 mrclean: clean
        rm -rf docs
 
 tags::
        ctags -R
+
+tests:: $(LIB_SO)
+       $(MAKE) -C $(TESTS)
diff --git a/common.mk b/common.mk
new file mode 100644 (file)
index 0000000..378a659
--- /dev/null
+++ b/common.mk
@@ -0,0 +1,9 @@
+# A few common Makefile items
+
+CC=gcc
+CXX=g++
+
+LIB_NAME=model
+LIB_SO=lib$(LIB_NAME).so
+
+CPPFLAGS=-Wall -g -O0
diff --git a/run.sh b/run.sh
index 7ef8e9b..fecd43d 100755 (executable)
--- a/run.sh
+++ b/run.sh
@@ -1,13 +1,28 @@
 #!/bin/sh
+#
+# Runs a simple test (default: ./test/userprog.o)
+# Syntax:
+#  ./run.sh [gdb]
+#  ./run.sh [test program] [gdb]
+#
+# If you include a 'gdb' argument, the your program will be launched with gdb.
+# You can also supply a test program argument to run something besides the
+# default program.
+#
+
+BIN=./test/userprog.o
+
 export LD_LIBRARY_PATH=.
 
+[ $# -gt 0 ] && [ "$1" != "gdb" ] && BIN=$1 && shift
+
 if [ $# -gt 0 ]; then
        if [ "$1" = "gdb" ]; then
-               gdb ./model
+               gdb $BIN
        else
                echo "Invalid argument(s)"
                exit 1
        fi
 else
-       ./model
+       $BIN
 fi
diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..f7a01be
--- /dev/null
@@ -0,0 +1,15 @@
+include ../common.mk
+
+CPPFLAGS += -I.. -I../include
+TESTS=userprog
+
+SRCS = $(wildcard *.c)
+OBJS = $(patsubst %.c,%.o,$(SRCS))
+
+all: $(OBJS)
+
+%.o: %.c
+       $(CC) -o $@ $< $(CPPFLAGS) -L.. -l$(LIB_NAME)
+
+clean::
+       rm -f *.o $(TESTS)
diff --git a/test/userprog.c b/test/userprog.c
new file mode 100644 (file)
index 0000000..645dc30
--- /dev/null
@@ -0,0 +1,38 @@
+#include <stdio.h>
+
+#include "libthreads.h"
+#include "librace.h"
+#include "stdatomic.h"
+
+atomic_int x;
+atomic_int y;
+
+static void a(void *obj)
+{
+       int r1=atomic_load_explicit(&y, memory_order_relaxed);
+       atomic_store_explicit(&x, r1, memory_order_relaxed);
+       printf("r1=%u\n",r1);
+}
+
+static void b(void *obj)
+{
+       int r2=atomic_load_explicit(&x, memory_order_relaxed);
+       atomic_store_explicit(&y, 42, memory_order_relaxed);
+       printf("r2=%u\n",r2);
+}
+
+void user_main()
+{
+       thrd_t t1, t2;
+
+       atomic_init(&x, 0);
+       atomic_init(&y, 0);
+
+       printf("Thread %d: creating 2 threads\n", thrd_current());
+       thrd_create(&t1, (thrd_start_t)&a, NULL);
+       thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+       thrd_join(t1);
+       thrd_join(t2);
+       printf("Thread %d is finished\n", thrd_current());
+}
diff --git a/userprog.c b/userprog.c
deleted file mode 100644 (file)
index 645dc30..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <stdio.h>
-
-#include "libthreads.h"
-#include "librace.h"
-#include "stdatomic.h"
-
-atomic_int x;
-atomic_int y;
-
-static void a(void *obj)
-{
-       int r1=atomic_load_explicit(&y, memory_order_relaxed);
-       atomic_store_explicit(&x, r1, memory_order_relaxed);
-       printf("r1=%u\n",r1);
-}
-
-static void b(void *obj)
-{
-       int r2=atomic_load_explicit(&x, memory_order_relaxed);
-       atomic_store_explicit(&y, 42, memory_order_relaxed);
-       printf("r2=%u\n",r2);
-}
-
-void user_main()
-{
-       thrd_t t1, t2;
-
-       atomic_init(&x, 0);
-       atomic_init(&y, 0);
-
-       printf("Thread %d: creating 2 threads\n", thrd_current());
-       thrd_create(&t1, (thrd_start_t)&a, NULL);
-       thrd_create(&t2, (thrd_start_t)&b, NULL);
-
-       thrd_join(t1);
-       thrd_join(t2);
-       printf("Thread %d is finished\n", thrd_current());
-}