Go to the documentation of this file.
30 #include "../internal.h"
38 is_kas_test_(is_kas_test),
39 comment_callback_(
std::
move(comment_callback)) {}
47 if (*
str ==
':' || *
str ==
'=') {
59 while (
len > 0 && isspace(*
str)) {
63 while (
len > 0 && isspace(
str[
len - 1])) {
72 if (delimiter ==
nullptr) {
83 if (!unused_attributes_.empty()) {
85 PrintLine(
"Unused attribute: %s",
key.c_str());
89 if (!unused_instructions_.empty()) {
91 PrintLine(
"Unused instruction: %s",
key.c_str());
98 static const size_t kBufLen = 8192 * 4;
99 std::unique_ptr<char[]>
buf(
new char[kBufLen]);
101 bool in_instruction_block =
false;
102 is_at_new_instruction_block_ =
false;
106 switch (reader_->ReadLine(
buf.get(), kBufLen)) {
108 fprintf(
stderr,
"Error reading from input at line %u.\n",
line_ + 1);
112 return start_line_ > 0 ? kReadSuccess : kReadEOF;
118 size_t len = strlen(
buf.get());
119 if (
buf[0] ==
'\n' ||
buf[0] ==
'\r' ||
buf[0] ==
'\0') {
121 if (start_line_ > 0) {
124 if (in_instruction_block) {
125 in_instruction_block =
false;
127 current_test_ +=
"\r\n";
128 }
else if (is_kas_test_) {
130 current_test_ +=
"\r\n";
132 }
else if (
buf[0] ==
'#') {
133 if (is_kas_test_ && seen_non_comment_) {
137 }
else if (comment_callback_) {
138 comment_callback_(
buf.get());
141 }
else if (strcmp(
"[B.4.2 Key Pair Generation by Testing Candidates]\r\n",
145 }
else if (
buf[0] ==
'[') {
146 is_at_new_instruction_block_ =
true;
147 seen_non_comment_ =
true;
148 if (start_line_ != 0) {
150 fprintf(
stderr,
"Line %u is an instruction in a test case.\n",
line_);
153 if (!in_instruction_block) {
155 in_instruction_block =
true;
162 const bool is_broken_kas_instruction =
164 (kv ==
"[SHA(s) supported (Used for hashing Z): SHA512 \r\n");
166 if (!is_broken_kas_instruction) {
168 if (kv[kv.size() - 1] !=
']') {
169 fprintf(
stderr,
"Line %u, invalid instruction: '%s'\n",
line_,
175 kv = kv.substr(0, kv.size() - 2);
178 current_test_ += kv +
"\r\n";
182 size_t idx = kv.find(
',');
183 if (
idx == std::string::npos) {
189 if (
idx == kv.size())
191 kv = kv.substr(
idx + 1);
195 if (in_instruction_block) {
199 in_instruction_block =
false;
209 const size_t num_occurrences = ++attribute_count_[
key];
210 if (num_occurrences > 1) {
214 unused_attributes_.insert(mapped_key);
215 attributes_[mapped_key] =
value;
216 if (start_line_ == 0) {
221 for (
const auto &kv : instructions_) {
222 unused_instructions_.insert(kv.first);
233 fprintf(
stderr,
"Line %u: ", start_line_);
252 return attributes_.count(
key) > 0;
257 auto iter = attributes_.find(
key);
258 if (
iter == attributes_.end()) {
259 PrintLine(
"Missing attribute '%s'.",
key.c_str());
262 *out_value =
iter->second;
267 if (!HasAttribute(
key)) {
270 return attributes_[
key];
274 OnInstructionUsed(
key);
275 return instructions_.count(
key) > 0;
279 OnInstructionUsed(
key);
280 auto iter = instructions_.find(
key);
281 if (
iter == instructions_.end()) {
282 PrintLine(
"Missing instruction '%s'.",
key.c_str());
285 *out_value =
iter->second;
290 unused_instructions_.clear();
294 if (!HasInstruction(
key)) {
297 return instructions_[
key];
307 return current_test_;
319 attribute_count_.clear();
321 unused_attributes_.clear();
322 unused_instructions_.clear();
327 instructions_.clear();
328 unused_attributes_.clear();
332 unused_attributes_.erase(
key);
336 unused_instructions_.erase(
key);
347 PrintLine(
"Error decoding value: %s",
value.c_str());
354 return is_at_new_instruction_block_;
366 if (
file_ !=
nullptr) {
376 if (
file_ ==
nullptr) {
385 fprintf(
stderr,
"Line too long.\n");
409 std::unique_ptr<FileLineReader>
reader(
412 fprintf(
stderr,
"Could not open file %s: %s.\n",
opts.path,
429 if (t.HasAttribute(
"Error")) {
431 t.PrintLine(
"Operation unexpectedly succeeded.");
437 t.PrintLine(
"Unexpected error; wanted '%s', got '%s'.",
438 t.GetAttributeOrDie(
"Error").c_str(),
448 t.PrintLine(
"Test failed");
455 if (!
opts.silent && !failed) {
459 return failed ? 1 : 0;
bool GetBytes(std::vector< uint8_t > *out, const std::string &key)
FileTest::ReadResult ReadLine(char *out, size_t len) override
const std::string & GetParameter()
int FileTestMain(FileTestFunc run_test, void *arg, const char *path)
bool IsAtNewInstructionBlock() const
bool GetInstruction(std::string *out_value, const std::string &key)
void InjectInstruction(const std::string &key, const std::string &value)
FileDescriptorProto * file_
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
#define ERR_print_errors_fp
bool HasInstruction(const std::string &key)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
const std::string & GetInstructionOrDie(const std::string &key)
bool(* FileTestFunc)(FileTest *t, void *arg)
const std::string & GetAttributeOrDie(const std::string &key)
static std::string StripSpace(const char *str, size_t len)
bool GetInstructionBytes(std::vector< uint8_t > *out, const std::string &key)
static const char * FindDelimiter(const char *str)
const std::string & GetType()
static std::pair< std::string, std::string > ParseKeyValue(const char *str, const size_t len)
void OnKeyUsed(const std::string &key)
~FileLineReader() override
bool GetAttribute(std::string *out_value, const std::string &key)
bool DecodeHex(std::vector< uint8_t > *out, const std::string &in)
UniquePtr< SSL_SESSION > ret
void PrintLine(const char *format,...) OPENSSL_PRINTF_FORMAT_FUNC(2
FileLineReader(const char *path)
bool HasAttribute(const std::string &key)
void OnInstructionUsed(const std::string &key)
static bool to_string(zval *from)
const std::string & CurrentTestToString() const
FileTest(std::unique_ptr< LineReader > reader, std::function< void(const std::string &)> comment_callback, bool is_kas_test)
void IgnoreAllUnusedInstructions()
bool ConvertToBytes(std::vector< uint8_t > *out, const std::string &value)
#define ERR_reason_error_string
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:20