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