blob: 26775ff6024123e2faf8a77e1068dde5e3a4225b [file] [log] [blame]
Ben Tyner0205f3b2020-02-24 10:24:47 -06001#include <analyzer/analyzer_main.hpp>
Ben Tyner8c2f8b22020-03-27 10:39:31 -05002#include <boost/interprocess/ipc/message_queue.hpp>
Ben Tyner7212d212020-03-31 09:44:41 -05003#include <cli.hpp>
Ben Tyner8c2f8b22020-03-27 10:39:31 -05004#include <listener.hpp>
Ben Tyner0205f3b2020-02-24 10:24:47 -06005
6/**
7 * @brief Attention handler application main()
8 *
9 * This is the main interface to the hardware diagnostics application. This
10 * application will either be loaded as a daemon for monitoring the attention
11 * gpio or it will be loaded as an application to analyze hardware and
12 * diagnose hadrware error conditions.
13 *
Ben Tyner8c2f8b22020-03-27 10:39:31 -050014 * Usage:
15 * --analyze: Analyze the hardware
16 * --start: Start the attention handler
17 * --stop: Stop the attention handler
18 * --all <on|off>: All attention handling
19 * --vital <on|off>: Vital attention handling
20 * --checkstop <on|off>: Checkstop attention handling
21 * --terminate <on|off>: Terminate Immiediately attention handling
22 * --breakpoints <on|off>: Breakpoint attention handling
Ben Tyner0205f3b2020-02-24 10:24:47 -060023 *
Ben Tyner8c2f8b22020-03-27 10:39:31 -050024 * Example: openpower-hw-diags --start --vital off
Ben Tyner0205f3b2020-02-24 10:24:47 -060025 *
26 * @return 0 = success
27 */
28int main(int argc, char* argv[])
29{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050030 int rc = RC_SUCCESS; // assume success
Ben Tyner0205f3b2020-02-24 10:24:47 -060031
Ben Tyner8c2f8b22020-03-27 10:39:31 -050032 using namespace boost::interprocess;
Ben Tyner3fb52e52020-03-31 10:10:07 -050033
Ben Tyner8c2f8b22020-03-27 10:39:31 -050034 if (argc == 1)
Ben Tyner0205f3b2020-02-24 10:24:47 -060035 {
Ben Tyner8c2f8b22020-03-27 10:39:31 -050036 printf("openpower-hw-diags <options>\n");
37 printf("options:\n");
38 printf(" --analyze: Analyze the hardware\n");
39 printf(" --start: Start the attention handler\n");
40 printf(" --stop: Stop the attention handler\n");
41 printf(" --all <on|off>: All attention handling\n");
42 printf(" --vital <on|off>: Vital attention handling\n");
43 printf(" --checkstop <on|off>: Checkstop attention handling\n");
44 printf(" --terminate <on|off>: Terminate Immediately attention "
45 "handling\n");
46 printf(" --breakpoints <on|off>: Breakpoint attention handling\n");
Ben Tyner0205f3b2020-02-24 10:24:47 -060047 }
Ben Tyner0205f3b2020-02-24 10:24:47 -060048 else
49 {
Ben Tyner8c2f8b22020-03-27 10:39:31 -050050 // todo usage
51
52 // Either analyze (application mode) or daemon mode
53 if (true == getCliOption(argv, argv + argc, "--analyze"))
Ben Tyner0205f3b2020-02-24 10:24:47 -060054 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050055 // errors that were isolated
56 std::map<std::string, std::string> errors;
57
58 rc = analyzer::analyzeHardware(errors); // analyze hardware
59 if (RC_SUCCESS == rc)
60 {
61 // TODO - add error processing/display
62
63 printf("analyzer isolated %i errors", (int)errors.size());
64 }
65 else
66 {
67 printf("analyzer/isolator error encountered\n");
68 }
Ben Tyner0205f3b2020-02-24 10:24:47 -060069 }
Ben Tyner8c2f8b22020-03-27 10:39:31 -050070 // daemon mode
71 else
72 {
73 // assume listener is not running
74 bool listenerStarted = false;
75 bool newListener = false;
Ben Tyner0205f3b2020-02-24 10:24:47 -060076
Ben Tyner8c2f8b22020-03-27 10:39:31 -050077 pthread_t ptidListener; // handle to listener thread
78
79 // see if listener is already started
80 listenerStarted = listenerMqExists();
81
82 // listener is not running so start it
83 if (false == listenerStarted)
84 {
85 // create listener thread
86 if (0 ==
87 pthread_create(&ptidListener, NULL, &threadListener, NULL))
88 {
89 listenerStarted = true;
90 newListener = true;
91 }
92 else
93 {
94 rc = 1;
95 }
96 }
97
98 // listener was running or just started
99 if (true == listenerStarted)
100 {
101 // If we created a new listener this instance of
102 // openpower-hw-diags will become our daemon (it will not exit
103 // until stopped).
104 if (true == newListener)
105 {
106 bool listenerReady = false;
107
108 // It may take some time for the listener to become ready,
109 // we will wait until the message queue has been created
110 // before starting to communicate with our daemon.
111 while (false == listenerReady)
112 {
113 usleep(500);
114 listenerReady = listenerMqExists();
115 }
116 }
117
118 // send cmd line to listener thread
119 if (argc != sendCmdLine(argc, argv))
120 {
121 rc = 1;
122 }
123
124 // if this is a new listener let it run until "stopped"
125 if (true == newListener)
126 {
127 pthread_join(ptidListener, NULL);
128 }
129 }
130 }
131 }
Ben Tyner0205f3b2020-02-24 10:24:47 -0600132 return rc;
133}