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(int * y)34 void fun(int* y){
35 int x = 1;
36 x = x + 1; /* x == 2*/
37 YCF_YIELD();
38 x = x + 1; /* x == 3*/
39 *y = x;
40 }
41
allocator(size_t size,void * context)42 void* allocator(size_t size, void* context){
43 (void)context;
44 return malloc(size);
45 }
46
freer(void * data,void * context)47 void freer(void* data, void* context){
48 (void)context;
49 free(data);
50 }
51
main(int argc,const char * argv[])52 int main( int argc, const char* argv[] )
53 {
54 #ifdef YCF_YIELD_CODE_GENERATED
55 void* wb = NULL;
56 #endif
57 int nr_of_trapps = 0;
58 int ret = 0;
59 long nr_of_reductions = 1;
60 #ifdef YCF_YIELD_CODE_GENERATED
61 do{
62 fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL,&ret);
63 if(wb != NULL){
64 printf("TRAP\n");
65 nr_of_trapps++;
66 }
67 }while(wb != NULL);
68 if(wb != NULL){
69 free(wb);
70 }
71 if(nr_of_trapps != 1){
72 printf("ERROR\n");
73 exit(1);
74 }
75 #else
76 fun(&ret);
77 #endif
78 printf("RETURNED %d\n", ret);
79 if(ret != 3){
80 printf("ERROR\n");
81 exit(1);
82 }
83 return 0;
84 }
85
86