1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <cstdlib>
16 #include <gtest/gtest.h>
17 #include <securec.h>
18 #include <sys/time.h>
19
20 #include "astc_codec.h"
21 #include "buffer_packer_stream.h"
22 #ifdef ENABLE_ASTC_ENCODE_BASED_GPU
23 #include "image_compressor.h"
24 #endif
25 #include "image_source_util.h"
26 #include "image_system_properties.h"
27 #include "image_utils.h"
28 #include "media_errors.h"
29
30 using namespace testing::ext;
31 using namespace OHOS::Media;
32 using namespace OHOS::ImagePlugin;
33 namespace OHOS {
34 namespace Media {
35
36 #ifdef ENABLE_ASTC_ENCODE_BASED_GPU
37 using namespace AstcEncBasedCl;
38 constexpr uint8_t RGBA_BYTES_PIXEL_LOG2 = 2;
39 constexpr int32_t RGBA_MAX_WIDTH = 8192;
40 constexpr int32_t RGBA_MAX_HEIGHT = 8192;
41 #endif
42
43 constexpr int32_t RGBA_TEST0001_WIDTH = 256;
44 constexpr int32_t RGBA_TEST0001_HEIGHT = 256;
45 constexpr int32_t PIXEL_VALUE_MAX = 256;
46 constexpr int32_t TEXTURE_BLOCK_BYTES = 16;
47 constexpr int32_t TEXTURE_HEAD_BYTES = 16;
48 constexpr int32_t ASTC_BLOCK_WIDTH = 4;
49 constexpr int32_t ASTC_BLOCK_HEIGHT = 4;
50 constexpr int32_t OUTPUT_SIZE_MAX = 200000;
51 constexpr int32_t BYTES_PER_PIXEL = 4;
52 constexpr int64_t SECOND_TO_MICROS = 1000000;
53 constexpr size_t FILE_NAME_LENGTH = 512;
54 struct AstcEncTestPara {
55 TextureEncodeOptions param;
56 int32_t width;
57 int32_t height;
58 uint8_t block;
59 size_t frames;
60 bool isBasedOnGpu;
61 bool isSelfCreatePixMap;
62 QualityProfile privateProfile;
63 int64_t totalTime;
64 bool sutEncEnable;
65 };
66
67 enum class TestEncRet {
68 ERR_OK = 0,
69 ERR_FILE_NOT_FIND,
70 ERR_ENC_FAILED,
71 ERR_LOW_LEVEL_FAILED
72 };
73
74 class PluginTextureEncodeTest : public testing::Test {
75 public:
PluginTextureEncodeTest()76 PluginTextureEncodeTest() {}
~PluginTextureEncodeTest()77 ~PluginTextureEncodeTest() {}
78 };
79
CreateDefaultEncParam()80 static TextureEncodeOptions CreateDefaultEncParam()
81 {
82 TextureEncodeOptions param;
83 param.width_ = RGBA_TEST0001_WIDTH;
84 param.height_ = RGBA_TEST0001_HEIGHT;
85 param.stride_ = RGBA_TEST0001_WIDTH;
86 param.blockX_ = ASTC_BLOCK_WIDTH;
87 param.blockY_ = ASTC_BLOCK_HEIGHT;
88 return param;
89 }
90
ConstructPixmap(int32_t width,int32_t height)91 static std::unique_ptr<PixelMap> ConstructPixmap(int32_t width, int32_t height)
92 {
93 std::unique_ptr<PixelMap> pixelMap = std::make_unique<PixelMap>();
94 ImageInfo info;
95 info.size.width = width;
96 info.size.height = height;
97 info.pixelFormat = PixelFormat::RGBA_8888;
98 info.colorSpace = ColorSpace::SRGB;
99 info.alphaType = AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
100 pixelMap->SetImageInfo(info);
101
102 int32_t bytesPerPixel = BYTES_PER_PIXEL;
103 int32_t rowDataSize = width * bytesPerPixel;
104 uint32_t bufferSize = rowDataSize * height;
105 if (bufferSize <= 0) {
106 return nullptr;
107 }
108 void *buffer = malloc(bufferSize);
109 if (buffer == nullptr) {
110 return nullptr;
111 }
112 uint8_t *ch = static_cast<uint8_t *>(buffer);
113 for (unsigned int i = 0; i < bufferSize; ++i) {
114 *(ch++) = static_cast<uint8_t>(i % PIXEL_VALUE_MAX);
115 }
116
117 pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
118
119 return pixelMap;
120 }
121
CurrentTimeInUs(void)122 static int64_t CurrentTimeInUs(void)
123 {
124 struct timeval tv;
125 gettimeofday(&tv, nullptr);
126 return tv.tv_sec * SECOND_TO_MICROS + tv.tv_usec;
127 }
128
129 /**
130 * @tc.name: ASTCEncode001
131 * @tc.desc: Test the AstcSoftwareEncode function
132 * @tc.type: FUNC
133 */
134 HWTEST_F(PluginTextureEncodeTest, ASTCEncode001, TestSize.Level3)
135 {
136 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode001 start";
137
138 std::unique_ptr<PixelMap> pixelMap = ConstructPixmap(RGBA_TEST0001_WIDTH, RGBA_TEST0001_HEIGHT);
139 ASSERT_NE(pixelMap, nullptr);
140 PixelMap *pixelMapPtr = pixelMap.get();
141 ASSERT_NE(pixelMapPtr, nullptr);
142
143 uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
144 ASSERT_NE(output, nullptr);
145 BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
146 ASSERT_NE(stream, nullptr);
147
148 struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
149 AstcCodec astcEncoder;
150 uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
151 ASSERT_EQ(setRet, SUCCESS);
152 uint32_t astcRet = astcEncoder.ASTCEncode();
153 ASSERT_EQ(astcRet, SUCCESS);
154
155 option.quality = 20; // quality 20: HIGH_SPEED_PROFILE
156 setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
157 ASSERT_EQ(setRet, SUCCESS);
158 astcRet = astcEncoder.ASTCEncode();
159 ASSERT_EQ(astcRet, SUCCESS);
160
161 if (output != nullptr) {
162 free(output);
163 output = nullptr;
164 }
165 if (stream != nullptr) {
166 delete stream;
167 stream = nullptr;
168 }
169 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode001 end";
170 }
171
172 /**
173 * @tc.name: ASTCEncode002
174 * @tc.desc: Test the SetAstcEncode function
175 * @tc.desc: Set outputStream to nullptr
176 * @tc.type: FUNC
177 */
178 HWTEST_F(PluginTextureEncodeTest, ASTCEncode002, TestSize.Level3)
179 {
180 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode002 start";
181
182 std::unique_ptr<PixelMap> pixelMap = ConstructPixmap(RGBA_TEST0001_WIDTH, RGBA_TEST0001_HEIGHT);
183 ASSERT_NE(pixelMap, nullptr);
184 Media::PixelMap *pixelMapPtr = pixelMap.get();
185 ASSERT_NE(pixelMapPtr, nullptr);
186
187 BufferPackerStream *stream = nullptr;
188
189 struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
190 AstcCodec astcEncoder;
191 uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
192 ASSERT_EQ(setRet, ERROR);
193 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode002 end";
194 }
195
196 /**
197 * @tc.name: ASTCEncode003
198 * @tc.desc: Test the SetAstcEncode function
199 * @tc.desc: Set pixelMap to nullptr
200 * @tc.type: FUNC
201 */
202 HWTEST_F(PluginTextureEncodeTest, ASTCEncode003, TestSize.Level3)
203 {
204 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode003 start";
205
206 Media::PixelMap *pixelMapPtr = nullptr;
207
208 uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
209 ASSERT_NE(output, nullptr);
210 BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
211 ASSERT_NE(stream, nullptr);
212
213 struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
214 AstcCodec astcEncoder;
215 uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
216 ASSERT_EQ(setRet, ERROR);
217
218 if (output != nullptr) {
219 free(output);
220 output = nullptr;
221 }
222 if (stream != nullptr) {
223 delete stream;
224 stream = nullptr;
225 }
226 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode003 end";
227 }
228
229 /**
230 * @tc.name: ASTCEncode004
231 * @tc.desc: AstcSoftwareEncode return error test
232 * @tc.type: FUNC
233 */
234 HWTEST_F(PluginTextureEncodeTest, ASTCEncode004, TestSize.Level3)
235 {
236 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode004 start";
237
238 std::unique_ptr<PixelMap> pixelMap = ConstructPixmap(RGBA_TEST0001_WIDTH, RGBA_TEST0001_HEIGHT);
239 ASSERT_NE(pixelMap, nullptr);
240 Media::PixelMap *pixelMapPtr = pixelMap.get();
241 ASSERT_NE(pixelMapPtr, nullptr);
242
243 uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
244 ASSERT_NE(output, nullptr);
245 BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
246 ASSERT_NE(stream, nullptr);
247
248 struct PlEncodeOptions option = { "image/astc/7*7", 100, 1 }; // quality set to 100
249 AstcCodec astcEncoder;
250 uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
251 ASSERT_EQ(setRet, SUCCESS);
252 uint32_t astcRet = astcEncoder.ASTCEncode();
253 ASSERT_EQ(astcRet, ERROR);
254
255 if (output != nullptr) {
256 free(output);
257 output = nullptr;
258 }
259 if (stream != nullptr) {
260 delete stream;
261 stream = nullptr;
262 }
263 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: ASTCEncode004 end";
264 }
265
266 /**
267 * @tc.name: AstcSoftwareEncode001
268 * @tc.desc: Test the AstcSoftwareEncode function
269 * @tc.desc: Set enableQualityCheck to true
270 * @tc.type: FUNC
271 */
272 HWTEST_F(PluginTextureEncodeTest, AstcSoftwareEncode001, TestSize.Level3)
273 {
274 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcSoftwareEncode001 start";
275
276 std::unique_ptr<PixelMap> pixelMap = ConstructPixmap(RGBA_TEST0001_WIDTH, RGBA_TEST0001_HEIGHT);
277 ASSERT_NE(pixelMap, nullptr);
278 Media::PixelMap *pixelMapPtr = pixelMap.get();
279 ASSERT_NE(pixelMapPtr, nullptr);
280
281 uint8_t *output = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
282 ASSERT_NE(output, nullptr);
283 BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(output, OUTPUT_SIZE_MAX);
284 ASSERT_NE(stream, nullptr);
285
286 TextureEncodeOptions param = CreateDefaultEncParam();
287 param.privateProfile_ = QualityProfile::HIGH_QUALITY_PROFILE;
288 int32_t blocksNum = ((param.width_ + param.blockX_ - 1) / param.blockX_) *
289 ((param.height_ + param.blockY_ - 1) / param.blockY_);
290 int32_t outSize = blocksNum * TEXTURE_BLOCK_BYTES + TEXTURE_BLOCK_BYTES;
291 auto outBuffer = static_cast<uint8_t *>(malloc(outSize));
292 ASSERT_NE(outBuffer, nullptr);
293
294 bool enableQualityCheck = true;
295
296 struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
297 AstcCodec astcEncoder;
298 uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
299 ASSERT_EQ(setRet, SUCCESS);
300 uint32_t softwareRet = astcEncoder.AstcSoftwareEncode(param, enableQualityCheck, blocksNum, outBuffer, outSize);
301 ASSERT_EQ(softwareRet, SUCCESS);
302
303 param.privateProfile_ = QualityProfile::HIGH_SPEED_PROFILE;
304 softwareRet = astcEncoder.AstcSoftwareEncode(param, enableQualityCheck, blocksNum, outBuffer, outSize);
305 ASSERT_EQ(softwareRet, SUCCESS);
306
307 if (output != nullptr) {
308 free(output);
309 output = nullptr;
310 }
311 if (stream != nullptr) {
312 delete stream;
313 stream = nullptr;
314 }
315 if (outBuffer != nullptr) {
316 free(outBuffer);
317 outBuffer = nullptr;
318 }
319 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcSoftwareEncode001 end";
320 }
321
322 /**
323 * @tc.name: AstcSoftwareEncode002
324 * @tc.desc: GenAstcHeader return error test
325 * @tc.desc: header == nullptr
326 * @tc.type: FUNC
327 */
328 HWTEST_F(PluginTextureEncodeTest, AstcSoftwareEncode002, TestSize.Level3)
329 {
330 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcSoftwareEncode003 start";
331
332 std::unique_ptr<PixelMap> pixelMap = ConstructPixmap(RGBA_TEST0001_WIDTH, RGBA_TEST0001_HEIGHT);
333 ASSERT_NE(pixelMap, nullptr);
334 Media::PixelMap *pixelMapPtr = pixelMap.get();
335 ASSERT_NE(pixelMapPtr, nullptr);
336
337 BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(nullptr, OUTPUT_SIZE_MAX);
338 ASSERT_NE(stream, nullptr);
339
340 TextureEncodeOptions param = CreateDefaultEncParam();
341 int32_t blocksNum = ((param.width_ + param.blockX_ - 1) / param.blockX_) *
342 ((param.height_ + param.blockY_ - 1) / param.blockY_);
343 int32_t outSize = blocksNum * TEXTURE_BLOCK_BYTES + TEXTURE_BLOCK_BYTES;
344 bool enableQualityCheck = false;
345 struct PlEncodeOptions option = { "image/astc/4*4", 100, 1 }; // quality set to 100
346 AstcCodec astcEncoder;
347 uint32_t setRet = astcEncoder.SetAstcEncode(stream, option, pixelMapPtr);
348 ASSERT_EQ(setRet, SUCCESS);
349 uint32_t softwareRet = astcEncoder.AstcSoftwareEncode(param, enableQualityCheck, blocksNum, nullptr, outSize);
350 ASSERT_EQ(softwareRet, ERROR);
351
352 if (stream != nullptr) {
353 delete stream;
354 stream = nullptr;
355 }
356 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcSoftwareEncode003 end";
357 }
358
359 #ifdef ENABLE_ASTC_ENCODE_BASED_GPU
360 /**
361 * @tc.name: AstcEncBasedOnCl001
362 * @tc.desc: Test the AstcClFillImage function
363 * @tc.type: FUNC
364 */
365 HWTEST_F(PluginTextureEncodeTest, AstcEncBasedOnCl001, TestSize.Level3)
366 {
367 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcEncBasedOnCl001 start";
368
369 TextureEncodeOptions param = CreateDefaultEncParam();
370 param.stride_ = param.stride_ << RGBA_BYTES_PIXEL_LOG2;
371 int32_t inputSize = (param.width_ * param.height_) << RGBA_BYTES_PIXEL_LOG2;
372 uint8_t *input = static_cast<uint8_t *>(malloc(inputSize));
373 ASSERT_NE(input, nullptr);
374 for (int32_t i = 0; i < inputSize; ++i) {
375 input[i] = static_cast<uint8_t>(i % PIXEL_VALUE_MAX);
376 }
377
378 ClAstcImageOption imageIn;
379 uint32_t ret = AstcClFillImage(&imageIn, input, param.stride_, param.width_, param.height_);
380 ASSERT_EQ(ret, CL_ASTC_ENC_SUCCESS);
381
382 ret = AstcClFillImage(&imageIn, input, param.stride_, 0, param.height_);
383 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
384
385 ret = AstcClFillImage(&imageIn, input, param.stride_, param.width_, 0);
386 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
387
388 ret = AstcClFillImage(&imageIn, input, param.width_ - 1, param.width_, param.height_);
389 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
390
391 ret = AstcClFillImage(&imageIn, input, param.stride_, RGBA_MAX_WIDTH + 1, param.height_);
392 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
393
394 ret = AstcClFillImage(&imageIn, input, param.stride_, param.width_, RGBA_MAX_HEIGHT + 1);
395 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
396
397 ClAstcImageOption *imageInPtr = nullptr;
398 ret = AstcClFillImage(imageInPtr, input, param.stride_, param.width_, param.height_);
399 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
400
401 if (input != nullptr) {
402 free(input);
403 input = nullptr;
404 }
405
406 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcEncBasedOnCl001 end";
407 }
408
409 /**
410 * @tc.name: AstcEncBasedOnCl002
411 * @tc.desc: AstcClEncImage return failed test
412 * @tc.type: FUNC
413 */
414 HWTEST_F(PluginTextureEncodeTest, AstcEncBasedOnCl002, TestSize.Level3)
415 {
416 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcEncBasedOnCl002 start";
417
418 ClAstcHandle *astcClEncoder = static_cast<ClAstcHandle *>(malloc(sizeof(ClAstcHandle)));
419 uint8_t *buffer = static_cast<uint8_t *>(malloc(OUTPUT_SIZE_MAX));
420 ClAstcImageOption imageIn;
421
422 uint32_t ret = AstcClEncImage(nullptr, &imageIn, buffer);
423 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
424
425 ret = AstcClEncImage(astcClEncoder, nullptr, buffer);
426 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
427
428 ret = AstcClEncImage(astcClEncoder, &imageIn, nullptr);
429 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
430
431 astcClEncoder->encObj.blockErrs_ = nullptr;
432 ret = AstcClEncImage(astcClEncoder, &imageIn, buffer);
433 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
434
435 if (astcClEncoder != nullptr) {
436 free(astcClEncoder);
437 astcClEncoder = nullptr;
438 }
439 if (buffer != nullptr) {
440 free(buffer);
441 buffer = nullptr;
442 }
443
444 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcEncBasedOnCl002 end";
445 }
446
447 /**
448 * @tc.name: AstcEncBasedOnCl003
449 * @tc.desc: AstcClClose return failed test
450 * @tc.type: FUNC
451 */
452 HWTEST_F(PluginTextureEncodeTest, AstcEncBasedOnCl003, TestSize.Level3)
453 {
454 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcEncBasedOnCl003 start";
455
456 ClAstcHandle *astcClEncoder = static_cast<ClAstcHandle *>(calloc(1, sizeof(ClAstcHandle)));
457 uint32_t ret = AstcClClose(astcClEncoder);
458 ASSERT_EQ(ret, CL_ASTC_ENC_SUCCESS);
459
460 ret = AstcClClose(nullptr);
461 ASSERT_EQ(ret, CL_ASTC_ENC_FAILED);
462
463 GTEST_LOG_(INFO) << "PluginTextureEncodeTest: AstcEncBasedOnCl003 end";
464 }
465 #endif
466
FillEncodeOptions(TextureEncodeOptions & param,int32_t width,int32_t height,uint8_t block,QualityProfile privateProfile)467 static bool FillEncodeOptions(TextureEncodeOptions ¶m,
468 int32_t width, int32_t height, uint8_t block, QualityProfile privateProfile)
469 {
470 param.enableQualityCheck = false;
471 param.hardwareFlag = false;
472 param.sutProfile = SutProfile::SKIP_SUT;
473 param.width_ = width;
474 param.height_ = height;
475 param.stride_ = width;
476 param.privateProfile_ = privateProfile;
477 param.blockX_ = block;
478 param.blockY_ = block;
479 if ((param.blockX_ != 0) && (param.blockY_ != 0)) {
480 param.blocksNum = ((param.width_ + param.blockX_ - 1) / param.blockX_) *
481 ((param.height_ + param.blockY_ - 1) / param.blockY_);
482 } else {
483 return false;
484 }
485 param.astcBytes = param.blocksNum * TEXTURE_BLOCK_BYTES + TEXTURE_HEAD_BYTES;
486 return true;
487 }
488
489 #ifdef ENABLE_ASTC_ENCODE_BASED_GPU
TryAstcEncBasedOnCl(TextureEncodeOptions & param,uint8_t * inData,uint8_t * buffer,const std::string & clBinPath)490 static bool TryAstcEncBasedOnCl(TextureEncodeOptions ¶m, uint8_t *inData,
491 uint8_t *buffer, const std::string &clBinPath)
492 {
493 ClAstcHandle *astcClEncoder = nullptr;
494 if ((inData == nullptr) || (buffer == nullptr)) {
495 GTEST_LOG_(ERROR) << "astc Please check TryAstcEncBasedOnCl input!";
496 return false;
497 }
498 if (AstcClCreate(&astcClEncoder, clBinPath) != CL_ASTC_ENC_SUCCESS) {
499 GTEST_LOG_(ERROR) << "astc AstcClCreate failed!";
500 return false;
501 }
502 ClAstcImageOption imageIn;
503 if (AstcClFillImage(&imageIn, inData, param.stride_, param.width_, param.height_) != CL_ASTC_ENC_SUCCESS) {
504 GTEST_LOG_(ERROR) << "astc AstcClFillImage failed!";
505 AstcClClose(astcClEncoder);
506 return false;
507 }
508 if (AstcClEncImage(astcClEncoder, &imageIn, buffer) != CL_ASTC_ENC_SUCCESS) {
509 GTEST_LOG_(ERROR) << "astc AstcClEncImage failed!";
510 AstcClClose(astcClEncoder);
511 return false;
512 }
513 if (AstcClClose(astcClEncoder) != CL_ASTC_ENC_SUCCESS) {
514 GTEST_LOG_(ERROR) << "astc AstcClClose failed!";
515 return false;
516 }
517 return true;
518 }
519 #endif
520
SelfCreatePixMap(uint8_t * pixelMap,size_t bytesPerFile,size_t idx)521 static void SelfCreatePixMap(uint8_t *pixelMap, size_t bytesPerFile, size_t idx)
522 {
523 uint8_t *buf = pixelMap;
524 for (size_t pixel = 0; pixel < bytesPerFile; pixel++) {
525 *buf++ = (pixel + idx) % PIXEL_VALUE_MAX;
526 }
527 }
528
CheckFileIsExist(const std::string & name)529 static bool CheckFileIsExist(const std::string &name)
530 {
531 return (access(name.c_str(), F_OK) != -1); // -1 means that the file is not exist
532 }
533
ReadFileExtern(uint8_t * pixelMap,size_t bytesPerFile,size_t idx,AstcEncTestPara & testPara)534 static TestEncRet ReadFileExtern(uint8_t *pixelMap, size_t bytesPerFile, size_t idx, AstcEncTestPara &testPara)
535 {
536 const std::string testPath = "/data/local/tmp";
537 char inFile[FILE_NAME_LENGTH];
538 if (sprintf_s(inFile, sizeof(inFile), "%s/%dx%d/a%04ld_%dx%d.rgb", testPath.c_str(),
539 testPara.width, testPara.height, idx + 1, testPara.width, testPara.height) < 0) {
540 return TestEncRet::ERR_LOW_LEVEL_FAILED;
541 }
542 std::string fileStr(inFile);
543 if (!CheckFileIsExist(fileStr)) {
544 GTEST_LOG_(ERROR) << "File is not exist: " << inFile;
545 return TestEncRet::ERR_FILE_NOT_FIND;
546 }
547 std::ifstream contents{fileStr};
548 std::string fileContent{std::istreambuf_iterator<char>{contents}, {}};
549 if (fileContent.length() < bytesPerFile) {
550 GTEST_LOG_(ERROR) << "File size is too small: need " << bytesPerFile <<
551 " bytes, but the file only " << fileContent.length() << " bytes in " << inFile;
552 return TestEncRet::ERR_LOW_LEVEL_FAILED;
553 }
554 if (memcpy_s(pixelMap, bytesPerFile, static_cast<const char *>(fileContent.c_str()), bytesPerFile) != 0) {
555 GTEST_LOG_(ERROR) << "file memcpy_s failed";
556 return TestEncRet::ERR_LOW_LEVEL_FAILED;
557 }
558 return TestEncRet::ERR_OK;
559 }
560
FreeMem(uint8_t * pixelMap,uint8_t * astcBuf)561 static void FreeMem(uint8_t *pixelMap, uint8_t *astcBuf)
562 {
563 if (pixelMap != nullptr) {
564 free(pixelMap);
565 }
566 if (astcBuf != nullptr) {
567 free(astcBuf);
568 }
569 }
570
EncodeMutiFrames(AstcEncTestPara & testPara)571 TestEncRet EncodeMutiFrames(AstcEncTestPara &testPara)
572 {
573 testPara.totalTime = 0;
574 size_t bytesPerFile = testPara.width * testPara.height * BYTES_PER_PIXEL;
575 std::string clBinPath = "/sys_prod/etc/graphic/AstcEncShader_ALN-AL00.bin";
576 for (size_t idx = 0; idx < testPara.frames; idx++) {
577 uint8_t *pixelMap = static_cast<uint8_t *>(malloc(bytesPerFile * sizeof(uint8_t)));
578 if (pixelMap == nullptr) {
579 return TestEncRet::ERR_LOW_LEVEL_FAILED;
580 }
581 uint8_t *astcBuf = static_cast<uint8_t *>(malloc(testPara.param.astcBytes * sizeof(uint8_t)));
582 if (astcBuf == nullptr) {
583 free(pixelMap);
584 return TestEncRet::ERR_LOW_LEVEL_FAILED;
585 }
586 if (testPara.isSelfCreatePixMap) {
587 SelfCreatePixMap(pixelMap, bytesPerFile, idx);
588 } else {
589 TestEncRet ret = ReadFileExtern(pixelMap, bytesPerFile, idx, testPara);
590 if (ret != TestEncRet::ERR_OK) {
591 FreeMem(pixelMap, astcBuf);
592 return ret;
593 }
594 }
595 int64_t startTime = CurrentTimeInUs();
596 bool isBasedGpu = false;
597 #ifdef ENABLE_ASTC_ENCODE_BASED_GPU
598 if (testPara.isBasedOnGpu) {
599 if (!TryAstcEncBasedOnCl(testPara.param, pixelMap, astcBuf, clBinPath)) {
600 GTEST_LOG_(ERROR) << "astc encoding based on GPU failed";
601 FreeMem(pixelMap, astcBuf);
602 return TestEncRet::ERR_ENC_FAILED;
603 }
604 isBasedGpu = true;
605 }
606 #endif
607 if (!isBasedGpu && !AstcCodec::AstcSoftwareEncodeCore(testPara.param, pixelMap, astcBuf)) {
608 GTEST_LOG_(ERROR) << "astc encoding based on CPU failed";
609 FreeMem(pixelMap, astcBuf);
610 return TestEncRet::ERR_ENC_FAILED;
611 }
612 FreeMem(pixelMap, astcBuf);
613 testPara.totalTime += CurrentTimeInUs() - startTime;
614 }
615 return TestEncRet::ERR_OK;
616 }
617
TestCaseMultiFrameEnc(AstcEncTestPara & testPara)618 TestEncRet TestCaseMultiFrameEnc(AstcEncTestPara &testPara)
619 {
620 if (!FillEncodeOptions(testPara.param, testPara.width, testPara.height,
621 testPara.block, testPara.privateProfile)) {
622 GTEST_LOG_(ERROR) << "FillEncodeOptions failed";
623 return TestEncRet::ERR_LOW_LEVEL_FAILED;
624 }
625 TestEncRet ret = EncodeMutiFrames(testPara);
626 if (ret == TestEncRet::ERR_OK) {
627 GTEST_LOG_(INFO) << "isGPU:" << testPara.isBasedOnGpu << " SelfPixel:" << testPara.isSelfCreatePixMap <<
628 " profile:" << testPara.privateProfile << " " << testPara.param.width_ << "x" <<
629 testPara.param.height_ << " frames " <<
630 testPara.frames << " gpu astc encoding average time: " <<
631 static_cast<float>(testPara.totalTime) / static_cast<float>(testPara.frames) << "us";
632 }
633 return ret;
634 }
635
CreateAstcEncTestPara(int32_t width,int32_t height,uint8_t block,size_t frames,bool isBasedOnGpu)636 static AstcEncTestPara CreateAstcEncTestPara(int32_t width, int32_t height,
637 uint8_t block, size_t frames, bool isBasedOnGpu)
638 {
639 AstcEncTestPara testPara;
640 testPara.width = width;
641 testPara.height = height;
642 testPara.isBasedOnGpu = isBasedOnGpu;
643 testPara.block = block;
644 testPara.frames = frames;
645 testPara.isSelfCreatePixMap = true;
646 testPara.privateProfile = HIGH_SPEED_PROFILE;
647 testPara.sutEncEnable = false;
648 return testPara;
649 }
650
651 /**
652 * @tc.name: AstcEncoderTime_001
653 * @tc.desc: Calculate the average time
654 * : BasedOnCPU / 64x64 / quality 20 / self-created images / 5000frames
655 * @tc.type: Performance
656 */
657 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_001, TestSize.Level3)
658 {
659 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
660 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false);
661 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
662 }
663
664 /**
665 * @tc.name: AstcEncoderTime_002
666 * @tc.desc: Calculate the average time
667 * : BasedOnCPU / 64x64 / quality 100 / self-created images / 5000frames
668 * @tc.type: Performance
669 */
670 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_002, TestSize.Level3)
671 {
672 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
673 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false);
674 testPara.privateProfile = HIGH_QUALITY_PROFILE;
675 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
676 }
677
678 /**
679 * @tc.name: AstcEncoderTime_003
680 * @tc.desc: Calculate the average time
681 * : BasedOnCPU / 64x64 / quality 20 / Extern images / 5000frames
682 * @tc.type: Performance
683 */
684 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_003, TestSize.Level3)
685 {
686 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
687 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false);
688 testPara.isSelfCreatePixMap = false;
689 ASSERT_LE(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_FILE_NOT_FIND);
690 }
691
692 /**
693 * @tc.name: AstcEncoderTime_004
694 * @tc.desc: Calculate the average time
695 * : BasedOnCPU / 64x64 / quality 100 / Extern images / 5000frames
696 * @tc.type: Performance
697 */
698 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_004, TestSize.Level3)
699 {
700 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
701 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false);
702 testPara.isSelfCreatePixMap = false;
703 testPara.privateProfile = HIGH_QUALITY_PROFILE;
704 ASSERT_LE(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_FILE_NOT_FIND);
705 }
706
707 /**
708 * @tc.name: AstcEncoderTime_005
709 * @tc.desc: Calculate the average time
710 * : BasedOnGPU / 64x64 / self-created images / 5000frames
711 * @tc.type: Performance
712 */
713 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_005, TestSize.Level3)
714 {
715 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: true
716 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, true);
717 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
718 }
719
720 /**
721 * @tc.name: AstcEncoderTime_006
722 * @tc.desc: Calculate the average time
723 * : BasedOnGPU / 64x64 / Extern images / 5000frames
724 * @tc.type: Performance
725 */
726 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_006, TestSize.Level3)
727 {
728 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: true
729 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, true);
730 testPara.isSelfCreatePixMap = false;
731 ASSERT_LE(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_FILE_NOT_FIND);
732 }
733
734 /**
735 * @tc.name: AstcEncoderTime_007
736 * @tc.desc: Calculate the average time
737 * : BasedOnGPU / different resolution / self-created images
738 * @tc.type: Performance
739 */
740 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_007, TestSize.Level3)
741 {
742 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: true
743 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, true);
744 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
745
746 testPara = CreateAstcEncTestPara(128, 128, 4, 5000, true); // 64x64 block 4x4 , frames 5000
747 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
748
749 testPara = CreateAstcEncTestPara(256, 256, 4, 5000, true); // 256x256 block 4x4 , frames 5000
750 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
751
752 testPara = CreateAstcEncTestPara(512, 512, 4, 1, true); // 512x512 block 4x4 , frames 1
753 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
754
755 testPara = CreateAstcEncTestPara(1024, 1024, 4, 1, true); // 1024x1024 block 4x4 , frames 1
756 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
757
758 testPara = CreateAstcEncTestPara(1920, 1080, 4, 1, true); // 1920x1080 block 4x4 , frames 1
759 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
760
761 testPara = CreateAstcEncTestPara(2560, 1440, 4, 1, true); // 2560x1440 block 4x4 , frames 1
762 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
763
764 testPara = CreateAstcEncTestPara(3840, 2160, 4, 1, true); // 3840x2160 block 4x4 , frames 1
765 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
766
767 testPara = CreateAstcEncTestPara(8192, 8192, 4, 1, true); // 8192x8192 block 4x4 , frames 1
768 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
769 }
770
771 /**
772 * @tc.name: AstcEncoderTime_008
773 * @tc.desc: Calculate the average time
774 * : BasedOnCPU / different resolution / self-created images
775 * @tc.type: Performance
776 */
777 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_008, TestSize.Level3)
778 {
779 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
780 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false);
781 testPara.isSelfCreatePixMap = true;
782 testPara.privateProfile = HIGH_SPEED_PROFILE;
783 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
784
785 testPara = CreateAstcEncTestPara(128, 128, 4, 5000, false); // 64x64 block 4x4 , frames 5000
786 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
787
788 testPara = CreateAstcEncTestPara(256, 256, 4, 5000, false); // 256x256 block 4x4 , frames 5000
789 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
790
791 testPara = CreateAstcEncTestPara(512, 512, 4, 1, false); // 512x512 block 4x4 , frames 1
792 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
793
794 testPara = CreateAstcEncTestPara(1024, 1024, 4, 1, false); // 1024x1024 block 4x4 , frames 1
795 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
796
797 testPara = CreateAstcEncTestPara(1920, 1080, 4, 1, false); // 1920x1080 block 4x4 , frames 1
798 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
799
800 testPara = CreateAstcEncTestPara(2560, 1440, 4, 1, false); // 2560x1440 block 4x4 , frames 1
801 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
802
803 testPara = CreateAstcEncTestPara(3840, 2160, 4, 1, false); // 3840x2160 block 4x4 , frames 1
804 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
805
806 testPara = CreateAstcEncTestPara(8192, 8192, 4, 1, false); // 8192x8192 block 4x4 , frames 1
807 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
808 }
809
810 /**
811 * @tc.name: AstcEncoderTime_009
812 * @tc.desc: BoundCheck for new function
813 * @tc.type: Performance
814 */
815 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_009, TestSize.Level3)
816 {
817 TextureEncodeOptions param;
818 ASSERT_EQ(AstcCodec::AstcSoftwareEncodeCore(param, nullptr, nullptr), false);
819
820 uint8_t pixmapIn = 0;
821 ASSERT_EQ(AstcCodec::AstcSoftwareEncodeCore(param, &pixmapIn, nullptr), false);
822 }
823
824 #ifdef ASTC_CUSTOMIZED_ENABLE
825 /**
826 * @tc.name: AstcEncoderTime_010
827 * @tc.desc: Calculate the average time
828 * : BasedOnCPU / different resolution / self-created images, extern-created images
829 * @tc.type: Performance
830 */
831 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_010, TestSize.Level3)
832 {
833 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
834 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false); // 64x64 block 4x4 , frames 5000
835 testPara.privateProfile = CUSTOMIZED_PROFILE;
836 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
837
838 testPara = CreateAstcEncTestPara(128, 128, 4, 5000, false); // 128x128 block 4x4 , frames 5000
839 testPara.privateProfile = CUSTOMIZED_PROFILE;
840 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
841
842 testPara = CreateAstcEncTestPara(256, 256, 4, 5000, false); // 256x256 block 4x4 , frames 5000
843 testPara.privateProfile = CUSTOMIZED_PROFILE;
844 ASSERT_EQ(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_OK);
845
846 // test condition: width 64, height 64, block 4x4 , frames 5000, isBasedOnGpu: false
847 testPara = CreateAstcEncTestPara(64, 64, 4, 5000, false); // 64x64 block 4x4 , frames 5000
848 testPara.isSelfCreatePixMap = false;
849 testPara.privateProfile = CUSTOMIZED_PROFILE;
850 ASSERT_LE(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_FILE_NOT_FIND);
851
852 testPara = CreateAstcEncTestPara(128, 128, 4, 5000, false); // 128x128 block 4x4 , frames 5000
853 testPara.isSelfCreatePixMap = false;
854 testPara.privateProfile = CUSTOMIZED_PROFILE;
855 ASSERT_LE(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_FILE_NOT_FIND);
856
857 testPara = CreateAstcEncTestPara(256, 256, 4, 5000, false); // 256x256 block 4x4 , frames 5000
858 testPara.isSelfCreatePixMap = false;
859 testPara.privateProfile = CUSTOMIZED_PROFILE;
860 ASSERT_LE(TestCaseMultiFrameEnc(testPara), TestEncRet::ERR_FILE_NOT_FIND);
861 }
862 #endif
863
864 #ifdef ENABLE_ASTC_ENCODE_BASED_GPU
865 /**
866 * @tc.name: AstcEncoderTime_011
867 * @tc.desc: BoundCheck for TryAstcEncBasedOnCl function
868 * @tc.type: branch coverage
869 */
EncodeMutiFramesCL(AstcEncTestPara & testPara,const string shaderPath)870 TestEncRet EncodeMutiFramesCL(AstcEncTestPara &testPara, const string shaderPath)
871 {
872 testPara.totalTime = 0;
873 size_t bytesPerFile = testPara.width * testPara.height * BYTES_PER_PIXEL;
874 for (size_t idx = 0; idx < testPara.frames; idx++) {
875 uint8_t *pixelMap = static_cast<uint8_t *>(malloc(bytesPerFile * sizeof(uint8_t)));
876 if (pixelMap == nullptr) {
877 return TestEncRet::ERR_LOW_LEVEL_FAILED;
878 }
879 uint8_t *astcBuf = static_cast<uint8_t *>(malloc(testPara.param.astcBytes * sizeof(uint8_t)));
880 if (astcBuf == nullptr) {
881 free(pixelMap);
882 return TestEncRet::ERR_LOW_LEVEL_FAILED;
883 }
884 SelfCreatePixMap(pixelMap, bytesPerFile, idx);
885 int64_t startTime = CurrentTimeInUs();
886 if (!AstcCodec::TryAstcEncBasedOnCl(testPara.param, pixelMap, astcBuf, shaderPath)) {
887 GTEST_LOG_(ERROR) << "astc encoding based on GPU failed";
888 FreeMem(pixelMap, astcBuf);
889 return TestEncRet::ERR_ENC_FAILED;
890 }
891 #ifdef SUT_ENCODE_ENABLE
892 testPara.param.sutProfile = testPara.sutEncEnable ? SutProfile::EXTREME_SPEED : SutProfile::SKIP_SUT;
893 testPara.param.hardwareFlag = true;
894 if (!AstcCodec::TryTextureSuperCompress(testPara.param, astcBuf)) {
895 GTEST_LOG_(ERROR) << "TryTextureSuperCompress failed";
896 FreeMem(pixelMap, astcBuf);
897 return TestEncRet::ERR_ENC_FAILED;
898 }
899 #endif
900 FreeMem(pixelMap, astcBuf);
901 testPara.totalTime += CurrentTimeInUs() - startTime;
902 }
903 return TestEncRet::ERR_OK;
904 }
905
TestCaseMultiFrameEncCL(AstcEncTestPara & testPara,const string shaderPath)906 TestEncRet TestCaseMultiFrameEncCL(AstcEncTestPara &testPara, const string shaderPath)
907 {
908 if (!FillEncodeOptions(testPara.param, testPara.width, testPara.height,
909 testPara.block, testPara.privateProfile)) {
910 GTEST_LOG_(ERROR) << "FillEncodeOptions failed";
911 return TestEncRet::ERR_LOW_LEVEL_FAILED;
912 }
913 TestEncRet ret = EncodeMutiFramesCL(testPara, shaderPath);
914 if (ret == TestEncRet::ERR_OK) {
915 GTEST_LOG_(INFO) << "isGPU:" << testPara.isBasedOnGpu << " SelfPixel:" << testPara.isSelfCreatePixMap <<
916 " profile:" << testPara.privateProfile << " " << testPara.param.width_ << "x" <<
917 testPara.param.height_ << " frames " <<
918 testPara.frames << " gpu astc encoding average time: " <<
919 static_cast<float>(testPara.totalTime) / static_cast<float>(testPara.frames) << "us";
920 }
921 return ret;
922 }
923
924 HWTEST_F(PluginTextureEncodeTest, AstcEncoderTime_011, TestSize.Level3)
925 {
926 // test condition: width 64, height 64, block 4x4 , frames 1, isBasedOnGpu: false
927 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 1, false); // 64x64 block 4x4 , frames 1
928 const std::string clBinInvalidPath = "/data/local/tmp/AstcEncShader_ALN-AL00.bin";
929 ASSERT_EQ(AstcCodec::TryAstcEncBasedOnCl(testPara.param, nullptr, nullptr, clBinInvalidPath), false);
930 ASSERT_EQ(TestCaseMultiFrameEncCL(testPara, clBinInvalidPath), TestEncRet::ERR_OK);
931 testPara.sutEncEnable = true;
932 ASSERT_EQ(TestCaseMultiFrameEncCL(testPara, clBinInvalidPath), TestEncRet::ERR_OK);
933 const std::string clBinFalsePath = "/data/false/AstcEncShader_ALN-AL00.bin";
934 ASSERT_EQ(TestCaseMultiFrameEncCL(testPara, clBinFalsePath), TestEncRet::ERR_OK);
935 }
936 #endif
937
938 #ifdef SUT_ENCODE_ENABLE
939 /**
940 * @tc.name: SutEncoderBoundCheck_012
941 * @tc.desc: BoundCheck for SutEncoderBoundCheck_012 function
942 * @tc.type: branch coverage
943 */
944 HWTEST_F(PluginTextureEncodeTest, SutEncoderBoundCheck_012, TestSize.Level3)
945 {
946 // test condition: width 64, height 64, block 4x4 , frames 1, isBasedOnGpu: false
947 AstcEncTestPara testPara = CreateAstcEncTestPara(64, 64, 4, 1, false); // 64x64 block 4x4 , frames 1
948 ASSERT_EQ(AstcCodec::TryTextureSuperCompress(testPara.param, nullptr), true);
949 uint8_t astcBuf;
950 testPara.param.astcBytes = 0;
951 testPara.param.sutProfile = SutProfile::EXTREME_SPEED;
952 testPara.param.hardwareFlag = true;
953 testPara.param.blockX_ = ASTC_BLOCK_WIDTH;
954 testPara.param.blockY_ = ASTC_BLOCK_HEIGHT;
955 ASSERT_EQ(AstcCodec::TryTextureSuperCompress(testPara.param, &astcBuf), false);
956 }
957 #endif
958 } // namespace Multimedia
959 } // namespace OHOS