1cc1dc7a3Sopenharmony_ci# Testing astcenc
2cc1dc7a3Sopenharmony_ci
3cc1dc7a3Sopenharmony_ciThe repository contains a small suite of tests which can be used to sanity
4cc1dc7a3Sopenharmony_cicheck source code changes to the compressor. It must be noted that this test
5cc1dc7a3Sopenharmony_cisuite is relatively limited in scope and does not cover every feature or
6cc1dc7a3Sopenharmony_cibitrate of the standard.
7cc1dc7a3Sopenharmony_ci
8cc1dc7a3Sopenharmony_ci# Required software
9cc1dc7a3Sopenharmony_ci
10cc1dc7a3Sopenharmony_ciRunning the tests requires Python 3.7 to be installed on the host machine, and
11cc1dc7a3Sopenharmony_cian `astcenc-avx2` release build to have been previously compiled and installed
12cc1dc7a3Sopenharmony_ciinto an directory called `astcenc` in the root of the git checkout. This
13cc1dc7a3Sopenharmony_cican be achieved by configuring the CMake build using the install prefix
14cc1dc7a3Sopenharmony_ci`-DCMAKE_INSTALL_PREFIX=../` and then running a build with the `install` build
15cc1dc7a3Sopenharmony_citarget.
16cc1dc7a3Sopenharmony_ci
17cc1dc7a3Sopenharmony_ci# Running C++ unit tests
18cc1dc7a3Sopenharmony_ci
19cc1dc7a3Sopenharmony_ciWe support a small (but growing) number of C++ unit tests, which are written
20cc1dc7a3Sopenharmony_ciusing the `googletest` framework and integrated in the CMake "CTest" test
21cc1dc7a3Sopenharmony_ciframework.
22cc1dc7a3Sopenharmony_ci
23cc1dc7a3Sopenharmony_ciTo build unit tests pull the `googletest` git submodule and add
24cc1dc7a3Sopenharmony_ci`-DASTCENC_UNITTEST=ON` to the CMake command line when configuring.
25cc1dc7a3Sopenharmony_ci
26cc1dc7a3Sopenharmony_ciTo run unit tests use the CMake `ctest` utility from your build directory after
27cc1dc7a3Sopenharmony_ciyou have built the tests.
28cc1dc7a3Sopenharmony_ci
29cc1dc7a3Sopenharmony_ci```shell
30cc1dc7a3Sopenharmony_cicd build
31cc1dc7a3Sopenharmony_cictest --verbose
32cc1dc7a3Sopenharmony_ci```
33cc1dc7a3Sopenharmony_ci
34cc1dc7a3Sopenharmony_ci# Running command line tests
35cc1dc7a3Sopenharmony_ci
36cc1dc7a3Sopenharmony_ciTo run the command line tests, which aim to get coverage of the command line
37cc1dc7a3Sopenharmony_cioptions and core codec stability without testing the compression quality
38cc1dc7a3Sopenharmony_ciitself, run the command line:
39cc1dc7a3Sopenharmony_ci
40cc1dc7a3Sopenharmony_ci    python3 -m unittest discover -s Test -p astc_test*.py -v
41cc1dc7a3Sopenharmony_ci
42cc1dc7a3Sopenharmony_ci# Running image tests
43cc1dc7a3Sopenharmony_ci
44cc1dc7a3Sopenharmony_ciTo run the image test suite run the following command from the root directory
45cc1dc7a3Sopenharmony_ciof the repository:
46cc1dc7a3Sopenharmony_ci
47cc1dc7a3Sopenharmony_ci    python3 ./Test/astc_test_image.py
48cc1dc7a3Sopenharmony_ci
49cc1dc7a3Sopenharmony_ciThis will run though a series of image compression tests, comparing the image
50cc1dc7a3Sopenharmony_ciPSNR against a set of reference results from the last stable baseline. The test
51cc1dc7a3Sopenharmony_ciwill fail if any reduction in PSNR above a set threshold is detected. Note that
52cc1dc7a3Sopenharmony_ciperformance information is reported, but regressions will not flag a failure.
53cc1dc7a3Sopenharmony_ci
54cc1dc7a3Sopenharmony_ciFor debug purposes, all decompressed test output images and result CSV files
55cc1dc7a3Sopenharmony_ciare stored in the `TestOutput` directory, using the same test set structure as
56cc1dc7a3Sopenharmony_cithe `Test/Images` folder.
57cc1dc7a3Sopenharmony_ci
58cc1dc7a3Sopenharmony_ci## Test selection
59cc1dc7a3Sopenharmony_ci
60cc1dc7a3Sopenharmony_ciThe runner supports a number of options to filter down what is run, enabling
61cc1dc7a3Sopenharmony_cidevelopers to focus local testing on the parts of the code they are working on.
62cc1dc7a3Sopenharmony_ci
63cc1dc7a3Sopenharmony_ci* `--encoder` selects which encoder to run. By default the `avx2` encoder is
64cc1dc7a3Sopenharmony_ci  selected. Note that some out-of-tree reference encoders (older encoders, and
65cc1dc7a3Sopenharmony_ci  some third-party encoders) are supported for comparison purposes. These will
66cc1dc7a3Sopenharmony_ci  not work without the binaries being manually provided; they are not
67cc1dc7a3Sopenharmony_ci  distributed here.
68cc1dc7a3Sopenharmony_ci* `--test-set` selects which image set to run. By default the `Small` image
69cc1dc7a3Sopenharmony_ci  test set is selected, which aims to provide basic coverage of many different
70cc1dc7a3Sopenharmony_ci  color formats and color profiles.
71cc1dc7a3Sopenharmony_ci* `--block-size` selects which block size to run. By default a range of
72cc1dc7a3Sopenharmony_ci  block sizes (2D and 3D) are used.
73cc1dc7a3Sopenharmony_ci* `--color-profile` selects which color profiles from the standard should be
74cc1dc7a3Sopenharmony_ci  used (LDR, LDR sRGB, or HDR) to select images. By default all are selected.
75cc1dc7a3Sopenharmony_ci* `--color-format` selects which color formats should be used (L, XY, RGB,
76cc1dc7a3Sopenharmony_ci  RGBA) to select images. By default all are selected.
77cc1dc7a3Sopenharmony_ci
78cc1dc7a3Sopenharmony_ci## Performance tests
79cc1dc7a3Sopenharmony_ci
80cc1dc7a3Sopenharmony_ciTo provide less noisy performance results the test suite supports compressing
81cc1dc7a3Sopenharmony_cieach image multiple times and returning the best measured performance. To
82cc1dc7a3Sopenharmony_cienable this mode use the following options:
83cc1dc7a3Sopenharmony_ci
84cc1dc7a3Sopenharmony_ci* `--repeats <M>` : Run M test compression passes which are timed.
85cc1dc7a3Sopenharmony_ci
86cc1dc7a3Sopenharmony_ci**Note:**  The reference CSV contains performance results measured on an Intel
87cc1dc7a3Sopenharmony_ciCore i5 9600K running at 4.3GHz, running each test 5 times.
88cc1dc7a3Sopenharmony_ci
89cc1dc7a3Sopenharmony_ci## Updating reference data
90cc1dc7a3Sopenharmony_ci
91cc1dc7a3Sopenharmony_ciThe reference PSNR and performance scores are stored in CSVs committed to the
92cc1dc7a3Sopenharmony_cirepository. This data is created by running the tests using the last stable
93cc1dc7a3Sopenharmony_cirelease on a standard test machine we use for performance testing builds.
94cc1dc7a3Sopenharmony_ci
95cc1dc7a3Sopenharmony_ciIt can be useful for developers to rebuild the reference results for their
96cc1dc7a3Sopenharmony_cilocal machine, in particular for measuring performance improvements. To build
97cc1dc7a3Sopenharmony_cinew reference CSVs, download the current reference `astcenc` binary (1.7) from
98cc1dc7a3Sopenharmony_ciGitHub for your host OS and place it in to the `./Binaries/1.7/` directory.
99cc1dc7a3Sopenharmony_ciOnce this is done, run the command:
100cc1dc7a3Sopenharmony_ci
101cc1dc7a3Sopenharmony_ci    python3 ./Test/astc_test_image.py --encoder 1.7 --test-set all --repeats 5
102cc1dc7a3Sopenharmony_ci
103cc1dc7a3Sopenharmony_ci... to regenerate the reference CSV files.
104cc1dc7a3Sopenharmony_ci
105cc1dc7a3Sopenharmony_ci**WARNING:** This can take some hours to complete, and it is best done when the
106cc1dc7a3Sopenharmony_citest suite gets exclusive use of the machine to avoid other processing slowing
107cc1dc7a3Sopenharmony_cidown the compression and disturbing the performance data. It is recommended to
108cc1dc7a3Sopenharmony_cishutdown or disable any background applications that are running.
109cc1dc7a3Sopenharmony_ci
110cc1dc7a3Sopenharmony_ci## Valgrind memcheck
111cc1dc7a3Sopenharmony_ci
112cc1dc7a3Sopenharmony_ciIt is always worth running the Valgrind memcheck tool to validate that we have
113cc1dc7a3Sopenharmony_cinot introduced any obvious memory errors. Build a release build with symbols
114cc1dc7a3Sopenharmony_ciinformation with `-DCMAKE_BUILD_TYPE=RelWithDebInfo` and then run:
115cc1dc7a3Sopenharmony_ci
116cc1dc7a3Sopenharmony_ci    valgrind --tool=memcheck --track-origins=yes <command>
117cc1dc7a3Sopenharmony_ci
118cc1dc7a3Sopenharmony_ci- - -
119cc1dc7a3Sopenharmony_ci
120cc1dc7a3Sopenharmony_ci_Copyright © 2019-2022, Arm Limited and contributors. All rights reserved._
121