aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralan-baker <alanbaker@google.com>2021-01-14 15:26:09 -0500
committerGitHub <noreply@github.com>2021-01-14 15:26:09 -0500
commit508bc75eda4f7f8c942093d8c6a2bd0a621e2da4 (patch)
tree4b0360cceed3431b779344b1a5aaeafb4f65c4bf
parentace2bdee2dbcc2f21ac823ea2f2a9d5698a6cc2c (diff)
downloadamber-508bc75eda4f7f8c942093d8c6a2bd0a621e2da4.tar.gz
Allow hex for values in expect commands (#937)
* Handled the same as parsing buffer data
-rw-r--r--src/amberscript/parser.cc7
-rw-r--r--src/amberscript/parser_expect_test.cc54
2 files changed, 58 insertions, 3 deletions
diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc
index fc5c948..50760f0 100644
--- a/src/amberscript/parser.cc
+++ b/src/amberscript/parser.cc
@@ -2907,7 +2907,7 @@ Result Parser::ParseValues(const std::string& name,
}
if (type::Type::IsFloat(segs[seg_idx].GetFormatMode())) {
- if (!token->IsInteger() && !token->IsDouble()) {
+ if (!token->IsInteger() && !token->IsDouble() && !token->IsHex()) {
return Result(std::string("Invalid value provided to ") + name +
" command: " + token->ToOriginalString());
}
@@ -2918,12 +2918,13 @@ Result Parser::ParseValues(const std::string& name,
v.SetDoubleValue(token->AsDouble());
} else {
- if (!token->IsInteger()) {
+ if (!token->IsInteger() && !token->IsHex()) {
return Result(std::string("Invalid value provided to ") + name +
" command: " + token->ToOriginalString());
}
- v.SetIntValue(token->AsUint64());
+ uint64_t val = token->IsHex() ? token->AsHex() : token->AsUint64();
+ v.SetIntValue(val);
}
++seg_idx;
if (seg_idx >= segs.size())
diff --git a/src/amberscript/parser_expect_test.cc b/src/amberscript/parser_expect_test.cc
index 125e38b..b7e8c59 100644
--- a/src/amberscript/parser_expect_test.cc
+++ b/src/amberscript/parser_expect_test.cc
@@ -1278,5 +1278,59 @@ EXPECT buf_1 RMSE_BUFFER buf_2)";
r.Error());
}
+TEST_F(AmberScriptParserTest, ExpectAllowIntegerHexValue) {
+ std::string in = R"(
+BUFFER b1 DATA_TYPE uint32 SIZE 4 FILL 0
+EXPECT b1 IDX 0 EQ 0x0 0x1 0x2 0x3
+)";
+
+ Parser parser;
+ Result r = parser.Parse(in);
+ ASSERT_TRUE(r.IsSuccess());
+
+ auto script = parser.GetScript();
+ const auto& commands = script->GetCommands();
+ ASSERT_EQ(1U, commands.size());
+
+ auto* cmd = commands[0].get();
+ ASSERT_TRUE(cmd->IsProbeSSBO());
+
+ auto* probe = cmd->AsProbeSSBO();
+ EXPECT_EQ(probe->GetComparator(), ProbeSSBOCommand::Comparator::kEqual);
+
+ EXPECT_EQ(4, probe->GetValues().size());
+ EXPECT_EQ(0, probe->GetValues()[0].AsUint64());
+ EXPECT_EQ(1, probe->GetValues()[1].AsUint64());
+ EXPECT_EQ(2, probe->GetValues()[2].AsUint64());
+ EXPECT_EQ(3, probe->GetValues()[3].AsUint64());
+}
+
+TEST_F(AmberScriptParserTest, ExpectAllowFloatHexValue) {
+ std::string in = R"(
+BUFFER b1 DATA_TYPE float SIZE 4 FILL 0
+EXPECT b1 IDX 0 EQ 0x0 0x1 0x2 0x3
+)";
+
+ Parser parser;
+ Result r = parser.Parse(in);
+ ASSERT_TRUE(r.IsSuccess());
+
+ auto script = parser.GetScript();
+ const auto& commands = script->GetCommands();
+ ASSERT_EQ(1U, commands.size());
+
+ auto* cmd = commands[0].get();
+ ASSERT_TRUE(cmd->IsProbeSSBO());
+
+ auto* probe = cmd->AsProbeSSBO();
+ EXPECT_EQ(probe->GetComparator(), ProbeSSBOCommand::Comparator::kEqual);
+
+ EXPECT_EQ(4, probe->GetValues().size());
+ EXPECT_EQ(static_cast<double>(0), probe->GetValues()[0].AsDouble());
+ EXPECT_EQ(static_cast<double>(1), probe->GetValues()[1].AsDouble());
+ EXPECT_EQ(static_cast<double>(2), probe->GetValues()[2].AsDouble());
+ EXPECT_EQ(static_cast<double>(3), probe->GetValues()[3].AsDouble());
+}
+
} // namespace amberscript
} // namespace amber