/* Compile against an experiment's generated model/support, not production. */ #include #define CHECK(x) do{if(!(x)){fprintf(stderr,"guard self-test failed line %d\n",__LINE__);return 1;}}while(0) int main(void){ lp_start();CHECK(saved && lp_mask); int group=-1,region=-1; for(int g=0;g=0){group=g;region=lp_plan[g][p];break;} CHECK(group>=0);lp_color=group;lp_active=group+1; double y[NSTATES]={0},p[LP_NP]={0},h[LP_NQ]={0},q[LP_NQ]={0},w[NOUTPUTS]={0},fb[LP_NFB]={0}; NativePropertyState states[LP_NPS]={0}; NativePipeCache pipes[LP_NPC]={0};NativeJacobianScalars jacobian={0}; NativePropertyCache context={.states=states,.count=1,.capacity=LP_NPS,.jacobian=&jacobian}; states[0].p=123;states[0].T=456;states[0].valid=NATIVE_PROPERTY_PT;states[0].jacobian=&jacobian; lp_begin(.5,y);lp_snapshot(lp_before[region],&context,pipes); states[0].rho=42;states[0].valid|=NATIVE_PROPERTY_RHO; lp_snapshot(lp_after[region],&context,pipes); lp_save(p,h,q,w,fb);lp_ready(1); CHECK(lp_valid(.5,y));CHECK(!lp_valid(nextafter(.5,1),y)); int own=-1,other=-1; for(int i=0;i=0 && other>=0);y[own]=1;CHECK(lp_valid(.5,y));y[other]=1;CHECK(!lp_valid(.5,y));y[other]=0; Snapshot *before=&saved->snapshots[lp_before[region]],*after=&saved->snapshots[lp_after[region]]; context.count=before->count;memcpy(states,before->states,before->count*sizeof(*states));memcpy(pipes,before->pipes,sizeof(pipes)); CHECK(lp_reuse(region,&context,pipes,p,h,q,w,fb)); CHECK(context.count==after->count && !memcmp(states,after->states,after->count*sizeof(*states))); memcpy(states,before->states,before->count*sizeof(*states));context.count=before->count; states[0].rho=nextafter(states[0].rho,1);CHECK(!lp_reuse(region,&context,pipes,p,h,q,w,fb)); memcpy(states,before->states,before->count*sizeof(*states));pipes[0].valid=1;CHECK(!lp_reuse(region,&context,pipes,p,h,q,w,fb)); memcpy(pipes,before->pipes,sizeof(pipes));context.count++;CHECK(!lp_reuse(region,&context,pipes,p,h,q,w,fb)); context.count=before->count;context.jacobian=NULL;CHECK(!lp_reuse(region,&context,pipes,p,h,q,w,fb)); int pure=-1;for(int r=0;r=0);NativePropertyState held=states[0];NativePipeCache held_pipe=pipes[0]; size_t held_count=context.count; CHECK(lp_reuse(pure,&context,pipes,p,h,q,w,fb)); CHECK(context.count==held_count && context.jacobian==NULL); CHECK(!memcmp(&held,states,sizeof(held)) && !memcmp(&held_pipe,pipes,sizeof(held_pipe))); lp_begin(.5,y);CHECK(!lp_valid(.5,y)); lp_finish();puts("exact context, pipe-cache, time, state and lifetime guards passed");return 0; }