2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
15 #include "config/aom_config.h"
16 #include "config/av1_rtcd.h"
18 #include "aom_ports/aom_timer.h"
19 #include "av1/encoder/hash.h"
20 #include "test/acm_random.h"
21 #include "test/util.h"
22 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
26 typedef uint32_t (*get_crc32c_value_func
)(void *calculator
, uint8_t *p
,
29 typedef ::testing::tuple
<get_crc32c_value_func
, int> HashParam
;
31 class AV1Crc32cHashTest
: public ::testing::TestWithParam
<HashParam
> {
39 void RunCheckOutput(get_crc32c_value_func test_impl
);
40 void RunSpeedTest(get_crc32c_value_func test_impl
);
42 void RunZeroTest(get_crc32c_value_func test_impl
);
44 libaom_test::ACMRandom rnd_
;
51 AV1Crc32cHashTest::~AV1Crc32cHashTest() { ; }
53 void AV1Crc32cHashTest::SetUp() {
54 rnd_
.Reset(libaom_test::ACMRandom::DeterministicSeed());
55 av1_crc32c_calculator_init(&calc_
);
57 bsize_
= GET_PARAM(1);
58 length_
= bsize_
* bsize_
* sizeof(uint16_t);
59 buffer_
= new uint8_t[length_
];
60 ASSERT_TRUE(buffer_
!= NULL
);
61 for (int i
= 0; i
< length_
; ++i
) {
62 buffer_
[i
] = rnd_
.Rand8();
66 void AV1Crc32cHashTest::TearDown() { delete[] buffer_
; }
68 void AV1Crc32cHashTest::RunCheckOutput(get_crc32c_value_func test_impl
) {
69 get_crc32c_value_func ref_impl
= av1_get_crc32c_value_c
;
70 // for the same buffer crc should be the same
71 uint32_t crc0
= test_impl(&calc_
, buffer_
, length_
);
72 uint32_t crc1
= test_impl(&calc_
, buffer_
, length_
);
73 uint32_t crc2
= ref_impl(&calc_
, buffer_
, length_
);
74 ASSERT_EQ(crc0
, crc1
);
75 ASSERT_EQ(crc0
, crc2
); // should equal to software version
78 uint32_t crc3
= test_impl(&calc_
, buffer_
, length_
);
79 uint32_t crc4
= ref_impl(&calc_
, buffer_
, length_
);
80 ASSERT_NE(crc0
, crc3
); // crc shoud not equal to previous one
81 ASSERT_EQ(crc3
, crc4
);
84 void AV1Crc32cHashTest::RunSpeedTest(get_crc32c_value_func test_impl
) {
85 get_crc32c_value_func impls
[] = { av1_get_crc32c_value_c
, test_impl
};
86 const int repeat
= 10000000 / (bsize_
+ bsize_
);
90 for (int i
= 0; i
< 2; ++i
) {
91 aom_usec_timer_start(&timer
);
92 for (int j
= 0; j
< repeat
; ++j
) {
93 impls
[i
](&calc_
, buffer_
, length_
);
95 aom_usec_timer_mark(&timer
);
96 time
[i
] = static_cast<double>(aom_usec_timer_elapsed(&timer
));
98 printf("hash %3dx%-3d:%7.2f/%7.2fus", bsize_
, bsize_
, time
[0], time
[1]);
99 printf("(%3.2f)\n", time
[0] / time
[1]);
102 void AV1Crc32cHashTest::RunZeroTest(get_crc32c_value_func test_impl
) {
103 uint8_t buffer0
[1024] = { 0 };
104 // for buffer with different size the crc should not be the same
105 const uint32_t crc0
= test_impl(&calc_
, buffer0
, 32);
106 const uint32_t crc1
= test_impl(&calc_
, buffer0
, 128);
107 const uint32_t crc2
= test_impl(&calc_
, buffer0
, 1024);
108 ASSERT_NE(crc0
, crc1
);
109 ASSERT_NE(crc0
, crc2
);
110 ASSERT_NE(crc1
, crc2
);
113 TEST_P(AV1Crc32cHashTest
, CheckOutput
) { RunCheckOutput(GET_PARAM(0)); }
115 TEST_P(AV1Crc32cHashTest
, CheckZero
) { RunZeroTest(GET_PARAM(0)); }
117 TEST_P(AV1Crc32cHashTest
, DISABLED_Speed
) { RunSpeedTest(GET_PARAM(0)); }
119 const int kValidBlockSize
[] = { 64, 32, 8, 4 };
121 INSTANTIATE_TEST_CASE_P(
122 C
, AV1Crc32cHashTest
,
123 ::testing::Combine(::testing::Values(&av1_get_crc32c_value_c
),
124 ::testing::ValuesIn(kValidBlockSize
)));
127 INSTANTIATE_TEST_CASE_P(
128 SSE4_2
, AV1Crc32cHashTest
,
129 ::testing::Combine(::testing::Values(&av1_get_crc32c_value_sse4_2
),
130 ::testing::ValuesIn(kValidBlockSize
)));