Changeset b56ad5e for tests/concurrent


Ignore:
Timestamp:
Feb 4, 2022, 10:10:34 PM (4 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
f8143a6
Parents:
5f3ba11 (diff), 67e86ae6 (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/concurrent
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/.expect/ctor-check.txt

    r5f3ba11 rb56ad5e  
    22?{}: function
    33... with parameters
    4   lvalue reference to instance of struct Empty with body
     4  this: lvalue reference to instance of struct Empty with body
    55... returning nothing
    66 with body
  • tests/concurrent/mutexstmt/.expect/locks.txt

    r5f3ba11 rb56ad5e  
    33Start Test: multi lock deadlock/mutual exclusion
    44End Test: multi lock deadlock/mutual exclusion
     5Start Test: single scoped lock mutual exclusion
     6End Test: single scoped lock mutual exclusion
     7Start Test: multi scoped lock deadlock/mutual exclusion
     8End Test: multi scoped lock deadlock/mutual exclusion
  • tests/concurrent/mutexstmt/locks.cfa

    r5f3ba11 rb56ad5e  
    5959}
    6060
     61thread T_Mutex_Scoped {};
    6162
     63void main( T_Mutex_Scoped & this ) {
     64        for (unsigned int i = 0; i < num_times; i++) {
     65                {
     66                        scoped_lock(single_acquisition_lock) s{m1};
     67                        count++;
     68                }
     69                {
     70                        scoped_lock(single_acquisition_lock) s{m1};
     71                        assert(!insideFlag);
     72                        insideFlag = true;
     73                        assert(insideFlag);
     74                        insideFlag = false;
     75                }
     76        }
     77}
     78
     79thread T_Multi_Scoped {};
     80
     81void main( T_Multi_Scoped & this ) {
     82        for (unsigned int i = 0; i < num_times; i++) {
     83                {
     84                        scoped_lock(single_acquisition_lock) s{m1};
     85                        assert(!insideFlag);
     86                        insideFlag = true;
     87                        assert(insideFlag);
     88                        insideFlag = false;
     89                }
     90                {
     91                        scoped_lock(single_acquisition_lock) s1{m1};
     92                        scoped_lock(single_acquisition_lock) s2{m2};
     93                        scoped_lock(single_acquisition_lock) s3{m3};
     94                        scoped_lock(single_acquisition_lock) s4{m4};
     95                        scoped_lock(single_acquisition_lock) s5{m5};
     96                        assert(!insideFlag);
     97                        insideFlag = true;
     98                        assert(insideFlag);
     99                        insideFlag = false;
     100                }
     101                {
     102                        scoped_lock(single_acquisition_lock) s1{m1};
     103                        scoped_lock(single_acquisition_lock) s3{m3};
     104                        assert(!insideFlag);
     105                        insideFlag = true;
     106                        assert(insideFlag);
     107                        insideFlag = false;
     108                }
     109                {
     110                        scoped_lock(single_acquisition_lock) s1{m1};
     111                        scoped_lock(single_acquisition_lock) s2{m2};
     112                        scoped_lock(single_acquisition_lock) s4{m4};
     113                        assert(!insideFlag);
     114                        insideFlag = true;
     115                        assert(insideFlag);
     116                        insideFlag = false;
     117                }
     118                {
     119                        scoped_lock(single_acquisition_lock) s1{m1};
     120                        scoped_lock(single_acquisition_lock) s3{m3};
     121                        scoped_lock(single_acquisition_lock) s4{m4};
     122                        scoped_lock(single_acquisition_lock) s5{m5};
     123                        assert(!insideFlag);
     124                        insideFlag = true;
     125                        assert(insideFlag);
     126                        insideFlag = false;
     127                }
     128        }
     129}
     130
     131int num_tasks = 10;
    62132int main() {
    63133        processor p[10];
     
    67137                T_Mutex t[10];
    68138        }
     139        assert(count == num_tasks * num_times);
    69140        printf("End Test: single lock mutual exclusion\n");
    70141        printf("Start Test: multi lock deadlock/mutual exclusion\n");
     
    73144        }
    74145        printf("End Test: multi lock deadlock/mutual exclusion\n");
     146       
     147        count = 0;
     148        printf("Start Test: single scoped lock mutual exclusion\n");
     149        {
     150                T_Mutex_Scoped t[10];
     151        }
     152        assert(count == num_tasks * num_times);
     153        printf("End Test: single scoped lock mutual exclusion\n");
     154        printf("Start Test: multi scoped lock deadlock/mutual exclusion\n");
     155        {
     156                T_Multi_Scoped t[10];
     157        }
     158        printf("End Test: multi scoped lock deadlock/mutual exclusion\n");     
    75159}
  • tests/concurrent/preempt.cfa

    r5f3ba11 rb56ad5e  
     1#include <clock.hfa>
    12#include <fstream.hfa>
    23#include <kernel.hfa>
     
    2223extern void __cfaabi_check_preemption();
    2324
    24 static volatile int counter = 0;
     25static struct {
     26        volatile int counter;
     27        volatile Time prev;
     28        Duration durations[6];
     29} globals;
    2530
    2631thread worker_t {
    2732        int value;
    28         unsigned spin;
     33        unsigned long long spin;
    2934};
    3035
     
    3540
    3641void main(worker_t & this) {
    37         while(TEST(counter < N)) {
    38                 if(this.spin > 100_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")";
     42        while(TEST(globals.counter < N)) {
     43                if(this.spin > 50_000_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")";
    3944                __cfaabi_check_preemption();
    40                 if( (counter % 7) == this.value ) {
     45                if( (globals.counter % 7) == this.value ) {
    4146                        __cfaabi_check_preemption();
    42                         int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
     47                        #if !defined(TEST_LONG)
     48                                Time now = timeHiRes();
     49                                Duration diff = now - globals.prev;
     50                                globals.prev = now;
     51                        #endif
     52                        int next = __atomic_add_fetch( &globals.counter, 1, __ATOMIC_SEQ_CST );
    4353                        __cfaabi_check_preemption();
    44                         if( (next % 100) == 0 ) printf("%d\n", (int)next);
     54                        if( (next % 100) == 0 ) {
     55                                #if !defined(TEST_LONG)
     56                                        unsigned idx = next / 100;
     57                                        if (idx >= 6) abort | "Idx from next is invalid: " | idx | "vs" | next;
     58                                        globals.durations[idx] = diff;
     59                                        if(diff > 12`s) serr | "Duration suspiciously large:" | diff;
     60                                #endif
     61                                printf("%d\n", (int)next);
     62
     63                        }
    4564                        __cfaabi_check_preemption();
    4665                        this.spin = 0;
     
    5473int main(int argc, char* argv[]) {
    5574        processor p;
     75        globals.counter = 0;
     76        globals.durations[0] = 0;
     77        globals.durations[1] = 0;
     78        globals.durations[2] = 0;
     79        globals.durations[3] = 0;
     80        globals.durations[4] = 0;
     81        globals.durations[5] = 0;
    5682        {
     83                globals.prev = timeHiRes();
    5784                worker_t w0 = 0;
    5885                worker_t w1 = 1;
Note: See TracChangeset for help on using the changeset viewer.