blob: 864fa9caed55319c26dc6fb4b46288be438d247f [file] [log] [blame]
Jeremy Johnson48df8c72023-09-12 14:52:34 +01001"""Tests for the python interface to the verifier library."""
2# Copyright (c) 2023, ARM Limited.
3# SPDX-License-Identifier: Apache-2.0
4from pathlib import Path
5
6import numpy as np
7import pytest
8from checker.verifier import VerifierError
9from checker.verifier import VerifierLibrary
10
11# NOTE: These tests are set to POST COMMIT - so will only run on the CI
12
13# Location of reference model binaries
14REF_MODEL_BUILD_PATH = Path(__file__).resolve().parents[2] / "build" / "reference_model"
15VERIFIER_LIB = "libtosa_reference_verify_lib.so"
16VERIFIER_LIB_PATH = REF_MODEL_BUILD_PATH / VERIFIER_LIB
17
18
19@pytest.mark.postcommit
20def test_verifier_lib_built():
21 """First test to check the library has been built."""
22 assert VERIFIER_LIB_PATH.is_file()
23
24
25@pytest.mark.postcommit
26def test_checker_verifier_load_fail():
27 with pytest.raises(VerifierError) as excinfo:
28 VerifierLibrary(Path("/place-that-does-not-exist"))
Jeremy Johnsonf0348ea2023-09-27 16:10:59 +010029 assert str(excinfo.value).startswith("Could not find verify library")
Jeremy Johnson48df8c72023-09-12 14:52:34 +010030
31
32@pytest.mark.postcommit
33def test_checker_verifier_load():
Jeremy Johnsonf0348ea2023-09-27 16:10:59 +010034 vlib = VerifierLibrary(VERIFIER_LIB_PATH)
Jeremy Johnson48df8c72023-09-12 14:52:34 +010035 assert vlib
36
37
38JSON_COMPLIANCE_DOT_PRODUCT = {
39 "version": "0.1",
40 "tensors": {
41 "output1": {
42 "mode": "DOT_PRODUCT",
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010043 "data_type": "FP32",
44 "dot_product_info": {"ks": 1000, "s": 0},
Jeremy Johnson48df8c72023-09-12 14:52:34 +010045 }
46 },
47}
48
49
50@pytest.mark.postcommit
51def test_checker_verifier_dot_product_check():
Jeremy Johnsonf0348ea2023-09-27 16:10:59 +010052 vlib = VerifierLibrary(VERIFIER_LIB_PATH)
Jeremy Johnson48df8c72023-09-12 14:52:34 +010053 assert vlib
54
55 imp_arr = np.zeros((10, 10, 10), dtype=np.float32)
56 ref_arr = np.zeros((10, 10, 10), dtype=np.float64)
57 bnd_arr = np.zeros((10, 10, 10), dtype=np.float64)
58
59 json_config = JSON_COMPLIANCE_DOT_PRODUCT
60
61 ret = vlib.verify_data("output1", json_config, imp_arr, ref_arr, bnd_arr)
62 assert ret
63
64
65@pytest.mark.postcommit
66def test_checker_verifier_dot_product_check_fail():
Jeremy Johnsonf0348ea2023-09-27 16:10:59 +010067 vlib = VerifierLibrary(VERIFIER_LIB_PATH)
Jeremy Johnson48df8c72023-09-12 14:52:34 +010068 assert vlib
69
70 imp_arr = np.zeros((10, 10, 10), dtype=np.float32)
71 ref_arr = np.ones((10, 10, 10), dtype=np.float64)
72 bnd_arr = np.zeros((10, 10, 10), dtype=np.float64)
73
74 json_config = JSON_COMPLIANCE_DOT_PRODUCT
75
76 ret = vlib.verify_data("output1", json_config, imp_arr, ref_arr, bnd_arr)
77 assert not ret