Changeset 4f9636f for src/tests


Ignore:
Timestamp:
May 5, 2017, 11:05:53 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
982ed5b, c10ee66
Parents:
45a4ea7 (diff), bd951f7 (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:/u/cforall/software/cfa/cfa-cc

Location:
src/tests
Files:
3 added
3 deleted
2 edited
3 moved

Legend:

Unmodified
Added
Removed
  • src/tests/Makefile.am

    r45a4ea7 r4f9636f  
    2222concurrent=yes
    2323quick_test+= coroutine thread monitor
    24 concurrent_test=coroutine thread monitor multi-monitor sched-int sched-int-multi sched-int-multi2 sched-ext sched-ext-multi preempt
     24concurrent_test=coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt
    2525else
    2626concurrent=no
  • src/tests/Makefile.in

    r45a4ea7 r4f9636f  
    230230@BUILD_CONCURRENCY_TRUE@concurrent = yes
    231231@BUILD_CONCURRENCY_FALSE@concurrent_test =
    232 @BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int sched-int-multi sched-int-multi2 sched-ext sched-ext-multi preempt
     232@BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt
    233233
    234234# applies to both programs
  • src/tests/sched-int-barge.c

    r45a4ea7 r4f9636f  
    22#include <kernel>
    33#include <monitor>
     4#include <stdlib>
    45#include <thread>
    56
     
    1213        int counter;
    1314        state_t state;
     15
     16        unsigned short do_signal;
     17        unsigned short do_wait2;
     18        unsigned short do_wait1;
    1419};
    1520
     
    1823        this->counter = 0;
    1924        this->state = BARGE;
     25
     26        this->do_signal = 6;
     27        this->do_wait1  = 1;
     28        this->do_wait2  = 3;
    2029}
    2130
     
    3342        c->counter++;
    3443
     44        if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
     45
    3546        int action = c->counter % 10;
    3647
    37         if( action == 1 || action == 3 ) {
    38                 if(c->state != BARGE) {
    39                         sout | "ERROR Mutual exclusion is inconsistent for wait" | endl;
    40                         abort();
    41                 }
     48        if( action == 0 ) {
     49                c->do_signal = max( ((unsigned)rand48()) % 10, 1);
     50                c->do_wait1 = ((unsigned)rand48()) % (c->do_signal);
     51                c->do_wait2 = ((unsigned)rand48()) % (c->do_signal);
    4252
     53                // if(c->do_wait1 == c->do_wait2) sout | "Same" | endl;
     54        }
     55
     56        if( action == c->do_wait1 || action == c->do_wait2 ) {
    4357                c->state = WAIT;
    4458                wait( &cond );
    4559
    4660                if(c->state != SIGNAL) {
    47                         sout | "ERROR Barging detected" | endl;
     61                        sout | "ERROR Barging detected" | c->counter | endl;
    4862                        abort();
    4963                }
    5064        }
    51         else if( action == 6 ) {
    52                 if(c->state != BARGE) {
    53                         sout | "ERROR Mutual exclusion is inconsistent for signal" | endl;
    54                         abort();
    55                 }
    56 
     65        else if( action == c->do_signal ) {
    5766                c->state = SIGNAL;
    5867
     
    6473        }
    6574
    66         if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
    67         if( c->counter == 100_000 ) c->done = true;
     75        if( c->counter >= 100_000 ) c->done = true;
    6876        return !c->done;
    6977}
     
    8290
    8391int main(int argc, char* argv[]) {
    84         processor p[3];
     92        rand48seed(0);
     93        processor p;
    8594        {
    86                 Threads t[20];
     95                Threads t[17];
    8796        }
    8897}
  • src/tests/sched-int-wait.c

    r45a4ea7 r4f9636f  
    22#include <kernel>
    33#include <monitor>
     4#include <stdlib>
    45#include <thread>
    56
     
    1213condition condAB, condAC, condBC, condABC;
    1314
    14 thread Signaler {};
     15thread Signaler {
     16        int signals[4];
     17};
     18
     19void ?{}( Signaler * this ){
     20        this->signals[0] = 0;
     21        this->signals[1] = 0;
     22        this->signals[2] = 0;
     23        this->signals[3] = 0;
     24}
     25
    1526thread WaiterAB {};
    1627thread WaiterAC {};
     
    1829thread WaiterABC{};
    1930
    20 int state;
    21 
    22 /*
    23 multi phase
    24 */
     31volatile bool done;
    2532
    2633//----------------------------------------------------------------------------------------------------
     
    3542
    3643void wait( condition * cond, global_t * mutex a, global_t * mutex b ) {
    37         state++;
    38         sout | "Waiting" | state | endl;
    3944        wait( cond );
    40         sout | "Waking" | state | endl;
    41         state--;
    4245}
    4346
    4447void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
    45         state++;
    46         sout | "Waiting" | state | endl;
    4748        wait( cond );
    48         sout | "Waking" | state | endl;
    49         state--;
    5049}
    5150
    5251//----------------------------------------------------------------------------------------------------
    5352// Signaler
    54 // signals respectively AB, AC, BC, ABC
    55 void signalerABC( global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
    56         sout | "Signaling ABC" | endl;
    57         signal( &condABC, a, b, c );
    58         sout | "Signaling AB" | endl;
    59         signal( &condAB , a, b );
    60         sout | "Signaling BC" | endl;
    61         signal( &condBC , b, c );
    62         sout | "Signaling AC" | endl;
    63         signal( &condAC , a, c );
    64 }
     53void main( Signaler* this ) {
    6554
    66 void signalerAB( global_t * mutex a, global_t * mutex b, global_t * c ) {
    67         signalerABC(a, b, c);
    68 }
     55        while( true ) {
     56                int action = (unsigned)rand48() % 4;
     57                bool finished = true;
    6958
    70 void signalerA( global_t * mutex a, global_t * b, global_t * c ) {
    71         signalerAB (a, b, c);
    72 }
     59                for(int i = 0; i < 4; i++) {
     60                        if( this->signals[action] < 10_000 ) {
     61                                finished = false;
     62                                break;
     63                        }
     64                        else {
     65                                action = (action + 1) % 4;
     66                        }
     67                }
    7368
    74 void main( Signaler* this ) {
    75         while( state != 4 ) { yield(); }
    76         signalerA( &globalA, &globalB, &globalC );
     69                this->signals[action]++;
     70                if( finished ) break;
     71
     72                //sout | action | this->signals[0] | this->signals[1] | this->signals[2] | this->signals[3] | endl;
     73
     74                switch( action ) {
     75                        case 0:
     76                                signal( &condABC, &globalA, &globalB, &globalC );
     77                                break;
     78                        case 1:
     79                                signal( &condAB , &globalA, &globalB );
     80                                break;
     81                        case 2:
     82                                signal( &condBC , &globalB, &globalC );
     83                                break;
     84                        case 3:
     85                                signal( &condAC , &globalA, &globalC );
     86                                break;
     87                        default:
     88                                sout | "Something went wrong" | endl;
     89                                abort();
     90                }
     91        }       
    7792}
    7893
     
    8095// Waiter ABC
    8196void main( WaiterABC* this ) {
    82         while( state != 0 ) { yield(); }
    83         wait( &condABC, &globalA, &globalB, &globalC );
     97        while( !done ) {
     98                wait( &condABC, &globalA, &globalB, &globalC );
     99        }
    84100}
    85101
     
    87103// Waiter AB
    88104void main( WaiterAB* this ) {
    89         while( state != 1 ) { yield(); }
    90         wait( &condAB , &globalA, &globalB );
     105        while( !done ) {
     106                wait( &condAB , &globalA, &globalB );
     107        }
    91108}
    92109
     
    94111// Waiter AC
    95112void main( WaiterAC* this ) {
    96         while( state != 2 ) { yield(); }
    97         wait( &condAC , &globalA, &globalC );
     113        while( !done ) {
     114                wait( &condAC , &globalA, &globalC );
     115        }
    98116}
    99117
     
    101119// Waiter BC
    102120void main( WaiterBC* this ) {
    103         while( state != 3 ) { yield(); }
    104         wait( &condBC , &globalB, &globalC );
     121        while( !done ) {
     122                wait( &condBC , &globalB, &globalC );
     123        }
    105124}
    106125
     
    108127// Main
    109128int main(int argc, char* argv[]) {
    110         state = 0;
     129        done = false;
    111130        processor p;
    112131        {
     
    115134                WaiterBC  c;
    116135                WaiterAC  d;
    117                 Signaler  e;
     136                {
     137                        Signaler  e;
     138                }
     139                done = true;
     140                signal( &condABC, &globalA, &globalB, &globalC );
     141                signal( &condAB , &globalA, &globalB );
     142                signal( &condBC , &globalB, &globalC );
     143                signal( &condAC , &globalA, &globalC );
    118144        }
    119145}
Note: See TracChangeset for help on using the changeset viewer.