[m-rev.] diff: Address weak_pointer test review comments.

Paul Bone paul at bone.id.au
Mon Aug 4 16:54:07 AEST 2014


Address weak_pointer test review comments.

tests/general/weak_ptr.m:
tests/general/weak_ptr.exp:
tests/hard_coded/Mmakefile:
tests/general/Mmakefile:
    Move week_ptr test into tests/hard_coded

    The weak_ptr test should te executed conditionally, this is easy to do in
    the hard_coded/ test suite.

tests/general/weak_ptr.m:
    Fix spelling error.

tests/general/weak_ptr.exp2:
    Remove unnecessary file.
---
 tests/general/Mmakefile       |  11 +--
 tests/general/weak_ptr.exp    |   1 -
 tests/general/weak_ptr.exp2   |   1 -
 tests/general/weak_ptr.m      | 166 ------------------------------------------
 tests/hard_coded/Mmakefile    |  11 ++-
 tests/hard_coded/weak_ptr.exp |   1 +
 tests/hard_coded/weak_ptr.m   | 166 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 178 insertions(+), 179 deletions(-)
 delete mode 100644 tests/general/weak_ptr.exp
 delete mode 100644 tests/general/weak_ptr.exp2
 delete mode 100644 tests/general/weak_ptr.m
 create mode 100644 tests/hard_coded/weak_ptr.exp
 create mode 100644 tests/hard_coded/weak_ptr.m

diff --git a/tests/general/Mmakefile b/tests/general/Mmakefile
index 035afe2..b83817f 100644
--- a/tests/general/Mmakefile
+++ b/tests/general/Mmakefile
@@ -74,8 +74,7 @@ ORDINARY_PROGS=	\
 		test_string_to_int_overflow \
 		test_univ \
 		unreachable \
-		unsafe_uniqueness \
-		weak_ptr
+		unsafe_uniqueness
 
 EXCEPTION_PROGS = \
 		map_corresponding \
@@ -151,12 +150,4 @@ string_format_test_3.out: string_format_test_3
 io_foldl.out: io_foldl io_foldl.exp
 	./io_foldl < io_foldl.exp > io_foldl.out 2>&1
 
-# weak_ptr's output is extreamly volatile, it depends on Boehm GC's behavour
-# which can vary depending on many different things.  All we can hope to do
-# is check that it doesn't crash.
-
-weak_ptr.out: weak_ptr
-	./weak_ptr
-	echo "Output is not part of test, see Mmakefile" > $@
-
 #-----------------------------------------------------------------------------#
