• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef GPU_CONFIG_GPU_TEST_EXPECTATIONS_PARSER_H_
6 #define GPU_CONFIG_GPU_TEST_EXPECTATIONS_PARSER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "gpu/config/gpu_test_config.h"
14 #include "gpu/gpu_export.h"
15 
16 namespace gpu {
17 
18 class GPU_EXPORT GPUTestExpectationsParser {
19  public:
20   enum GPUTestExpectation {
21     kGpuTestPass = 1 << 0,
22     kGpuTestFail = 1 << 1,
23     kGpuTestFlaky = 1 << 2,
24     kGpuTestTimeout = 1 << 3,
25     kGpuTestSkip = 1 << 4,
26   };
27 
28   GPUTestExpectationsParser();
29   ~GPUTestExpectationsParser();
30 
31   // Parse the text expectations, and if no error is encountered,
32   // save all the entries. Otherwise, generate error messages.
33   // Return true if parsing succeeds.
34   bool LoadTestExpectations(const std::string& data);
35   bool LoadTestExpectations(const base::FilePath& path);
36 
37   // Query error messages from the last LoadTestExpectations() call.
38   const std::vector<std::string>& GetErrorMessages() const;
39 
40   // Get the test expectation of a given test on a given bot.
41   int32 GetTestExpectation(const std::string& test_name,
42                            const GPUTestBotConfig& bot_config) const;
43 
44   // Parse a list of config modifiers. If we have a valid entry with no
45   // conflicts, | config | stores it, and the function returns true.
46   bool ParseConfig(const std::string& config_data, GPUTestConfig* config);
47 
48  private:
49   struct GPUTestExpectationEntry {
50     GPUTestExpectationEntry();
51 
52     std::string test_name;
53     GPUTestConfig test_config;
54     int32 test_expectation;
55     size_t line_number;
56   };
57 
58   // Parse a line of text. If we have a valid entry, save it; otherwise,
59   // generate error messages.
60   bool ParseLine(const std::string& line_data, size_t line_number);
61 
62   // Update OS/GPUVendor/BuildType modifiers. May generate an error message.
63   bool UpdateTestConfig(
64       GPUTestConfig* config, int32 token, size_t line_number);
65 
66   // Update GPUDeviceID modifier. May generate an error message.
67   bool UpdateTestConfig(GPUTestConfig* config,
68                         const std::string & gpu_device_id,
69                         size_t line_number);
70 
71   // Check if two entries' config overlap with each other. May generate an
72   // error message.
73   bool DetectConflictsBetweenEntries();
74 
75   // Save an error message, which can be queried later.
76   void PushErrorMessage(const std::string& message, size_t line_number);
77   void PushErrorMessage(const std::string& message,
78                         size_t entry1_line_number,
79                         size_t entry2_line_number);
80 
81   std::vector<GPUTestExpectationEntry> entries_;
82   std::vector<std::string> error_messages_;
83 };
84 
85 }  // namespace gpu
86 
87 #endif  // GPU_CONFIG_GPU_TEST_EXPECTATIONS_PARSER_H_
88 
89