aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorColm Donelan <Colm.Donelan@arm.com>2020-03-02 21:35:10 +0000
committerJim Flynn <jim.flynn@arm.com>2020-03-12 13:13:12 +0000
commite9b5d2989abc8008df7ff3ea287ee896ee1121a6 (patch)
treedeaa54824e251207566500c778aae72fe06cd6bd /tests
parentc9e52794083eb73dd1bbf15ce7b16bb26394d7f5 (diff)
downloadarmnn-e9b5d2989abc8008df7ff3ea287ee896ee1121a6.tar.gz
GatordMock: Fixing errors in parsing command file.
An empty line resulted in program exit. * Ignore empty lines. * Add error message when an invalid number of parameters to SET or WAIT command is encountered. Signed-off-by: Colm Donelan <Colm.Donelan@arm.com> Change-Id: Ie2d229c1330b71b559d988d4ecb8019f2f850333
Diffstat (limited to 'tests')
-rw-r--r--tests/profiling/gatordmock/CommandFileParser.cpp103
1 files changed, 58 insertions, 45 deletions
diff --git a/tests/profiling/gatordmock/CommandFileParser.cpp b/tests/profiling/gatordmock/CommandFileParser.cpp
index 7c746f16e9..6f67e4d113 100644
--- a/tests/profiling/gatordmock/CommandFileParser.cpp
+++ b/tests/profiling/gatordmock/CommandFileParser.cpp
@@ -26,56 +26,69 @@ void CommandFileParser::ParseFile(std::string CommandFile, GatordMockService& mo
while (mockService.ReceiveThreadRunning() && std::getline(infile, line))
{
std::istringstream iss(line);
-
std::vector<std::string> tokens;
std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
std::back_inserter(tokens));
-
- std::string command = tokens[0];
-
- if (command == "LIST")
- {
- // Expected format for the SET command
- //
- // LIST
- //
-
- mockService.SendRequestCounterDir();
- }
- if (command == "SET")
- {
- // Expected format for the SET command
- //
- // SET 500000 1 2 5 10
- //
- // This breaks down to:
- // SET command
- // 500000 polling period in micro seconds
- // 1 2 5 10 counter list
-
- uint32_t period = static_cast<uint32_t>(std::stoul(tokens[1]));
-
- std::vector<uint16_t> counters;
-
- std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
- [](const std::string& str) { return static_cast<uint16_t>(std::stoul(str)); });
-
- mockService.SendPeriodicCounterSelectionList(period, counters);
- }
- else if (command == "WAIT")
+ if (tokens.size() > 0)
{
- // Expected format for the SET command
- //
- // WAIT 11000000
- //
- // This breaks down to:
- // WAIT command
- // 11000000 timeout period in micro seconds
-
- uint32_t timeout = static_cast<uint32_t>(std::stoul(tokens[1]));
-
- mockService.WaitCommand(timeout);
+ std::string command = tokens[0];
+ if (command == "LIST")
+ {
+ // Expected format for the SET command
+ //
+ // LIST
+ //
+
+ mockService.SendRequestCounterDir();
+ }
+ if (command == "SET")
+ {
+ // Expected format for the SET command
+ //
+ // SET 500000 1 2 5 10
+ //
+ // This breaks down to:
+ // SET command
+ // 500000 polling period in micro seconds
+ // 1 2 5 10 counter list
+
+ if (tokens.size() > 2) // minimum of 3 tokens.
+ {
+ uint32_t period = static_cast<uint32_t>(std::stoul(tokens[1]));
+
+ std::vector<uint16_t> counters;
+
+ std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
+ [](const std::string& str)
+ { return static_cast<uint16_t>(std::stoul(str)); });
+
+ mockService.SendPeriodicCounterSelectionList(period, counters);
+ }
+ else
+ {
+ std::cerr << "Invalid SET command. Format is: SET <polling period> <id list>" << std::endl;
+ }
+ }
+ else if (command == "WAIT")
+ {
+ // Expected format for the SET command
+ //
+ // WAIT 11000000
+ //
+ // This breaks down to:
+ // WAIT command
+ // 11000000 timeout period in micro seconds
+ if (tokens.size() > 1) // minimum of 2 tokens.
+ {
+ uint32_t timeout = static_cast<uint32_t>(std::stoul(tokens[1]));
+ mockService.WaitCommand(timeout);
+ }
+ else
+ {
+ std::cerr << "Invalid WAIT command. Format is: WAIT <interval>" << std::endl;
+ }
+ }
}
}
}