lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [10/14] lucy-clownfish git commit: Test idempotence of bootstrap process
Date Sat, 19 Mar 2016 17:27:20 GMT
Test idempotence of bootstrap process


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/7cc75eb8
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/7cc75eb8
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/7cc75eb8

Branch: refs/heads/master
Commit: 7cc75eb8dd53bb63966170629ec66cdbc62e7d34
Parents: 25f58a6
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Thu Mar 10 20:05:20 2016 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Thu Mar 10 21:49:25 2016 +0100

----------------------------------------------------------------------
 compiler/src/CFCBindCore.c                | 10 +--
 runtime/core/Clownfish/Test.c             |  2 +
 runtime/core/Clownfish/Test/TestClass.c   | 93 ++++++++++++++++++++++++++
 runtime/core/Clownfish/Test/TestClass.cfh | 28 ++++++++
 runtime/perl/t/core/010-class.t           | 23 +++++++
 5 files changed, 151 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7cc75eb8/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index 4b2d3c6..7d43415 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -362,7 +362,7 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
         "\n"
         "%s" // Extra definitions.
         "%sVISIBLE void\n"
-        "%sbootstrap_internal(void);\n"
+        "%sbootstrap_internal(int force);\n"
         "\n"
         "%sVISIBLE void\n"
         "%sbootstrap_parcel(void);\n"
@@ -444,7 +444,7 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
     for (size_t i = 0; prereq_parcels[i]; ++i) {
         const char *prereq_prefix = CFCParcel_get_prefix(prereq_parcels[i]);
         prereq_bootstrap = CFCUtil_cat(prereq_bootstrap, "    ", prereq_prefix,
-                                       "bootstrap_internal();\n", NULL);
+                                       "bootstrap_internal(0);\n", NULL);
     }
     FREEMEM(prereq_parcels);
 
@@ -473,9 +473,9 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
         "%s" // spec_init_func
         "\n"
         "void\n"
-        "%sbootstrap_internal() {\n"
+        "%sbootstrap_internal(int force) {\n"
         "    static int bootstrapped = 0;\n"
-        "    if (bootstrapped) { return; }\n"
+        "    if (bootstrapped && !force) { return; }\n"
         "    S_bootstrap_specs();\n"
         "    %sinit_parcel();\n"
         "    bootstrapped = 1;\n"
@@ -484,7 +484,7 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
         "void\n"
         "%sbootstrap_parcel() {\n"
         "%s" // Bootstrap prerequisite parcels.
-        "    %sbootstrap_internal();\n"
+        "    %sbootstrap_internal(0);\n"
         "}\n"
         "\n"
         "%s\n";

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7cc75eb8/runtime/core/Clownfish/Test.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test.c b/runtime/core/Clownfish/Test.c
index 9f03448..a275b0c 100644
--- a/runtime/core/Clownfish/Test.c
+++ b/runtime/core/Clownfish/Test.c
@@ -26,6 +26,7 @@
 #include "Clownfish/Test/TestByteBuf.h"
 #include "Clownfish/Test/TestString.h"
 #include "Clownfish/Test/TestCharBuf.h"
+#include "Clownfish/Test/TestClass.h"
 #include "Clownfish/Test/TestErr.h"
 #include "Clownfish/Test/TestHash.h"
 #include "Clownfish/Test/TestHashIterator.h"
@@ -41,6 +42,7 @@ TestSuite*
 Test_create_test_suite() {
     TestSuite *suite = TestSuite_new();
 
+    TestSuite_Add_Batch(suite, (TestBatch*)TestClass_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestVector_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestHash_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestHashIterator_new());

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7cc75eb8/runtime/core/Clownfish/Test/TestClass.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestClass.c b/runtime/core/Clownfish/Test/TestClass.c
new file mode 100644
index 0000000..fc16a90
--- /dev/null
+++ b/runtime/core/Clownfish/Test/TestClass.c
@@ -0,0 +1,93 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+
+#define C_CFISH_BOOLEAN
+#define C_CFISH_CLASS
+#define CFISH_USE_SHORT_NAMES
+#define TESTCFISH_USE_SHORT_NAMES
+
+#include "charmony.h"
+
+#include <string.h>
+
+#include "Clownfish/Test/TestClass.h"
+
+#include "Clownfish/Boolean.h"
+#include "Clownfish/Class.h"
+#include "Clownfish/TestHarness/TestBatchRunner.h"
+#include "Clownfish/Util/Memory.h"
+
+TestClass*
+TestClass_new() {
+    return (TestClass*)Class_Make_Obj(TESTCLASS);
+}
+
+#if DEBUG_CLASS_CONTENTS
+
+#include <stdio.h>
+
+static void
+S_memdump(void *vptr, size_t size) {
+    unsigned char *ptr = (unsigned char*)vptr;
+    for (size_t i = 0; i < size; i++) {
+        printf("%02X ", ptr[i]);
+    }
+    printf("\n");
+}
+
+#endif /* DEBUG_CLASS_CONTENTS */
+
+static void
+test_bootstrap_idempotence(TestBatchRunner *runner) {
+    Class    *bool_class        = BOOLEAN;
+    uint32_t  bool_class_size   = BOOLEAN->class_alloc_size;
+    uint32_t  bool_ivars_offset = cfish_Bool_IVARS_OFFSET;
+    Boolean  *true_singleton    = Bool_true_singleton;
+
+    char *bool_class_contents = (char*)MALLOCATE(bool_class_size);
+    memcpy(bool_class_contents, BOOLEAN, bool_class_size);
+
+    // Force another bootstrap run.
+    cfish_bootstrap_internal(1);
+
+#if DEBUG_CLASS_CONTENTS
+    printf("Before\n");
+    S_memdump(bool_class_contents, bool_class_size);
+    printf("After\n");
+    S_memdump(BOOLEAN, bool_class_size);
+#endif
+
+    TEST_TRUE(runner, bool_class == BOOLEAN,
+              "Boolean class pointer unchanged");
+    TEST_TRUE(runner,
+              memcmp(bool_class_contents, BOOLEAN, bool_class_size) == 0,
+              "Boolean class unchanged");
+    TEST_TRUE(runner, bool_ivars_offset == cfish_Bool_IVARS_OFFSET,
+              "Boolean ivars offset unchanged");
+    TEST_TRUE(runner, true_singleton == Bool_true_singleton,
+              "Boolean singleton unchanged");
+
+    FREEMEM(bool_class_contents);
+}
+
+void
+TestClass_Run_IMP(TestClass *self, TestBatchRunner *runner) {
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 4);
+    test_bootstrap_idempotence(runner);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7cc75eb8/runtime/core/Clownfish/Test/TestClass.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestClass.cfh b/runtime/core/Clownfish/Test/TestClass.cfh
new file mode 100644
index 0000000..615c34e
--- /dev/null
+++ b/runtime/core/Clownfish/Test/TestClass.cfh
@@ -0,0 +1,28 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel TestClownfish;
+
+class Clownfish::Test::TestClass
+    inherits Clownfish::TestHarness::TestBatch {
+
+    inert incremented TestClass*
+    new();
+
+    void
+    Run(TestClass *self, TestBatchRunner *runner);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7cc75eb8/runtime/perl/t/core/010-class.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/core/010-class.t b/runtime/perl/t/core/010-class.t
new file mode 100644
index 0000000..4577941
--- /dev/null
+++ b/runtime/perl/t/core/010-class.t
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+
+use Clownfish::Test;
+my $success = Clownfish::Test::run_tests("Clownfish::Test::TestClass");
+
+exit($success ? 0 : 1);
+


Mime
View raw message