Changeset dfa4360


Ignore:
Timestamp:
Mar 5, 2020, 5:50:29 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
9306559f
Parents:
427854b
Message:

Added several tests for generators

Location:
tests
Files:
7 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • tests/concurrent/suspend_then.cfa

    r427854b rdfa4360  
    11#include <fstream.hfa>
    22#include <kernel.hfa>
    3 #include <monitor.hfa>
    43#include <thread.hfa>
    54#include <time.hfa>
     
    109#include "long_tests.hfa"
    1110
    12 #ifndef PREEMPTION_RATE
    13 #define PREEMPTION_RATE 10`ms
    14 #endif
    15 
    1611Duration default_preemption() {
    17         return PREEMPTION_RATE;
     12        return 0;
    1813}
    1914
     
    2621#if !defined(TEST_FOREVER)
    2722        static inline void print(const char * const text ) {
    28                 write( STDERR_FILENO, text, strlen(text) );
     23                write( STDOUT_FILENO, text, strlen(text) );
    2924        }
    3025#else
     
    3227#endif
    3328
    34 coroutine Coroutine {};
     29generator Coroutine { int i; };
    3530
    3631volatile bool done = false;
     
    4944
    5045void main(Coroutine& this) {
     46        this.i = 0;
    5147        suspend;
    52         for(int i = 0; TEST(i < N); i++) {
     48        for(;TEST(this.i < N); this.i++) {
    5349
    54                 print("C - Suspending");
     50                print("C - Suspending\n");
    5551                suspend{
    56                         print("C - Publishing");
     52                        print("C - Publishing\n");
    5753                        assert(!the_cor);
    5854                        store( this );
    5955                }
    6056                assert(!the_cor);
    61                 print("Coroutine 2");
     57                print("C - Back\n");
    6258                KICK_WATCHDOG;
    6359                yield();
     
    7672                if(!mine) continue;
    7773
    78                 print("T - took");
     74                print("T - took\n");
    7975                resume(*mine);
    80                 print("T - back");
    8176        }
    8277}
  • tests/coroutine/suspend_then.cfa

    r427854b rdfa4360  
    1515
    1616#include <fstream.hfa>
    17 #include <coroutine.hfa>
    1817
    19 void then() {
    20 
    21 }
    22 
    23 coroutine Fibonacci { int fn; };                                                // used for communication
     18generator Fibonacci {
     19        int fn;                                                                         // used for communication
     20        int fn1, fn2;                                                           // retained between resumes
     21};
    2422
    2523void main( Fibonacci & fib ) with( fib ) {                              // called on first resume
    26         int fn1, fn2;                                                           // retained between resumes
    2724        fn = 0;  fn1 = fn;                                                      // 1st case
    2825        suspend { sout | "Then!"; }                                             // restart last resume
Note: See TracChangeset for help on using the changeset viewer.