[pypy-commit] pypy stm-gc: Tests tests tests... and found one missing "return; " :-)

arigo noreply at buildbot.pypy.org
Sun Apr 22 23:00:06 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54634:4aa01a6e557f
Date: 2012-04-22 22:51 +0200
http://bitbucket.org/pypy/pypy/changeset/4aa01a6e557f/

Log:	Tests tests tests... and found one missing "return;" :-)

diff --git a/pypy/translator/stm/src_stm/core.c b/pypy/translator/stm/src_stm/core.c
--- a/pypy/translator/stm/src_stm/core.c
+++ b/pypy/translator/stm/src_stm/core.c
@@ -550,6 +550,7 @@
         }
       d->num_commits++;
       common_cleanup(d);
+      return;
     }
 
   // bring that variable over to this CPU core (optimization, maybe)
diff --git a/pypy/translator/stm/src_stm/et.h b/pypy/translator/stm/src_stm/et.h
--- a/pypy/translator/stm/src_stm/et.h
+++ b/pypy/translator/stm/src_stm/et.h
@@ -49,14 +49,8 @@
 #endif
 
 
-void* stm_perform_transaction(void*(*)(void*, long), void*, void*);
 void stm_try_inevitable(STM_CCHARP1(why));
 void stm_abort_and_retry(void);
-long stm_debug_get_state(void);  /* -1: descriptor_init() was not called
-                                     0: not in a transaction
-                                     1: in a regular transaction
-                                     2: in an inevitable transaction */
-void _stm_activate_transaction(long);
 
 void stm_copy_transactional_to_raw(void *src, void *dst, long size);
 
diff --git a/pypy/translator/stm/test/test_stmgcintf.c b/pypy/translator/stm/test/test_stmgcintf.c
--- a/pypy/translator/stm/test/test_stmgcintf.c
+++ b/pypy/translator/stm/test/test_stmgcintf.c
@@ -1,3 +1,4 @@
+#include <stddef.h>
 
 #define PYPY_LONG_BIT   (sizeof(long) * 8)
 
@@ -13,6 +14,17 @@
     void (*callback)(void);
 };
 
+typedef struct {
+    struct pypy_header0 header;
+    char value1;
+    short value2;
+    int value4;
+    long long value8;
+    double value8f;
+    float value4f;
+    char last_16_bytes[16];
+} S1;
+
 typedef char bool_t;
 
 
@@ -59,7 +71,7 @@
         return NULL;
     }
     t->callback();
-    t->foobar = 81;
+    t->foobar = '.';
     return NULL;
 }
 void run_in_transaction(void(*cb)(void), int expected)
@@ -69,6 +81,7 @@
     cb_run_transaction = rt2;
     stm_run_all_transactions(&t, 1);
     assert(t.foobar == expected);
+
 }
 
 /************************************************************/
