[PATCH 7/7] cr_tests: epoll: Factor out label code

Matt Helsley matthltc at us.ibm.com
Thu Nov 12 21:59:01 PST 2009


Label generation code is common between my epoll, eventfd, and soon
unlinked file/dir/etc. code. Factor it out for re-use amongst these
tests by putting it in libcrtest/.

Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
 epoll/Makefile        |    8 ++++--
 epoll/libeptest.c     |    4 ---
 epoll/libeptest.h     |   57 +---------------------------------------------
 epoll/libeptest.lds   |    9 -------
 libcrtest/Makefile    |   14 +++++-----
 libcrtest/labels.c    |    6 +++++
 libcrtest/labels.h    |   61 +++++++++++++++++++++++++++++++++++++++++++++++++
 libcrtest/labels.lds  |    9 +++++++
 libcrtest/libcrtest.h |    4 +++
 9 files changed, 93 insertions(+), 79 deletions(-)
 delete mode 100644 epoll/libeptest.lds
 create mode 100644 libcrtest/labels.c
 create mode 100644 libcrtest/labels.h
 create mode 100644 libcrtest/labels.lds

diff --git a/epoll/Makefile b/epoll/Makefile
index f80e2e5..7267ac5 100644
--- a/epoll/Makefile
+++ b/epoll/Makefile
@@ -4,7 +4,7 @@ LIBS := ../libcrtest/libcrtest.a ./libeptest.a
 CFLAGS := -Wall $(ARCHOPTS) -I../ -I../libcrtest
 
 # Properly generate special symbols for the labels ELF section
-LDFLAGS :=  -Xlinker -dT -Xlinker ./libeptest.lds
+LDFLAGS :=  -Xlinker -dT -Xlinker ../libcrtest/labels.lds
 
 PROGS=empty pipe sk10k cycle scm
 
@@ -15,8 +15,10 @@ all: $(PROGS)
 ../libcrtest/libcrtest.a: ../libcrtest/libcrtest.h ../libcrtest/common.c
 	$(MAKE) -C ../libcrtest libcrtest.a
 
-libeptest.a: libeptest.o libeptest.h
-	ar cr libeptest.a libeptest.o
+libeptest.o: libeptest.h
+
+libeptest.a: libeptest.o
+	ar cr $@ $<
 
 $(PROGS): %: %.c $(LIBS)
 	gcc -Wall $(CFLAGS) -o $@ $< $(LIBS) $(LDFLAGS)
diff --git a/epoll/libeptest.c b/epoll/libeptest.c
index b21548e..95b42f8 100644
--- a/epoll/libeptest.c
+++ b/epoll/libeptest.c
@@ -52,7 +52,3 @@ void do_ckpt(void)
 		usleep(10000);
 
 }
-
-/* The spot (LABEL or label number) where we should test checkpoint/restart */
-char const *ckpt_label;
-int ckpt_op_num = 0;
diff --git a/epoll/libeptest.h b/epoll/libeptest.h
index 999cedd..990412d 100644
--- a/epoll/libeptest.h
+++ b/epoll/libeptest.h
@@ -6,6 +6,7 @@
 #include <sys/epoll.h>
 
 #include "libcrtest/libcrtest.h"
+#include "libcrtest/labels.h"
 
 extern FILE *logfp;
 