diff --git a/tests/general/weak_ptr.exp b/tests/general/weak_ptr.exp
deleted file mode 100644
index 44d96fa..0000000
--- a/tests/general/weak_ptr.exp
+++ /dev/null
@@ -1 +0,0 @@
-Output is not part of test, see Mmakefile
diff --git a/tests/general/weak_ptr.exp2 b/tests/general/weak_ptr.exp2
deleted file mode 100644
index 0b2cc3a..0000000
--- a/tests/general/weak_ptr.exp2
+++ /dev/null
@@ -1 +0,0 @@
-Test not supported in this grade.
diff --git a/tests/general/weak_ptr.m b/tests/general/weak_ptr.m
deleted file mode 100644
index 5b39ef2..0000000
--- a/tests/general/weak_ptr.m
+++ /dev/null
@@ -1,166 +0,0 @@
-%
-% Test the RTS' weak pointer support.
-%
-% Running this with GC_PRINT_STATS=1 GC_PRINT_VERBOSE_STATS=1 in the
-% environment will show that this support is working.
-%
-
-% The output of this test is extreamly volatile.  It depends on the garbage
-% collector's state (which objects get collected when) which can depend on a
-% lot of other things.  Therefore we don't compare it's output with expected
-% output.  The best we can do is test that it exits cleanly.
-
-:- module weak_ptr.
-:- interface.
-:- import_module io.
-
-:- pred main(io::di, io::uo) is det.
-
-:- implementation.
-
-main(!IO) :-
-    test(!IO).
-
-:- pragma foreign_decl("C", local,
-"
-#include \"gc.mh\"
-
-struct list {
-    int             item;
-    struct list*    next;
-    MR_weak_ptr     prev;
-};
-
-typedef struct list list;
-
-static list* build_list(void);
-
-static void traverse_forwards(list* list);
-
-static void traverse_backwards(list* list);
-
-static list* get_tail(list* list);
-
-static list* drop(int n, list* list);
-").
-
-:- pragma foreign_code("C",
-"
-static list*
-build_list(void)
-{
-    list*   head;
-    list*   cur;
-    list*   prev;
-    int     i;
-
-    cur = MR_GC_malloc(sizeof(struct list));
-    cur->item = 0;
-    cur->next = NULL;
-    cur->prev = MR_NULL_WEAK_PTR;
-    prev = cur;
-    head = cur;
-
-    for (i = 1; i < 10000; i++) {
-        cur = MR_GC_malloc(sizeof(struct list));
-        cur->item = i;
-        cur->next = NULL;
-
-        prev->next = cur;
-        MR_new_weak_ptr(&(cur->prev), prev);
-
-        prev = cur;
-    }
-
-    /* Help the GC */
-    cur = NULL;
-    prev = NULL;
-
-    return head;
-}
-
-static void
-traverse_forwards(list* cur)
-{
-    printf(\"Forwards: \");
-
-    while (NULL != cur) {
-        printf(\"%d \", cur->item);
-        cur = cur->next;
-    }
-
-    printf(\"\\n\");
-}
-
-static void
-traverse_backwards(list* cur)
-{
-    printf(\"Backwards: \");
-
-    while (NULL != cur) {
-        printf(\"%d \", cur->item);
-        cur = MR_weak_ptr_read(&(cur->prev));
-    }
-
-    printf(\"\\n\");
-}
-
-static list*
-get_tail(list* cur)
-{
-    list *prev = NULL;
-
-    while (NULL != cur) {
-        prev = cur;
-        cur = cur->next;
-    }
-
-    return prev;
-}
-
-static list*
-drop(int n, list* cur)
-{
-    int i;
-
-    for (i = 0; (i < n) && (cur != NULL); i++) {
-        cur = cur->next;
-    }
-
-    return cur;
-}
-").
-
-:- pred test(io::di, io::uo) is det.
-
-:- pragma foreign_proc("C", test(_IO0::di, _IO::uo),
-    [will_not_throw_exception, thread_safe, promise_pure],
-    "
-        list*   list_head;
-        list*   list_tail;
-
-        ML_garbage_collect();
-
-        list_head = build_list();
-        ML_garbage_collect();
-
-        list_tail = get_tail(list_head);
-        traverse_forwards(list_head);
-        ML_garbage_collect();
-
-        traverse_backwards(list_tail);
-        ML_garbage_collect();
-
-        list_head = drop(9000, list_head);
-        ML_garbage_collect();
-        traverse_forwards(list_head);
-        traverse_backwards(list_tail);
-
-    ").
-
-test(!IO) :-
-    % We provide a weak_ptr.exp2 file so that the test passws in non C
-    % grades.  Java and C# provide their own weak pointer code that we do
-    % not need to test as part of the Mercury test suite.
-    io.write_string("Test not supported in this grade.\n", !IO).
-
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 12ff867..e65f9de 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -513,7 +513,8 @@ ifeq "$(filter il% csharp% java% erlang%,$(GRADE))" ""
 		foreign_type_assertion \
 		pragma_export \
 		runtime_opt \
-		target_mlobjs
+		target_mlobjs \
+        weak_ptr
 else
 	C_ONLY_PROGS =
 endif
@@ -883,6 +884,14 @@ tl_backjump_test.out: tl_backjump_test
 		exit 1; \
 	fi	
 
+# weak_ptr's output is extreamly volatile, it depends on Boehm GC's behavour
+# which can vary depending on many different things.  All we can hope to do
+# is check that it doesn't crash.
+
+weak_ptr.out: weak_ptr
+	./weak_ptr
+	echo "Output is not part of test, see Mmakefile" > $@
+
 #-----------------------------------------------------------------------------#
 
 dir_test.out: prepare_for_dir_test
diff --git a/tests/hard_coded/weak_ptr.exp b/tests/hard_coded/weak_ptr.exp
new file mode 100644
index 0000000..44d96fa
--- /dev/null
+++ b/tests/hard_coded/weak_ptr.exp
@@ -0,0 +1 @@
+Output is not part of test, see Mmakefile
diff --git a/tests/hard_coded/weak_ptr.m b/tests/hard_coded/weak_ptr.m
new file mode 100644
index 0000000..5e14320
--- /dev/null
+++ b/tests/hard_coded/weak_ptr.m
@@ -0,0 +1,166 @@
+%
+% Test the RTS' weak pointer support.
+%
+% Running this with GC_PRINT_STATS=1 GC_PRINT_VERBOSE_STATS=1 in the
+% environment will show that this support is working.
+%
+
+% The output of this test is extreamly volatile.  It depends on the garbage
+% collector's state (which objects get collected when) which can depend on a
+% lot of other things.  Therefore we don't compare it's output with expected
+% output.  The best we can do is test that it exits cleanly.
+
+:- module weak_ptr.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main(!IO) :-
+    test(!IO).
+
+:- pragma foreign_decl("C", local,
+"
+#include \"gc.mh\"
+
+struct list {
+    int             item;
+    struct list*    next;
+    MR_weak_ptr     prev;
+};
+
+typedef struct list list;
+
+static list* build_list(void);
+
+static void traverse_forwards(list* list);
+
+static void traverse_backwards(list* list);
+
+static list* get_tail(list* list);
+
+static list* drop(int n, list* list);
+").
+
+:- pragma foreign_code("C",
+"
+static list*
+build_list(void)
+{
+    list*   head;
+    list*   cur;
+    list*   prev;
+    int     i;
+
+    cur = MR_GC_malloc(sizeof(struct list));
+    cur->item = 0;
+    cur->next = NULL;
+    cur->prev = MR_NULL_WEAK_PTR;
+    prev = cur;
+    head = cur;
+
+    for (i = 1; i < 10000; i++) {
+        cur = MR_GC_malloc(sizeof(struct list));
+        cur->item = i;
+        cur->next = NULL;
+
+        prev->next = cur;
+        MR_new_weak_ptr(&(cur->prev), prev);
+
+        prev = cur;
+    }
+
+    /* Help the GC */
+    cur = NULL;
+    prev = NULL;
+
+    return head;
+}
+
+static void
+traverse_forwards(list* cur)
+{
+    printf(\"Forwards: \");
+
+    while (NULL != cur) {
+        printf(\"%d \", cur->item);
+        cur = cur->next;
+    }
+
+    printf(\"\\n\");
+}
+
+static void
+traverse_backwards(list* cur)
+{
+    printf(\"Backwards: \");
+
+    while (NULL != cur) {
+        printf(\"%d \", cur->item);
+        cur = MR_weak_ptr_read(&(cur->prev));
+    }
+
+    printf(\"\\n\");
+}
+
+static list*
+get_tail(list* cur)
+{
+    list *prev = NULL;
+
+    while (NULL != cur) {
+        prev = cur;
+        cur = cur->next;
+    }
+
+    return prev;
+}
+
+static list*
+drop(int n, list* cur)
+{
+    int i;
+
+    for (i = 0; (i < n) && (cur != NULL); i++) {
+        cur = cur->next;
+    }
+
+    return cur;
+}
+").
+
+:- pred test(io::di, io::uo) is det.
+
+:- pragma foreign_proc("C", test(_IO0::di, _IO::uo),
+    [will_not_throw_exception, thread_safe, promise_pure],
+    "
+        list*   list_head;
+        list*   list_tail;
+
+        ML_garbage_collect();
+
+        list_head = build_list();
+        ML_garbage_collect();
+
+        list_tail = get_tail(list_head);
+        traverse_forwards(list_head);
+        ML_garbage_collect();
+
+        traverse_backwards(list_tail);
+        ML_garbage_collect();
+
+        list_head = drop(9000, list_head);
+        ML_garbage_collect();
+        traverse_forwards(list_head);
+        traverse_backwards(list_tail);
+
+    ").
+
+test(!IO) :-
+    % We provide a weak_ptr.exp2 file so that the test passes in non C
+    % grades.  Java and C# provide their own weak pointer code that we do
+    % not need to test as part of the Mercury test suite.
+    io.write_string("Test not supported in this grade.\n", !IO).
+
-- 
2.0.0




More information about the reviews mailing list