@@ -124,10 +137,10 @@
 
 void tldict_large(void)
 {
-    void *content[1024] = { 0 };
+    void *content[4096] = { 0 };
     int i;
     for (i=0; i<120000; i++) {
-        long key_index = rand() & 1023;
+        long key_index = rand() & 4095;
         void *a1 = (void *)(10000 + key_index * 8);
         void *a2 = stm_tldict_lookup(a1);
 
@@ -148,6 +161,189 @@
 
 /************************************************************/
 
+void enum_tldict_empty(void)
+{
+    stm_tldict_enum();
+}
+void test_enum_tldict_empty(void) {
+    run_in_transaction(enum_tldict_empty, '.'); }
+
+/************************************************************/
+
+int check_enum_1_found;
+void check_enum_1(void *tls, void *a, void *b)
+{
+    int n;
+    assert(tls == (void *)742);
+    if (a == (void *)0x4020 && b == (void *)10002)
+        n = 1;
+    else if (a == (void *)0x4028 && b == (void *)10004)
+        n = 2;
+    else
+        assert(!"unexpected a or b");
+    assert((check_enum_1_found & n) == 0);
+    check_enum_1_found |= n;
+}
+void enum_tldict_nonempty(void)
+{
+    void *a1 = (void *)0x4020;
+    void *a2 = (void *)10002;
+    void *a3 = (void *)0x4028;
+    void *a4 = (void *)10004;
+
+    stm_tldict_add(a1, a2);
+    stm_tldict_add(a3, a4);
+    cb_enum_callback = check_enum_1;
+    check_enum_1_found = 0;
+    stm_tldict_enum();
+    assert(check_enum_1_found == (1|2));
+    stm_abort_and_retry();
+}
+void test_enum_tldict_nonempty(void) {
+    run_in_transaction(enum_tldict_nonempty, 1); }
+
+/************************************************************/
+
+void test_read_main_thread(void)
+{
+    S1 s1;
+    int i;
+    for (i=0; i<2; i++) {
+        s1.header.h_tid = GCFLAG_GLOBAL | (i ? GCFLAG_WAS_COPIED : 0);
+        s1.header.h_version = NULL;
+        s1.value1 = 49;
+        s1.value2 = 3981;
+        s1.value4 = 4204229;
+        s1.value8 = 3419103092099219LL;
+        s1.value8f = 289.25;
+        s1.value4f = -5.5;
+
+        assert(stm_read_int1( &s1, offsetof(S1, value1 )) == 49);
+        assert(stm_read_int2( &s1, offsetof(S1, value2 )) == 3981);
+        assert(stm_read_int4( &s1, offsetof(S1, value4 )) == 4204229);
+        assert(stm_read_int8( &s1, offsetof(S1, value8))== 3419103092099219LL);
+        assert(stm_read_int8f(&s1, offsetof(S1, value8f)) == 289.25);
+        assert(stm_read_int4f(&s1, offsetof(S1, value4f)) == -5.5);
+    }
+}
+
+/************************************************************/
+
+void read_transaction(void)
+{
+    S1 s1, s2;
+    int i;
+    for (i=0; i<2; i++) {
+        s1.header.h_tid = GCFLAG_GLOBAL | (i ? GCFLAG_WAS_COPIED : 0);
+        s1.header.h_version = NULL;
+        s1.value1 = 49;
+        s1.value2 = 3981;
+        s1.value4 = 4204229;
+        s1.value8 = 3419103092099219LL;
+        s1.value8f = 289.25;
+        s1.value4f = -5.5;
+
+        assert(stm_read_int1( &s1, offsetof(S1, value1 )) == 49);
+        assert(stm_read_int2( &s1, offsetof(S1, value2 )) == 3981);
+        assert(stm_read_int4( &s1, offsetof(S1, value4 )) == 4204229);
+        assert(stm_read_int8( &s1, offsetof(S1, value8))== 3419103092099219LL);
+        assert(stm_read_int8f(&s1, offsetof(S1, value8f)) == 289.25);
+        assert(stm_read_int4f(&s1, offsetof(S1, value4f)) == -5.5);
+    }
+
+    s1.header.h_tid = GCFLAG_GLOBAL | GCFLAG_WAS_COPIED;
+    s1.header.h_version = NULL;
+    s2.header.h_tid = GCFLAG_WAS_COPIED;
+    s2.header.h_version = &s1;
+    s2.value1 = -49;
+    s2.value2 = -3981;
+    s2.value4 = -4204229;
+    s2.value8 = -3419103092099219LL;
+    s2.value8f = -289.25;
+    s2.value4f = 5.5;
+    stm_tldict_add(&s1, &s2);
+
+    assert(stm_read_int1( &s1, offsetof(S1, value1 )) == -49);
+    assert(stm_read_int2( &s1, offsetof(S1, value2 )) == -3981);
+    assert(stm_read_int4( &s1, offsetof(S1, value4 )) == -4204229);
+    assert(stm_read_int8( &s1, offsetof(S1, value8))  == -3419103092099219LL);
+    assert(stm_read_int8f(&s1, offsetof(S1, value8f)) == -289.25);
+    assert(stm_read_int4f(&s1, offsetof(S1, value4f)) == 5.5);
+    stm_abort_and_retry();
+}
+void test_read_transaction(void) { run_in_transaction(read_transaction, 1); }
+
+/************************************************************/
+
+int sg_seen = 0;
+S1 sg_global;
+void size_getter(void)
+{
+    S1 *s2 = malloc(sizeof(S1));
+    int i;
+    sg_global.header.h_tid = GCFLAG_GLOBAL | GCFLAG_WAS_COPIED;
+    sg_global.header.h_version = NULL;
+    s2->header.h_tid = GCFLAG_WAS_COPIED;
+    s2->header.h_version = &sg_global;
+    for (i=0; i<16; i++)
+        s2->last_16_bytes[i] = 'A' + i;
+    stm_tldict_add(&sg_global, s2);
+}
+long size_getter_cb(void *x)
+{
+    return offsetof(S1, last_16_bytes) + 15;
+}
+void test_size_getter(void)
+{
+    int i;
+    cb_getsize = size_getter_cb;
+    sg_global.last_16_bytes[15] = '!';
+    run_in_transaction(size_getter, '.');
+    for (i=0; i<15; i++)
+        assert(sg_global.last_16_bytes[i] == 'A' + i);
+    assert(sg_global.last_16_bytes[15] == '!');   /* not overwritten */
+}
+
+/************************************************************/
+
+void copy_transactional_to_raw(void)
+{
+    S1 s1, s2;
+    int i;
+    s1.header.h_tid = GCFLAG_GLOBAL | 99;
+    s1.header.h_version = NULL;
+    for (i=0; i<16; i++)
+        s1.last_16_bytes[i] = 'A' + i;
+    s2.header.h_tid = 101;
+    s2.last_16_bytes[15] = '!';
+    stm_copy_transactional_to_raw(&s1, &s2, offsetof(S1, last_16_bytes) + 15);
+    for (i=0; i<15; i++)
+        assert(s2.last_16_bytes[i] == 'A' + i);
+    assert(s2.last_16_bytes[15] == '!');   /* not overwritten */
+    assert(s2.header.h_tid = 101);         /* not overwritten */
+}
+void test_copy_transactional_to_raw(void) {
+    run_in_transaction(copy_transactional_to_raw, '.');
+}
+
+/************************************************************/
+
+void try_inevitable(void)
+{
+    assert(stm_in_transaction() == 1);
+    assert(stm_thread_id() != 0);
+    /* not really testing anything more than the presence of the function */
+    stm_try_inevitable(STM_EXPLAIN1("some explanation"));
+}
+void test_try_inevitable(void)
+{
+    assert(stm_in_transaction() == 0);
+    assert(stm_thread_id() == 0);
+    run_in_transaction(try_inevitable, '.');
+}
+
+/************************************************************/
+
 
 #define XTEST(name)  if (!strcmp(argv[1], #name)) { test_##name(); return 0; }
 
@@ -157,6 +353,13 @@
     XTEST(run_all_transactions);
     XTEST(tldict);
     XTEST(tldict_large);
+    XTEST(enum_tldict_empty);
+    XTEST(enum_tldict_nonempty);
+    XTEST(read_main_thread);
+    XTEST(read_transaction);
+    XTEST(size_getter);
+    XTEST(copy_transactional_to_raw);
+    XTEST(try_inevitable);
     printf("bad test name\n");
     return 1;
 }


More information about the pypy-commit mailing list