summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests/lleventcoro_test.cpp
blob: a459d17fb8b58b2692bf731910eb204116ab8495 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
/**
 * @file   coroutine_test.cpp
 * @author Nat Goodspeed
 * @date   2009-04-22
 * @brief  Test for coroutine.
 * 
 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

/*****************************************************************************/
//  test<1>() is cloned from a Boost.Coroutine example program whose copyright
//  info is reproduced here:
/*---------------------------------------------------------------------------*/
//  Copyright (c) 2006, Giovanni P. Deretta
//
//  This code may be used under either of the following two licences:
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy 
//  of this software and associated documentation files (the "Software"), to deal 
//  in the Software without restriction, including without limitation the rights 
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
//  copies of the Software, and to permit persons to whom the Software is 
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in 
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
//  THE SOFTWARE. OF SUCH DAMAGE.
//
//  Or:
//
//  Distributed under the Boost Software License, Version 1.0.
//  (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
/*****************************************************************************/

#define BOOST_RESULT_OF_USE_TR1 1
// On some platforms, Boost.Coroutine must #define magic symbols before
// #including platform-API headers. Naturally, that's ineffective unless the
// Boost.Coroutine #include is the *first* #include of the platform header.
// That means that client code must generally #include Boost.Coroutine headers
// before anything else.
#include <boost/dcoroutine/coroutine.hpp>
#include <boost/bind.hpp>
#include <boost/range.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>

#include "linden_common.h"

#include <iostream>
#include <string>

#include "../test/lltut.h"
#include "llsd.h"
#include "llsdutil.h"
#include "llevents.h"
#include "tests/wrapllerrs.h"
#include "stringize.h"
#include "llcoros.h"
#include "lleventcoro.h"
#include "../test/debug.h"

using namespace llcoro;

/*****************************************************************************
*   from the banana.cpp example program borrowed for test<1>()
*****************************************************************************/
namespace coroutines = boost::dcoroutines;
using coroutines::coroutine;

template<typename Iter>
bool match(Iter first, Iter last, std::string match) {
  std::string::iterator i = match.begin();
  for(; (first != last) && (i != match.end()); ++i) {
    if (*first != *i)
      return false;
    ++first;
  }
  return i == match.end();
}

template<typename BidirectionalIterator> 
BidirectionalIterator 
match_substring(BidirectionalIterator begin, 
		BidirectionalIterator end, 
		std::string xmatch,
		BOOST_DEDUCED_TYPENAME coroutine<BidirectionalIterator(void)>::self& self) { 
//BidirectionalIterator begin_ = begin;
  for(; begin != end; ++begin) 
    if(match(begin, end, xmatch)) {
      self.yield(begin);
    }
  return end;
} 

typedef coroutine<std::string::iterator(void)> match_coroutine_type;

/*****************************************************************************
*   Test helpers
*****************************************************************************/
/// Simulate an event API whose response is immediate: sent on receipt of the
/// initial request, rather than after some delay. This is the case that
/// distinguishes postAndSuspend() from calling post(), then calling
/// suspendUntilEventOn().
class ImmediateAPI
{
public:
    ImmediateAPI():
        mPump("immediate", true)
    {
        mPump.listen("API", boost::bind(&ImmediateAPI::operator(), this, _1));
    }

    LLEventPump& getPump() { return mPump; }

    // Invoke this with an LLSD map containing:
    // ["value"]: Integer value. We will reply with ["value"] + 1.
    // ["reply"]: Name of LLEventPump on which to send success response.
    // ["error"]: Name of LLEventPump on which to send error response.
    // ["fail"]: Presence of this key selects ["error"], else ["success"] as
    // the name of the pump on which to send the response.
    bool operator()(const LLSD& event) const
    {
        LLSD::Integer value(event["value"]);
        LLSD::String replyPumpName(event.has("fail")? "error" : "reply");
        LLEventPumps::instance().obtain(event[replyPumpName]).post(value + 1);
        return false;
    }

private:
    LLEventStream mPump;
};

