• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef TEST_EXPECTATIONS_GPU_TEST_EXPECTATIONS_PARSER_H_
8 #define TEST_EXPECTATIONS_GPU_TEST_EXPECTATIONS_PARSER_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include <string>
14 #include <vector>
15 
16 #include "GPUTestConfig.h"
17 
18 namespace angle
19 {
20 struct GPUTestConfig;
21 
22 class GPUTestExpectationsParser
23 {
24   public:
25     enum GPUTestExpectation
26     {
27         kGpuTestPass    = 1 << 0,
28         kGpuTestFail    = 1 << 1,
29         kGpuTestFlaky   = 1 << 2,
30         kGpuTestTimeout = 1 << 3,
31         kGpuTestSkip    = 1 << 4,
32     };
33 
34     GPUTestExpectationsParser();
35     ~GPUTestExpectationsParser();
36 
37     // Parse the text expectations, and if no error is encountered,
38     // save all the entries. Otherwise, generate error messages.
39     // Return true if parsing succeeds.
40     bool loadTestExpectations(const GPUTestConfig &config, const std::string &data);
41     bool loadTestExpectationsFromFile(const GPUTestConfig &config, const std::string &path);
42     bool loadAllTestExpectations(const std::string &data);
43     bool loadAllTestExpectationsFromFile(const std::string &path);
44 
45     // Query error messages from the last LoadTestExpectations() call.
46     const std::vector<std::string> &getErrorMessages() const;
47 
48     // Query error messages from any expectations that weren't used before being queried.
49     std::vector<std::string> getUnusedExpectationsMessages() const;
50 
51     // Get the test expectation of a given test on a given bot.
52     int32_t getTestExpectation(const std::string &testName);
53     int32_t getTestExpectationWithConfig(const GPUTestConfig &config, const std::string &testName);
setTestExpectationsAllowMask(uint32_t mask)54     void setTestExpectationsAllowMask(uint32_t mask) { mExpectationsAllowMask = mask; }
55 
56   private:
57     struct GPUTestExpectationEntry
58     {
59         GPUTestExpectationEntry();
60 
61         std::string testName;
62         int32_t testExpectation;
63         size_t lineNumber;
64         bool used;
65         GPUTestConfig::ConditionArray conditions;
66     };
67 
68     // Parse a line of text. If we have a valid entry, save it; otherwise,
69     // generate error messages.
70     bool parseLine(const GPUTestConfig *config, const std::string &lineData, size_t lineNumber);
71 
72     // Check a the condition assigned to a particular token.
73     bool checkTokenCondition(const GPUTestConfig &config,
74                              bool &err,
75                              int32_t token,
76                              size_t lineNumber);
77 
78     // Check if two entries' config overlap with each other. May generate an
79     // error message.
80     bool detectConflictsBetweenEntries();
81 
82     // Query a list of any expectations that were's used before being queried.
83     std::vector<GPUTestExpectationEntry> getUnusedExpectations() const;
84 
85     // Save an error message, which can be queried later.
86     void pushErrorMessage(const std::string &message, size_t lineNumber);
87     void pushErrorMessage(const std::string &message,
88                           size_t entry1LineNumber,
89                           size_t entry2LineNumber);
90 
91     // Config is optional.
92     bool loadTestExpectationsFromFileImpl(const GPUTestConfig *config, const std::string &path);
93     bool loadTestExpectationsImpl(const GPUTestConfig *config, const std::string &data);
94 
95     int32_t getTestExpectationImpl(const GPUTestConfig *config, const std::string &testName);
96 
97     std::vector<GPUTestExpectationEntry> mEntries;
98     std::vector<std::string> mErrorMessages;
99 
100     uint32_t mExpectationsAllowMask;
101 };
102 
103 const char *GetConditionName(uint32_t condition);
104 
105 }  // namespace angle
106 
107 #endif  // TEST_EXPECTATIONS_GPU_TEST_EXPECTATIONS_PARSER_H_
108