xref: /petsc/src/sys/tests/options/ex55.c (revision ffa8c5705e8ab2cf85ee1d14dbe507a6e2eb5283)
1 
2 static char help[] = "Tests options database monitoring and precedence.\n\n";
3 
4 #include <petscsys.h>
5 #include <petscviewer.h>
6 
7 PetscErrorCode PetscOptionsMonitorCustom(const char name[],const char value[],void *ctx)
8 {
9   PetscViewer    viewer = (PetscViewer)ctx;
10 
11   PetscFunctionBegin;
12   if (!value) {
13     PetscCall(PetscViewerASCIIPrintf(viewer,"* Removing option: %s\n",name));
14   } else if (!value[0]) {
15     PetscCall(PetscViewerASCIIPrintf(viewer,"* Setting option: %s (no value)\n",name));
16   } else {
17     PetscCall(PetscViewerASCIIPrintf(viewer,"* Setting option: %s = %s\n",name,value));
18   }
19   PetscFunctionReturn(0);
20 }
21 
22 int main(int argc,char **argv)
23 {
24   PetscViewer       viewer=NULL;
25   PetscViewerFormat format;
26 
27   PetscCall(PetscInitialize(&argc,&argv,"ex55options",help));
28   PetscCall(PetscOptionsInsertString(NULL,"-option1 1 -option2 -option3 value3"));
29   PetscCall(PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,NULL,"-options_monitor_viewer",&viewer,&format,NULL));
30   if (viewer) {
31     PetscCall(PetscViewerPushFormat(viewer,format));
32     PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorCustom,viewer,NULL));
33     PetscCall(PetscViewerPopFormat(viewer));
34     PetscCall(PetscViewerDestroy(&viewer));
35   }
36   PetscCall(PetscOptionsInsertString(NULL,"-option4 value4 -option5"));
37   PetscCall(PetscFinalize());
38   return 0;
39 }
40 
41 /*TEST
42 
43    testset:
44       localrunfiles: ex55options .petscrc petscrc
45       filter: egrep -v -e "(malloc|nox|display|saws_port|vecscatter|options_left|check_pointer_intensity|cuda_initialize|error_output_stdout|use_gpu_aware_mpi|checkstack)"
46       args: -options_left 0 -options_view -options_monitor_viewer ascii
47       args: -skip_petscrc {{0 1}separate output} -options_monitor_cancel {{0 1}separate output}
48       test:
49         suffix: 1
50       test:
51         suffix: 2
52         args: -options_monitor
53       test:
54         suffix: 3
55         args: -options_monitor -option_cmd_1 option_cmd_1_val -option_cmd_2
56    test:
57       # test effect of -skip_petscrc in ex55options file
58       suffix: 4
59       localrunfiles: ex55options .petscrc petscrc
60       filter: egrep -v -e "(malloc|nox|display|saws_port|vecscatter|options_left|check_pointer_intensity|cuda_initialize|error_output_stdout|use_gpu_aware_mpi|checkstack)"
61       args: -options_left 0 -options_view -options_monitor
62    testset:
63       # test -help / -help intro / -version from command line
64       localrunfiles: ex55options .petscrc petscrc
65       filter: egrep -e "(version|help|^See)"
66       args: -options_left -options_view -options_monitor
67       test:
68         suffix: 5a
69         args: -help
70       test:
71         suffix: 5b
72         args: -help intro
73       test:
74         suffix: 5c
75         args: -version
76    testset:
77       # test -help / -help intro / -version from file
78       localrunfiles: ex55options rc_help rc_help_intro rc_version
79       filter: egrep -e "(version|help|^See)"
80       args: -skip_petscrc
81       args: -options_left -options_view -options_monitor
82       test:
83         suffix: 6a
84         args: -options_file rc_help
85       test:
86         suffix: 6b
87         args: -options_file rc_help_intro
88       test:
89         suffix: 6c
90         args: -options_file rc_version
91 
92 TEST*/
93