Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Use descriptive test name suffix for parameterized unit tests #335

Open
@uartie

Description

@uartie

Currently, gtest automatically appends an incremented number (index) to each parameterized test case to uniquely distinguish it from the others. Unfortunately, if the order of those parameters are redefined in source then the index previously associated with a specific parameter is changed. This causes issues when collecting test statistics and test reports based on test name. For example, we currently have the following parameterized unit tests:

Misc/JPEGEncodeInputTest.
  Full/0  # GetParam() = (Fixed Size 150x75, 0x5ff61d pointing to "I420")
  Full/1  # GetParam() = (Fixed Size 150x75, 0x5ff618 pointing to "NV12")
  Full/2  # GetParam() = (Fixed Size 150x75, 0x5ff613 pointing to "UYVY")
  Full/3  # GetParam() = (Fixed Size 150x75, 0x5ff60e pointing to "YUY2")
  Full/4  # GetParam() = (Fixed Size 150x75, 0x5ff609 pointing to "Y800")
  Full/5  # GetParam() = (Fixed Size 10x10, 0x5ff61d pointing to "I420")
  Full/6  # GetParam() = (Fixed Size 10x10, 0x5ff618 pointing to "NV12")
  Full/7  # GetParam() = (Fixed Size 10x10, 0x5ff613 pointing to "UYVY")
  Full/8  # GetParam() = (Fixed Size 10x10, 0x5ff60e pointing to "YUY2")
  Full/9  # GetParam() = (Fixed Size 10x10, 0x5ff609 pointing to "Y800")
  Full/10  # GetParam() = (Fixed Size 385x610, 0x5ff61d pointing to "I420")
  Full/11  # GetParam() = (Fixed Size 385x610, 0x5ff618 pointing to "NV12")
  Full/12  # GetParam() = (Fixed Size 385x610, 0x5ff613 pointing to "UYVY")
  Full/13  # GetParam() = (Fixed Size 385x610, 0x5ff60e pointing to "YUY2")
  Full/14  # GetParam() = (Fixed Size 385x610, 0x5ff609 pointing to "Y800")
  Full/15  # GetParam() = (Fixed Size 1245x1281, 0x5ff61d pointing to "I420")
  Full/16  # GetParam() = (Fixed Size 1245x1281, 0x5ff618 pointing to "NV12")
  Full/17  # GetParam() = (Fixed Size 1245x1281, 0x5ff613 pointing to "UYVY")
  Full/18  # GetParam() = (Fixed Size 1245x1281, 0x5ff60e pointing to "YUY2")
  Full/19  # GetParam() = (Fixed Size 1245x1281, 0x5ff609 pointing to "Y800")

... if we were to remove, say, the Fixed Size 10x10 parameter tests (i.e. Full/5 thru Full/9), then starting from "Fixed Size 385x610, gtest would then associate those with Full/5and onward. Hence, any statistics forFull/5` onward would be erroneous/invalid.

Fortunately, the INSTANTIATE_TEST_CASE_P gtest macro allows a fourth parameter (a generator) that allows us to customize the test name suffix for each parameter. This would allow us to create test names derived directly from it's parameters (not index), for example:

Misc/JPEGEncodeInputTest.
  Full/I420_150x75  # GetParam() = (Fixed Size 150x75, 0x5ff83d pointing to "I420")
  Full/NV12_150x75  # GetParam() = (Fixed Size 150x75, 0x5ff838 pointing to "NV12")
  Full/UYVY_150x75  # GetParam() = (Fixed Size 150x75, 0x5ff833 pointing to "UYVY")
  Full/YUY2_150x75  # GetParam() = (Fixed Size 150x75, 0x5ff82e pointing to "YUY2")
  Full/Y800_150x75  # GetParam() = (Fixed Size 150x75, 0x5ff829 pointing to "Y800")
  Full/I420_10x10  # GetParam() = (Fixed Size 10x10, 0x5ff83d pointing to "I420")
  Full/NV12_10x10  # GetParam() = (Fixed Size 10x10, 0x5ff838 pointing to "NV12")
  Full/UYVY_10x10  # GetParam() = (Fixed Size 10x10, 0x5ff833 pointing to "UYVY")
  Full/YUY2_10x10  # GetParam() = (Fixed Size 10x10, 0x5ff82e pointing to "YUY2")
  Full/Y800_10x10  # GetParam() = (Fixed Size 10x10, 0x5ff829 pointing to "Y800")
  Full/I420_385x610  # GetParam() = (Fixed Size 385x610, 0x5ff83d pointing to "I420")
  Full/NV12_385x610  # GetParam() = (Fixed Size 385x610, 0x5ff838 pointing to "NV12")
  Full/UYVY_385x610  # GetParam() = (Fixed Size 385x610, 0x5ff833 pointing to "UYVY")
  Full/YUY2_385x610  # GetParam() = (Fixed Size 385x610, 0x5ff82e pointing to "YUY2")
  Full/Y800_385x610  # GetParam() = (Fixed Size 385x610, 0x5ff829 pointing to "Y800")
  Full/I420_1245x1281  # GetParam() = (Fixed Size 1245x1281, 0x5ff83d pointing to "I420")
  Full/NV12_1245x1281  # GetParam() = (Fixed Size 1245x1281, 0x5ff838 pointing to "NV12")
  Full/UYVY_1245x1281  # GetParam() = (Fixed Size 1245x1281, 0x5ff833 pointing to "UYVY")
  Full/YUY2_1245x1281  # GetParam() = (Fixed Size 1245x1281, 0x5ff82e pointing to "YUY2")
  Full/Y800_1245x1281  # GetParam() = (Fixed Size 1245x1281, 0x5ff829 pointing to "Y800")

Note that randomized parameters will need to be handled with care to ensure the test name is unique and not randomly changing.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions