external/boringssl: Sync to 5e578c9dba73460c3eb17f771c77fc8e36f7812e.
This includes the following changes:
https://boringssl.googlesource.com/boringssl/+log/58e449904e248f34bdfc2be7a609c58bcb0257b7..5e578c9dba73460c3eb17f771c77fc8e36f7812e
Test: BoringSSL CTS Presubmits
Change-Id: Ic1541b034545fa58a284ca35134b3719303455c7
diff --git a/src/crypto/test/file_test.h b/src/crypto/test/file_test.h
index aac9289..8c476c4 100644
--- a/src/crypto/test/file_test.h
+++ b/src/crypto/test/file_test.h
@@ -18,12 +18,13 @@
#include <openssl/base.h>
#include <stdint.h>
-#include <stdio.h>
OPENSSL_MSVC_PRAGMA(warning(push))
OPENSSL_MSVC_PRAGMA(warning(disable : 4702))
+#include <functional>
#include <map>
+#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -83,21 +84,42 @@
// consumed. When a test completes, if any attributes or insturctions haven't
// been processed, the framework reports an error.
+class FileTest;
+typedef bool (*FileTestFunc)(FileTest *t, void *arg);
class FileTest {
public:
- explicit FileTest(const char *path);
- ~FileTest();
-
- // is_open returns true if the file was successfully opened.
- bool is_open() const { return file_ != nullptr; }
-
enum ReadResult {
kReadSuccess,
kReadEOF,
kReadError,
};
+ class LineReader {
+ public:
+ virtual ~LineReader() {}
+ virtual ReadResult ReadLine(char *out, size_t len) = 0;
+ };
+
+ struct Options {
+ // path is the path to the input file.
+ const char *path = nullptr;
+ // callback is called for each test. It should get the parameters from this
+ // object and signal any errors by returning false.
+ FileTestFunc callback = nullptr;
+ // arg is an opaque pointer that is passed to |callback|.
+ void *arg = nullptr;
+ // silent suppressed the "PASS" string that is otherwise printed after
+ // successful runs.
+ bool silent = false;
+ // comment_callback is called after each comment in the input is parsed.
+ std::function<void(const std::string&)> comment_callback;
+ };
+
+ explicit FileTest(std::unique_ptr<LineReader> reader,
+ std::function<void(const std::string &)> comment_callback);
+ ~FileTest();
+
// ReadNext reads the next test from the file. It returns |kReadSuccess| if
// successfully reading a test and |kReadEOF| at the end of the file. On
// error or if the previous test had unconsumed attributes, it returns
@@ -139,6 +161,10 @@
bool ExpectBytesEqual(const uint8_t *expected, size_t expected_len,
const uint8_t *actual, size_t actual_len);
+ // AtNewInstructionBlock returns true if the current test was immediately
+ // preceded by an instruction block.
+ bool IsAtNewInstructionBlock() const;
+
// HasInstruction returns true if the current test has an instruction.
bool HasInstruction(const std::string &key);
@@ -154,7 +180,9 @@
// other blank or comment lines are omitted.
const std::string &CurrentTestToString() const;
- void SetIgnoreUnusedAttributes(bool ignore);
+ // InjectInstruction adds a key value pair to the most recently parsed set of
+ // instructions.
+ void InjectInstruction(const std::string &key, const std::string &value);
private:
void ClearTest();
@@ -162,7 +190,7 @@
void OnKeyUsed(const std::string &key);
void OnInstructionUsed(const std::string &key);
- FILE *file_ = nullptr;
+ std::unique_ptr<LineReader> reader_;
// line_ is the number of lines read.
unsigned line_ = 0;
@@ -185,7 +213,11 @@
std::string current_test_;
- bool ignore_unused_attributes_ = false;
+ bool is_at_new_instruction_block_ = false;
+
+ // comment_callback_, if set, is a callback function that is called with the
+ // contents of each comment as they are parsed.
+ std::function<void(const std::string&)> comment_callback_;
FileTest(const FileTest &) = delete;
FileTest &operator=(const FileTest &) = delete;
@@ -202,12 +234,13 @@
// list of keys. This may be used to initialize a shared set of keys for many
// tests. However, if one test fails, the framework will continue to run
// subsequent tests.
-int FileTestMain(bool (*run_test)(FileTest *t, void *arg), void *arg,
- const char *path);
+int FileTestMain(FileTestFunc run_test, void *arg, const char *path);
-// FileTestMainSilent behaves like FileTestMain but does not print a final
-// FAIL/PASS message to stdout.
-int FileTestMainSilent(bool (*run_test)(FileTest *t, void *arg), void *arg,
- const char *path);
+// FileTestMain accepts a larger number of options via a struct.
+int FileTestMain(const FileTest::Options &opts);
+
+// FileTestGTest behaves like FileTestMain, but for GTest. |path| must be the
+// name of a test file embedded in the test binary.
+void FileTestGTest(const char *path, std::function<void(FileTest *)> run_test);
#endif /* OPENSSL_HEADER_CRYPTO_TEST_FILE_TEST_H */