# @name Graphics RGX demos
# @desc Running various graphics demos
# @requires graphics

errorMessage="Demo reports failed. Re-run manually to find rootcause."

RGX_S_FUNC_8K_TEXTURE source 'common.sh'; output=`srender_to_tex_test -w 8192 -h 8192 -f 1`;if [[ $output != *"Color match at (10,20)"* ]]; then die "$errorMessage";fi;

RGX_S_FUNC_BLIT source 'common.sh'; stop_daemon emptty; output=`rgx_blit_test`;if [[ $output != *"Output matches input file"* ]]; then die "Output and Input do not match";fi; if [[ $output != *"Test PASS"* ]]; then die "$errorMessage";fi;

RGX_S_FUNC_BLIT_BTYPEBLIT source 'common.sh'; stop_daemon emptty; output=`rgx_blit_test -btype BLIT`;if [[ $output != *"Output matches input file"* ]]; then die "Output and Input do not match";fi; if [[ $output != *"Test PASS"* ]]; then die "$errorMessage";fi;

RGX_S_FUNC_BLIT_BTYPEFILL source 'common.sh'; stop_daemon emptty; output=`rgx_blit_test -btype FILL`;if [[ $output != *"Output matches input file"* ]]; then die "Output and Input do not match";fi; if [[ $output != *"Test PASS"* ]]; then die "$errorMessage";fi;

RGX_S_FUNC_BLIT_BTYPECLIP source 'common.sh'; stop_daemon emptty; output=`rgx_blit_test -btype CLIP`;if [[ $output != *"Output matches input file"* ]]; then die "Output and Input do not match";fi; if [[ $output != *"Test PASS"* ]]; then die "$errorMessage";fi;

RGX_S_FUNC_KICKSYNC_1 source 'common.sh'; output=`rgx_kicksync_test -n 1`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_VERBOSE_1 source 'common.sh'; output=`rgx_kicksync_test -ver -n 1`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_VERBOSE_10 source 'common.sh'; output=`rgx_kicksync_test -ver -n 10`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_M_FUNC_KICKSYNC_VERBOSE_100 source 'common.sh'; output=`rgx_kicksync_test -ver -n 100`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_L_STRESS_KICKSYNC_VERBOSE_1000 source 'common.sh'; output=`rgx_kicksync_test -ver -n 1000`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_SYNCCONTEXTLOOP_31_13_1000 source 'common.sh'; output=`rgx_kicksync_test -ver -ndvctx 31 -ndvcmd 13 -n 1000`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_SYNCCONTEXTLOOP_32_13_100 source 'common.sh'; output=`rgx_kicksync_test -ver -nc 32 -ndvcmd 13 -n 1 -loop 100`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_SYNCCONTEXTLOOP_16_31_13 source 'common.sh'; output=`rgx_kicksync_test -ver -nc 16 -ndvctx 31 -ndvcmd 13 -loop 100 -n 10000 -r -seed 81576`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_SYNCCONTEXTLOOP_31_13_100 source 'common.sh'; output=`rgx_kicksync_test -ndvctx 31 -ndvcmd 13 -n 100`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_KICKSYNC_SYNCCONTEXTLOOP_4_10_100 source 'common.sh'; output=`rgx_kicksync_test -ver -nc 4 -loop 10 -n 100`;if [[ $output != *"Test successful"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_TWIDDLING source 'common.sh'; output=`rgx_twiddling_test`;if [[ $output = *"FAILED"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_GLES1 source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles1test1 -f' || bin='gles1test1'; $bin 1200

RGX_S_FUNC_GLES2 source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles2test1 -f' || bin='gles2test1'; $bin 1200

RGX_L_STRESS_GLES1 source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles1test1 -f' || bin='gles1test1'; $bin 1000

RGX_L_STRESS_GLES2 source 'common.sh';  cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles2test1 -f' || bin='gles2test1'; $bin 1000

RGX_S_FUNC_GLES1_ARGB32 source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles1test1 -f' || bin='gles1test1'; $bin 10 argb32

RGX_S_FUNC_GLES2_ARGB32 source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles2test1 -f' || bin='gles2test1'; $bin 10 argb32

RGX_S_FUNC_GLES1IMAGEEXTERNAL source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles1test1 -f 1200' || bin='gles1image_external -D tidss -f 2'; $bin

RGX_S_FUNC_GLES3RENDERPVR source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles3test1 -f 1200' || bin='gles3_render_to_image 3 pvr'; $bin

RGX_S_FUNC_GLES3RENDERTIDSS source 'common.sh'; cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles3test1 -f 1200' || bin='gles3_render_to_image 2 tidss'; $bin

RGX_S_FUNC_GLES3 source 'common.sh';  cat /sys/kernel/debug/pvr/version | grep WS && bin='wgles3test1 -f 1200' || bin='gles3test1 -f 1200'; $bin

RGX_XS_FUNC_MODULE_LOAD source 'common.sh'; lsmod | grep pvrsrvkm || die "Graphics module pvrsrvkm not detected"

RGX_S_FUNC_COMPUTE source 'common.sh'; output=`rgx_compute_test`;if [[ $output != *"--- End ---"* ]]; then die "$errorMessage";fi

RGX_S_FUNC_APM source 'common.sh'; stop_daemon emptty && sleep 1; pre=$(k3conf dump device | grep -i 'gpu'); rgx_compute_test -f 10000 > /dev/null & sleep 1 && post=$(k3conf dump device | grep -i 'gpu'); if wait "$!" && [ "$pre" != "$post" ] ; then printf '%s\n\n' "$pre" "$post" 'Power domain states changed as expected'; else die 'Power domain states did not change when expected!'; fi
