From: Iain Sandoe Date: Wed, 22 Apr 2020 09:43:22 +0000 (+0100) Subject: coroutines, testsuite: Tidy some test names (NFC). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=56b15072aa41633235be57851ab342114e0bacba;p=gcc.git coroutines, testsuite: Tidy some test names (NFC). Try to make sure that we have consistent naming for the tests before first release. gcc/testsuite/ChangeLog: 2020-04-22 Iain Sandoe * g++.dg/coroutines/torture/local-var-0.C: Rename to... * g++.dg/coroutines/torture/local-var-00-const.C: ...this. * g++.dg/coroutines/torture/local-var-1.C: Rename to... * g++.dg/coroutines/torture/local-var-01-single.C: ...this. * g++.dg/coroutines/torture/local-var-2.C: Rename to... * g++.dg/coroutines/torture/local-var-02-conditional.C: ...this. * g++.dg/coroutines/torture/local-var-3.C: Rename to... * g++.dg/coroutines/torture/local-var-03-with-awaits.C: ...this. * g++.dg/coroutines/torture/local-var-4.C: Rename to... * g++.dg/coroutines/torture/local-var-04-hiding-nested-scopes.C: this. * g++.dg/coroutines/torture/local-var-5-awaitable.C: Rename to... * g++.dg/coroutines/torture/local-var-05-awaitable.C: ...this. --- diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-0.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-0.C deleted file mode 100644 index a8956457dcd..00000000000 --- a/gcc/testsuite/g++.dg/coroutines/torture/local-var-0.C +++ /dev/null @@ -1,37 +0,0 @@ -// { dg-do run } - -// Simplest local decl. - -#include "../coro.h" - -// boiler-plate for tests of codegen -#include "../coro1-ret-int-yield-int.h" - -struct coro1 -f () noexcept -{ - const int answer = 42; - PRINTF ("coro1: about to return %d\n", answer); - co_return answer; -} - -int main () -{ - PRINT ("main: create coro1"); - struct coro1 x = f (); - PRINT ("main: got coro1 - resuming"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume"); - int y = x.handle.promise().get_value(); - if ( y != 42 ) - abort (); - if (!x.handle.done()) - { - PRINT ("main: apparently not done..."); - abort (); - } - PRINT ("main: returning"); - return 0; -} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-00-const.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-00-const.C new file mode 100644 index 00000000000..a8956457dcd --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/local-var-00-const.C @@ -0,0 +1,37 @@ +// { dg-do run } + +// Simplest local decl. + +#include "../coro.h" + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + +struct coro1 +f () noexcept +{ + const int answer = 42; + PRINTF ("coro1: about to return %d\n", answer); + co_return answer; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 x = f (); + PRINT ("main: got coro1 - resuming"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume"); + int y = x.handle.promise().get_value(); + if ( y != 42 ) + abort (); + if (!x.handle.done()) + { + PRINT ("main: apparently not done..."); + abort (); + } + PRINT ("main: returning"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-01-single.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-01-single.C new file mode 100644 index 00000000000..69a5b707563 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/local-var-01-single.C @@ -0,0 +1,37 @@ +// { dg-do run } + +// Simplest local var + +#include "../coro.h" + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + +struct coro1 +f (int x) noexcept +{ + int answer = x + 6132; + PRINTF ("coro1: about to return %d\n", answer); + co_return answer; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 x = f (42); + PRINT ("main: got coro1 - resuming"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume"); + int y = x.handle.promise().get_value(); + if ( y != 6174 ) + abort (); + if (!x.handle.done()) + { + PRINT ("main: apparently not done..."); + abort (); + } + PRINT ("main: returning"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-02-conditional.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-02-conditional.C new file mode 100644 index 00000000000..f232edabdae --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/local-var-02-conditional.C @@ -0,0 +1,50 @@ +// { dg-do run } + +// Test local vars in nested scopes + +#include "../coro.h" + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + +struct coro1 +f (int x) noexcept +{ + int y = x; + const int test = 20; + if (y > test) + { + int fred = y - 20; + PRINTF ("coro1: about to return %d\n", fred); + co_return fred; + } + else + { + PRINT ("coro1: about to return the answer\n"); + co_return y; + } + + co_return x; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 x = f (6194); + PRINT ("main: got coro1 - resuming"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume"); + int y = x.handle.promise().get_value(); + if ( y != 6174 ) + abort (); + if (!x.handle.done()) + { + PRINT ("main: apparently not done..."); + abort (); + //x.handle.resume(); + } + PRINT ("main: returning"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-03-with-awaits.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-03-with-awaits.C new file mode 100644 index 00000000000..bd06db53d48 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/local-var-03-with-awaits.C @@ -0,0 +1,65 @@ +// { dg-do run } + +// Test modifying a local var and yielding several instances of it. + +#include "../coro.h" + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + +struct coro1 +f (int start) noexcept +{ + int value = start; + PRINT ("f: about to yield start"); + co_yield start; + + value -= 31; + PRINT ("f: about to yield (value-31)"); + co_yield value; + + value += 6163; + PRINT ("f: about to return (value+6163)"); + co_return value; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 x = f (42); + PRINT ("main: got coro1 - resuming (1)"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume (1)"); + int y = x.handle.promise().get_value(); + if ( y != 42 ) + abort (); + PRINT ("main: apparently got 42 - resuming (2)"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume (2)"); + y = x.handle.promise().get_value(); + if ( y != 11 ) + abort (); + PRINT ("main: apparently got 11 - resuming (3)"); + if (x.handle.done()) + { + PRINT ("main: done?"); + abort(); + } + x.handle.resume(); + PRINT ("main: after resume (2) checking return"); + y = x.handle.promise().get_value(); + if ( y != 6174 ) + abort (); + PRINT ("main: apparently got 6174"); + if (!x.handle.done()) + { + PRINT ("main: apparently not done..."); + abort (); + } + PRINT ("main: returning"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-04-hiding-nested-scopes.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-04-hiding-nested-scopes.C new file mode 100644 index 00000000000..419eb6b6467 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/local-var-04-hiding-nested-scopes.C @@ -0,0 +1,75 @@ +// { dg-do run } + +// Test modifying a local var across nested scopes containing vars +// hiding those at outer scopes. + +#include "../coro.h" + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + +struct coro1 +f (int start) noexcept +{ + int value = start; + { + int value = start + 5; + { + int value = start + 20; + } + { + int value = start + 1; + PRINT ("f: about to yield start"); + co_yield value; + } + } + + value -= 31; + PRINT ("f: about to yield (value-31)"); + co_yield value; + + value += 6163; + PRINT ("f: about to return (value+6163)"); + co_return value; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 x = f (42); + PRINT ("main: got coro1 - resuming (1)"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume (1)"); + int y = x.handle.promise().get_value(); + if ( y != 43 ) + abort (); + PRINT ("main: apparently got 42 - resuming (2)"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume (2)"); + y = x.handle.promise().get_value(); + if ( y != 11 ) + abort (); + PRINT ("main: apparently got 11 - resuming (3)"); + if (x.handle.done()) + { + PRINT ("main: done?"); + abort(); + } + x.handle.resume(); + PRINT ("main: after resume (2) checking return"); + y = x.handle.promise().get_value(); + if ( y != 6174 ) + abort (); + PRINT ("main: apparently got 6174"); + if (!x.handle.done()) + { + PRINT ("main: apparently not done..."); + abort (); + } + PRINT ("main: returning"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-05-awaitable.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-05-awaitable.C new file mode 100644 index 00000000000..7ea00434c87 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/local-var-05-awaitable.C @@ -0,0 +1,73 @@ +// { dg-do run } + +// Test the case where the awaitables are local vars, and therefore already +// have a frame representation - and should not be copied to a second frame +// entry (since elision of that copy would break the assumptions made in the +// management of the lifetime of the awaitable). + +#include "../coro.h" +#include + +// boiler-plate for tests of codegen +#include "../coro1-ret-int-yield-int.h" + +/* Make a non-trivial awaitable. */ +struct Awaitable +{ + int v; + std::vector x; + Awaitable () : v(0), x(1,0) {PRINTF ("Awaitable()\n");} + Awaitable (int _v) : v(_v), x(1,_v) {PRINTF ("Awaitable(%d)\n",_v);} + + bool await_ready () { return false; } + void await_suspend(coro::coroutine_handle<>) {} + int await_resume() { return v + x[0];} + + ~Awaitable () {PRINTF ("~Awaitable(%d)\n",v);} +}; + +coro1 +my_coro (int start) noexcept +{ + PRINT ("my_coro"); + Awaitable aw0 = Awaitable (start); + Awaitable aw1 = Awaitable (4); + Awaitable aw2 = Awaitable (10); + + int sum; + /* We are started with a suspend_always init suspend expr. */ + sum = co_await aw0; + PRINT ("my_coro 1"); + sum += co_await aw1; + PRINT ("my_coro 2"); + sum += co_await aw2; + PRINT ("my_coro 3"); + + co_return sum; +} + +int main () +{ + PRINT ("main: create my_coro"); + struct coro1 x = my_coro (7); + PRINT ("main: ramp done, resuming init suspend"); + if (x.handle.done()) + abort(); + x.handle.resume(); + + // now do the three co_awaits. + while(!x.handle.done()) + x.handle.resume(); + PRINT ("main: after resuming 3 co_awaits"); + + /* Now we should have the co_returned value. */ + int y = x.handle.promise().get_value(); + if (y != 42) + { + PRINTF ("main: wrong result (%d).", y); + abort (); + } + + PRINT ("main: returning"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-1.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-1.C deleted file mode 100644 index 69a5b707563..00000000000 --- a/gcc/testsuite/g++.dg/coroutines/torture/local-var-1.C +++ /dev/null @@ -1,37 +0,0 @@ -// { dg-do run } - -// Simplest local var - -#include "../coro.h" - -// boiler-plate for tests of codegen -#include "../coro1-ret-int-yield-int.h" - -struct coro1 -f (int x) noexcept -{ - int answer = x + 6132; - PRINTF ("coro1: about to return %d\n", answer); - co_return answer; -} - -int main () -{ - PRINT ("main: create coro1"); - struct coro1 x = f (42); - PRINT ("main: got coro1 - resuming"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume"); - int y = x.handle.promise().get_value(); - if ( y != 6174 ) - abort (); - if (!x.handle.done()) - { - PRINT ("main: apparently not done..."); - abort (); - } - PRINT ("main: returning"); - return 0; -} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-2.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-2.C deleted file mode 100644 index f232edabdae..00000000000 --- a/gcc/testsuite/g++.dg/coroutines/torture/local-var-2.C +++ /dev/null @@ -1,50 +0,0 @@ -// { dg-do run } - -// Test local vars in nested scopes - -#include "../coro.h" - -// boiler-plate for tests of codegen -#include "../coro1-ret-int-yield-int.h" - -struct coro1 -f (int x) noexcept -{ - int y = x; - const int test = 20; - if (y > test) - { - int fred = y - 20; - PRINTF ("coro1: about to return %d\n", fred); - co_return fred; - } - else - { - PRINT ("coro1: about to return the answer\n"); - co_return y; - } - - co_return x; -} - -int main () -{ - PRINT ("main: create coro1"); - struct coro1 x = f (6194); - PRINT ("main: got coro1 - resuming"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume"); - int y = x.handle.promise().get_value(); - if ( y != 6174 ) - abort (); - if (!x.handle.done()) - { - PRINT ("main: apparently not done..."); - abort (); - //x.handle.resume(); - } - PRINT ("main: returning"); - return 0; -} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-3.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-3.C deleted file mode 100644 index bd06db53d48..00000000000 --- a/gcc/testsuite/g++.dg/coroutines/torture/local-var-3.C +++ /dev/null @@ -1,65 +0,0 @@ -// { dg-do run } - -// Test modifying a local var and yielding several instances of it. - -#include "../coro.h" - -// boiler-plate for tests of codegen -#include "../coro1-ret-int-yield-int.h" - -struct coro1 -f (int start) noexcept -{ - int value = start; - PRINT ("f: about to yield start"); - co_yield start; - - value -= 31; - PRINT ("f: about to yield (value-31)"); - co_yield value; - - value += 6163; - PRINT ("f: about to return (value+6163)"); - co_return value; -} - -int main () -{ - PRINT ("main: create coro1"); - struct coro1 x = f (42); - PRINT ("main: got coro1 - resuming (1)"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume (1)"); - int y = x.handle.promise().get_value(); - if ( y != 42 ) - abort (); - PRINT ("main: apparently got 42 - resuming (2)"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume (2)"); - y = x.handle.promise().get_value(); - if ( y != 11 ) - abort (); - PRINT ("main: apparently got 11 - resuming (3)"); - if (x.handle.done()) - { - PRINT ("main: done?"); - abort(); - } - x.handle.resume(); - PRINT ("main: after resume (2) checking return"); - y = x.handle.promise().get_value(); - if ( y != 6174 ) - abort (); - PRINT ("main: apparently got 6174"); - if (!x.handle.done()) - { - PRINT ("main: apparently not done..."); - abort (); - } - PRINT ("main: returning"); - return 0; -} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-4.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-4.C deleted file mode 100644 index 419eb6b6467..00000000000 --- a/gcc/testsuite/g++.dg/coroutines/torture/local-var-4.C +++ /dev/null @@ -1,75 +0,0 @@ -// { dg-do run } - -// Test modifying a local var across nested scopes containing vars -// hiding those at outer scopes. - -#include "../coro.h" - -// boiler-plate for tests of codegen -#include "../coro1-ret-int-yield-int.h" - -struct coro1 -f (int start) noexcept -{ - int value = start; - { - int value = start + 5; - { - int value = start + 20; - } - { - int value = start + 1; - PRINT ("f: about to yield start"); - co_yield value; - } - } - - value -= 31; - PRINT ("f: about to yield (value-31)"); - co_yield value; - - value += 6163; - PRINT ("f: about to return (value+6163)"); - co_return value; -} - -int main () -{ - PRINT ("main: create coro1"); - struct coro1 x = f (42); - PRINT ("main: got coro1 - resuming (1)"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume (1)"); - int y = x.handle.promise().get_value(); - if ( y != 43 ) - abort (); - PRINT ("main: apparently got 42 - resuming (2)"); - if (x.handle.done()) - abort(); - x.handle.resume(); - PRINT ("main: after resume (2)"); - y = x.handle.promise().get_value(); - if ( y != 11 ) - abort (); - PRINT ("main: apparently got 11 - resuming (3)"); - if (x.handle.done()) - { - PRINT ("main: done?"); - abort(); - } - x.handle.resume(); - PRINT ("main: after resume (2) checking return"); - y = x.handle.promise().get_value(); - if ( y != 6174 ) - abort (); - PRINT ("main: apparently got 6174"); - if (!x.handle.done()) - { - PRINT ("main: apparently not done..."); - abort (); - } - PRINT ("main: returning"); - return 0; -} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/local-var-5-awaitable.C b/gcc/testsuite/g++.dg/coroutines/torture/local-var-5-awaitable.C deleted file mode 100644 index 7ea00434c87..00000000000 --- a/gcc/testsuite/g++.dg/coroutines/torture/local-var-5-awaitable.C +++ /dev/null @@ -1,73 +0,0 @@ -// { dg-do run } - -// Test the case where the awaitables are local vars, and therefore already -// have a frame representation - and should not be copied to a second frame -// entry (since elision of that copy would break the assumptions made in the -// management of the lifetime of the awaitable). - -#include "../coro.h" -#include - -// boiler-plate for tests of codegen -#include "../coro1-ret-int-yield-int.h" - -/* Make a non-trivial awaitable. */ -struct Awaitable -{ - int v; - std::vector x; - Awaitable () : v(0), x(1,0) {PRINTF ("Awaitable()\n");} - Awaitable (int _v) : v(_v), x(1,_v) {PRINTF ("Awaitable(%d)\n",_v);} - - bool await_ready () { return false; } - void await_suspend(coro::coroutine_handle<>) {} - int await_resume() { return v + x[0];} - - ~Awaitable () {PRINTF ("~Awaitable(%d)\n",v);} -}; - -coro1 -my_coro (int start) noexcept -{ - PRINT ("my_coro"); - Awaitable aw0 = Awaitable (start); - Awaitable aw1 = Awaitable (4); - Awaitable aw2 = Awaitable (10); - - int sum; - /* We are started with a suspend_always init suspend expr. */ - sum = co_await aw0; - PRINT ("my_coro 1"); - sum += co_await aw1; - PRINT ("my_coro 2"); - sum += co_await aw2; - PRINT ("my_coro 3"); - - co_return sum; -} - -int main () -{ - PRINT ("main: create my_coro"); - struct coro1 x = my_coro (7); - PRINT ("main: ramp done, resuming init suspend"); - if (x.handle.done()) - abort(); - x.handle.resume(); - - // now do the three co_awaits. - while(!x.handle.done()) - x.handle.resume(); - PRINT ("main: after resuming 3 co_awaits"); - - /* Now we should have the co_returned value. */ - int y = x.handle.promise().get_value(); - if (y != 42) - { - PRINTF ("main: wrong result (%d).", y); - abort (); - } - - PRINT ("main: returning"); - return 0; -}