From b2039ad7643d024a5541af33da574068f194ee81 Mon Sep 17 00:00:00 2001 From: Michael Butler Date: Thu, 30 Mar 2017 17:20:12 -0700 Subject: [PATCH] Added protections for RenderScript VTS tests. Changed many EXPECT_NE to ASSERT_NE for objects that are required later in the test which would potentially cause a segfault. Additionally updated a few descriptions. Bug: 35915961 Test: mm and run on angler Change-Id: I17c85b2c774688d82b59be2f0b383447e03349e0 --- .../1.0/vts/functional/VtsCopyTests.cpp | 75 +++++++++++- .../vts/functional/VtsMiscellaneousTests.cpp | 51 ++++++-- .../1.0/vts/functional/VtsScriptTests.cpp | 111 +++++++++++++----- 3 files changed, 196 insertions(+), 41 deletions(-) diff --git a/renderscript/1.0/vts/functional/VtsCopyTests.cpp b/renderscript/1.0/vts/functional/VtsCopyTests.cpp index 168e681993..f47253f99f 100644 --- a/renderscript/1.0/vts/functional/VtsCopyTests.cpp +++ b/renderscript/1.0/vts/functional/VtsCopyTests.cpp @@ -30,12 +30,18 @@ TEST_F(RenderscriptHidlTest, Simple1DCopyTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x float1 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 128 x float1 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + std::vector dataIn(128), dataOut(128); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -60,12 +66,18 @@ TEST_F(RenderscriptHidlTest, Simple1DCopyTest) { TEST_F(RenderscriptHidlTest, Simple2DCopyTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x 128 x float1 Type type = context->typeCreate(element, 128, 128, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 128 x 128 x float1 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + std::vector dataIn(128*128), dataOut(128*128); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -91,12 +103,18 @@ TEST_F(RenderscriptHidlTest, Simple2DCopyTest) { TEST_F(RenderscriptHidlTest, Simple3DCopyTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 32 x 32 x 32 x float1 Type type = context->typeCreate(element, 32, 32, 32, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 32 x 32 x 32 x float1 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + std::vector dataIn(32*32*32), dataOut(32*32*32); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -122,8 +140,12 @@ TEST_F(RenderscriptHidlTest, Simple3DCopyTest) { TEST_F(RenderscriptHidlTest, SimpleBitmapTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 512 x 512 x float1 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(512*512), dataOut1(512*512), dataOut2(512*512); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -133,7 +155,7 @@ TEST_F(RenderscriptHidlTest, SimpleBitmapTest) { AllocationMipmapControl::NONE, _data, (int)AllocationUsageType::SCRIPT); - EXPECT_NE(Allocation(0), allocation); + ASSERT_NE(Allocation(0), allocation); context->allocationCopyToBitmap(allocation, (Ptr)dataOut1.data(), (Size)dataOut1.size()*sizeof(float)); @@ -158,10 +180,16 @@ TEST_F(RenderscriptHidlTest, SimpleBitmapTest) { TEST_F(RenderscriptHidlTest, AllocationCopy2DRangeTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 512 x 512 x float1 Type typeSrc = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), typeSrc); + // 256 x 256 x float1 Type typeDst = context->typeCreate(element, 256, 256, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), typeDst); + std::vector dataIn(512*512), dataOut(256*256), expected(256*256); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -170,10 +198,14 @@ TEST_F(RenderscriptHidlTest, AllocationCopy2DRangeTest) { Allocation allocSrc = context->allocationCreateFromBitmap(typeSrc, AllocationMipmapControl::NONE, _data, (int)AllocationUsageType::SCRIPT); + ASSERT_NE(Allocation(0), allocSrc); + // 256 x 256 x float1 Allocation allocDst = context->allocationCreateTyped(typeDst, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocDst); + context->allocationCopy2DRange(allocDst, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, allocSrc, 128, 128, 0, AllocationCubemapFace::POSITIVE_X); context->allocationRead(allocDst, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float)); @@ -200,10 +232,16 @@ TEST_F(RenderscriptHidlTest, AllocationCopy2DRangeTest) { TEST_F(RenderscriptHidlTest, AllocationCopy3DRangeTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x 128 x 128 x float1 Type typeSrc = context->typeCreate(element, 128, 128, 128, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), typeSrc); + // 64 x 64 x 64 x float1 Type typeDst = context->typeCreate(element, 64, 64, 64, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), typeDst); + std::vector dataIn(128*128*128), dataOut(64*64*64), expected(64*64*64); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -212,10 +250,14 @@ TEST_F(RenderscriptHidlTest, AllocationCopy3DRangeTest) { Allocation allocSrc = context->allocationCreateTyped(typeSrc, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocSrc); + // 256 x 256 x float1 Allocation allocDst = context->allocationCreateTyped(typeDst, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocDst); + context->allocation3DWrite(allocSrc, 0, 0, 0, 0, 128, 128, 128, _data, 128*sizeof(float)); context->allocationCopy3DRange(allocDst, 0, 0, 0, 0, 64, 64, 64, allocSrc, 32, 32, 32, 0); context->allocationRead(allocDst, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float)); @@ -243,8 +285,12 @@ TEST_F(RenderscriptHidlTest, AllocationCopy3DRangeTest) { TEST_F(RenderscriptHidlTest, SimpleAdapterTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 512 x 512 x float1 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(512*512), dataOut(256*256), expected; std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -254,11 +300,15 @@ TEST_F(RenderscriptHidlTest, SimpleAdapterTest) { AllocationMipmapControl::NONE, _data, (int)AllocationUsageType::SCRIPT); + ASSERT_NE(Allocation(0), allocation); + // 256 x 256 x float1 Type subType = context->typeCreate(element, 256, 256, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), subType); + // 256 x 256 x float1 AllocationAdapter allocationAdapter = context->allocationAdapterCreate(subType, allocation); - EXPECT_NE(AllocationAdapter(0), allocationAdapter); + ASSERT_NE(AllocationAdapter(0), allocationAdapter); std::vector offsets(9, 0); offsets[0] = 128; @@ -292,8 +342,12 @@ TEST_F(RenderscriptHidlTest, SimpleAdapterTest) { TEST_F(RenderscriptHidlTest, SimpleMipmapTest) { // uint8_t Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 64 x 64 x uint8_t Type type = context->typeCreate(element, 64, 64, 0, true, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(64*64), dataOut(32*32), expected(32*32); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (uint8_t)(0xFF & val++); }); @@ -303,6 +357,8 @@ TEST_F(RenderscriptHidlTest, SimpleMipmapTest) { Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::FULL, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + context->allocation2DWrite(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 64, 64, _data, 64*sizeof(uint8_t)); context->allocationGenerateMipmaps(allocation); @@ -333,8 +389,12 @@ TEST_F(RenderscriptHidlTest, SimpleMipmapTest) { TEST_F(RenderscriptHidlTest, SimpleCubemapTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x 128 x float1 Type type = context->typeCreate(element, 128, 128, 0, false, true, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(128*128*6), dataOut(128*128), expected(128*128); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); hidl_vec _data; @@ -342,7 +402,7 @@ TEST_F(RenderscriptHidlTest, SimpleCubemapTest) { // 128 x 128 x float1 x 6 Allocation allocation = context->allocationCubeCreateFromBitmap( type, AllocationMipmapControl::NONE, _data, (int)AllocationUsageType::SCRIPT); - EXPECT_NE(Allocation(0), allocation); + ASSERT_NE(Allocation(0), allocation); context->allocation2DRead(allocation, 0, 0, 0, AllocationCubemapFace::NEGATIVE_Z, 128, 128, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float), @@ -367,13 +427,16 @@ TEST_F(RenderscriptHidlTest, SimpleCubemapTest) { */ TEST_F(RenderscriptHidlTest, ComplexElementTest) { Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element1); + Element element2 = context->elementCreate(DataType::UNSIGNED_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element2); hidl_vec eins = {element1, element2}; hidl_vec names = {hidl_string("first"), hidl_string("second")}; hidl_vec arraySizesPtr = {1, 1}; Element element3 = context->elementComplexCreate(eins, names, arraySizesPtr); - EXPECT_NE(Element(0), element3); + ASSERT_NE(Element(0), element3); std::vector ids; std::vector namesOut; @@ -395,10 +458,14 @@ TEST_F(RenderscriptHidlTest, ComplexElementTest) { // 1 x (uint8_t, uint32_t) Type type = context->typeCreate(element3, 1, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 1 x (uint8_t, uint32_t) Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + std::vector dataIn(1), dataOut(1); std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; }); hidl_vec _data; diff --git a/renderscript/1.0/vts/functional/VtsMiscellaneousTests.cpp b/renderscript/1.0/vts/functional/VtsMiscellaneousTests.cpp index 39d63ca9f9..23b09ac53c 100644 --- a/renderscript/1.0/vts/functional/VtsMiscellaneousTests.cpp +++ b/renderscript/1.0/vts/functional/VtsMiscellaneousTests.cpp @@ -46,18 +46,18 @@ TEST_F(RenderscriptHidlTest, ElementCreate) { TEST_F(RenderscriptHidlTest, ElementTypeAllocationCreate) { // Element create test Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); - EXPECT_NE(Element(0), element); + ASSERT_NE(Element(0), element); // Type create test Type type = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE); - EXPECT_NE(Type(0), type); + ASSERT_NE(Type(0), type); // Allocation create test Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)((uint32_t)AllocationUsageType::ALL & ~(uint32_t)AllocationUsageType::OEM), (Ptr)nullptr); - EXPECT_NE(Allocation(0), allocation); + ASSERT_NE(Allocation(0), allocation); // Allocation type test Type type2 = context->allocationGetType(allocation); @@ -74,8 +74,11 @@ TEST_F(RenderscriptHidlTest, ElementTypeAllocationCreate) { TEST_F(RenderscriptHidlTest, MetadataTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x float1 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); std::vector elementMetadata(5); context->elementGetNativeMetadata(element, [&](const hidl_vec& _metadata){ @@ -107,24 +110,30 @@ TEST_F(RenderscriptHidlTest, MetadataTest) { TEST_F(RenderscriptHidlTest, ResizeTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x float1 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 128 x float1 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + Ptr dataPtr1, dataPtr2; Size stride; context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0, [&](Ptr _dataPtr, Size _stride){ dataPtr1 = _dataPtr; stride = _stride; }); - EXPECT_EQ(0ul, stride); + EXPECT_EQ(Size(0), stride); context->allocationResize1D(allocation, 1024*1024); context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0, [&](Ptr _dataPtr, Size _stride){ dataPtr2 = _dataPtr; stride = _stride; }); - EXPECT_EQ(0ul, stride); + EXPECT_EQ(Size(0), stride); EXPECT_NE(dataPtr1, dataPtr2); } @@ -139,8 +148,12 @@ TEST_F(RenderscriptHidlTest, ResizeTest) { TEST_F(RenderscriptHidlTest, NativeWindowIoTest) { // uint8x4 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4); + ASSERT_NE(Element(0), element); + // 512 x 512 x uint8x4 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(512*512), dataOut(512*512); std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; }); hidl_vec _data; @@ -150,12 +163,16 @@ TEST_F(RenderscriptHidlTest, NativeWindowIoTest) { (int)(AllocationUsageType::SCRIPT | AllocationUsageType::IO_INPUT), (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocationRecv); + Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)(AllocationUsageType::SCRIPT | AllocationUsageType::IO_OUTPUT), (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocationSend); + NativeWindow nativeWindow = context->allocationGetNativeWindow(allocationRecv); - EXPECT_NE(NativeWindow(0), nativeWindow); + ASSERT_NE(NativeWindow(0), nativeWindow); ((ANativeWindow *)nativeWindow)->incStrong(nullptr); @@ -174,14 +191,20 @@ TEST_F(RenderscriptHidlTest, NativeWindowIoTest) { * two allocations with IO_INPUT are made to share the same BufferQueue. * * Calls: elementCreate, typeCreate, allocationCreateTyped, - * allocationCreateFromBitmap, allocationSetupBufferQueue, - * allocationShareBufferQueue + * allocationSetupBufferQueue, allocationShareBufferQueue, + * allocationGetNativeWindow, allocationSetNativeWindow, + * allocation2DWrite, allocation2DRead, allocationIoSend, + * allocationIoReceive */ TEST_F(RenderscriptHidlTest, BufferQueueTest) { // uint8x4 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4); + ASSERT_NE(Element(0), element); + // 512 x 512 x uint8x4 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(512*512), dataOut1(512*512), dataOut2(512*512); std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; }); hidl_vec _data; @@ -191,20 +214,28 @@ TEST_F(RenderscriptHidlTest, BufferQueueTest) { (int)(AllocationUsageType::SCRIPT | AllocationUsageType::IO_INPUT), (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocationRecv1); + Allocation allocationRecv2 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)(AllocationUsageType::SCRIPT | AllocationUsageType::IO_INPUT), (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocationRecv2); + Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)(AllocationUsageType::SCRIPT | AllocationUsageType::IO_INPUT), (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocationSend); + context->allocationSetupBufferQueue(allocationRecv1, 2); context->allocationShareBufferQueue(allocationRecv2, allocationRecv1); NativeWindow nativeWindow1 = context->allocationGetNativeWindow(allocationRecv1); - EXPECT_NE(NativeWindow(0), nativeWindow1); + ASSERT_NE(NativeWindow(0), nativeWindow1); + NativeWindow nativeWindow2 = context->allocationGetNativeWindow(allocationRecv2); + ASSERT_NE(NativeWindow(0), nativeWindow2); EXPECT_EQ(nativeWindow2, nativeWindow1); ((ANativeWindow *)nativeWindow1)->incStrong(nullptr); @@ -269,6 +300,8 @@ TEST_F(RenderscriptHidlTest, MiscellaneousTests) { context->contextSetCacheDir("/data/local/tmp/temp/"); Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + std::string nameIn = "element_test_name"; std::string nameOut = "not_name"; hidl_string _nameIn; diff --git a/renderscript/1.0/vts/functional/VtsScriptTests.cpp b/renderscript/1.0/vts/functional/VtsScriptTests.cpp index 6bb375ada5..fed7c6eb92 100644 --- a/renderscript/1.0/vts/functional/VtsScriptTests.cpp +++ b/renderscript/1.0/vts/functional/VtsScriptTests.cpp @@ -25,6 +25,8 @@ TEST_F(RenderscriptHidlTest, IntrinsicTest) { // uint8 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + EXPECT_NE(Element(0), element); + Script script = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element); EXPECT_NE(Script(0), script); @@ -43,7 +45,7 @@ TEST_F(RenderscriptHidlTest, ScriptVarTest) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); // arg tests context->scriptSetVarI(script, mExportVarIdx_var_int, 100); @@ -75,12 +77,18 @@ TEST_F(RenderscriptHidlTest, ScriptVarTest) { // float1 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 128 x float1 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 128 x float1 Allocation allocationIn = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocationIn); + Allocation allocationOut = Allocation(0); context->scriptSetVarObj(script, mExportVarIdx_var_allocation, (ObjectBase)allocationIn); context->scriptGetVarV(script, mExportVarIdx_var_allocation, sizeof(ObjectBase), @@ -107,6 +115,8 @@ TEST_F(RenderscriptHidlTest, ScriptVarTest) { _dimsVE.setToExternal((uint32_t*)dimsVE.data(), dimsVE.size()); // intx2 to represent point2 which is {int, int} Element elementVE = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 2); + ASSERT_NE(Element(0), elementVE); + context->scriptSetVarVE(script, mExportVarIdx_var_point2, _dataVE, elementVE, _dimsVE); context->scriptGetVarV(script, mExportVarIdx_var_point2, 2*sizeof(int), [&](const hidl_vec& _data){ @@ -126,7 +136,7 @@ TEST_F(RenderscriptHidlTest, ScriptInvokeTest) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); // invoke test int resultI = 0; @@ -185,12 +195,16 @@ TEST_F(RenderscriptHidlTest, ScriptForEachTest) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); // uint8_t Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 64 x uint8_t Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + std::vector dataIn(64), dataOut(64), expected(64); std::generate(dataIn.begin(), dataIn.end(), [](){ static uint8_t val = 0; return val++; }); std::generate(expected.begin(), expected.end(), [](){ static uint8_t val = 1; return val++; }); @@ -200,9 +214,13 @@ TEST_F(RenderscriptHidlTest, ScriptForEachTest) { Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + Allocation vout = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), vout); + context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data); hidl_vec vains; vains.setToExternal(&allocation, 1); @@ -223,13 +241,19 @@ TEST_F(RenderscriptHidlTest, ScriptReduceTest) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); // uint8_t Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 64 x uint8_t Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + Type type2 = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type2); + std::vector dataIn(64), dataOut(1); std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return val++; }); hidl_vec _data; @@ -238,9 +262,13 @@ TEST_F(RenderscriptHidlTest, ScriptReduceTest) { Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + Allocation vaout = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), vaout); + context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data); hidl_vec vains; vains.setToExternal(&allocation, 1); @@ -257,22 +285,29 @@ TEST_F(RenderscriptHidlTest, ScriptReduceTest) { * RenderScript script, represented in the bitcode. * * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, - * scriptSetVarV, scriptBindAllocation, allocationRead + * allocation1DWrite, scriptBindAllocation, scriptSetVarV, scriptBindAllocation, + * allocationRead, scriptInvokeV, allocationRead */ TEST_F(RenderscriptHidlTest, ScriptBindTest) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); // in32 Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + // 64 x int32 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + // 64 x int32 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + std::vector dataIn(64), dataOut(64), expected(64, 5); hidl_vec _data; _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(int)); @@ -295,7 +330,8 @@ TEST_F(RenderscriptHidlTest, ScriptBindTest) { * * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite, * scriptIntrinsicCreate, scriptKernelIDCreate, scriptFieldIDCreate, - * scriptGroupCreate, scriptGroupSetOutput, scriptGroupExecute, allocation2DRead + * scriptGroupCreate, scriptSetVarObj, scriptGroupSetOutput, scriptGroupExecute, + * contextFinish, allocation2DRead */ TEST_F(RenderscriptHidlTest, ScriptGroupTest) { std::vector dataIn(256*256*1, 128), dataOut(256*256*4, 0), zeros(256*256*4, 0); @@ -305,36 +341,49 @@ TEST_F(RenderscriptHidlTest, ScriptGroupTest) { // 256 x 256 YUV pixels Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_YUV, true, 1); + ASSERT_NE(Element(0), element1); + Type type1 = context->typeCreate(element1, 256, 256, 0, false, false, YuvFormat::YUV_420_888); + ASSERT_NE(Type(0), type1); + Allocation allocation1 = context->allocationCreateTyped(type1, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation1); + context->allocation2DWrite(allocation1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, _dataIn, 0); // 256 x 256 RGBA pixels Element element2 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_RGBA, true, 4); + ASSERT_NE(Element(0), element2); + Type type2 = context->typeCreate(element2, 256, 256, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type2); + Allocation allocation2 = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation2); + context->allocation2DWrite(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, _dataOut, 0); // create scripts Script yuv2rgb = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_YUV_TO_RGB, element1); - EXPECT_NE(Script(0), yuv2rgb); + ASSERT_NE(Script(0), yuv2rgb); ScriptKernelID yuv2rgbKID = context->scriptKernelIDCreate(yuv2rgb, 0, 2); - EXPECT_NE(ScriptKernelID(0), yuv2rgbKID); + ASSERT_NE(ScriptKernelID(0), yuv2rgbKID); Script blur = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element2); - EXPECT_NE(Script(0), blur); + ASSERT_NE(Script(0), blur); ScriptKernelID blurKID = context->scriptKernelIDCreate(blur, 0, 2); - EXPECT_NE(ScriptKernelID(0), blurKID); + ASSERT_NE(ScriptKernelID(0), blurKID); + ScriptFieldID blurFID = context->scriptFieldIDCreate(blur, 1); - EXPECT_NE(ScriptFieldID(0), blurFID); + ASSERT_NE(ScriptFieldID(0), blurFID); // ScriptGroup hidl_vec kernels = {yuv2rgbKID, blurKID}; @@ -343,7 +392,7 @@ TEST_F(RenderscriptHidlTest, ScriptGroupTest) { hidl_vec dstF = {blurFID}; hidl_vec types = {type2}; ScriptGroup scriptGroup = context->scriptGroupCreate(kernels, srcK, dstK, dstF, types); - EXPECT_NE(ScriptGroup(0), scriptGroup); + ASSERT_NE(ScriptGroup(0), scriptGroup); context->scriptSetVarObj(yuv2rgb, 0, (ObjectBase)allocation1); context->scriptGroupSetOutput(scriptGroup, blurKID, allocation2); @@ -360,14 +409,16 @@ TEST_F(RenderscriptHidlTest, ScriptGroupTest) { * Similar to the ScriptGroup test, this test verifies the execution flow of * RenderScript kernels and invokables. * - * Calls: scriptFieldIDCreate, closureCreate, scriptInvokeIDCreate, - * invokeClosureCreate, closureSetGlobal, scriptGroup2Create, scriptGroupExecute + * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, + * allocation1DWrite, scriptFieldIDCreate, scriptInvokeIDCreate, + * invokeClosureCreate, closureCreate, closureSetGlobal, scriptGroup2Create, + * scriptGroupExecute, allocationRead */ TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); std::vector dataIn(128, 128), dataOut(128, 0), expected(128, 7+1); hidl_vec _dataIn, _dataOut; @@ -375,19 +426,23 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { // 256 x 256 YUV pixels Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + context->allocation1DWrite(allocation, 0, 0, (Size)_dataIn.size(), _dataIn); ScriptFieldID fieldID = context->scriptFieldIDCreate(script, mExportVarIdx_var_allocation); - EXPECT_NE(ScriptFieldID(0), fieldID); ASSERT_NE(ScriptFieldID(0), fieldID); // invoke ScriptInvokeID invokeID = context->scriptInvokeIDCreate(script, mExportFuncIdx_setAllocation); - EXPECT_NE(ScriptInvokeID(0), invokeID); ASSERT_NE(ScriptInvokeID(0), invokeID); int dim = 128; @@ -397,12 +452,10 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { hidl_vec values1 = {int64_t(0)}; hidl_vec sizes1 = {int32_t(0)}; Closure closure1 = context->invokeClosureCreate(invokeID, params, fieldIDS1, values1, sizes1); - EXPECT_NE(Closure(0), closure1); ASSERT_NE(Closure(0), closure1); // kernel ScriptKernelID kernelID = context->scriptKernelIDCreate(script, mExportForEachIdx_increment, 3); - EXPECT_NE(ScriptKernelID(0), kernelID); ASSERT_NE(ScriptKernelID(0), kernelID); hidl_vec fieldIDS2 = {ScriptFieldID(0)}; @@ -412,7 +465,6 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { hidl_vec depFieldIDS2 = {fieldID}; Closure closure2 = context->closureCreate(kernelID, allocation /* returnValue */, fieldIDS2, values2, sizes2, depClosures2, depFieldIDS2); - EXPECT_NE(Closure(0), closure2); ASSERT_NE(Closure(0), closure2); // set argument @@ -424,7 +476,6 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { hidl_string cacheDir = "/data/local/tmp"; hidl_vec closures = {closure1, closure2}; ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures); - EXPECT_NE(ScriptGroup2(0), scriptGroup2); ASSERT_NE(ScriptGroup2(0), scriptGroup2); context->scriptGroupExecute(scriptGroup2); @@ -436,14 +487,15 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { * Similar to the ScriptGroup test, this test verifies a single kernel can be * called by ScriptGroup with an unbound allocation specified before launch * - * Calls: scriptFieldIDCreate, closureCreate, scriptInvokeIDCreate, - * invokeClosureCreate, closureSetArg, scriptGroup2Create, scriptGroupExecute + * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, + * allocation1DWrite, scriptKernelIDCreate, closureCreate, closureSetArg, + * scriptGroup2Create, scriptGroupExecute, allocationRead */ TEST_F(RenderscriptHidlTest, ScriptGroup2KernelTest) { hidl_vec bitcode; bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); - EXPECT_NE(Script(0), script); + ASSERT_NE(Script(0), script); std::vector dataIn(128, 128), dataOut(128, 0), expected(128, 128 + 1); hidl_vec _dataIn, _dataOut; @@ -451,15 +503,20 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2KernelTest) { // 256 x 256 YUV pixels Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); + ASSERT_NE(Element(0), element); + Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); + ASSERT_NE(Type(0), type); + Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, (int)AllocationUsageType::SCRIPT, (Ptr)nullptr); + ASSERT_NE(Allocation(0), allocation); + context->allocation1DWrite(allocation, 0, 0, (Size)_dataIn.size(), _dataIn); // kernel ScriptKernelID kernelID = context->scriptKernelIDCreate(script, mExportForEachIdx_increment, 3); - EXPECT_NE(ScriptKernelID(0), kernelID); ASSERT_NE(ScriptKernelID(0), kernelID); hidl_vec fieldIDS = {ScriptFieldID(0)}; @@ -469,7 +526,6 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2KernelTest) { hidl_vec depFieldIDS = {ScriptFieldID(0)}; Closure closure = context->closureCreate(kernelID, allocation /* returnValue */, fieldIDS, values, sizes, depClosures, depFieldIDS); - EXPECT_NE(Closure(0), closure); ASSERT_NE(Closure(0), closure); // set argument @@ -480,7 +536,6 @@ TEST_F(RenderscriptHidlTest, ScriptGroup2KernelTest) { hidl_string cacheDir = "/data/local/tmp"; hidl_vec closures = {closure}; ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures); - EXPECT_NE(ScriptGroup2(0), scriptGroup2); ASSERT_NE(ScriptGroup2(0), scriptGroup2); context->scriptGroupExecute(scriptGroup2);