1 /*
2 * %CopyrightBegin%
3 *
4 * Copyright Ericsson AB and Kjell Winblad 2019. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * %CopyrightEnd%
19 */
20
21 /*
22 * Description:
23 *
24 * Author: Kjell Winblad
25 *
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #define YCF_YIELD()
32
33
fun()34 int fun(){
35 int x;
36 int y;
37 int z;
38 int outer = 0;
39 int inner = 0;
40 for(x = 0; x < 2; x++){
41 for(y = 0; y < 2; y++){ /* 2 times */
42 for(z = 0; z < 2; z++){ /* 4 times */
43 YCF_YIELD(); /* 8 times */
44 outer++;
45 printf("outer %d: x=%d y=%d z=%d\n", outer, x, y, z);
46 {
47 int x;
48 int y;
49 int z;
50 for(x = 0; x < 2; x++){ /* 8 times */
51 for(y = 0; y < 2; y++){ /* 16 times */
52 for(z = 0; z < 2; z++){ /* 32 times */
53 YCF_YIELD(); /* 64 times */
54 inner++;
55 printf("inner %d: x=%d y=%d z=%d\n", inner, x, y, z);
56 }
57 }
58 }
59 }
60 }
61 }
62 }
63 return inner + outer;
64 }
65
allocator(size_t size,void * context)66 void* allocator(size_t size, void* context){
67 (void)context;
68 return malloc(size);
69 }
70
freer(void * data,void * context)71 void freer(void* data, void* context){
72 (void)context;
73 free(data);
74 }
75
main(int argc,const char * argv[])76 int main( int argc, const char* argv[] )
77 {
78 #ifdef YCF_YIELD_CODE_GENERATED
79 void* wb = NULL;
80 #endif
81 int ret = 0;
82 int nr_of_traps = 0;
83 long nr_of_reductions = 1;
84 #ifdef YCF_YIELD_CODE_GENERATED
85 do{
86 ret = fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL);
87 if(wb != NULL){
88 nr_of_traps++;
89 }
90 }while(wb != NULL);
91 if(wb != NULL){
92 free(wb);
93 }
94 #else
95 ret = fun();
96 #endif
97 printf("NR OF TRAPS %d\n", nr_of_traps);
98 printf("RETURNED %d\n", ret);
99 if(ret != 72 || nr_of_traps != ret){
100 return 1;
101 }else{
102 return 0;
103 }
104 }
105