@@ -30,60 +31,4 @@ do { \
 /* Non-reentrant!! */
 const char * eflags(unsigned int events);
 
-/*
- * A LABEL is a point in the program we can goto where it's interesting to
- * checkpoint. These enable us to have a set of labels that can be specified
- * on the commandline.
- */
-extern const char *labels[];
-extern const char *___labels_end[];
-
-/* The spot (LABEL or label number) where we should test checkpoint/restart */
-extern char const *ckpt_label;
-extern int ckpt_op_num;
-
-/*#define num_labels ((&last_label - &first_label) - 1)*/
-#define num_labels ((int)(___labels_end - labels))
-
-/* Print the labels that this program has to pout */
-static inline void print_labels(FILE *pout)
-{
-	int i;
-
-	if (num_labels > 0)
-		fprintf(pout, "\tNUM\tLABEL\n");
-	for (i = 0; i < num_labels; i++)
-		fprintf(pout, "\t%d\t%s\n", i, labels[i]);
-}
-
-
-/* Signal ready for and await the checkpoint */
-void do_ckpt(void);
-
-
-#define stringify(expr) #expr
-
-/* Label a spot in the code... */
-#define label(lbl, ret, action) \
-do { \
-	static char __attribute__((section(".LABELs"))) *___ ##lbl## _l = stringify(lbl); \
-	goto lbl ; \
-lbl: \
-\
-        log("INFO", "label: %s: \"%s\"\n", \
-		    labels[op_num], stringify(action)); \
-\
-	ret = action ; \
-\
-	if ((ckpt_op_num == op_num) || \
-	    (strcmp(ckpt_label, ___ ##lbl## _l) == 0)) \
-		do_ckpt(); \
-	if (ret < 0) { \
-		log("FAIL", "%d\t%s: %s\n", \
-		    op_num, ___ ##lbl## _l, stringify(action) ); \
-		goto out; \
-	} \
-	op_num++; \
-} while(0)
-
 #define HELLO "Hello world!\n"
diff --git a/epoll/libeptest.lds b/epoll/libeptest.lds
deleted file mode 100644
index a083bde..0000000
--- a/epoll/libeptest.lds
+++ /dev/null
@@ -1,9 +0,0 @@
-SECTIONS {
-	. = ALIGN(8);
-	LABELs : {
-		labels = . ;
-		*(.LABELs);
-		___labels_end = . ;
-	}
-}
-INSERT BEFORE .data ;
diff --git a/libcrtest/Makefile b/libcrtest/Makefile
index de9e36f..1181fe3 100644
--- a/libcrtest/Makefile
+++ b/libcrtest/Makefile
@@ -1,11 +1,11 @@
+TARGETS := libcrtest.a
+all: $(TARGETS)
 
-all: libcrtest.a
+common.o: libcrtest.h
+labels.o: labels.h
 
-common.o: libcrtest.h common.c
-	cc $(CFLAGS) -c common.c
-
-libcrtest.a: common.o
-	ar cr libcrtest.a common.o
+libcrtest.a: common.o labels.o
+	ar cr $@ $^
 
 clean:
-	rm -f common.o libcrtest.a
+	rm -f *.o $(TARGETS)
diff --git a/libcrtest/labels.c b/libcrtest/labels.c
new file mode 100644
index 0000000..a64e1c8
--- /dev/null
+++ b/libcrtest/labels.c
@@ -0,0 +1,6 @@
+#include "labels.h"
+
+/* The spot (LABEL or label number) where we should test checkpoint/restart */
+char const *ckpt_label = NULL;
+int ckpt_op_num = 0;
+
diff --git a/libcrtest/labels.h b/libcrtest/labels.h
new file mode 100644
index 0000000..f0137dc
--- /dev/null
+++ b/libcrtest/labels.h
@@ -0,0 +1,61 @@
+#ifndef LIBCRTEST_LABELS_H
+#define LIBCRTEST_LABELS_H 1
+#include <stdio.h>
+
+/*
+ * A LABEL is a point in the program we can goto where it's interesting to
+ * checkpoint. These enable us to have a set of labels that can be specified
+ * on the commandline.
+ */
+extern const char *labels[];
+extern const char *___labels_end[];
+
+extern int op_num; /* current operation count */
+
+/* The spot (LABEL or label number) where we should test checkpoint/restart */
+extern char const *ckpt_label; /* label to checkpoint at */
+extern int ckpt_op_num; /* op_num to checkpoint at. -1 -> all */
+
+/*#define num_labels ((&last_label - &first_label) - 1)*/
+#define num_labels ((int)(___labels_end - labels))
+
+/* Print the labels that this program has to pout */
+static inline void print_labels(FILE *pout)
+{
+	int i;
+
+	if (num_labels > 0)
+		fprintf(pout, "\tNUM\tLABEL\n");
+	for (i = 0; i < num_labels; i++)
+		fprintf(pout, "\t%d\t%s\n", i, labels[i]);
+}
+
+/* Signal ready for and await the checkpoint. */
+extern void do_ckpt(void);
+
+#define stringify(expr) #expr
+
+/* Label a spot in the code. TODO: Find a nicer way to do "out" */
+#define label(lbl, ret, action) \
+do { \
+	static char __attribute__((section(".LABELs"))) *___ ##lbl## _l = stringify(lbl); \
+	goto lbl ; \
+lbl: \
+\
+        fprintf(logfp, "INFO: label: %s: \"%s\"\n", \
+		    labels[op_num], stringify(action)); \
+\
+	ret = action ; \
+\
+	if ((ckpt_op_num == op_num) || (ckpt_op_num == -1) || \
+	    (strcmp(ckpt_label, ___ ##lbl## _l) == 0)) \
+		do_ckpt(); \
+	if (ret < 0) { \
+		fprintf(logfp, "FAIL: %d\t%s: %s\n", \
+		    op_num, ___ ##lbl## _l, stringify(action) ); \
+		goto out ; \
+	} \
+	op_num++; \
+} while(0)
+
+#endif /* LIBCRTEST_LABELS_H */
diff --git a/libcrtest/labels.lds b/libcrtest/labels.lds
new file mode 100644
index 0000000..a083bde
--- /dev/null
+++ b/libcrtest/labels.lds
@@ -0,0 +1,9 @@
+SECTIONS {
+	. = ALIGN(8);
+	LABELs : {
+		labels = . ;
+		*(.LABELs);
+		___labels_end = . ;
+	}
+}
+INSERT BEFORE .data ;
diff --git a/libcrtest/libcrtest.h b/libcrtest/libcrtest.h
index abc192f..a42c178 100644
--- a/libcrtest/libcrtest.h
+++ b/libcrtest/libcrtest.h
@@ -1,3 +1,5 @@
+#ifndef LIBCRTEST_H
+#define LIBCRTEST_H 1
 
 #define CKPT_READY		"checkpoint-ready"
 #define CKPT_DONE		"checkpoint-done"
@@ -20,3 +22,5 @@ extern void copy_data(char *srcfile, char *destfile);
 extern char *freezer_mountpoint(void);
 /* right now, subsys must always be "freezer" */
 extern int move_to_cgroup(char *subsys, char *grp, int pid);
+
+#endif /* LIBCRTEST_H */
-- 
1.6.3.3



More information about the Containers mailing list