xref: /aosp_15_r20/external/deqp/external/vulkancts/scripts/amber_verify.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# Vulkan CTS
5# ----------
6#
7# Copyright (c) 2022 Google LLC.
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import os
24import sys
25import argparse
26import tempfile
27
28scriptPath = os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts")
29sys.path.insert(0, scriptPath)
30
31from ctsbuild.common import *
32from ctsbuild.config import *
33from ctsbuild.build import *
34
35class Module:
36    def __init__ (self, name, dirName, binName):
37        self.name = name
38        self.dirName = dirName
39        self.binName = binName
40
41VULKAN_MODULE = Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk")
42DEFAULT_BUILD_DIR = os.path.join(tempfile.gettempdir(), "amber-verify", "{targetName}-{buildType}")
43DEFAULT_TARGET = "null"
44DEFAULT_DST_DIR = os.path.join(DEQP_DIR, "external", "vulkancts", "data", "vulkan", "prebuilt")
45
46def getBuildConfig (buildPathPtrn, targetName, buildType):
47    buildPath = buildPathPtrn.format(
48        targetName = targetName,
49        buildType = buildType)
50
51    return BuildConfig(buildPath, buildType, [f"-DDEQP_TARGET={targetName}"])
52
53def execBuildPrograms (buildCfg, generator, module):
54    workDir = os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
55
56    pushWorkingDir(workDir)
57
58    try:
59        binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "deqp-vk"))
60        execute([binPath, "--deqp-runmode=amber-verify"])
61    finally:
62        popWorkingDir()
63
64def parseArgs ():
65    parser = argparse.ArgumentParser(description = "Verify amber device requirements between CTS and .amber file",
66                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
67    parser.add_argument("-b",
68                        "--build-dir",
69                        dest="buildDir",
70                        default=DEFAULT_BUILD_DIR,
71                        help="Temporary build directory")
72    parser.add_argument("-t",
73                        "--build-type",
74                        dest="buildType",
75                        default="Release",
76                        help="Build type")
77    parser.add_argument("-c",
78                        "--deqp-target",
79                        dest="targetName",
80                        default=DEFAULT_TARGET,
81                        help="dEQP build target")
82    parser.add_argument("-d",
83                        "--dst-path",
84                        dest="dstPath",
85                        default=DEFAULT_DST_DIR,
86                        help="Destination path")
87    return parser.parse_args()
88
89if __name__ == "__main__":
90    args = parseArgs()
91
92    generator = ANY_GENERATOR
93    buildCfg = getBuildConfig(args.buildDir, args.targetName, args.buildType)
94    module = VULKAN_MODULE
95
96    build(buildCfg, generator, ["deqp-vk"])
97
98    if not os.path.exists(args.dstPath):
99        os.makedirs(args.dstPath)
100
101    execBuildPrograms(buildCfg, generator, module)
102