/*****************************************************************************
*   TUT
*****************************************************************************/
namespace tut
{
    struct coroutine_data {};
    typedef test_group<coroutine_data> coroutine_group;
    typedef coroutine_group::object object;
    coroutine_group coroutinegrp("coroutine");

    template<> template<>
    void object::test<1>()
    {
        set_test_name("From banana.cpp example program in Boost.Coroutine distro");
        std::string buffer = "banananana"; 
        std::string match = "nana"; 
        std::string::iterator begin = buffer.begin();
        std::string::iterator end = buffer.end();

#if defined(BOOST_CORO_POSIX_IMPL)
//      std::cout << "Using Boost.Coroutine " << BOOST_CORO_POSIX_IMPL << '\n';
#else
//      std::cout << "Using non-Posix Boost.Coroutine implementation" << std::endl;
#endif

        typedef std::string::iterator signature(std::string::iterator, 
                                                std::string::iterator, 
                                                std::string,
                                                match_coroutine_type::self&);

        coroutine<std::string::iterator(void)> matcher
            (boost::bind(static_cast<signature*>(match_substring), 
                         begin, 
                         end, 
                         match, 
                         _1)); 

        std::string::iterator i = matcher();
/*==========================================================================*|
        while(matcher && i != buffer.end()) {
            std::cout <<"Match at: "<< std::distance(buffer.begin(), i)<<'\n'; 
            i = matcher();
        }
|*==========================================================================*/
        size_t matches[] = { 2, 4, 6 };
        for (size_t *mi(boost::begin(matches)), *mend(boost::end(matches));
             mi != mend; ++mi, i = matcher())
        {
            ensure("more", matcher);
            ensure("found", i != buffer.end());
            ensure_equals("value", std::distance(buffer.begin(), i), *mi);
        }
        ensure("done", ! matcher);
    }

    // use static data so we can intersperse coroutine functions with the
    // tests that engage them
    ImmediateAPI immediateAPI;
    std::string replyName, errorName, threw, stringdata;
    LLSD result, errordata;
    int which;

    // reinit vars at the start of each test
    void clear()
    {
        replyName.clear();
        errorName.clear();
        threw.clear();
        stringdata.clear();
        result = LLSD();
        errordata = LLSD();
        which = 0;
    }

    void explicit_wait(boost::shared_ptr<LLCoros::Future<std::string>::callback_t>& cbp)
    {
        BEGIN
        {
            // The point of this test is to verify / illustrate suspending a
            // coroutine for something other than an LLEventPump. In other
            // words, this shows how to adapt to any async operation that
            // provides a callback-style notification (and prove that it
            // works).

            LLCoros::Future<std::string> future;
            // get the callback from that future
            LLCoros::Future<std::string>::callback_t callback(future.make_callback());

            // Perhaps we would send a request to a remote server and arrange
            // for 'callback' to be called on response. Of course that might
            // involve an adapter object from the actual callback signature to
            // the signature of 'callback' -- in this case, void(std::string).
            // For test purposes, instead of handing 'callback' (or the
            // adapter) off to some I/O subsystem, we'll just pass it back to
            // our caller.
            cbp.reset(new LLCoros::Future<std::string>::callback_t(callback));

            ensure("Not yet", ! future);
            // calling get() on the future causes us to suspend
            debug("about to suspend");
            stringdata = future.get();
            ensure("Got it", bool(future));
        }
        END
    }

    template<> template<>
    void object::test<2>()
    {
        clear();
        set_test_name("explicit_wait");
        DEBUG;

        // Construct the coroutine instance that will run explicit_wait.
        boost::shared_ptr<LLCoros::Future<std::string>::callback_t> respond;
        LLCoros::instance().launch("test<2>",
                                   boost::bind(explicit_wait, boost::ref(respond)));
        // When the coroutine waits for the future, it returns here.
        debug("about to respond");
        // Now we're the I/O subsystem delivering a result. This immediately
        // transfers control back to the coroutine.
        (*respond)("received");
        // ensure the coroutine ran and woke up again with the intended result
        ensure_equals(stringdata, "received");
    }

