include ../benchmarks.mk
-TESTNAME = main
+BENCH := deque
-HEADERS = deque.h
-OBJECTS = main.o deque.o
+NORMAL_TESTS := testcase1 testcase2
-all: $(TESTNAME)
+WILDCARD_TESTS := $(patsubst %, %_wildcard, $(NORMAL_TESTS))
-$(TESTNAME): $(HEADERS) $(OBJECTS)
- $(CC) -o $@ $(OBJECTS) $(CPPFLAGS) $(LDFLAGS)
+TESTS := $(NORMAL_TESTS) $(WILDCARD_TESTS)
-%.o: %.c
- $(CC) -c -o $@ $< $(CPPFLAGS)
+all: $(TESTS)
+
+$(BENCH).o : $(BENCH).c $(BENCH).h
+ $(CC) -o $@ $< $(CFLAGS) -c $(LDFLAGS)
+
+$(BENCH)_wildcard.o : $(BENCH)_wildcard.c $(BENCH).h
+ $(CC) -o $@ $< $(CFLAGS) -c $(LDFLAGS)
+
+$(WILDCARD_TESTS): %_wildcard : %.c $(BENCH)_wildcard.o
+ $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
+
+$(NORMAL_TESTS): % : %.c $(BENCH).o
+ $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
clean:
- rm -f $(TESTNAME) *.o
+ rm -f *.o *.d $(TESTS)
--- /dev/null
+#1: Ordering parameters
+
+wildcard8 -> sc (fence in take())
+wildcard12 -> sc (update of top in take())
+*wildcard23 -> release (update of array in resize())
+wildcard25 -> acquire (load of top in push())
+*wildcard31 -> release (fence in push())
+wildcard33 -> acquire (load of top in steal())
+wildcard34 -> sc (fence in steal())
+*wildcard35 -> acquire (load of bottom in steal())
+*wildcard36 -> acquire (load of array in steal())
+wildcard39 -> sc (update of top in steal())
+
+#1:
+wildcard23 -> release
+wildcard36 -> acquire
+Update of array in resize(), should be release; since only steal() need to
+establish hb, so in steal wildcard36 should be acquire.
+
+wildcard31 -> release (fence)
+wildcard35 -> acquire
+Establish hb between push() and steal() via the variable bottom.
+
+wildcard33 -> acquire
+wildcard12 -> release (at least)
+Establish hb between take() and steal() when there's only one element in the
+deque, and take() gets the last element. The hb ensures that the steal() will
+see the updated bottom in take().
--- /dev/null
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#include <threads.h>
+#include <stdatomic.h>
+
+#include "model-assert.h"
+
+#include "deque.h"
+
+Deque *q;
+int a;
+int b;
+int c;
+
+static void task(void * param) {
+ a=steal(q);
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t;
+ q=create();
+ thrd_create(&t, task, 0);
+ push(q, 1);
+ push(q, 2);
+ //push(q, 4);
+ b=take(q);
+ c=take(q);
+ thrd_join(t);
+
+/*
+ bool correct=true;
+ if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
+ correct=false;
+ if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
+ correct=false;
+ if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
+ correct=false;
+ if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
+ correct=false;
+ //if (!correct)
+ printf("a=%d b=%d c=%d\n",a,b,c);
+ MODEL_ASSERT(correct);
+ */
+
+ return 0;
+}