Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS 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 __VKBENCH_TESTBASE_H__ |
| 6 | #define __VKBENCH_TESTBASE_H__ |
| 7 | |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 8 | #include <vector> |
| 9 | #include <vulkan/vulkan.hpp> |
| 10 | |
Po-Hsien Wang | a956e65 | 2020-11-11 16:29:04 -0800 | [diff] [blame] | 11 | #include "filepath.h" |
Po-Hsien Wang | a0e1c31 | 2020-09-24 22:06:52 +0800 | [diff] [blame] | 12 | #include "vkBase.h" |
Po-Hsien Wang | a956e65 | 2020-11-11 16:29:04 -0800 | [diff] [blame] | 13 | #include "utils.h" |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 14 | |
| 15 | namespace vkbench { |
| 16 | class testBase { |
| 17 | public: |
Po-Hsien Wang | 42e116c | 2020-06-09 16:10:27 -0700 | [diff] [blame] | 18 | virtual ~testBase() {} |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 19 | // Name of test. |
| 20 | virtual const char* Name() const = 0; |
| 21 | // Description of the test. |
| 22 | virtual const char* Desp() const = 0; |
| 23 | // Unit for formatted measurement. |
| 24 | virtual const char* Unit() const = 0; |
| 25 | // Given time elapse per iteration, format it into meaningful numbers. |
| 26 | virtual double FormatMeasurement(double time) { return time; } |
| 27 | |
Po-Hsien Wang | a0e1c31 | 2020-09-24 22:06:52 +0800 | [diff] [blame] | 28 | // SaveImage saves the rendered image to file_name. |
Po-Hsien Wang | a956e65 | 2020-11-11 16:29:04 -0800 | [diff] [blame] | 29 | virtual void SaveImage(FilePath file_path) const { |
Po-Hsien Wang | a0e1c31 | 2020-09-24 22:06:52 +0800 | [diff] [blame] | 30 | throw std::runtime_error("Not Implemented!"); |
| 31 | }; |
| 32 | |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 33 | // Test related resources allocation. The resources allocated here would be |
Po-Hsien Wang | 42e116c | 2020-06-09 16:10:27 -0700 | [diff] [blame] | 34 | // shared by all Run iterations. Time spent here will not be recorded. |
| 35 | virtual void Initialize() {} |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 36 | // Test configuration before running the test. This will run once before |
Po-Hsien Wang | 42e116c | 2020-06-09 16:10:27 -0700 | [diff] [blame] | 37 | // each Run loop. Time spent here will be recorded. |
| 38 | virtual void Setup() {} |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 39 | // Test body. Time spent will be recorded. |
Po-Hsien Wang | 42e116c | 2020-06-09 16:10:27 -0700 | [diff] [blame] | 40 | virtual void Run() = 0; |
| 41 | // Test cleanup after looping Run. Time spent here will be recorded. |
Po-Hsien Wang | a956e65 | 2020-11-11 16:29:04 -0800 | [diff] [blame] | 42 | virtual void Cleanup(){}; |
Po-Hsien Wang | 42e116c | 2020-06-09 16:10:27 -0700 | [diff] [blame] | 43 | // Free and Destroy any resources allocated during Initialize. Time |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 44 | // spent here will not be recorded. |
Po-Hsien Wang | 42e116c | 2020-06-09 16:10:27 -0700 | [diff] [blame] | 45 | virtual void Destroy() = 0; |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 46 | |
Po-Hsien Wang | a0e1c31 | 2020-09-24 22:06:52 +0800 | [diff] [blame] | 47 | vkbench::vkBase* vk; |
Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | } // namespace vkbench |
| 51 | #endif |