    void waitForEventOn1()
    {
        BEGIN
        {
            result = suspendUntilEventOn("source");
        }
        END
    }

    template<> template<>
    void object::test<3>()
    {
        clear();
        set_test_name("waitForEventOn1");
        DEBUG;
        LLCoros::instance().launch("test<3>", waitForEventOn1);
        debug("about to send");
        LLEventPumps::instance().obtain("source").post("received");
        debug("back from send");
        ensure_equals(result.asString(), "received");
    }

    void waitForEventOn2()
    {
        BEGIN
        {
            LLEventWithID pair = suspendUntilEventOn("reply", "error");
            result = pair.first;
            which  = pair.second;
            debug(STRINGIZE("result = " << result << ", which = " << which));
        }
        END
    }

    template<> template<>
    void object::test<4>()
    {
        clear();
        set_test_name("waitForEventOn2 reply");
        {
        DEBUG;
        LLCoros::instance().launch("test<4>", waitForEventOn2);
        debug("about to send");
        LLEventPumps::instance().obtain("reply").post("received");
        debug("back from send");
        }
        ensure_equals(result.asString(), "received");
        ensure_equals("which pump", which, 0);
    }

    template<> template<>
    void object::test<5>()
    {
        clear();
        set_test_name("waitForEventOn2 error");
        DEBUG;
        LLCoros::instance().launch("test<5>", waitForEventOn2);
        debug("about to send");
        LLEventPumps::instance().obtain("error").post("badness");
        debug("back from send");
        ensure_equals(result.asString(), "badness");
        ensure_equals("which pump", which, 1);
    }

    void coroPump()
    {
        BEGIN
        {
            LLCoroEventPump waiter;
            replyName = waiter.getName();
            result = waiter.suspend();
        }
        END
    }

    template<> template<>
    void object::test<6>()
    {
        clear();
        set_test_name("coroPump");
        DEBUG;
        LLCoros::instance().launch("test<6>", coroPump);
        debug("about to send");
        LLEventPumps::instance().obtain(replyName).post("received");
        debug("back from send");
        ensure_equals(result.asString(), "received");
    }

