Changeset d83b266 for tests


Ignore:
Timestamp:
Jul 26, 2021, 2:42:34 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0a061c0
Parents:
c86ee4c (diff), 98233b3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
tests
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • tests/.expect/counter.txt

    rc86ee4c rd83b266  
    1 45
    2 42
     1inc 45
     2dec 42
  • tests/.expect/polymorphism.txt

    rc86ee4c rd83b266  
    11123 456 456
    225 5
     3=== checkPlan9offsets
     4static:
     5  offset of inner double: 8
     6  offset of inner float:  16
     7dynamic:
     8  offset of inner double: 8
     9  offset of inner float:  16
  • tests/.expect/rational.txt

    rc86ee4c rd83b266  
    11constructor
    2 3/1 4/1 0/1 0/1 1/1
    3 1/2 5/7
    4 2/3 -3/2
    5 -2/3 3/2
    6 logical
    7 -2/1 -3/2
    8 1
    9 1
    10 1
    11 0
    12 0
     2a : 3/1 b : 4/1 c : 0/1 d : 0/1 e : 1/1
     3a : 1/2 b : 5/7
     4a : 2/3 b : -3/2
     5a : -2/3 b : 3/2
     6
     7comparison
     8a : -2/1 b : -3/2
     9a == 0 : 0
     10a == 1 : 0
     11a != 0 : 1
     12! a : 0
     13a != b : 1
     14a <  b : 1
     15a <=  b : 1
     16a >  b : 0
     17a >=  b : 0
     18
    1319arithmetic
    14 -2/1 -3/2
    15 -7/2
    16 -1/2
    17 3/1
    18 4/3
     20a : -2/1 b : -3/2
     21a + b : -7/2
     22a += b : -7/2
     23++a : -5/2
     24a++ : -5/2
     25a : -3/2
     26a - b : 0/1
     27a -= b : 0/1
     28--a : -1/1
     29a-- : -1/1
     30a : -2/1
     31a * b : 3/1
     32a / b : 4/3
     33a \ 2 : 4/1 b \ 2 : 9/4
     34a \ -2 : 1/4 b \ -2 : 4/9
     35
    1936conversion
    20370.75
     
    24411/7
    2542355/113
    26 decompose
     43
    2744more tests
    2845-3/2
  • tests/Makefile.am

    rc86ee4c rd83b266  
    8282        concurrent/clib_tls.c \
    8383        exceptions/with-threads.hfa \
    84         exceptions/except-io.hfa
     84        exceptions/except-io.hfa \
     85        unified_locking/mutex_test.hfa
    8586
    8687dist-hook:
  • tests/counter.cfa

    rc86ee4c rd83b266  
    1010// Created On       : Thu Feb 22 15:27:00 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Nov  6 17:50:23 2018
    13 // Update Count     : 2
     12// Last Modified On : Tue Jul 20 21:25:30 2021
     13// Update Count     : 4
    1414//
     15
     16#include <fstream.hfa>
    1517
    1618// Tests unified increment/decrement builtin functions.
     
    1921struct counter { int x; };
    2022
    21 counter& ?+=?( counter& c, one_t ) { ++c.x; return c; }
    22 
    23 counter& ?-=?( counter& c, one_t ) { --c.x; return c; }
     23counter ?+=?( counter & c, one_t ) { ++c.x; return c; }
     24counter ?-=?( counter & c, one_t ) { --c.x; return c; }
    2425
    2526int main() {
     
    2829    ++c;
    2930    c++;
    30     printf("%d\n", c.x);
     31    sout | "inc" | c.x;
    3132    c -= 1;
    3233    --c;
    3334    c--;
    34     printf("%d\n", c.x);
     35    sout | "dec" | c.x;
    3536}
    3637
  • tests/polymorphism.cfa

    rc86ee4c rd83b266  
    5454        b.i = s.i;
    5555        return b.j;
     56}
     57
     58void checkPlan9offsets() {
     59
     60        forall( T )
     61        struct thing {
     62                T q;                // variable-sized padding
     63                inline double;
     64                inline float;
     65        };
     66
     67        #define SHOW_OFFSETS \
     68                double & x_inner_double = x; \
     69                float  & x_inner_float  = x; \
     70                printf("  offset of inner double: %ld\n", ((char *) & x_inner_double) - ((char *) & x) ); \
     71                printf("  offset of inner float:  %ld\n", ((char *) & x_inner_float ) - ((char *) & x) );
     72
     73        void showStatic( thing(long long int) & x ) {
     74                printf("static:\n");
     75                SHOW_OFFSETS
     76        }
     77
     78        forall( T )
     79        void showDynamic( thing(T) & x ) {
     80                printf("dynamic:\n");
     81                SHOW_OFFSETS
     82        }
     83
     84        #undef SHOW_OFFSETS
     85
     86        printf("=== checkPlan9offsets\n");
     87        thing(long long int) x;
     88        showStatic(x);
     89        showDynamic(x);
    5690}
    5791
     
    114148                assertf(ret == u.f2, "union operation fails in polymorphic context.");
    115149        }
     150
     151        checkPlan9offsets();
    116152}
    117153
  • tests/rational.cfa

    rc86ee4c rd83b266  
    1010// Created On       : Mon Mar 28 08:43:12 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb  8 18:46:23 2020
    13 // Update Count     : 86
     12// Last Modified On : Tue Jul 20 18:13:40 2021
     13// Update Count     : 107
    1414//
    1515
     
    2626        sout | "constructor";
    2727        RatInt a = { 3 }, b = { 4 }, c, d = 0, e = 1;
    28         sout | a | b | c | d | e;
     28        sout | "a : " | a | "b : " | b | "c : " | c | "d : " | d | "e : " | e;
    2929
    3030        a = (RatInt){ 4, 8 };
    3131        b = (RatInt){ 5, 7 };
    32         sout | a | b;
     32        sout | "a : " | a | "b : " | b;
    3333        a = (RatInt){ -2, -3 };
    3434        b = (RatInt){ 3, -2 };
    35         sout | a | b;
     35        sout | "a : " | a | "b : " | b;
    3636        a = (RatInt){ -2, 3 };
    3737        b = (RatInt){ 3, 2 };
    38         sout | a | b;
     38        sout | "a : " | a | "b : " | b;
     39        sout | nl;
    3940
    40         sout | "logical";
     41        sout | "comparison";
    4142        a = (RatInt){ -2 };
    4243        b = (RatInt){ -3, 2 };
    43         sout | a | b;
    44 //      sout | a == 1; // FIX ME
    45         sout | a != b;
    46         sout | a <  b;
    47         sout | a <= b;
    48         sout | a >  b;
    49         sout | a >= b;
     44        sout | "a : " | a | "b : " | b;
     45        sout | "a == 0 : " | a == (Rational(int)){0}; // FIX ME
     46        sout | "a == 1 : " | a == (Rational(int)){1}; // FIX ME
     47        sout | "a != 0 : " | a != 0;
     48        sout | "! a : " | ! a;
     49        sout | "a != b : " | a != b;
     50        sout | "a <  b : " | a <  b;
     51        sout | "a <=  b : " | a <= b;
     52        sout | "a >  b : " | a >  b;
     53        sout | "a >=  b : " | a >= b;
     54        sout | nl;
    5055
    5156        sout | "arithmetic";
    52         sout | a | b;
    53         sout | a + b;
    54         sout | a - b;
    55         sout | a * b;
    56         sout | a / b;
    57 //      sout | a \ 2 | b \ 2; // FIX ME
    58 //      sout | a \ -2 | b \ -2;
     57        sout | "a : " | a | "b : " | b;
     58        sout | "a + b : " | a + b;
     59        sout | "a += b : " | (a += b);
     60        sout | "++a : " | ++a;
     61        sout | "a++ : " | a++;
     62        sout | "a : " | a;
     63        sout | "a - b : " | a - b;
     64        sout | "a -= b : " | (a -= b);
     65        sout | "--a : " | --a;
     66        sout | "a-- : " | a--;
     67        sout | "a : " | a;
     68        sout | "a * b : " | a * b;
     69        sout | "a / b : " | a / b;
     70        sout | "a \\ 2 : " | a \ 2u | "b \\ 2 : " | b \ 2u;
     71        sout | "a \\ -2 : " | a \ -2 | "b \\ -2 : " | b \ -2;
     72        sout | nl;
    5973
    6074        sout | "conversion";
     
    6882        sout | narrow( 0.14285714285714, 16 );
    6983        sout | narrow( 3.14159265358979, 256 );
     84        sout | nl;
    7085
    71         sout | "decompose";
    72         int n, d;
    73 //      [n, d] = a;
    74 //      sout | a | n | d;
     86        // sout | "decompose";
     87        // int n, d;
     88        // [n, d] = a;
     89        // sout | a | n | d;
    7590
    7691        sout | "more tests";
  • tests/unified_locking/fast.cfa

    rc86ee4c rd83b266  
    1 #include <fstream.hfa>
    21#include <locks.hfa>
    3 #include <thread.hfa>
    42
    5 const unsigned int num_times = 50;
    6 
    7 struct MutexObj {
    8         fast_lock l;
    9         thread$ * id;
    10         uint32_t sum;
    11 };
    12 
    13 MutexObj mo;
    14 
    15 void trash() {
    16         unsigned t[100];
    17         for(i; 100) {
    18                 t[i] = 0xDEADBEEF;
    19         }
    20 }
    21 
    22 uint32_t cs() {
    23         thread$ * me = active_thread();
    24         uint32_t value;
    25         lock(mo.l);
    26         {
    27                 uint32_t tsum = mo.sum;
    28                 mo.id = me;
    29                 yield(random(5));
    30                 value = ((uint32_t)random()) ^ ((uint32_t)me);
    31                 if(mo.id != me) sout | "Intruder!";
    32                 mo.sum = tsum + value;
    33         }
    34         unlock(mo.l);
    35         return value;
    36 }
    37 
    38 thread LockCheck {
    39         uint32_t sum;
    40 };
    41 
    42 void main(LockCheck & this) {
    43         this.sum = 0;
    44         for(num_times) {
    45                 trash();
    46                 this.sum += cs();
    47                 trash();
    48                 yield(random(10));
    49         }
    50 }
     3#define LOCK fast_lock
     4#include "mutex_test.hfa"
    515
    526int main() {
    53         uint32_t sum = -32;
    54         mo.sum = -32;
    55         processor p[2];
    56         sout | "Starting";
    57         {
    58                 LockCheck checkers[13];
    59                 for(i;13) {
    60                         sum += join(checkers[i]).sum;
    61                 }
    62         }
    63         sout | "Done!";
    64         if(sum == mo.sum) sout | "Match!";
    65         else sout | "No Match!" | sum | "vs" | mo.sum;
     7    test();
    668}
  • tests/unified_locking/thread_test.cfa

    rc86ee4c rd83b266  
    88static unsigned int threadCount = 2;
    99static unsigned int lockCount = 1;
    10 static unsigned int num_times = 10000;
     10static unsigned int total_times = 320000;
     11static unsigned int num_times;
    1112static const int workBufferSize = 16;
    1213static unsigned int work_unlocked = 10000;
     
    2526thread worker {
    2627    linear_backoff_then_block_lock * locks;
     28    bool improved;
    2729};
    2830
    29 void ?{}( worker & w, linear_backoff_then_block_lock * locks ) {
     31void ?{}( worker & w, linear_backoff_then_block_lock * locks, bool improved ) {
    3032        w.locks = locks;
     33    w.improved = improved;
    3134}
    3235
    33 linear_backoff_then_block_lock norm_lock;
    3436
    3537void main( worker & this ) with(this) {
     
    3739    for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024;
    3840    unsigned int lck = rand() % lockCount;
    39     linear_backoff_then_block_lock * curr_lock = locks;//[lck];
     41    linear_backoff_then_block_lock * curr_lock = &locks[lck];
    4042    for (unsigned int i = 0; i < num_times; i++) {
    4143        dowork(buffer, work_unlocked);
    42         lock(*curr_lock);
    43         //printf("lock: %d %p ENTER\n", i, &curr_lock);
    44         //lock(norm_lock);
     44        if (improved) lock_improved(*curr_lock);
     45        else lock(*curr_lock);
    4546        dowork(buffer, work_locked);
    46         //printf("lock: %d %p LEAVE\n", i, &curr_lock);
    4747        unlock(*curr_lock);
    48         //unlock(norm_lock);
    4948        lck = rand() % lockCount;
    50         //curr_lock = locks[lck];
     49        curr_lock = &locks[lck];
    5150    }
    5251}
    5352
     53
    5454int main(int argc, char* argv[]) {
    5555    switch (argc) {
     56        case 7:
     57            work_unlocked = atoi(argv[5]);
     58        case 6:
     59            work_locked = atoi(argv[5]);
    5660        case 5:
    5761            num_times = atoi(argv[4]);
     
    6872    }
    6973        processor p[threadCount];
    70     linear_backoff_then_block_lock locks;//[lockCount];
    71     printf("lock allocation address: %p \n", &locks);
     74    linear_backoff_then_block_lock locks[lockCount];
    7275    worker * worker_arr[taskCount];
     76    num_times = total_times  / taskCount;
    7377
    74         printf("Start Test: martin lock simple\n");
     78        //printf("Start Test: martin lock simple\n");
    7579        clock_t begin = clock();
    7680        for (unsigned int i = 0; i < taskCount; i++) {
    77         worker_arr[i] = new( &locks );
     81        worker_arr[i] = new( locks, false );
    7882    }
    7983    for (unsigned int i = 0; i < taskCount; i++) {
    80         free( worker_arr[i] );
     84        delete( worker_arr[i] );
    8185    }
    8286        clock_t end = clock();
    8387        double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    84         printf("Done Test, time: %f\n", time_spent);
     88        printf("norm: %f\n", time_spent);
     89
     90    //printf("Start Test: martin lock improved\n");
     91        begin = clock();
     92        for (unsigned int i = 0; i < taskCount; i++) {
     93        worker_arr[i] = new( locks, true );
     94    }
     95    for (unsigned int i = 0; i < taskCount; i++) {
     96        delete( worker_arr[i] );
     97    }
     98        end = clock();
     99        time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
     100        printf("improved: %f\n", time_spent);
    85101}
Note: See TracChangeset for help on using the changeset viewer.