xref: /openbmc/openpower-hw-diags/test/test-cli.cpp (revision d28d5f8b6d6a6122a06c285b6841ba2a46d9267f)
1 #include <cli.hpp>
2 
3 #include "gtest/gtest.h"
4 
5 using namespace attn;
6 
7 TEST(TestCli, TestCliOptAll)
8 {
9 
10     // Test --all on options
11     Config* config = new Config();
12     char* argv[2];
13     int i     = 0;
14     argv[i++] = (char*)"--all";
15     argv[i++] = (char*)"on";
16     parseConfig(argv, argv + i, config);
17     EXPECT_EQ(true, config->getFlag(AttentionFlag::enVital));
18     EXPECT_EQ(true, config->getFlag(AttentionFlag::enCheckstop));
19     EXPECT_EQ(true, config->getFlag(AttentionFlag::enTerminate));
20     EXPECT_EQ(true, config->getFlag(AttentionFlag::enBreakpoints));
21     // The dfltTi flag is cleared by default and is not updated in the function.
22     EXPECT_EQ(false, config->getFlag(AttentionFlag::dfltTi));
23     EXPECT_EQ(true, config->getFlag(AttentionFlag::enClrAttnIntr));
24 
25     // Test --all off options
26     // Set the dfltTi flag to default value.
27     config->clearFlag(dfltTi);
28     i         = 0;
29     argv[i++] = (char*)"--all";
30     argv[i++] = (char*)"off";
31     parseConfig(argv, argv + i, config);
32     EXPECT_EQ(false, config->getFlag(AttentionFlag::enVital));
33     EXPECT_EQ(false, config->getFlag(AttentionFlag::enCheckstop));
34     EXPECT_EQ(false, config->getFlag(AttentionFlag::enTerminate));
35     EXPECT_EQ(false, config->getFlag(AttentionFlag::enBreakpoints));
36     // The same, the dfltTi flag is not updated in the function.
37     EXPECT_EQ(false, config->getFlag(AttentionFlag::dfltTi));
38     EXPECT_EQ(false, config->getFlag(AttentionFlag::enClrAttnIntr));
39     delete config;
40 }
41 
42 TEST(TestCli, TestCliNonAll)
43 {
44     // Test options with on switch.
45     Config* config = new Config();
46     char* argv[11];
47     int i     = 0;
48     argv[i++] = (char*)"--vital";
49     argv[i++] = (char*)"on";
50     argv[i++] = (char*)"--checkstop";
51     argv[i++] = (char*)"on";
52     argv[i++] = (char*)"--terminate";
53     argv[i++] = (char*)"on";
54     argv[i++] = (char*)"--breakpoints";
55     argv[i++] = (char*)"on";
56     argv[i++] = (char*)"--clrattnintr";
57     argv[i++] = (char*)"on";
58     // The --defaultti option does not have on/off switch.
59     // If this option is specified, it is enabled.
60     argv[i++] = (char*)"--defaultti";
61 
62     parseConfig(argv, argv + i, config);
63     EXPECT_EQ(true, config->getFlag(AttentionFlag::enVital));
64     EXPECT_EQ(true, config->getFlag(AttentionFlag::enCheckstop));
65     EXPECT_EQ(true, config->getFlag(AttentionFlag::enTerminate));
66     EXPECT_EQ(true, config->getFlag(AttentionFlag::enBreakpoints));
67     EXPECT_EQ(true, config->getFlag(AttentionFlag::enClrAttnIntr));
68     EXPECT_EQ(true, config->getFlag(AttentionFlag::dfltTi));
69 
70     // Test options with off switch.
71     // Set the dfltTi flag to default value.
72     config->clearFlag(dfltTi);
73     i         = 0;
74     argv[i++] = (char*)"--vital";
75     argv[i++] = (char*)"off";
76     argv[i++] = (char*)"--checkstop";
77     argv[i++] = (char*)"off";
78     argv[i++] = (char*)"--terminate";
79     argv[i++] = (char*)"off";
80     argv[i++] = (char*)"--breakpoints";
81     argv[i++] = (char*)"off";
82     argv[i++] = (char*)"--clrattnintr";
83     argv[i++] = (char*)"off";
84 
85     parseConfig(argv, argv + i, config);
86     EXPECT_EQ(false, config->getFlag(AttentionFlag::enVital));
87     EXPECT_EQ(false, config->getFlag(AttentionFlag::enCheckstop));
88     EXPECT_EQ(false, config->getFlag(AttentionFlag::enTerminate));
89     EXPECT_EQ(false, config->getFlag(AttentionFlag::enBreakpoints));
90     EXPECT_EQ(false, config->getFlag(AttentionFlag::enClrAttnIntr));
91     // If the --defaultti option is not specified, it is disabled by default.
92     EXPECT_EQ(false, config->getFlag(AttentionFlag::dfltTi));
93     delete config;
94 }
95