• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <unistd.h>
3 
4 #include <memory>
5 #include <iostream>
6 #include <vector>
7 
8 #include "google/protobuf/empty.pb.h"
9 #include "nugget/app/protoapi/control.pb.h"
10 #include "nugget/app/protoapi/header.pb.h"
11 #include "nugget/app/protoapi/testing_api.pb.h"
12 #include "src/util.h"
13 
14 using google::protobuf::Empty;
15 using nugget::app::protoapi::APImessageID;
16 using nugget::app::protoapi::Notice;
17 using nugget::app::protoapi::OneofTestParametersCase;
18 using nugget::app::protoapi::OneofTestResultsCase;
19 using std::unique_ptr;
20 using std::vector;
21 using test_harness::BYTE_TIME;
22 using test_harness::TestHarness;
23 
24 unique_ptr<TestHarness> harness = unique_ptr<TestHarness>(new TestHarness());
25 
cleanup()26 void cleanup() {
27   std::cout << "Performing Reboot!\n";
28   harness->RebootNugget();
29   std::cout << "Done!\n";
30 }
31 
signal_handler(int signal)32 void signal_handler(int signal) {
33   if (signal) {}
34   exit(0);
35 }
signal_ignore(int signal)36 void signal_ignore(int signal) { if (signal) {} }
37 
main(void)38 int main(void) {
39   vector<uint8_t> input_buffer;
40   vector<uint8_t> output_buffer;
41   input_buffer.reserve(0x4000);
42   output_buffer.reserve(0x4000);
43 
44   std::atexit(cleanup);
45   signal(SIGINT, signal_handler);
46   signal(SIGABRT, signal_handler);
47   signal(SIGHUP, signal_ignore);
48 
49   std::cout << "SendOneofProto()\n";
50   int result = harness->SendOneofProto(
51       APImessageID::TESTING_API_CALL,
52       OneofTestParametersCase::kFullStressTest,
53       Empty());
54   if (result != test_harness::error_codes::NO_ERROR) {
55     std::cerr << "SendOneofProto() ERROR: "
56               << test_harness::error_codes_name(result) << "\n";
57     return 1;
58   }
59 
60   std::cout << "GetData()\n";
61   test_harness::raw_message msg;
62   if(harness->GetData(&msg, 4096 * BYTE_TIME) !=
63       test_harness::error_codes::NO_ERROR) {
64     std::cerr << "GetData() ERROR: "
65               << test_harness::error_codes_name(result) << "\n";
66     return 1;
67   }
68 
69   if (msg.type != APImessageID::TESTING_API_RESPONSE) {
70     std::cerr << "Unexpected received message type: "
71               << nugget::app::protoapi::APImessageID_Name(
72                   (APImessageID)msg.type) << " (" << msg.type << ")\n";
73     if (msg.type == APImessageID::NOTICE) {
74       Notice notice;
75       if (notice.ParseFromArray(
76           reinterpret_cast<char *>(msg.data), msg.data_len)) {
77         std::cerr << notice.DebugString();
78       }
79     }
80     return 1;
81   }
82 
83   if (msg.data_len != 2) {
84     std::cerr << "Unexpected received message length: "
85               << msg.data_len << "\n";
86     return 1;
87   }
88 
89   uint16_t subtype = (msg.data[0] << 8) | msg.data[1];
90   if (subtype != OneofTestResultsCase::kFullStressResult) {
91     std::cerr << "Unexpected received message sub type: "
92               << nugget::app::protoapi::OneofTestResultsCase_Name(
93                   (OneofTestResultsCase)subtype) << " (" << subtype << ")\n";
94     return 1;
95   }
96 
97   std::cout << "Waiting!\n";
98   while (true) {
99     sleep(15);
100   }
101   return 0;
102 }
103