    void coroPumps()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            replyName = waiter.getName0();
            errorName = waiter.getName1();
            LLEventWithID pair(waiter.suspend());
            result = pair.first;
            which  = pair.second;
        }
        END
    }

    template<> template<>
    void object::test<7>()
    {
        clear();
        set_test_name("coroPumps reply");
        DEBUG;
        LLCoros::instance().launch("test<7>", coroPumps);
        debug("about to send");
        LLEventPumps::instance().obtain(replyName).post("received");
        debug("back from send");
        ensure_equals(result.asString(), "received");
        ensure_equals("which pump", which, 0);
    }

    template<> template<>
    void object::test<8>()
    {
        clear();
        set_test_name("coroPumps error");
        DEBUG;
        LLCoros::instance().launch("test<8>", coroPumps);
        debug("about to send");
        LLEventPumps::instance().obtain(errorName).post("badness");
        debug("back from send");
        ensure_equals(result.asString(), "badness");
        ensure_equals("which pump", which, 1);
    }

    void coroPumpsNoEx()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            replyName = waiter.getName0();
            errorName = waiter.getName1();
            result = waiter.suspendWithException();
        }
        END
    }

    template<> template<>
    void object::test<9>()
    {
        clear();
        set_test_name("coroPumpsNoEx");
        DEBUG;
        LLCoros::instance().launch("test<9>", coroPumpsNoEx);
        debug("about to send");
        LLEventPumps::instance().obtain(replyName).post("received");
        debug("back from send");
        ensure_equals(result.asString(), "received");
    }

    void coroPumpsEx()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            replyName = waiter.getName0();
            errorName = waiter.getName1();
            try
            {
                result = waiter.suspendWithException();
                debug("no exception");
            }
            catch (const LLErrorEvent& e)
            {
                debug(STRINGIZE("exception " << e.what()));
                errordata = e.getData();
            }
        }
        END
    }

    template<> template<>
    void object::test<10>()
    {
        clear();
        set_test_name("coroPumpsEx");
        DEBUG;
        LLCoros::instance().launch("test<10>", coroPumpsEx);
        debug("about to send");
        LLEventPumps::instance().obtain(errorName).post("badness");
        debug("back from send");
        ensure("no result", result.isUndefined());
        ensure_equals("got error", errordata.asString(), "badness");
    }

    void coroPumpsNoLog()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            replyName = waiter.getName0();
            errorName = waiter.getName1();
            result = waiter.suspendWithLog();
        }
        END
    }

    template<> template<>
    void object::test<11>()
    {
        clear();
        set_test_name("coroPumpsNoLog");
        DEBUG;
        LLCoros::instance().launch("test<11>", coroPumpsNoLog);
        debug("about to send");
        LLEventPumps::instance().obtain(replyName).post("received");
        debug("back from send");
        ensure_equals(result.asString(), "received");
    }

    void coroPumpsLog()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            replyName = waiter.getName0();
            errorName = waiter.getName1();
            WrapLLErrs capture;
            try
            {
                result = waiter.suspendWithLog();
                debug("no exception");
            }
            catch (const WrapLLErrs::FatalException& e)
            {
                debug(STRINGIZE("exception " << e.what()));
                threw = e.what();
            }
        }
        END
    }

    template<> template<>
    void object::test<12>()
    {
        clear();
        set_test_name("coroPumpsLog");
        DEBUG;
        LLCoros::instance().launch("test<12>", coroPumpsLog);
        debug("about to send");
        LLEventPumps::instance().obtain(errorName).post("badness");
        debug("back from send");
        ensure("no result", result.isUndefined());
        ensure_contains("got error", threw, "badness");
    }

    void postAndWait1()
    {
        BEGIN
        {
            result = postAndSuspend(LLSDMap("value", 17),       // request event
                                 immediateAPI.getPump(),     // requestPump
                                 "reply1",                   // replyPump
                                 "reply");                   // request["reply"] = name
        }
        END
    }

    template<> template<>
    void object::test<13>()
    {
        clear();
        set_test_name("postAndWait1");
        DEBUG;
        LLCoros::instance().launch("test<13>", postAndWait1);
        ensure_equals(result.asInteger(), 18);
    }

    void postAndWait2()
    {
        BEGIN
        {
            LLEventWithID pair = ::postAndSuspend2(LLSDMap("value", 18),
                                                immediateAPI.getPump(),
                                                "reply2",
                                                "error2",
                                                "reply",
                                                "error");
            result = pair.first;
            which  = pair.second;
            debug(STRINGIZE("result = " << result << ", which = " << which));
        }
        END
    }

    template<> template<>
    void object::test<14>()
    {
        clear();
        set_test_name("postAndWait2");
        DEBUG;
        LLCoros::instance().launch("test<14>", postAndWait2);
        ensure_equals(result.asInteger(), 19);
        ensure_equals(which, 0);
    }

    void postAndWait2_1()
    {
        BEGIN
        {
            LLEventWithID pair = ::postAndSuspend2(LLSDMap("value", 18)("fail", LLSD()),
                                                immediateAPI.getPump(),
                                                "reply2",
                                                "error2",
                                                "reply",
                                                "error");
            result = pair.first;
            which  = pair.second;
            debug(STRINGIZE("result = " << result << ", which = " << which));
        }
        END
    }

    template<> template<>
    void object::test<15>()
    {
        clear();
        set_test_name("postAndWait2_1");
        DEBUG;
        LLCoros::instance().launch("test<15>", postAndWait2_1);
        ensure_equals(result.asInteger(), 19);
        ensure_equals(which, 1);
    }

    void coroPumpPost()
    {
        BEGIN
        {
            LLCoroEventPump waiter;
            result = waiter.postAndSuspend(LLSDMap("value", 17),
                                        immediateAPI.getPump(), "reply");
        }
        END
    }

    template<> template<>
    void object::test<16>()
    {
        clear();
        set_test_name("coroPumpPost");
        DEBUG;
        LLCoros::instance().launch("test<16>", coroPumpPost);
        ensure_equals(result.asInteger(), 18);
    }

    void coroPumpsPost()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            LLEventWithID pair(waiter.postAndSuspend(LLSDMap("value", 23),
                                                  immediateAPI.getPump(), "reply", "error"));
            result = pair.first;
            which  = pair.second;
        }
        END
    }

    template<> template<>
    void object::test<17>()
    {
        clear();
        set_test_name("coroPumpsPost reply");
        DEBUG;
        LLCoros::instance().launch("test<17>", coroPumpsPost);
        ensure_equals(result.asInteger(), 24);
        ensure_equals("which pump", which, 0);
    }

    void coroPumpsPost_1()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            LLEventWithID pair(
                waiter.postAndSuspend(LLSDMap("value", 23)("fail", LLSD()),
                                   immediateAPI.getPump(), "reply", "error"));
            result = pair.first;
            which  = pair.second;
        }
        END
    }

    template<> template<>
    void object::test<18>()
    {
        clear();
        set_test_name("coroPumpsPost error");
        DEBUG;
        LLCoros::instance().launch("test<18>", coroPumpsPost_1);
        ensure_equals(result.asInteger(), 24);
        ensure_equals("which pump", which, 1);
    }

    void coroPumpsPostNoEx()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            result = waiter.postAndSuspendWithException(LLSDMap("value", 8),
                                                     immediateAPI.getPump(), "reply", "error");
        }
        END
    }

    template<> template<>
    void object::test<19>()
    {
        clear();
        set_test_name("coroPumpsPostNoEx");
        DEBUG;
        LLCoros::instance().launch("test<19>", coroPumpsPostNoEx);
        ensure_equals(result.asInteger(), 9);
    }

    void coroPumpsPostEx()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            try
            {
                result = waiter.postAndSuspendWithException(
                    LLSDMap("value", 9)("fail", LLSD()),
                    immediateAPI.getPump(), "reply", "error");
                debug("no exception");
            }
            catch (const LLErrorEvent& e)
            {
                debug(STRINGIZE("exception " << e.what()));
                errordata = e.getData();
            }
        }
        END
    }

    template<> template<>
    void object::test<20>()
    {
        clear();
        set_test_name("coroPumpsPostEx");
        DEBUG;
        LLCoros::instance().launch("test<20>", coroPumpsPostEx);
        ensure("no result", result.isUndefined());
        ensure_equals("got error", errordata.asInteger(), 10);
    }

    void coroPumpsPostNoLog()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            result = waiter.postAndSuspendWithLog(LLSDMap("value", 30),
                                               immediateAPI.getPump(), "reply", "error");
        }
        END
    }

    template<> template<>
    void object::test<21>()
    {
        clear();
        set_test_name("coroPumpsPostNoLog");
        DEBUG;
        LLCoros::instance().launch("test<21>", coroPumpsPostNoLog);
        ensure_equals(result.asInteger(), 31);
    }

    void coroPumpsPostLog()
    {
        BEGIN
        {
            LLCoroEventPumps waiter;
            WrapLLErrs capture;
            try
            {
                result = waiter.postAndSuspendWithLog(
                    LLSDMap("value", 31)("fail", LLSD()),
                    immediateAPI.getPump(), "reply", "error");
                debug("no exception");
            }
            catch (const WrapLLErrs::FatalException& e)
            {
                debug(STRINGIZE("exception " << e.what()));
                threw = e.what();
            }
        }
        END
    }

    template<> template<>
    void object::test<22>()
    {
        clear();
        set_test_name("coroPumpsPostLog");
        DEBUG;
        LLCoros::instance().launch("test<22>", coroPumpsPostLog);
        ensure("no result", result.isUndefined());
        ensure_contains("got error", threw, "32");
    }
}

/*==========================================================================*|
#include <boost/context/guarded_stack_allocator.hpp>

namespace tut
{
    template<> template<>
    void object::test<23>()
    {
        set_test_name("stacksize");
        std::cout << "default_stacksize: " << boost::context::guarded_stack_allocator::default_stacksize() << '\n';
    }
} // namespace tut
|*==========================================================================*/