diff --git a/plugins/wasi_crypto/asymmetric_common/ecdsa.h b/plugins/wasi_crypto/asymmetric_common/ecdsa.h index 85990ca3..3a48e19d 100644 --- a/plugins/wasi_crypto/asymmetric_common/ecdsa.h +++ b/plugins/wasi_crypto/asymmetric_common/ecdsa.h @@ -82,7 +82,14 @@ class Ecdsa { } WasiCryptoExpect verify() const noexcept { - return WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_NOT_IMPLEMENTED); + EvpPkeyCtxPtr CheckCtx{EVP_PKEY_CTX_new(Ctx.get(), nullptr)}; + ensureOrReturn(CheckCtx, __WASI_CRYPTO_ERRNO_ALGORITHM_FAILURE); + // EVP_PKEY_public_check() returns 1 for a valid key and 0 for an invalid + // one. A negative value means the check is unsupported for this key type + // (e.g. on OpenSSL 1.1.1), so only an explicit 0 is treated as invalid. + ensureOrReturn(EVP_PKEY_public_check(CheckCtx.get()) != 0, + __WASI_CRYPTO_ERRNO_INVALID_KEY); + return {}; } protected: diff --git a/plugins/wasi_nn/GGML/tts/tts_core.h b/plugins/wasi_nn/GGML/tts/tts_core.h index f8ff281c..d1b270d9 100644 --- a/plugins/wasi_nn/GGML/tts/tts_core.h +++ b/plugins/wasi_nn/GGML/tts/tts_core.h @@ -31,11 +31,6 @@ const std::map Ones = { const std::map Tens = { {2, "twenty"}, {3, "thirty"}, {4, "forty"}, {5, "fifty"}, {6, "sixty"}, {7, "seventy"}, {8, "eighty"}, {9, "ninety"}}; - -std::vector embdToAudio(const float *Embd, const int NCodes, - const int NEmbd, const int NThread); -std::vector audioDataToWav(const std::vector &Data, - int SampleRate); } // namespace std::string processTTSPromptText(const std::string &Text); diff --git a/plugins/wasmedge_llmc/CMakeLists.txt b/plugins/wasmedge_llmc/CMakeLists.txt index da37ed2f..6798cef7 100644 --- a/plugins/wasmedge_llmc/CMakeLists.txt +++ b/plugins/wasmedge_llmc/CMakeLists.txt @@ -1,66 +1,4 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: 2019-2024 Second State INC -wasmedge_add_library(wasmedgePluginWasmEdgeLLMC - SHARED - llmc_func.cpp - llmc_module.cpp - llmc_env.cpp -) - -option(WASMEDGE_PLUGIN_LLMC_CUDA "Training GPT2 with CUDA" OFF) - -message(STATUS "Start fetching llm.c source") -include(FetchContent) - -if (WASMEDGE_PLUGIN_LLMC_CUDA) - set(CUDALIB ON) - message(STATUS "Build wasmedge_llmc with CUDA backend") -else() - message(STATUS "Build wasmedge_llmc with CPU backend") -endif() - -FetchContent_Declare( - llmc - GIT_REPOSITORY https://github.com/WasmEdge/llm.c -) -FetchContent_MakeAvailable(llmc) - -if (WASMEDGE_PLUGIN_LLMC_CUDA) - target_link_libraries(wasmedgePluginWasmEdgeLLMC PRIVATE - train_gpt2_cuda - ) -else() - target_link_libraries(wasmedgePluginWasmEdgeLLMC PRIVATE - train_gpt2_cpu - ) -endif() - -target_compile_options(wasmedgePluginWasmEdgeLLMC - PUBLIC - -DWASMEDGE_PLUGIN -) - -target_include_directories(wasmedgePluginWasmEdgeLLMC - PUBLIC - $ - ${CMAKE_CURRENT_SOURCE_DIR} -) - -if(WASMEDGE_LINK_PLUGINS_STATIC) - target_link_libraries(wasmedgePluginWasmEdgeLLMC - PRIVATE - wasmedgeCAPI - ) -else() - target_link_libraries(wasmedgePluginWasmEdgeLLMC - PRIVATE - wasmedge_shared - ) -endif() - -install( - TARGETS wasmedgePluginWasmEdgeLLMC - DESTINATION ${CMAKE_INSTALL_LIBDIR}/wasmedge - COMPONENT WasmEdge -) +message(FATAL_ERROR "WasmEdge LLMC plugin is removed due to the upstream end-of-life. Reference: https://github.com/WasmEdge/llm.c") diff --git a/plugins/wasmedge_llmc/llmc_base.h b/plugins/wasmedge_llmc/llmc_base.h deleted file mode 100644 index 6b35ffff..00000000 --- a/plugins/wasmedge_llmc/llmc_base.h +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#pragma once - -#include "llmc_env.h" - -#include "common/errcode.h" -#include "runtime/hostfunc.h" - -namespace WasmEdge { -namespace Host { -namespace WasmEdgeLLMC { - -template class HostFunction : public Runtime::HostFunction { -public: - HostFunction(LLMCEnv &HostEnv) : Runtime::HostFunction(0), Env(HostEnv) {} - -protected: - static constexpr uint32_t castErrNo(ErrNo E) noexcept { - return static_cast(E); - } - LLMCEnv &Env; -}; - -} // namespace WasmEdgeLLMC -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_llmc/llmc_env.cpp b/plugins/wasmedge_llmc/llmc_env.cpp deleted file mode 100644 index a960ec16..00000000 --- a/plugins/wasmedge_llmc/llmc_env.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#include "llmc_env.h" -#include "llmc_fwd.h" -#include "llmc_module.h" - -namespace WasmEdge { -namespace Host { -namespace WasmEdgeLLMC { - -uint32_t LLMCEnv::addModel(GPT2 *M) noexcept { - Models.push_back(M); - return Models.size() - 1; -} - -GPT2 *LLMCEnv::getModel(uint32_t Id) noexcept { - assert(Id < Models.size() && "Out of bounds"); - return Models[Id]; -} - -uint32_t LLMCEnv::addTokenizer(Tokenizer *T) noexcept { - Tokenizers.push_back(T); - return Tokenizers.size() - 1; -} - -Tokenizer *LLMCEnv::getTokenizer(uint32_t Id) noexcept { - assert(Id < Tokenizers.size() && "Out of bounds"); - return Tokenizers[Id]; -} - -uint32_t LLMCEnv::addDataLoader(DataLoader *D) noexcept { - DataLoaders.push_back(D); - return DataLoaders.size() - 1; -} - -DataLoader *LLMCEnv::getDataLoader(uint32_t Id) noexcept { - assert(Id < DataLoaders.size() && "Out of bounds"); - return DataLoaders[Id]; -} - -LLMCEnv::~LLMCEnv() { - for (GPT2 *M : Models) { - gpt2_destroy(M); - } - for (DataLoader *DL : DataLoaders) { - dataloader_destroy(DL); - } - for (Tokenizer *T : Tokenizers) { - tokenizer_destroy(T); - } -} - -namespace { -Runtime::Instance::ModuleInstance * -create(const Plugin::PluginModule::ModuleDescriptor *) noexcept { - return new WasmEdgeLLMCModule; -} - -static Plugin::PluginModule::ModuleDescriptor MD[] = { - { - /* Name */ "wasmedge_llmc", - /* Description */ "", - /* Create */ create, - }, -}; - -Plugin::Plugin::PluginDescriptor Descriptor{ - /* Name */ "wasmedge_llmc", - /* Description */ "", - /* APIVersion */ Plugin::Plugin::CurrentAPIVersion, - /* Version */ {0, 1, 0, 0}, - /* ModuleCount */ 1, - /* ModuleDescriptions */ MD, - /* ComponentCount */ 0, - /* ComponentDescriptions */ nullptr, - /*AddOptions*/ nullptr, -}; -} // namespace - -EXPORT_GET_DESCRIPTOR(Descriptor) - -} // namespace WasmEdgeLLMC -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_llmc/llmc_env.h b/plugins/wasmedge_llmc/llmc_env.h deleted file mode 100644 index 66b9b8c1..00000000 --- a/plugins/wasmedge_llmc/llmc_env.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#pragma once - -#include "plugin/plugin.h" - -#include -#include -#include - -extern "C" { -struct GPT2; -struct Tokenizer; -struct DataLoader; -} - -namespace WasmEdge { -namespace Host { -namespace WasmEdgeLLMC { - -enum class ErrNo : uint32_t { - Success = 0, - InvalidArgument = 1, - MissingMemory = 2, -}; - -class LLMCEnv { - std::vector Models; - std::vector Tokenizers; - std::vector DataLoaders; - -public: - uint32_t addModel(GPT2 *M) noexcept; - - GPT2 *getModel(uint32_t Id) noexcept; - - size_t getModelSize() const noexcept { return Models.size(); } - - uint32_t addTokenizer(Tokenizer *T) noexcept; - - Tokenizer *getTokenizer(uint32_t Id) noexcept; - - size_t getTokenizerSize() const noexcept { return Tokenizers.size(); } - - uint32_t addDataLoader(DataLoader *D) noexcept; - - DataLoader *getDataLoader(uint32_t Id) noexcept; - - size_t getDataLoaderSize() const noexcept { return DataLoaders.size(); } - - ~LLMCEnv(); -}; - -} // namespace WasmEdgeLLMC -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_llmc/llmc_func.cpp b/plugins/wasmedge_llmc/llmc_func.cpp deleted file mode 100644 index b90fba78..00000000 --- a/plugins/wasmedge_llmc/llmc_func.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#include "llmc_func.h" -#include "llmc_fwd.h" - -#include "common/errcode.h" -#include "common/spdlog.h" - -#include -#include - -namespace WasmEdge { -namespace Host { -namespace WasmEdgeLLMC { - -Expect ModelCreate::bodyImpl(const Runtime::CallingFrame &Frame, - uint32_t CheckPointPath, - uint32_t CheckPointPathLen, - uint32_t ModelIdPtr) { - auto *MemInst = Frame.getMemoryByIndex(0); - if (MemInst == nullptr) { - spdlog::error("[WasmEdge-LLMC] Memory instance not found."sv); - return ErrNo::MissingMemory; - } - auto CheckPointPathSpan = - MemInst->getSpan(CheckPointPath, CheckPointPathLen); - if (unlikely(CheckPointPathSpan.size() != CheckPointPathLen)) { - spdlog::error( - "[WasmEdge-LLMC] Failed when accessing the input checkpoint path memory."sv); - return ErrNo::MissingMemory; - } - - auto *ModelId = MemInst->getPointer(ModelIdPtr); - if (unlikely(ModelId == nullptr)) { - spdlog::error( - "[WasmEdge-LLMC] Failed when accessing the return model memory."sv); - return ErrNo::InvalidArgument; - } - std::string CheckPointPathStr = - std::string(CheckPointPathSpan.begin(), - CheckPointPathSpan.begin() + CheckPointPathSpan.size()); - GPT2 *Model = gpt2_create(CheckPointPathStr.data()); - *ModelId = Env.addModel(Model); - return ErrNo::Success; -} - -Expect DataLoaderCreate::bodyImpl( - const Runtime::CallingFrame &Frame, uint32_t DataPath, uint32_t DataPathLen, - uint32_t B, uint32_t T, uint32_t ProcessRank, uint32_t NumProcesses, - int32_t ShouldShuffle, uint32_t DataLoaderIdPtr) { - auto *MemInst = Frame.getMemoryByIndex(0); - if (MemInst == nullptr) { - spdlog::error("[WasmEdge-LLMC] Memory instance not found."sv); - return ErrNo::MissingMemory; - } - auto DataPathSpan = MemInst->getSpan(DataPath, DataPathLen); - if (unlikely(DataPathSpan.size() != DataPathLen)) { - spdlog::error( - "[WasmEdge-LLMC] Failed when accessing the input dataloader path memory."sv); - return ErrNo::MissingMemory; - } - - auto *DataLoaderId = MemInst->getPointer(DataLoaderIdPtr); - if (unlikely(DataLoaderId == nullptr)) { - spdlog::error( - "[WasmEdge-LLMC] Failed when accessing the return dataloader memory."sv); - return ErrNo::InvalidArgument; - } - - std::string DataPathStr = std::string( - DataPathSpan.begin(), DataPathSpan.begin() + DataPathSpan.size()); - DataLoader *D = dataloader_create(DataPathStr.data(), B, T, ProcessRank, - NumProcesses, ShouldShuffle); - *DataLoaderId = Env.addDataLoader(D); - return ErrNo::Success; -} - -Expect TokenizerCreate::bodyImpl(const Runtime::CallingFrame &Frame, - uint32_t FilePath, uint32_t FilePathLen, - uint32_t TokenizerIdPtr) { - auto *MemInst = Frame.getMemoryByIndex(0); - if (MemInst == nullptr) { - spdlog::error("[WasmEdge-LLMC] Memory instance not found."sv); - return ErrNo::MissingMemory; - } - auto FilePathSpan = MemInst->getSpan(FilePath, FilePathLen); - if (unlikely(FilePathSpan.size() != FilePathLen)) { - spdlog::error( - "[WasmEdge-LLMC] Failed when accessing the input tokenizer path memory."sv); - return ErrNo::MissingMemory; - } - - auto *TokenizerId = MemInst->getPointer(TokenizerIdPtr); - if (unlikely(TokenizerId == nullptr)) { - spdlog::error( - "[WasmEdge-LLMC] Failed when accessing the return tokenizer memory."sv); - return ErrNo::InvalidArgument; - } - std::string FilePathStr = std::string( - FilePathSpan.begin(), FilePathSpan.begin() + FilePathSpan.size()); - Tokenizer *T = tokenizer_create(FilePathStr.data()); - *TokenizerId = Env.addTokenizer(T); - return ErrNo::Success; -} - -Expect ModelTrain::bodyImpl(const Runtime::CallingFrame &Frame, - uint32_t ModelId, uint32_t TrainDataLoaderId, - uint32_t ValDataLoaderId, - uint32_t TokenizerId, uint32_t B, uint32_t T, - float Lr, uint32_t Epoch) { - auto *MemInst = Frame.getMemoryByIndex(0); - if (MemInst == nullptr) { - spdlog::error("[WasmEdge-LLMC] Memory instance not found."sv); - return ErrNo::MissingMemory; - } - GPT2 *Model = Env.getModel(ModelId); - DataLoader *TrainDataLoader = Env.getDataLoader(TrainDataLoaderId); - DataLoader *ValDataLoader = Env.getDataLoader(ValDataLoaderId); - Tokenizer *Tokenizer = Env.getTokenizer(TokenizerId); - gpt2_train(Model, TrainDataLoader, ValDataLoader, Tokenizer, B, T, Lr, Epoch); - return ErrNo::Success; -} - -} // namespace WasmEdgeLLMC -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_llmc/llmc_func.h b/plugins/wasmedge_llmc/llmc_func.h deleted file mode 100644 index 85c786f5..00000000 --- a/plugins/wasmedge_llmc/llmc_func.h +++ /dev/null @@ -1,91 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#pragma once - -#include "llmc_base.h" -#include "llmc_env.h" - -#include "runtime/callingframe.h" - -#include - -namespace WasmEdge { -namespace Host { -namespace WasmEdgeLLMC { - -class ModelCreate : public HostFunction { -public: - explicit ModelCreate(LLMCEnv &HostEnv) : HostFunction(HostEnv) {} - - Expect body(const Runtime::CallingFrame &Frame, - uint32_t CheckPointPath, uint32_t CheckPointPathLen, - uint32_t ModelIdPtr) { - return bodyImpl(Frame, CheckPointPath, CheckPointPathLen, ModelIdPtr) - .map(castErrNo); - } - -private: - Expect bodyImpl(const Runtime::CallingFrame &Frame, - uint32_t CheckPointPath, uint32_t CheckPointPathLen, - uint32_t ModelIdPtr); -}; - -class DataLoaderCreate : public HostFunction { -public: - explicit DataLoaderCreate(LLMCEnv &HostEnv) : HostFunction(HostEnv) {} - - Expect body(const Runtime::CallingFrame &Frame, uint32_t DataPath, - uint32_t DataPathLen, uint32_t B, uint32_t T, - uint32_t ProcessRank, uint32_t NumProcesses, - int32_t ShouldShuffle, uint32_t DataLoaderIdPtr) { - return bodyImpl(Frame, DataPath, DataPathLen, B, T, ProcessRank, - NumProcesses, ShouldShuffle, DataLoaderIdPtr) - .map(castErrNo); - } - -private: - Expect bodyImpl(const Runtime::CallingFrame &Frame, uint32_t DataPath, - uint32_t DataPathLen, uint32_t B, uint32_t T, - uint32_t ProcessRank, uint32_t NumProcesses, - int32_t ShouldShuffle, uint32_t DataLoaderIdPtr); -}; - -class TokenizerCreate : public HostFunction { -public: - explicit TokenizerCreate(LLMCEnv &HostEnv) : HostFunction(HostEnv) {} - - Expect body(const Runtime::CallingFrame &Frame, uint32_t FilePath, - uint32_t FilePathLen, uint32_t TokenizerIdPtr) { - return bodyImpl(Frame, FilePath, FilePathLen, TokenizerIdPtr) - .map(castErrNo); - } - -private: - Expect bodyImpl(const Runtime::CallingFrame &Frame, uint32_t FilePath, - uint32_t FilePathLen, uint32_t TokenizerIdPtr); -}; - -class ModelTrain : public HostFunction { -public: - explicit ModelTrain(LLMCEnv &HostEnv) : HostFunction(HostEnv) {} - - Expect body(const Runtime::CallingFrame &Frame, uint32_t ModelId, - uint32_t TrainDataLoaderId, uint32_t ValDataLoaderId, - uint32_t TokenizerId, uint32_t B, uint32_t T, float Lr, - uint32_t Epoch) { - return bodyImpl(Frame, ModelId, TrainDataLoaderId, ValDataLoaderId, - TokenizerId, B, T, Lr, Epoch) - .map(castErrNo); - } - -private: - Expect bodyImpl(const Runtime::CallingFrame &Frame, uint32_t ModelId, - uint32_t TrainDataLoaderId, uint32_t ValDataLoaderId, - uint32_t TokenizerId, uint32_t B, uint32_t T, float Lr, - uint32_t Epoch); -}; - -} // namespace WasmEdgeLLMC -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_llmc/llmc_fwd.h b/plugins/wasmedge_llmc/llmc_fwd.h deleted file mode 100644 index afa39f10..00000000 --- a/plugins/wasmedge_llmc/llmc_fwd.h +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#pragma once - -#include "llmc_env.h" - -extern "C" { - -struct GPT2; -struct Tokenizer; -struct DataLoader; - -GPT2 *gpt2_create(const char *checkpoint_path); - -void gpt2_destroy(GPT2 *model); - -DataLoader *dataloader_create(const char *filename_pattern, size_t B, size_t T, - int process_rank, int num_processes, - int should_shuffle); -void dataloader_destroy(DataLoader *loader); - -Tokenizer *tokenizer_create(const char *filename); - -void tokenizer_destroy(Tokenizer *tokenizer); - -void gpt2_train(GPT2 *model, DataLoader *train_loader, DataLoader *val_loader, - Tokenizer *tokenizer, int B, int T, float lr, int epoch); -} diff --git a/plugins/wasmedge_llmc/llmc_module.cpp b/plugins/wasmedge_llmc/llmc_module.cpp deleted file mode 100644 index 8914eb03..00000000 --- a/plugins/wasmedge_llmc/llmc_module.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#include "llmc_module.h" -#include "llmc_func.h" - -namespace WasmEdge { -namespace Host { - -WasmEdgeLLMCModule::WasmEdgeLLMCModule() : ModuleInstance("wasmedge_llmc") { - addHostFunc("model_create", std::make_unique(Env)); - addHostFunc("dataloader_create", - std::make_unique(Env)); - addHostFunc("tokenizer_create", - std::make_unique(Env)); - addHostFunc("model_train", std::make_unique(Env)); -} - -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_llmc/llmc_module.h b/plugins/wasmedge_llmc/llmc_module.h deleted file mode 100644 index 86a923c3..00000000 --- a/plugins/wasmedge_llmc/llmc_module.h +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#pragma once - -#include "llmc_env.h" - -#include "runtime/instance/module.h" - -namespace WasmEdge { -namespace Host { - -class WasmEdgeLLMCModule : public Runtime::Instance::ModuleInstance { -public: - WasmEdgeLLMCModule(); - -private: - WasmEdgeLLMC::LLMCEnv Env; -}; - -} // namespace Host -} // namespace WasmEdge diff --git a/plugins/wasmedge_zlib/zlibfunc.cpp b/plugins/wasmedge_zlib/zlibfunc.cpp index b283f69a..8e54dd8f 100644 --- a/plugins/wasmedge_zlib/zlibfunc.cpp +++ b/plugins/wasmedge_zlib/zlibfunc.cpp @@ -149,14 +149,14 @@ Expect WasmEdgeZlibDeflateInit::body(const Runtime::CallingFrame &Frame, uint32_t ZStreamPtr, int32_t Level) { - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = SyncRun( @@ -194,14 +194,14 @@ Expect WasmEdgeZlibInflateInit::body(const Runtime::CallingFrame &Frame, uint32_t ZStreamPtr) { - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = @@ -238,14 +238,14 @@ Expect WasmEdgeZlibDeflateInit2::body( const Runtime::CallingFrame &Frame, uint32_t ZStreamPtr, int32_t Level, int32_t Method, int32_t WindowBits, int32_t MemLevel, int32_t Strategy) { - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = @@ -308,10 +308,10 @@ WasmEdgeZlibDeflateCopy::body(const Runtime::CallingFrame &Frame, return Unexpect(ErrCode::Value::HostFuncError); } - auto DestZStream = std::make_unique(); + auto NewZStream = std::make_unique(); auto It = - Env.ZStreamMap.emplace(std::make_pair(DestPtr, std::move(DestZStream))) + Env.ZStreamMap.emplace(std::make_pair(DestPtr, std::move(NewZStream))) .second; const auto Res = SyncRun("WasmEdgeZlibDeflateCopy", Env, DestPtr, Frame, @@ -429,14 +429,14 @@ WasmEdgeZlibDeflateSetHeader::body(const Runtime::CallingFrame &Frame, Expect WasmEdgeZlibInflateInit2::body(const Runtime::CallingFrame &Frame, uint32_t ZStreamPtr, int32_t WindowBits) { - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = SyncRun("WasmEdgeZlibInflateInit2", Env, ZStreamPtr, Frame, @@ -500,10 +500,10 @@ WasmEdgeZlibInflateCopy::body(const Runtime::CallingFrame &Frame, return Unexpect(ErrCode::Value::HostFuncError); } - auto DestZStream = std::make_unique(); + auto NewZStream = std::make_unique(); auto It = - Env.ZStreamMap.emplace(std::make_pair(DestPtr, std::move(DestZStream))) + Env.ZStreamMap.emplace(std::make_pair(DestPtr, std::move(NewZStream))) .second; const auto Res = SyncRun("WasmEdgeZlibInflateCopy", Env, DestPtr, Frame, @@ -593,10 +593,10 @@ Expect WasmEdgeZlibInflateBackInit::body(const Runtime::CallingFrame &Frame, uint32_t ZStreamPtr, int32_t WindowBits, uint32_t WindowPtr) { - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored MEMINST_CHECK(MemInst, Frame, 0) @@ -604,7 +604,7 @@ WasmEdgeZlibInflateBackInit::body(const Runtime::CallingFrame &Frame, auto *Window = MemInst->getPointer(WindowPtr); auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = @@ -1112,16 +1112,16 @@ WasmEdgeZlibDeflateInit_::body(const Runtime::CallingFrame &Frame, MEMINST_CHECK(MemInst, Frame, 0) const auto *WasmZlibVersion = MemInst->getPointer(VersionPtr); - auto HostZStream = std::make_unique(); + auto NewZStream = std::make_unique(); // ignore wasm custom allocators - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; // Ignore opaque because zmalloc and zfree are ignored. - HostZStream->opaque = Z_NULL; + NewZStream->opaque = Z_NULL; auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = @@ -1147,16 +1147,16 @@ WasmEdgeZlibInflateInit_::body(const Runtime::CallingFrame &Frame, MEMINST_CHECK(MemInst, Frame, 0) const auto *WasmZlibVersion = MemInst->getPointer(VersionPtr); - auto HostZStream = std::make_unique(); + auto NewZStream = std::make_unique(); // ignore wasm custom allocators - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; // Ignore opaque because zmalloc and zfree are ignored. - HostZStream->opaque = Z_NULL; + NewZStream->opaque = Z_NULL; auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = SyncRun("WasmEdgeZlibInflateInit_", Env, ZStreamPtr, Frame, @@ -1181,14 +1181,14 @@ Expect WasmEdgeZlibDeflateInit2_::body( MEMINST_CHECK(MemInst, Frame, 0) const auto *WasmZlibVersion = MemInst->getPointer(VersionPtr); - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = SyncRun( @@ -1214,14 +1214,14 @@ WasmEdgeZlibInflateInit2_::body(const Runtime::CallingFrame &Frame, MEMINST_CHECK(MemInst, Frame, 0) const auto *WasmZlibVersion = MemInst->getPointer(VersionPtr); - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = @@ -1247,14 +1247,14 @@ Expect WasmEdgeZlibInflateBackInit_::body( const auto *WasmZlibVersion = MemInst->getPointer(VersionPtr); auto *Window = MemInst->getPointer(WindowPtr); - auto HostZStream = std::make_unique(); - HostZStream->zalloc = Z_NULL; - HostZStream->zfree = Z_NULL; - HostZStream->opaque = + auto NewZStream = std::make_unique(); + NewZStream->zalloc = Z_NULL; + NewZStream->zfree = Z_NULL; + NewZStream->opaque = Z_NULL; // ignore opaque since zmalloc and zfree was ignored auto It = - Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(HostZStream))) + Env.ZStreamMap.emplace(std::make_pair(ZStreamPtr, std::move(NewZStream))) .second; const auto ZRes = diff --git a/test/plugins/wasi_crypto/signatures.cpp b/test/plugins/wasi_crypto/signatures.cpp index 6d814992..b63609b1 100644 --- a/test/plugins/wasi_crypto/signatures.cpp +++ b/test/plugins/wasi_crypto/signatures.cpp @@ -62,6 +62,9 @@ TEST_F(WasiCryptoTest, Signatures) { WASI_CRYPTO_EXPECT_TRUE(publickeyVerify(PkHandle)); }; PublicKeyVerifyTest(__WASI_ALGORITHM_TYPE_SIGNATURES, "Ed25519"sv); + PublicKeyVerifyTest(__WASI_ALGORITHM_TYPE_SIGNATURES, "ECDSA_P256_SHA256"sv); + PublicKeyVerifyTest(__WASI_ALGORITHM_TYPE_SIGNATURES, "ECDSA_K256_SHA256"sv); + PublicKeyVerifyTest(__WASI_ALGORITHM_TYPE_SIGNATURES, "ECDSA_P384_SHA384"sv); // A raw public key with an invalid length is rejected on import. auto PublicKeyImportInvalidTest = [this](__wasi_algorithm_type_e_t AlgType, @@ -73,6 +76,21 @@ TEST_F(WasiCryptoTest, Signatures) { }; PublicKeyImportInvalidTest(__WASI_ALGORITHM_TYPE_SIGNATURES, "Ed25519"sv); + // A SEC1 public key whose point is not on the curve is rejected on import. + auto PublicKeyImportInvalidSecTest = [this](__wasi_algorithm_type_e_t AlgType, + std::string_view Alg) { + SCOPED_TRACE(Alg); + WASI_CRYPTO_EXPECT_FAILURE( + publickeyImport( + AlgType, Alg, + "04ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_u8v, + __WASI_PUBLICKEY_ENCODING_SEC), + __WASI_CRYPTO_ERRNO_INVALID_KEY); + }; + PublicKeyImportInvalidSecTest(__WASI_ALGORITHM_TYPE_SIGNATURES, + "ECDSA_P256_SHA256"sv); + auto SigEncodingTest = [this]( std::string_view Alg, diff --git a/test/plugins/wasi_logging/wasi_logging.cpp b/test/plugins/wasi_logging/wasi_logging.cpp index b523a177..ece53b93 100644 --- a/test/plugins/wasi_logging/wasi_logging.cpp +++ b/test/plugins/wasi_logging/wasi_logging.cpp @@ -83,14 +83,12 @@ TEST(WasiLoggingTests, func_log) { // Get the function "log". auto *FuncInst1 = WasiLoggingMod1->findFuncExports("log"); auto *FuncInst2 = WasiLoggingMod2->findFuncExports("log"); - EXPECT_NE(FuncInst1, nullptr); - EXPECT_NE(FuncInst2, nullptr); - EXPECT_TRUE(FuncInst1->isHostFunction()); - EXPECT_TRUE(FuncInst2->isHostFunction()); - auto &HostFuncInst1 = dynamic_cast( - FuncInst1->getHostFunc()); - auto &HostFuncInst2 = dynamic_cast( - FuncInst2->getHostFunc()); + ASSERT_NE(FuncInst1, nullptr); + ASSERT_NE(FuncInst2, nullptr); + ASSERT_TRUE(FuncInst1->isHostFunction()); + ASSERT_TRUE(FuncInst2->isHostFunction()); + auto &HostFuncInst1 = FuncInst1->getHostFunc(); + auto &HostFuncInst2 = FuncInst2->getHostFunc(); // Show All Level EXPECT_TRUE(HostFuncInst1.run( @@ -183,6 +181,49 @@ TEST(WasiLoggingTests, func_log) { {})); } +TEST(WasiLoggingTests, func_log_oob) { + using namespace std::literals::string_view_literals; + auto WasiLoggingMod = createModule(); + ASSERT_TRUE(WasiLoggingMod); + + WasmEdge::Runtime::Instance::ModuleInstance Mod(""); + Mod.addHostMemory( + "memory", std::make_unique( + WasmEdge::AST::MemoryType(1))); + auto *MemInstPtr = Mod.findMemoryExports("memory"); + ASSERT_NE(MemInstPtr, nullptr); + auto &MemInst = *MemInstPtr; + WasmEdge::Runtime::CallingFrame CallFrame(nullptr, &Mod); + + // Place a valid "stdout" context at offset 0. + fillMemContent(MemInst, 0, "stdout"sv); + // Place one byte of message data at the last byte of the page. + fillMemContent(MemInst, 65535, 1, 'x'); + + auto *FuncInst = WasiLoggingMod->findFuncExports("log"); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); + + // OOB context: CxtPtr=65535, CxtLen=100 extends 99 bytes past the page end. + // Expected: HostFuncError (not a crash). + EXPECT_FALSE(HostFuncInst.run( + CallFrame, + std::initializer_list{ + UINT32_C(0), UINT32_C(65535), UINT32_C(100), UINT32_C(0), + UINT32_C(6)}, + {})); + + // OOB message: valid context ("stdout"), MsgPtr=65535, MsgLen=100. + // Expected: HostFuncError (not a crash). + EXPECT_FALSE(HostFuncInst.run( + CallFrame, + std::initializer_list{ + UINT32_C(0), UINT32_C(0), UINT32_C(6), UINT32_C(65535), + UINT32_C(100)}, + {})); +} + GTEST_API_ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/plugins/wasi_nn/wasi_nn.cpp b/test/plugins/wasi_nn/wasi_nn.cpp index 514a0923..6a8214e4 100644 --- a/test/plugins/wasi_nn/wasi_nn.cpp +++ b/test/plugins/wasi_nn/wasi_nn.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2019-2024 Second State INC -#include "wasinnfunc.h" #include "wasinnmodule.h" #include "common/types.h" +#include "runtime/callingframe.h" #include "runtime/instance/module.h" #include @@ -176,32 +176,27 @@ TEST(WasiNNTest, OpenVINOBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // OpenVINO WASI-NN load tests. // Test: load -- meaningless binaries. @@ -599,32 +594,27 @@ TEST(WasiNNTest, PyTorchBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Torch WASI-NN load tests. // Test: load -- meaningless binaries. @@ -974,32 +964,27 @@ TEST(WasiNNTest, TFLiteBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Torch WASI-NN load tests. // Test: load -- meaningless binaries. @@ -1338,32 +1323,27 @@ TEST(WasiNNTest, GGMLBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // GGML WASI-NN load tests. // Test: load -- meaningless binaries. @@ -1616,39 +1596,32 @@ TEST(WasiNNTest, GGMLBackendWithRPC) { auto FuncInst = NNMod->findFuncExports("load_by_name"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoadByName = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoadByName = FuncInst->getHostFunc(); // Get the function "load_by_name_with_config". FuncInst = NNMod->findFuncExports("load_by_name_with_config"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoadByNameWithConfig = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncLoadByNameWithConfig = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Test: load_by_name -- load successfully. { @@ -1849,41 +1822,32 @@ TEST(WasiNNTest, GGMLBackendComputeSingleWithRPC) { auto FuncInst = NNMod->findFuncExports("load_by_name"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoadByName = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoadByName = FuncInst->getHostFunc(); // Get the function "load_by_name_with_config". FuncInst = NNMod->findFuncExports("load_by_name_with_config"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoadByNameWithConfig = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncLoadByNameWithConfig = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output_single"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutputSingle = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncGetOutputSingle = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute_single"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncComputeSingle = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncComputeSingle = FuncInst->getHostFunc(); // Test: load_by_name -- load successfully. { @@ -2044,32 +2008,27 @@ TEST(WasiNNTest, WhisperBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Whisper WASI-NN load tests. // Test: load -- meaningless binaries. @@ -2275,32 +2234,27 @@ TEST(WasiNNTest, PiperBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Piper WASI-NN load tests. // Test: load -- graph id ptr out of bounds. @@ -2657,38 +2611,32 @@ TEST(WasiNNTest, ChatTTSBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Get the function "unload". FuncInst = NNMod->findFuncExports("unload"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncUnload = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncUnload = FuncInst->getHostFunc(); // ChatTTS WASI-NN load tests. // Test: load -- graph id ptr out of bounds. @@ -2906,32 +2854,27 @@ TEST(WasiNNTest, MLXBackend) { auto *FuncInst = NNMod->findFuncExports("load"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); EXPECT_NE(FuncInst, nullptr); EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // MLX WASI-NN load tests. // Test: load -- meaningless binaries. @@ -3135,50 +3078,39 @@ TEST(WasiNNTest, BitNetBackend) { // Get the function "load". auto *FuncInst = NNMod->findFuncExports("load"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncLoad = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncLoad = FuncInst->getHostFunc(); // Get the function "init_execution_context". FuncInst = NNMod->findFuncExports("init_execution_context"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncInit = dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncInit = FuncInst->getHostFunc(); // Get the function "set_input". FuncInst = NNMod->findFuncExports("set_input"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncSetInput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncSetInput = FuncInst->getHostFunc(); // Get the function "get_output". FuncInst = NNMod->findFuncExports("get_output"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncGetOutput = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncGetOutput = FuncInst->getHostFunc(); // Get the function "compute". FuncInst = NNMod->findFuncExports("compute"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncCompute = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncCompute = FuncInst->getHostFunc(); // Get the function "unload". FuncInst = NNMod->findFuncExports("unload"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncUnload = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncUnload = FuncInst->getHostFunc(); // Get the function "compute_single". FuncInst = NNMod->findFuncExports("compute_single"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncComputeSingle = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncComputeSingle = FuncInst->getHostFunc(); // Get the function "get_output_single". FuncInst = NNMod->findFuncExports("get_output_single"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncGetOutputSingle = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncGetOutputSingle = FuncInst->getHostFunc(); // Get the function "fini_single". FuncInst = NNMod->findFuncExports("fini_single"); ASSERT_NE(FuncInst, nullptr); - auto &HostFuncFiniSingle = - dynamic_cast(FuncInst->getHostFunc()); + auto &HostFuncFiniSingle = FuncInst->getHostFunc(); // --- Test Data & Pointer Setup --- const std::string ModelPath = "./wasinn_bitnet_fixtures/ggml-model-i2_s.gguf"; diff --git a/test/plugins/wasm_bpf/simple_map_test.cpp b/test/plugins/wasm_bpf/simple_map_test.cpp index f8b84e4e..f8a711f9 100644 --- a/test/plugins/wasm_bpf/simple_map_test.cpp +++ b/test/plugins/wasm_bpf/simple_map_test.cpp @@ -113,8 +113,7 @@ TEST(WasmBpfTest, SimpleMapTest) { auto *loadFunc = module->findFuncExports("wasm_load_bpf_object"); ASSERT_NE(loadFunc, nullptr); ASSERT_TRUE(loadFunc->isHostFunction()); - auto &loadFuncHost = - dynamic_cast(loadFunc->getHostFunc()); + auto &loadFuncHost = loadFunc->getHostFunc(); // call "wasm_load_bpf_object" to Load `bootstrap.bpf.o`, and check the // result @@ -132,8 +131,7 @@ TEST(WasmBpfTest, SimpleMapTest) { auto *attachFunc = module->findFuncExports("wasm_attach_bpf_program"); ASSERT_NE(attachFunc, nullptr); ASSERT_TRUE(attachFunc->isHostFunction()); - auto &attachFuncHost = dynamic_cast( - attachFunc->getHostFunc()); + auto &attachFuncHost = attachFunc->getHostFunc(); // Call "wasm_attach_bpf_program" to attach, and check the result std::array attachResult; @@ -151,8 +149,7 @@ TEST(WasmBpfTest, SimpleMapTest) { auto *mapFdFunc = module->findFuncExports("wasm_bpf_map_fd_by_name"); ASSERT_NE(mapFdFunc, nullptr); ASSERT_TRUE(mapFdFunc->isHostFunction()); - auto &mapFdFuncHost = - dynamic_cast(mapFdFunc->getHostFunc()); + auto &mapFdFuncHost = mapFdFunc->getHostFunc(); // Call "wasm_bpf_map_fd_by_name" to get the map fd, and check the result std::array mapFdResult; @@ -164,12 +161,11 @@ TEST(WasmBpfTest, SimpleMapTest) { auto mapFd = mapFdResult[0].get(); ASSERT_GE(mapFd, 0); - // Get function `wasm_bpf_map_fd_by_name` + // Get function `wasm_bpf_map_operate` auto *mapOptFunc = module->findFuncExports("wasm_bpf_map_operate"); - EXPECT_NE(mapOptFunc, nullptr); - EXPECT_TRUE(mapOptFunc->isHostFunction()); - auto &mapOptFuncHost = - dynamic_cast(mapOptFunc->getHostFunc()); + ASSERT_NE(mapOptFunc, nullptr); + ASSERT_TRUE(mapOptFunc->isHostFunction()); + auto &mapOptFuncHost = mapOptFunc->getHostFunc(); // A wrapper to call wasm_bpf_map_operate auto callMapOperate = [&](int32_t fd, int32_t cmd, uint32_t key, @@ -278,8 +274,7 @@ TEST(WasmBpfTest, SimpleMapTest) { auto *closeFunc = module->findFuncExports("wasm_close_bpf_object"); ASSERT_NE(closeFunc, nullptr); ASSERT_TRUE(closeFunc->isHostFunction()); - auto &closeFuncHost = - dynamic_cast(closeFunc->getHostFunc()); + auto &closeFuncHost = closeFunc->getHostFunc(); // Call "wasm_close_bpf_object" to attach, and check the result std::array closeResult; diff --git a/test/plugins/wasm_bpf/simple_ringbuf_test.cpp b/test/plugins/wasm_bpf/simple_ringbuf_test.cpp index e2fbf94c..65f90ed8 100644 --- a/test/plugins/wasm_bpf/simple_ringbuf_test.cpp +++ b/test/plugins/wasm_bpf/simple_ringbuf_test.cpp @@ -133,8 +133,7 @@ TEST(WasmBpfTest, SimpleRingbuf) { auto *loadFunc = module->findFuncExports("wasm_load_bpf_object"); ASSERT_NE(loadFunc, nullptr); ASSERT_TRUE(loadFunc->isHostFunction()); - auto &loadFuncHost = - dynamic_cast(loadFunc->getHostFunc()); + auto &loadFuncHost = loadFunc->getHostFunc(); // call "wasm_load_bpf_object" to Load `bootstrap.bpf.o`, and check the // result @@ -152,8 +151,7 @@ TEST(WasmBpfTest, SimpleRingbuf) { auto *attachFunc = module->findFuncExports("wasm_attach_bpf_program"); ASSERT_NE(attachFunc, nullptr); ASSERT_TRUE(attachFunc->isHostFunction()); - auto &attachFuncHost = dynamic_cast( - attachFunc->getHostFunc()); + auto &attachFuncHost = attachFunc->getHostFunc(); // Call "wasm_attach_bpf_program" to attach, and check the result std::array attachResult; @@ -171,8 +169,7 @@ TEST(WasmBpfTest, SimpleRingbuf) { auto *mapFdFunc = module->findFuncExports("wasm_bpf_map_fd_by_name"); ASSERT_NE(mapFdFunc, nullptr); ASSERT_TRUE(mapFdFunc->isHostFunction()); - auto &mapFdFuncHost = - dynamic_cast(mapFdFunc->getHostFunc()); + auto &mapFdFuncHost = mapFdFunc->getHostFunc(); // Call "wasm_bpf_map_fd_by_name" to get the map fd, and check the result std::array mapFdResult; @@ -205,8 +202,7 @@ TEST(WasmBpfTest, SimpleRingbuf) { auto *bufferPollFunc = module->findFuncExports("wasm_bpf_buffer_poll"); ASSERT_NE(bufferPollFunc, nullptr); ASSERT_TRUE(bufferPollFunc->isHostFunction()); - auto &bufferPollFuncHost = dynamic_cast( - bufferPollFunc->getHostFunc()); + auto &bufferPollFuncHost = bufferPollFunc->getHostFunc(); // Call the polling function std::array pollResult; @@ -231,8 +227,7 @@ TEST(WasmBpfTest, SimpleRingbuf) { auto *closeFunc = module->findFuncExports("wasm_close_bpf_object"); ASSERT_NE(closeFunc, nullptr); ASSERT_TRUE(closeFunc->isHostFunction()); - auto &closeFuncHost = - dynamic_cast(closeFunc->getHostFunc()); + auto &closeFuncHost = closeFunc->getHostFunc(); // Call "wasm_close_bpf_object" to attach, and check the result std::array closeResult; diff --git a/test/plugins/wasm_bpf/wasm_bpf.cpp b/test/plugins/wasm_bpf/wasm_bpf.cpp index 34f8b116..0f0dcba6 100644 --- a/test/plugins/wasm_bpf/wasm_bpf.cpp +++ b/test/plugins/wasm_bpf/wasm_bpf.cpp @@ -212,10 +212,9 @@ TEST(WasmBpfTest, RunBpfProgramWithPolling) { // Get function "wasm_load_bpf_object" auto *loadFunc = module->findFuncExports("wasm_load_bpf_object"); - EXPECT_NE(loadFunc, nullptr); - EXPECT_TRUE(loadFunc->isHostFunction()); - auto &loadFuncHost = - dynamic_cast(loadFunc->getHostFunc()); + ASSERT_NE(loadFunc, nullptr); + ASSERT_TRUE(loadFunc->isHostFunction()); + auto &loadFuncHost = loadFunc->getHostFunc(); // call "wasm_load_bpf_object" to Load `bootstrap.bpf.o`, and check the // result @@ -231,10 +230,9 @@ TEST(WasmBpfTest, RunBpfProgramWithPolling) { // Get function `wasm_attach_bpf_program` auto *attachFunc = module->findFuncExports("wasm_attach_bpf_program"); - EXPECT_NE(attachFunc, nullptr); - EXPECT_TRUE(attachFunc->isHostFunction()); - auto &attachFuncHost = dynamic_cast( - attachFunc->getHostFunc()); + ASSERT_NE(attachFunc, nullptr); + ASSERT_TRUE(attachFunc->isHostFunction()); + auto &attachFuncHost = attachFunc->getHostFunc(); // Call "wasm_attach_bpf_program" to attach, and check the result std::array attachResult; @@ -265,10 +263,9 @@ TEST(WasmBpfTest, RunBpfProgramWithPolling) { // Get function `wasm_bpf_map_fd_by_name` auto *mapFdFunc = module->findFuncExports("wasm_bpf_map_fd_by_name"); - EXPECT_NE(mapFdFunc, nullptr); - EXPECT_TRUE(mapFdFunc->isHostFunction()); - auto &mapFdFuncHost = - dynamic_cast(mapFdFunc->getHostFunc()); + ASSERT_NE(mapFdFunc, nullptr); + ASSERT_TRUE(mapFdFunc->isHostFunction()); + auto &mapFdFuncHost = mapFdFunc->getHostFunc(); // Call "wasm_bpf_map_fd_by_name" to get the map fd, and check the result std::array mapFdResult; @@ -299,10 +296,9 @@ TEST(WasmBpfTest, RunBpfProgramWithPolling) { // Get the "wasm_bpf_buffer_poll" function auto *bufferPollFunc = module->findFuncExports("wasm_bpf_buffer_poll"); - EXPECT_NE(bufferPollFunc, nullptr); - EXPECT_TRUE(bufferPollFunc->isHostFunction()); - auto &bufferPollFuncHost = dynamic_cast( - bufferPollFunc->getHostFunc()); + ASSERT_NE(bufferPollFunc, nullptr); + ASSERT_TRUE(bufferPollFunc->isHostFunction()); + auto &bufferPollFuncHost = bufferPollFunc->getHostFunc(); // Call the polling function std::array pollResult; @@ -325,10 +321,9 @@ TEST(WasmBpfTest, RunBpfProgramWithPolling) { // Get function `wasm_close_bpf_object` auto *closeFunc = module->findFuncExports("wasm_close_bpf_object"); - EXPECT_NE(closeFunc, nullptr); - EXPECT_TRUE(closeFunc->isHostFunction()); - auto &closeFuncHost = - dynamic_cast(closeFunc->getHostFunc()); + ASSERT_NE(closeFunc, nullptr); + ASSERT_TRUE(closeFunc->isHostFunction()); + auto &closeFuncHost = closeFunc->getHostFunc(); // Call "wasm_close_bpf_object" to attach, and check the result std::array closeResult; @@ -405,10 +400,9 @@ TEST(WasmBpfTest, RunBpfProgramWithMapOperation) { // Get function "wasm_load_bpf_object" auto *loadFunc = module->findFuncExports("wasm_load_bpf_object"); - EXPECT_NE(loadFunc, nullptr); - EXPECT_TRUE(loadFunc->isHostFunction()); - auto &loadFuncHost = - dynamic_cast(loadFunc->getHostFunc()); + ASSERT_NE(loadFunc, nullptr); + ASSERT_TRUE(loadFunc->isHostFunction()); + auto &loadFuncHost = loadFunc->getHostFunc(); // call "wasm_load_bpf_object" to Load `bootstrap.bpf.o`, and check the // result @@ -424,10 +418,9 @@ TEST(WasmBpfTest, RunBpfProgramWithMapOperation) { // Get function `wasm_attach_bpf_program` auto *attachFunc = module->findFuncExports("wasm_attach_bpf_program"); - EXPECT_NE(attachFunc, nullptr); - EXPECT_TRUE(attachFunc->isHostFunction()); - auto &attachFuncHost = dynamic_cast( - attachFunc->getHostFunc()); + ASSERT_NE(attachFunc, nullptr); + ASSERT_TRUE(attachFunc->isHostFunction()); + auto &attachFuncHost = attachFunc->getHostFunc(); std::array programNameIndexes = {1, 2, 3}; // Attach the programs @@ -447,10 +440,9 @@ TEST(WasmBpfTest, RunBpfProgramWithMapOperation) { // Get function `wasm_bpf_map_fd_by_name` auto *mapFdFunc = module->findFuncExports("wasm_bpf_map_fd_by_name"); - EXPECT_NE(mapFdFunc, nullptr); - EXPECT_TRUE(mapFdFunc->isHostFunction()); - auto &mapFdFuncHost = - dynamic_cast(mapFdFunc->getHostFunc()); + ASSERT_NE(mapFdFunc, nullptr); + ASSERT_TRUE(mapFdFunc->isHostFunction()); + auto &mapFdFuncHost = mapFdFunc->getHostFunc(); // Call "wasm_bpf_map_fd_by_name" to get the map fd, and check the result std::array mapFdResult; @@ -462,12 +454,11 @@ TEST(WasmBpfTest, RunBpfProgramWithMapOperation) { auto histsFd = mapFdResult[0].get(); EXPECT_GE(histsFd, 0); - // Get function `wasm_bpf_map_fd_by_name` + // Get function `wasm_bpf_map_operate` auto *mapOptFunc = module->findFuncExports("wasm_bpf_map_operate"); - EXPECT_NE(mapOptFunc, nullptr); - EXPECT_TRUE(mapOptFunc->isHostFunction()); - auto &mapOptFuncHost = - dynamic_cast(mapOptFunc->getHostFunc()); + ASSERT_NE(mapOptFunc, nullptr); + ASSERT_TRUE(mapOptFunc->isHostFunction()); + auto &mapOptFuncHost = mapOptFunc->getHostFunc(); // A wrapper to call wasm_bpf_map_operate auto callMapOperate = [&](int32_t fd, int32_t cmd, uint32_t key, uint32_t value, uint32_t nextKey, @@ -540,13 +531,13 @@ TEST(WasmBpfTest, RunBpfProgramWithMapOperation) { EXPECT_GE(mapLookupElem(histsFd, nextKeyOffset, histOffset), 0); const auto &histRef = readHistRef(histOffset); size_t maxIdx = 0; - for (size_t i = 0; i < std::size(histRef.slots); i++) - if (histRef.slots[i] > 0) - maxIdx = i; - for (size_t i = 0; i < maxIdx; i++) { - auto low = UINT64_C(1) << (i); - auto high = (UINT64_C(1) << (i + 1)) - 1; - fmt::print("{:<6}...{:<6} {:<6}\n"sv, low, high, histRef.slots[i]); + for (size_t j = 0; j < std::size(histRef.slots); j++) + if (histRef.slots[j] > 0) + maxIdx = j; + for (size_t j = 0; j < maxIdx; j++) { + auto low = UINT64_C(1) << (j); + auto high = (UINT64_C(1) << (j + 1)) - 1; + fmt::print("{:<6}...{:<6} {:<6}\n"sv, low, high, histRef.slots[j]); } writeU32(lookUpKeyOffset, readU32(nextKeyOffset)); } @@ -560,10 +551,9 @@ TEST(WasmBpfTest, RunBpfProgramWithMapOperation) { // Get function `wasm_close_bpf_object` auto *closeFunc = module->findFuncExports("wasm_close_bpf_object"); - EXPECT_NE(closeFunc, nullptr); - EXPECT_TRUE(closeFunc->isHostFunction()); - auto &closeFuncHost = - dynamic_cast(closeFunc->getHostFunc()); + ASSERT_NE(closeFunc, nullptr); + ASSERT_TRUE(closeFunc->isHostFunction()); + auto &closeFuncHost = closeFunc->getHostFunc(); // Call "wasm_close_bpf_object" to attach, and check the result std::array closeResult; diff --git a/test/plugins/wasmedge_ffmpeg/avcodec/avCodec.cpp b/test/plugins/wasmedge_ffmpeg/avcodec/avCodec.cpp index 17dc5a49..91fafd42 100644 --- a/test/plugins/wasmedge_ffmpeg/avcodec/avCodec.cpp +++ b/test/plugins/wasmedge_ffmpeg/avcodec/avCodec.cpp @@ -28,12 +28,10 @@ TEST_F(FFmpegTest, AVCodec) { uint32_t AVCodecId = readUInt32(MemInst, AVCodecPtr); auto *FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_id"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecID = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecID = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecId"sv); { @@ -45,12 +43,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecType = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecType = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecType"sv); { @@ -63,12 +59,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_max_lowres"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecMaxLowres = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecMaxLowres = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecMaxLowres"sv); { @@ -80,12 +74,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_capabilities"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCapabilities = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCapabilities &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCapabilities = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecCapabilities"sv); { @@ -98,12 +90,10 @@ TEST_F(FFmpegTest, AVCodec) { int32_t Length = 0; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_get_name_len"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecGetNameLen = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecGetNameLen &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecGetNameLen = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecGetNameLen"sv); { @@ -116,12 +106,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_get_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecGetName = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecGetName = FuncInst->getHostFunc(); // Fill the Memory with 0. fillMemContent(MemInst, StringPtr, Length); @@ -133,16 +121,17 @@ TEST_F(FFmpegTest, AVCodec) { AVCodecId, StringPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StringPtr), + static_cast(Length)), + "h264"sv); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_get_long_name_len"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecGetLongNameLen = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecGetLongNameLen &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecGetLongNameLen = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecGetLongNameLen"sv); { @@ -155,12 +144,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_get_long_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecGetLongName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecGetLongName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecGetLongName = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecGetLongName"sv); { @@ -170,16 +157,17 @@ TEST_F(FFmpegTest, AVCodec) { Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StringPtr), + static_cast(Length)), + "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"sv); } FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_profiles"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecProfiles = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecProfiles = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecProfiles"sv); { @@ -191,12 +179,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_pix_fmts_is_null"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecPixFmtIsNull = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecPixFmtsIsNull &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecPixFmtIsNull = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecPixFmtsIsNull"sv); { @@ -208,12 +194,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_pix_fmts_iter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecPixFmtIter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecPixFmtsIter &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecPixFmtIter = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecPixFmtsIter"sv); { @@ -226,12 +210,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_supported_framerate_is_null"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSupportedFrameratesIsNull = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSupportedFrameratesIsNull - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecSupportedFrameratesIsNull = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSupportedFramratesIsNull"sv); { @@ -243,12 +225,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_supported_framerate_iter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSupportedFrameratesIter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSupportedFrameratesIter - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecSupportedFrameratesIter = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSupportedFrameratesIter"sv); { @@ -262,12 +242,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_supported_samplerates_is_null"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSupportedSampleRatesIsNull = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSupportedSampleRatesIsNull - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecSupportedSampleRatesIsNull = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSupportedSampleRatesIsNull"sv); { @@ -279,12 +257,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_supported_samplerates_iter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSupportedSampleRatesIter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSupportedSampleRatesIter - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecSupportedSampleRatesIter = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSupportedSampleRatesIter"sv); { @@ -296,12 +272,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_channel_layouts_is_null"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecChannelLayoutIsNull = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecChannelLayoutIsNull &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecChannelLayoutIsNull = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecChannelLayoutIsNull"sv); { @@ -313,12 +287,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_channel_layouts_iter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecChannelLayoutIter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecChannelLayoutIter &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecChannelLayoutIter = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecChannelLayoutIter"sv); { @@ -330,12 +302,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_sample_fmts_is_null"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSampleFmtsIsNull = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSampleFmtsIsNull &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecSampleFmtsIsNull = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSampleFmtsIsNull"sv); { @@ -347,12 +317,10 @@ TEST_F(FFmpegTest, AVCodec) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_sample_fmts_iter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSampleFmtsIter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSampleFmtsIter &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecSampleFmtsIter = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSampleFmtsIter"sv); { diff --git a/test/plugins/wasmedge_ffmpeg/avcodec/avCodecCtx.cpp b/test/plugins/wasmedge_ffmpeg/avcodec/avCodecCtx.cpp index 3407f4e7..35f58df1 100644 --- a/test/plugins/wasmedge_ffmpeg/avcodec/avCodecCtx.cpp +++ b/test/plugins/wasmedge_ffmpeg/avcodec/avCodecCtx.cpp @@ -29,12 +29,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { auto *FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_codec_id"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxCodecID = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxCodecID &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxCodecID = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxCodecID.run( @@ -46,12 +44,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { int32_t CodecType = 0; // MediaType Video FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_codec_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetCodecType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetCodecType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetCodecType = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetCodecType.run( @@ -63,12 +59,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_codec_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxCodecType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxCodecType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxCodecType = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxCodecType.run( @@ -81,12 +75,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { int32_t Den = 10; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_time_base"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetTimebase = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetTimebase &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetTimebase = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetTimebase.run( @@ -98,12 +90,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_time_base"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxTimeBase = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxTimeBase &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxTimeBase = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxTimeBase.run( @@ -121,12 +111,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { int32_t Dimension = 200; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_width"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetWidth = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetWidth &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetWidth = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetWidth.run( @@ -138,12 +126,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_width"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxWidth = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxWidth = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxWidth.run( @@ -154,12 +140,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_height"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetHeight = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetHeight &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetHeight = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetHeight.run( @@ -171,12 +155,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_height"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxHeight = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxHeight = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxHeight.run( @@ -189,12 +171,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { Den = 20; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_sample_aspect_ratio"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSampleAspectRatio = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSampleAspectRatio - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSampleAspectRatio = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetSampleAspectRatio.run( @@ -206,12 +186,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_sample_aspect_ratio"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSampleAspectRatio = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSampleAspectRatio &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSampleAspectRatio = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSampleAspectRatio.run( @@ -230,12 +208,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { uint64_t ChannelLayoutId = 1; // FRONT_LEFT; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_channel_layout"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetChannelLayout = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetChannelLayout &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetChannelLayout = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetChannelLayout.run( @@ -248,12 +224,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_channel_layout"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxChannelLayout = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxChannelLayout &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxChannelLayout = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxChannelLayout.run( @@ -266,12 +240,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_pix_fmt"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetPixFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetPixFormat &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetPixFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetPixFormat.run( @@ -283,12 +255,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_pix_fmt"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxPixFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxPixFormat &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxPixFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxPixFormat.run( @@ -300,12 +270,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { uint32_t SampleFmtId = 1; // SAMPLE_FMT_U8 FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_sample_format"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSampleFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSampleFormat &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSampleFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetSampleFormat.run( @@ -317,12 +285,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_sample_format"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSampleFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSampleFormat &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSampleFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSampleFormat.run( @@ -334,12 +300,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { int32_t SampleRate = 500; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_sample_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSampleRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSampleRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSampleRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetSampleRate.run( @@ -351,12 +315,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_sample_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSampleRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSampleRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSampleRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSampleRate.run( @@ -367,12 +329,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_gop_size"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetGopSize = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetGopSize &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetGopSize = FuncInst->getHostFunc(); { int32_t GopSize = 20; @@ -385,12 +345,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_max_b_frames"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMaxBFrames = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMaxBFrames &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMaxBFrames = FuncInst->getHostFunc(); { int32_t MaxBFrames = 30; @@ -403,12 +361,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_b_quant_factor"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetBQuantFactor = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetBQuantFactor &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetBQuantFactor = FuncInst->getHostFunc(); { float BQuantFactor = 12.32; @@ -421,12 +377,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_b_quant_offset"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetBQuantOffset = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetBQuantOffset &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetBQuantOffset = FuncInst->getHostFunc(); { float BQuantOffset = 3.53; @@ -439,12 +393,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_i_quant_factor"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetIQuantFactor = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetIQuantFactor &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetIQuantFactor = FuncInst->getHostFunc(); { float IQuantFactor = 3.435; @@ -457,12 +409,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_i_quant_offset"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetIQuantOffset = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetIQuantOffset &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetIQuantOffset = FuncInst->getHostFunc(); { float IQuantOffset = 6.322; @@ -475,12 +425,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_lumi_masking"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetLumiMasking = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetLumiMasking &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetLumiMasking = FuncInst->getHostFunc(); { float LumiMasking = 54.32432; @@ -493,12 +441,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_temporal_cplx_masking"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetTemporalCplxMasking = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetTemporalCplxMasking - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetTemporalCplxMasking = FuncInst->getHostFunc(); { float TemporialCplxMasking = 642.32; @@ -512,12 +458,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_spatial_cplx_masking"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSpatialCplxMasking = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSpatialCplxMasking - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSpatialCplxMasking = FuncInst->getHostFunc(); { float SpatialCplxMasking = 324.32; @@ -531,12 +475,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_p_masking"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetPMasking = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetPMasking &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetPMasking = FuncInst->getHostFunc(); { float PMasking = 65.3245; @@ -549,12 +491,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_dark_masking"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetDarkMasking = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetDarkMasking &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetDarkMasking = FuncInst->getHostFunc(); { float DarkMasking = 83.32; @@ -567,12 +507,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_me_cmp"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMeCmp = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMeCmp &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMeCmp = FuncInst->getHostFunc(); { int32_t MeCmp = 532; @@ -585,12 +523,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_me_sub_cmp"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMeSubCmp = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMeSubCmp &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMeSubCmp = FuncInst->getHostFunc(); { int32_t MeSubCmp = 321; @@ -603,12 +539,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_mb_cmp"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMbCmp = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMbCmp &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMbCmp = FuncInst->getHostFunc(); { int32_t MbCmp = 243; @@ -621,12 +555,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_ildct_cmp"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetIldctCmp = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetIldctCmp &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetIldctCmp = FuncInst->getHostFunc(); { int32_t IldctCmp = 3; @@ -639,12 +571,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_dia_size"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetDiaSize = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetDiaSize &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetDiaSize = FuncInst->getHostFunc(); { int32_t DiaSize = 9; @@ -657,12 +587,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_last_predictor_count"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetLastPredictorsCount = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetLastPredictorsCount - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetLastPredictorsCount = FuncInst->getHostFunc(); { int32_t LastPredictorCount = 21; @@ -676,12 +604,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_me_pre_cmp"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMePreCmp = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMePreCmp &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMePreCmp = FuncInst->getHostFunc(); { int32_t MePreCmp = 53; @@ -694,12 +620,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_pre_dia_size"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetPreDiaSize = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetPreDiaSize &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetPreDiaSize = FuncInst->getHostFunc(); { int32_t PreDiaSize = 74; @@ -712,12 +636,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_me_subpel_quality"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMeSubpelQuality = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMeSubpelQuality &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMeSubpelQuality = FuncInst->getHostFunc(); { int32_t MeSubpelQuality = 85; @@ -731,12 +653,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_me_range"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMeRange = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMeRange &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMeRange = FuncInst->getHostFunc(); { int32_t SetMeRange = 31; @@ -749,12 +669,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_mb_decision"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMbDecision = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMbDecision &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMbDecision = FuncInst->getHostFunc(); { int32_t MbDecision = 78; @@ -767,12 +685,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_mb_lmin"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMbLMin = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMbLMin &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMbLMin = FuncInst->getHostFunc(); { int32_t MbLMin = 11; @@ -785,12 +701,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_mb_lmax"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetMbLMax = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetMbLMax &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetMbLMax = FuncInst->getHostFunc(); { int32_t MbLMax = 18; @@ -803,13 +717,11 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_intra_dc_precision"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); int32_t IntraDcPrecision = 323; - auto &HostFuncAVCodecCtxSetIntraDcPrecision = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetIntraDcPrecision &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetIntraDcPrecision = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetIntraDcPrecision.run( @@ -822,12 +734,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_intra_dc_precision"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxIntraDcPrecision = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxIntraDcPrecision &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxIntraDcPrecision = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxIntraDcPrecision.run( @@ -838,12 +748,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_qmin"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetQMin = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetQMin &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetQMin = FuncInst->getHostFunc(); { int32_t QMin = 10; @@ -856,12 +764,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_qmax"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetQMax = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetQMax &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetQMax = FuncInst->getHostFunc(); { int32_t QMax = 20; @@ -874,12 +780,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_global_quality"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetGlobalQuality = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetGlobalQuality &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetGlobalQuality = FuncInst->getHostFunc(); { int32_t GlobalQuality = 93; @@ -893,12 +797,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_colorspace"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetColorspace = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetColorspace &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetColorspace = FuncInst->getHostFunc(); int32_t ColorspaceId = 1; // AVCOL_SPC_BT709 { @@ -911,12 +813,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_colorspace"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxColorspace = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxColorspace &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxColorspace = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxColorspace.run( @@ -927,12 +827,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_color_range"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetColorRange = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetColorRange &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetColorRange = FuncInst->getHostFunc(); int32_t ColorRangeId = 1; // MPEG { @@ -945,12 +843,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_color_range"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxColorRange = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxColorRange &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxColorRange = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxColorRange.run( @@ -961,12 +857,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_frame_size"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxFrameSize = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxFrameSize &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxFrameSize = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxFrameSize.run( @@ -977,12 +871,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_bit_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetBitRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetBitRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetBitRate = FuncInst->getHostFunc(); int64_t BitRate = 9932; { @@ -995,12 +887,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_bit_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxBitRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxBitRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxBitRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxBitRate.run( @@ -1011,13 +901,11 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_rc_max_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); int64_t RcMaxRate = 3245; - auto &HostFuncAVCodecCtxSetRcMaxRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetRcMaxRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetRcMaxRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetRcMaxRate.run( @@ -1029,12 +917,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_rc_max_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxRcMaxRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxRcMaxRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxRcMaxRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxRcMaxRate.run( @@ -1045,12 +931,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_bit_rate_tolerance"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetBitRateTolerance = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetBitRateTolerance &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetBitRateTolerance = FuncInst->getHostFunc(); { int32_t BitRateTolerance = 9543; @@ -1064,12 +948,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_compression_level"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetCompressionLevel = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetCompressionLevel &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetCompressionLevel = FuncInst->getHostFunc(); { int32_t CompressionLevel = 934; @@ -1083,14 +965,12 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_framerate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); Num = 20; Den = 30; - auto &HostFuncAVCodecCtxSetFrameRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetFrameRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetFrameRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetFrameRate.run( @@ -1102,12 +982,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_framerate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxFrameRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxFrameRate &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxFrameRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxFrameRate.run( @@ -1124,12 +1002,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_flags"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetFlags = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetFlags &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetFlags = FuncInst->getHostFunc(); { int32_t Flags = 3; @@ -1142,12 +1018,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_strict_std_compliance"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetStrictStdCompliance = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetStrictStdCompliance - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetStrictStdCompliance = FuncInst->getHostFunc(); { int32_t ComplianceId = 3; @@ -1160,12 +1034,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_debug"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetDebug = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetDebug &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetDebug = FuncInst->getHostFunc(); { int32_t Debug = 50; @@ -1178,12 +1050,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_codec"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxCodec = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxCodec = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxCodec.run( @@ -1196,12 +1066,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_channels"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetChannels = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetChannels &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetChannels = FuncInst->getHostFunc(); int32_t Channels = 10; { @@ -1214,12 +1082,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_channels"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxChannels = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxChannels &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxChannels = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxChannels.run( @@ -1230,12 +1096,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_skip_loop_filter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSkipLoopFilter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSkipLoopFilter &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSkipLoopFilter = FuncInst->getHostFunc(); int32_t DiscardId = 16; // Bidirectional { @@ -1248,12 +1112,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_skip_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSkipFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSkipFrame &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSkipFrame = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetSkipFrame.run( @@ -1265,12 +1127,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_skip_idct"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSkipIdct = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSkipIdct &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSkipIdct = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetSkipIdct.run( @@ -1282,12 +1142,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_error_concealment"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetErrorConcealment = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetErrorConcealment &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetErrorConcealment = FuncInst->getHostFunc(); { int32_t ErrorConcealment = 99; @@ -1301,12 +1159,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_err_recognition"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetErrorRecognition = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetErrorRecognition &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetErrorRecognition = FuncInst->getHostFunc(); { int32_t ErrorRecognition = 88; @@ -1320,12 +1176,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_delay"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxDelay = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxDelay = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxDelay.run( @@ -1336,12 +1190,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_skip_top"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSkipTop = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSkipTop &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSkipTop = FuncInst->getHostFunc(); { int32_t Value = 50; @@ -1354,12 +1206,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_skip_bottom"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSkipBottom = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSkipBottom &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSkipBottom = FuncInst->getHostFunc(); { int32_t Value = 60; @@ -1372,12 +1222,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_refs"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxRefs = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxRefs = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxRefs.run( @@ -1388,12 +1236,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_slice_flags"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSliceFlags = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSliceFlags &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSliceFlags = FuncInst->getHostFunc(); { int32_t Value = 70; @@ -1406,12 +1252,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_slice_count"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetSliceCount = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetSliceCount &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetSliceCount = FuncInst->getHostFunc(); { int32_t Value = 100; @@ -1424,12 +1268,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_field_order"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetFieldOrder = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetFieldOrder &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetFieldOrder = FuncInst->getHostFunc(); { int32_t Value = 200; @@ -1442,28 +1284,24 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_color_trc"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxColorTrc = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxColorTrc &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxColorTrc = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxColorTrc.run( CallFrame, std::initializer_list{AVCodecCtxId}, Result)); - ASSERT_TRUE(Result[0].get() > 0); + EXPECT_EQ(Result[0].get(), 2); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_chroma_sample_location"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxChromaSampleLocation = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxChromaSampleLocation - &>(FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxChromaSampleLocation = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxChromaSampleLocation.run( @@ -1474,12 +1312,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_frame_number"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxFrameNumber = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxFrameNumber &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxFrameNumber = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxFrameNumber.run( @@ -1490,12 +1326,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_block_align"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxBlockAlign = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxBlockAlign &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxBlockAlign = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxBlockAlign.run( @@ -1506,12 +1340,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_request_sample_fmt"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetRequestSampleFmt = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetRequestSampleFmt &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetRequestSampleFmt = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxSetRequestSampleFmt.run( @@ -1523,12 +1355,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_audio_service_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxAudioServiceType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxAudioServiceType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxAudioServiceType = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxAudioServiceType.run( @@ -1539,12 +1369,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_has_b_frames"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxHasBFrames = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxHasBFrames &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxHasBFrames = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxHasBFrames.run( @@ -1555,12 +1383,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_active_thread_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxActiveThreadType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxActiveThreadType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxActiveThreadType = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxActiveThreadType.run( @@ -1571,12 +1397,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_thread_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetThreadType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetThreadType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetThreadType = FuncInst->getHostFunc(); { int32_t ThreadType = 1; // Frame @@ -1589,12 +1413,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_set_thread_count"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxSetThreadCount = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxSetThreadCount &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxSetThreadCount = FuncInst->getHostFunc(); int32_t ThreadCount = 50; { @@ -1607,12 +1429,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_thread_count"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxThreadCount = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxThreadCount &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxThreadCount = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxThreadCount.run( @@ -1623,12 +1443,10 @@ TEST_F(FFmpegTest, AVCodecCtx) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_color_primaries"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecCtxColorPrimaries = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxColorPrimaries &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecCtxColorPrimaries = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecCtxColorPrimaries.run( diff --git a/test/plugins/wasmedge_ffmpeg/avcodec/avCodecParameters.cpp b/test/plugins/wasmedge_ffmpeg/avcodec/avCodecParameters.cpp index 2bcfdfd4..3c15bd91 100644 --- a/test/plugins/wasmedge_ffmpeg/avcodec/avCodecParameters.cpp +++ b/test/plugins/wasmedge_ffmpeg/avcodec/avCodecParameters.cpp @@ -27,12 +27,10 @@ TEST_F(FFmpegTest, AVCodecParameters) { auto *FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodecparam_codec_id"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParamCodecId = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParamCodecId &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParamCodecId = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecParamCodecId.run( @@ -43,12 +41,10 @@ TEST_F(FFmpegTest, AVCodecParameters) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodecparam_codec_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParamCodecType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParamCodecType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParamCodecType = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecParamCodecType.run( @@ -59,12 +55,10 @@ TEST_F(FFmpegTest, AVCodecParameters) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodecparam_set_codec_tag"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParamSetCodecTag = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParamSetCodecTag &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParamSetCodecTag = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVCodecParamSetCodecTag.run( diff --git a/test/plugins/wasmedge_ffmpeg/avcodec/avPacket.cpp b/test/plugins/wasmedge_ffmpeg/avcodec/avPacket.cpp index fa163e49..0ef091d1 100644 --- a/test/plugins/wasmedge_ffmpeg/avcodec/avPacket.cpp +++ b/test/plugins/wasmedge_ffmpeg/avcodec/avPacket.cpp @@ -23,12 +23,10 @@ TEST_F(FFmpegTest, AVPacketTest) { auto *FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_alloc"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketAlloc = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVPacketAlloc = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketAlloc.run( @@ -47,14 +45,26 @@ TEST_F(FFmpegTest, AVPacketTest) { ASSERT_TRUE(PacketId > 0); ASSERT_TRUE(PacketId2 > 0); + uint32_t PacketDataSize = 0; + FuncInst = + AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_size"); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSize = FuncInst->getHostFunc(); + auto ExpectPacketSize = [&](uint32_t ExpectedSize) { + EXPECT_TRUE(HostFuncAVPacketSize.run( + CallFrame, std::initializer_list{PacketId}, + Result)); + PacketDataSize = static_cast(Result[0].get()); + EXPECT_EQ(PacketDataSize, ExpectedSize); + }; + FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_new_packet"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVNewPacket = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVNewPacket = FuncInst->getHostFunc(); { uint32_t Size = 40; @@ -62,15 +72,14 @@ TEST_F(FFmpegTest, AVPacketTest) { CallFrame, std::initializer_list{PacketId, Size}, Result)); EXPECT_EQ(Result[0].get(), 0); + ExpectPacketSize(Size); } FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_grow_packet"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVGrowPacket = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGrowPacket = FuncInst->getHostFunc(); { uint32_t Size = 40; @@ -78,15 +87,14 @@ TEST_F(FFmpegTest, AVPacketTest) { CallFrame, std::initializer_list{PacketId, Size}, Result)); EXPECT_EQ(Result[0].get(), 0); + ExpectPacketSize(80); } FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_shrink_packet"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVShrinkPacket = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVShrinkPacket = FuncInst->getHostFunc(); { uint32_t Size = 40; @@ -94,16 +102,15 @@ TEST_F(FFmpegTest, AVPacketTest) { CallFrame, std::initializer_list{PacketId, Size}, Result)); EXPECT_EQ(Result[0].get(), 0); + ExpectPacketSize(Size); } uint32_t StreamIdx = 3; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_set_stream_index"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSetStreamIndex = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketSetStreamIndex &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSetStreamIndex = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketSetStreamIndex.run( @@ -115,11 +122,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_stream_index"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketStreamIndex = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketStreamIndex &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketStreamIndex = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketStreamIndex.run( @@ -128,32 +133,13 @@ TEST_F(FFmpegTest, AVPacketTest) { EXPECT_EQ(Result[0].get(), StreamIdx); } - uint32_t Size = 0; - FuncInst = - AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_size"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSize = - dynamic_cast( - FuncInst->getHostFunc()); - - { - EXPECT_TRUE(HostFuncAVPacketSize.run( - CallFrame, std::initializer_list{PacketId}, - Result)); - Size = Result[0].get(); - EXPECT_TRUE(Size > 0); - } - uint32_t Flags = 5; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_set_flags"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSetFlags = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSetFlags = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketSetFlags.run( @@ -164,11 +150,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_flags"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketFlags = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketFlags = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketFlags.run( @@ -180,11 +164,9 @@ TEST_F(FFmpegTest, AVPacketTest) { int64_t Pos = 500; FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_set_pos"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSetPos = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSetPos = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketSetPos.run( @@ -195,11 +177,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_pos"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketPos = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketPos = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketPos.run( @@ -211,11 +191,9 @@ TEST_F(FFmpegTest, AVPacketTest) { int64_t Duration = 100; FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_set_duration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSetDuration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketSetDuration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSetDuration = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketSetDuration.run( @@ -227,11 +205,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_duration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketDuration = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketDuration = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketDuration.run( @@ -243,11 +219,9 @@ TEST_F(FFmpegTest, AVPacketTest) { int64_t Dts = 1000; FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_set_dts"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSetDts = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSetDts = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketSetDts.run( @@ -258,11 +232,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_dts"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketDts = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketDts = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketDts.run( @@ -274,11 +246,9 @@ TEST_F(FFmpegTest, AVPacketTest) { int64_t Pts = 5000; FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_set_pts"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketSetPts = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketSetPts = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketSetPts.run( @@ -289,11 +259,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_pts"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketPts = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketPts = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketPts.run( @@ -304,11 +272,9 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_is_data_null"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketIsDataNull = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketIsDataNull &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketIsDataNull = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketIsDataNull.run( @@ -319,28 +285,25 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_data"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketData = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketData = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketData.run( CallFrame, - std::initializer_list{PacketId, DataPtr, Size}, + std::initializer_list{PacketId, DataPtr, + PacketDataSize}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); } FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_ref"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketRef = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVPacketRef = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketRef.run( @@ -352,12 +315,10 @@ TEST_F(FFmpegTest, AVPacketTest) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_unref"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketUnref = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVPacketUnref = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVPacketUnref.run( diff --git a/test/plugins/wasmedge_ffmpeg/avcodec/avcodec_func.cpp b/test/plugins/wasmedge_ffmpeg/avcodec/avcodec_func.cpp index f82fb2d6..2403fd80 100644 --- a/test/plugins/wasmedge_ffmpeg/avcodec/avcodec_func.cpp +++ b/test/plugins/wasmedge_ffmpeg/avcodec/avcodec_func.cpp @@ -33,12 +33,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { auto *FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_alloc_context3"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecAllocContext3 = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecAllocContext3 &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecAllocContext3 = FuncInst->getHostFunc(); spdlog::info("Testing AvCodecAllocContext3"sv); { @@ -53,12 +51,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_parameters_alloc"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParametersAlloc = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParametersAlloc &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParametersAlloc = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecParametersAlloc"sv); { @@ -81,12 +77,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_parameters_from_context"sv); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParametersFromContext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParametersFromContext &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParametersFromContext = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecParametersFromContext"sv); { @@ -100,12 +94,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_get_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecGetType = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecGetType = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecGetType"sv); { @@ -116,12 +108,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_find_decoder"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecFindDecoder = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFindDecoder &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecFindDecoder = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecFindDecoder"sv); { @@ -137,12 +127,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_find_encoder"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecFindEncoder = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFindEncoder &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecFindEncoder = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecFindEncoder"sv); { @@ -158,12 +146,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_open2"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecOpen2 = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecOpen2 = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecOpen2"sv); // Invalid argument passed. Return -22 Error code. Means functionality @@ -179,12 +165,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_codec_is_encoder"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecIsEncoder = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecIsEncoder = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecIsEncoder"sv); { @@ -196,12 +180,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_codec_is_decoder"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecIsDecoder = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecIsDecoder = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecIsDecoder"sv); { @@ -213,12 +195,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_find_decoder_by_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecFindDecoderByName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFindDecoderByName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecFindDecoderByName = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecFindDecoderByName"sv); { @@ -229,16 +209,20 @@ TEST_F(FFmpegTest, AVCodecFunc) { CodecNamePtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + + uint32_t DecoderByNameId = readUInt32(MemInst, CodecDecoderPtr); + EXPECT_TRUE(HostFuncAVCodecIsDecoder.run( + CallFrame, std::initializer_list{DecoderByNameId}, + Result)); + EXPECT_EQ(Result[0].get(), 1); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_find_encoder_by_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecFindEncoderByName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFindEncoderByName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecFindEncoderByName = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecFindEncoderByName"sv); { @@ -249,16 +233,20 @@ TEST_F(FFmpegTest, AVCodecFunc) { CodecNamePtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + + uint32_t EncoderByNameId = readUInt32(MemInst, CodecEncoderPtr); + EXPECT_TRUE(HostFuncAVCodecIsEncoder.run( + CallFrame, std::initializer_list{EncoderByNameId}, + Result)); + EXPECT_EQ(Result[0].get(), 1); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_parameters_to_context"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParametersToContext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParametersToContext &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParametersToContext = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecParametersToContext"sv); { @@ -288,28 +276,24 @@ TEST_F(FFmpegTest, AVCodecFunc) { // } FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_version"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecVersion = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecVersion = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecVersion"sv); { EXPECT_TRUE(HostFuncAVCodecVersion.run( CallFrame, std::initializer_list{}, Result)); - EXPECT_TRUE(Result[0].get() > 0); + EXPECT_TRUE((Result[0].get() >> 16) > 0); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_configuration_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecConfigurationLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecConfigurationLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecConfigurationLength = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecConfigurationLength"sv); int32_t Length = 0; @@ -322,12 +306,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_configuration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecConfiguration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecConfiguration &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecConfiguration = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecConfiguration"sv); { @@ -335,16 +317,18 @@ TEST_F(FFmpegTest, AVCodecFunc) { CallFrame, std::initializer_list{StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_NE(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_license_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecLicenseLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecLicenseLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecLicenseLength = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecLicenseLength"sv); { @@ -357,12 +341,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_license"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecLicense = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecLicense = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecLicense"sv); { @@ -370,16 +352,18 @@ TEST_F(FFmpegTest, AVCodecFunc) { CallFrame, std::initializer_list{StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_free_context"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecFreeContext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFreeContext &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecFreeContext = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecFreeContext"sv); { @@ -391,12 +375,10 @@ TEST_F(FFmpegTest, AVCodecFunc) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_parameters_free"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecParametersFree = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParametersFree &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecParametersFree = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecParametersFree"sv); { @@ -421,12 +403,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { auto *FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_send_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSendFrame = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecSendFrame = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSendFrame"sv); // Invalid Argument Error. Should Use Encoder, I'm using decoder @@ -443,12 +423,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { // Aim is to test the functionality. FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_receive_packet"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecReceivePacket = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecReceivePacket &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecReceivePacket = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecReceivePacket"sv); { @@ -461,12 +439,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_send_packet"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecSendPacket = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSendPacket &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecSendPacket = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecSendPacket"sv); // Send packet to Decoder. @@ -480,13 +456,11 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_receive_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); // Decoder Receives the Packet as Frame. - auto &HostFuncAVCodecReceiveFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecReceiveFrame &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecReceiveFrame = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecReceiveFrame"sv); { @@ -499,12 +473,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_rescale_ts"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketRescaleTs = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketRescaleTs &>( - FuncInst->getHostFunc()); + auto &HostFuncAVPacketRescaleTs = FuncInst->getHostFunc(); spdlog::info("Testing AVPacketRescaleTs"sv); { @@ -522,12 +494,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_make_writable"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVPacketMakeWritable = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketMakeWritable &>( - FuncInst->getHostFunc()); + auto &HostFuncAVPacketMakeWritable = FuncInst->getHostFunc(); spdlog::info("Testing AVPacketMakeWritable"sv); { @@ -539,12 +509,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_flush_buffers"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecFlushBuffers = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFlushBuffers &>( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecFlushBuffers = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecFlushBuffers"sv); { @@ -556,12 +524,10 @@ TEST_F(FFmpegTest, SendPacketReceiveFrame) { FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_close"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCodecClose = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVCodecClose = FuncInst->getHostFunc(); spdlog::info("Testing AVCodecClose"sv); { diff --git a/test/plugins/wasmedge_ffmpeg/avfilter/avfilter.cpp b/test/plugins/wasmedge_ffmpeg/avfilter/avfilter.cpp index c96448a2..0878e28a 100644 --- a/test/plugins/wasmedge_ffmpeg/avfilter/avfilter.cpp +++ b/test/plugins/wasmedge_ffmpeg/avfilter/avfilter.cpp @@ -14,6 +14,7 @@ namespace Host { namespace WasmEdgeFFmpeg { TEST_F(FFmpegTest, AVFilterStructs) { + using namespace std::literals::string_view_literals; ASSERT_TRUE(AVFilterMod != nullptr); uint32_t FilterPtr = UINT32_C(8); @@ -31,12 +32,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { auto *FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_get_by_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGetByName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGetByName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGetByName = FuncInst->getHostFunc(); { int32_t Length = InputName.length(); @@ -56,12 +55,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_name_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterNameLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterNameLength = FuncInst->getHostFunc(); int32_t Length = 0; { @@ -74,12 +71,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports("wasmedge_ffmpeg_avfilter_avfilter_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterName = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterName = FuncInst->getHostFunc(); fillMemContent(MemInst, StrPtr, Length); { @@ -88,16 +83,17 @@ TEST_F(FFmpegTest, AVFilterStructs) { std::initializer_list{FilterId, StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)), + "abuffer"sv); } FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_description_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterDescriptionLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterDescriptionLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterDescriptionLength = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterDescriptionLength.run( @@ -110,12 +106,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_description"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterDescription = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterDescription &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterDescription = FuncInst->getHostFunc(); fillMemContent(MemInst, StrPtr, Length); { @@ -124,16 +118,18 @@ TEST_F(FFmpegTest, AVFilterStructs) { std::initializer_list{FilterId, StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)), + "Buffer audio frames, and make them accessible to the " + "filterchain."sv); } FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_nb_inputs"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterNbInputs = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterNbInputs &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterNbInputs = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterNbInputs.run( @@ -144,12 +140,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_nb_outputs"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterNbOutputs = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterNbOutputs &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterNbOutputs = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterNbOutputs.run( @@ -160,12 +154,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports("wasmedge_ffmpeg_avfilter_avfilter_flags"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterFlags = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterFlags = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterFlags.run( @@ -176,30 +168,28 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_get_inputs_filter_pad"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGetInputsFilterPad = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGetInputsFilterPad &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGetInputsFilterPad = FuncInst->getHostFunc(); { + writeUInt32(MemInst, UINT32_C(0), InputFilterPadPtr); EXPECT_TRUE(HostFuncAVFilterGetInputsFilterPad.run( CallFrame, std::initializer_list{FilterId, InputFilterPadPtr}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(readUInt32(MemInst, InputFilterPadPtr), UINT32_C(0)); } FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_get_outputs_filter_pad"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGetOutputsFilterPad = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGetOutputsFilterPad &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGetOutputsFilterPad = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterGetOutputsFilterPad.run( @@ -215,12 +205,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_pad_get_name_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterPadGetNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterPadGetNameLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterPadGetNameLength = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterPadGetNameLength.run( @@ -233,12 +221,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_pad_get_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterPadGetName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterPadGetName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterPadGetName = FuncInst->getHostFunc(); { int32_t Idx = 0; @@ -248,16 +234,17 @@ TEST_F(FFmpegTest, AVFilterStructs) { StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)), + "default"sv); } FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_pad_get_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterPadGetType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterPadGetType &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterPadGetType = FuncInst->getHostFunc(); { int32_t Idx = 0; @@ -270,12 +257,10 @@ TEST_F(FFmpegTest, AVFilterStructs) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_pad_drop"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterPadDrop = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterPadDrop = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterPadDrop.run( diff --git a/test/plugins/wasmedge_ffmpeg/avfilter/avfilter_func.cpp b/test/plugins/wasmedge_ffmpeg/avfilter/avfilter_func.cpp index 1e50b401..41c4e219 100644 --- a/test/plugins/wasmedge_ffmpeg/avfilter/avfilter_func.cpp +++ b/test/plugins/wasmedge_ffmpeg/avfilter/avfilter_func.cpp @@ -60,12 +60,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { auto *FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_alloc"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphAlloc = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphAlloc &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphAlloc = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterGraphAlloc.run( @@ -79,12 +77,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_get_by_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGetByName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGetByName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGetByName = FuncInst->getHostFunc(); { int32_t Length = InputName.length(); @@ -111,12 +107,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_create_filter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphCreateFilter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphCreateFilter &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphCreateFilter = FuncInst->getHostFunc(); { int32_t NameLen = InputFilterName.length(); @@ -143,12 +137,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_inout_alloc"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterInOutAlloc = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterInOutAlloc &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterInOutAlloc = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterInOutAlloc.run( @@ -170,12 +162,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_get_filter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphGetFilter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphGetFilter &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphGetFilter = FuncInst->getHostFunc(); { int32_t Length = OutputFilterName.length(); @@ -207,12 +197,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_inout_set_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterInOutSetName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterInOutSetName &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterInOutSetName = FuncInst->getHostFunc(); { int32_t Length = InputFilterName.length(); @@ -234,12 +222,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_inout_set_filter_ctx"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterInOutSetFilterCtx = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterInOutSetFilterCtx &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterInOutSetFilterCtx = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterInOutSetFilterCtx.run( @@ -259,12 +245,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_inout_set_pad_idx"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterInOutSetPadIdx = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterInOutSetPadIdx &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterInOutSetPadIdx = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterInOutSetPadIdx.run( @@ -280,12 +264,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_inout_set_next"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterInOutSetNext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterInOutSetNext &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterInOutSetNext = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterInOutSetNext.run( @@ -305,12 +287,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_parse_ptr"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphParsePtr = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphParsePtr &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphParsePtr = FuncInst->getHostFunc(); { int32_t Length = SpecStr.length(); @@ -324,12 +304,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_config"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphConfig = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphConfig &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphConfig = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterGraphConfig.run( @@ -340,12 +318,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_dump_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphDumpLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphDumpLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphDumpLength = FuncInst->getHostFunc(); int32_t GraphStrLen = 0; { @@ -358,12 +334,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_dump"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphDump = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphDump &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphDump = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterGraphDump.run( @@ -402,27 +376,23 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports("wasmedge_ffmpeg_avfilter_avfilter_version"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterVersion = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterVersion = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterVersion.run( CallFrame, std::initializer_list{}, Result)); - ASSERT_TRUE(Result[0].get() > 0); + ASSERT_TRUE((Result[0].get() >> 16) > 0); } FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_configuration_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterConfigurationLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterConfigurationLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterConfigurationLength = FuncInst->getHostFunc(); int32_t Length = 0; { @@ -434,28 +404,28 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_configuration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterConfiguration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterConfiguration &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterConfiguration = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterConfiguration.run( CallFrame, std::initializer_list{StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_NE(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_license_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterLicenseLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterLicenseLength &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterLicenseLength = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterLicenseLength.run( @@ -466,18 +436,20 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports("wasmedge_ffmpeg_avfilter_avfilter_license"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterLicense = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterLicense = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterLicense.run( CallFrame, std::initializer_list{StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } // ================================================================== @@ -486,12 +458,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_av_buffersrc_get_nb_failed_requests"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVBufferSrcGetNbFailedRequests = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVBufferSrcGetNbFailedRequests - &>(FuncInst->getHostFunc()); + auto &HostFuncAVBufferSrcGetNbFailedRequests = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVBufferSrcGetNbFailedRequests.run( @@ -502,12 +472,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_av_buffersrc_add_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVBufferSrcAddFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVBufferSrcAddFrame &>( - FuncInst->getHostFunc()); + auto &HostFuncAVBufferSrcAddFrame = FuncInst->getHostFunc(); // Returning Error Code -22 (Invalid Argument), Due to Passing Empty Frame. { @@ -545,12 +513,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { // due to no frames present. FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_av_buffersink_get_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVBufferSinkGetFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVBufferSinkGetFrame &>( - FuncInst->getHostFunc()); + auto &HostFuncAVBufferSinkGetFrame = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVBufferSinkGetFrame.run( @@ -562,12 +528,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_av_buffersink_get_samples"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVBufferSinkGetSamples = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVBufferSinkGetSamples &>( - FuncInst->getHostFunc()); + auto &HostFuncAVBufferSinkGetSamples = FuncInst->getHostFunc(); // Passing Empty frames. Return AVERROR due to no frames presen Return AVERROR // due to no frames present. @@ -582,12 +546,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_av_buffersink_set_frame_size"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAvBufferSinkSetFrameSize = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AvBufferSinkSetFrameSize &>( - FuncInst->getHostFunc()); + auto &HostFuncAvBufferSinkSetFrameSize = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAvBufferSinkSetFrameSize.run( @@ -607,12 +569,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_free_graph_str"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterFreeGraphStr = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterFreeGraphStr &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterFreeGraphStr = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterFreeGraphStr.run( @@ -623,12 +583,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports("wasmedge_ffmpeg_avfilter_avfilter_drop"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterDrop = - dynamic_cast( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterDrop = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterDrop.run( @@ -639,12 +597,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_context_drop"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterContextDrop = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterContextDrop &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterContextDrop = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterContextDrop.run( @@ -661,12 +617,10 @@ TEST_F(FFmpegTest, AVFilterFunc) { FuncInst = AVFilterMod->findFuncExports( "wasmedge_ffmpeg_avfilter_avfilter_graph_free"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFilterGraphFree = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFilter::AVFilterGraphFree &>( - FuncInst->getHostFunc()); + auto &HostFuncAVFilterGraphFree = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFilterGraphFree.run( diff --git a/test/plugins/wasmedge_ffmpeg/avformat/avChapter.cpp b/test/plugins/wasmedge_ffmpeg/avformat/avChapter.cpp index 299d26f9..95f38262 100644 --- a/test/plugins/wasmedge_ffmpeg/avformat/avChapter.cpp +++ b/test/plugins/wasmedge_ffmpeg/avformat/avChapter.cpp @@ -30,11 +30,9 @@ TEST_F(FFmpegTest, AVChapter) { auto *FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avChapter_id"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterId = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterId = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVChapterId.run( @@ -46,11 +44,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avChapter_timebase"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterTimebase = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVChapterTimebase &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterTimebase = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVChapterTimebase.run( @@ -65,11 +61,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avChapter_start"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterStart = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterStart = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVChapterStart.run( @@ -81,11 +75,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avChapter_end"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterEnd = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterEnd = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVChapterEnd.run( @@ -97,11 +89,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avChapter_metadata"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterMetadata = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVChapterMetadata &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterMetadata = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVChapterMetadata.run( @@ -115,11 +105,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avChapter_set_id"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterSetId = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterSetId = FuncInst->getHostFunc(); { int64_t ChapterId = 10000; @@ -140,11 +128,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avChapter_set_timebase"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterSetTimebase = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVChapterSetTimebase &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterSetTimebase = FuncInst->getHostFunc(); { int32_t Num = 3; @@ -169,11 +155,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avChapter_set_start"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterSetStart = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVChapterSetStart &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterSetStart = FuncInst->getHostFunc(); { int64_t StartValue = 1000; @@ -194,11 +178,9 @@ TEST_F(FFmpegTest, AVChapter) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avChapter_set_end"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVChapterSetEnd = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVChapterSetEnd = FuncInst->getHostFunc(); { int64_t EndValue = 99999; diff --git a/test/plugins/wasmedge_ffmpeg/avformat/avInputOutputContext.cpp b/test/plugins/wasmedge_ffmpeg/avformat/avInputOutputContext.cpp index 99a1fcbe..0345bce0 100644 --- a/test/plugins/wasmedge_ffmpeg/avformat/avInputOutputContext.cpp +++ b/test/plugins/wasmedge_ffmpeg/avformat/avInputOutputContext.cpp @@ -14,6 +14,7 @@ namespace Host { namespace WasmEdgeFFmpeg { TEST_F(FFmpegTest, AVInputFormat) { + using namespace std::literals::string_view_literals; std::string FileName = "ffmpeg-assets/sample_video.mp4"; // 32 chars uint32_t FormatCtxPtr = UINT32_C(24); uint32_t InputFormatPtr = UINT32_C(28); @@ -30,11 +31,9 @@ TEST_F(FFmpegTest, AVInputFormat) { auto *FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_iformat"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxIFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxIFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxIFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxIFormat.run( @@ -53,11 +52,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avIOFormat_name_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOFormatNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVIOFormatNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOFormatNameLength = FuncInst->getHostFunc(); int32_t Length = 0; { @@ -70,11 +67,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avInputFormat_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVInputFormatName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVInputFormatName &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVInputFormatName = FuncInst->getHostFunc(); fillMemContent(MemInst, StrBuf, Length); { @@ -84,15 +79,16 @@ TEST_F(FFmpegTest, AVInputFormat) { Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrBuf), + static_cast(Length)), + "mov,mp4,m4a,3gp,3g2,mj2"sv); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avIOFormat_long_name_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOFormatLongNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVIOFormatLongNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOFormatLongNameLength = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVIOFormatLongNameLength.run( @@ -105,11 +101,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avInputFormat_long_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVInputFormatLongName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVInputFormatLongName &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVInputFormatLongName = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVInputFormatLongName.run( @@ -119,15 +113,16 @@ TEST_F(FFmpegTest, AVInputFormat) { Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrBuf), + static_cast(Length)), + "QuickTime / MOV"sv); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avIOFormat_extensions_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOFormatExtensionsLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVIOFormatExtensionsLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOFormatExtensionsLength = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVIOFormatExtensionsLength.run( @@ -140,11 +135,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avInputFormat_extensions"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVInputFormatExtensions = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVInputFormatExtensions &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVInputFormatExtensions = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVInputFormatExtensions.run( @@ -157,11 +150,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avIOFormat_mime_type_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOFormatMimeTypeLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVIOFormatMimeTypeLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOFormatMimeTypeLength = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVIOFormatMimeTypeLength.run( @@ -174,11 +165,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avInputFormat_mime_type"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVInputFormatMimeType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVInputFormatMimeType &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVInputFormatMimeType = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVInputFormatMimeType.run( @@ -191,11 +180,9 @@ TEST_F(FFmpegTest, AVInputFormat) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avInputOutputFormat_free"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVInputOutputFormatFree = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVInputOutputFormatFree &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVInputOutputFormatFree = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVInputOutputFormatFree.run( diff --git a/test/plugins/wasmedge_ffmpeg/avformat/avStream.cpp b/test/plugins/wasmedge_ffmpeg/avformat/avStream.cpp index 0cc0655b..099ebd61 100644 --- a/test/plugins/wasmedge_ffmpeg/avformat/avStream.cpp +++ b/test/plugins/wasmedge_ffmpeg/avformat/avStream.cpp @@ -31,11 +31,9 @@ TEST_F(FFmpegTest, AVStreamStruct) { auto *FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avStream_id"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamId = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamId = FuncInst->getHostFunc(); uint32_t AvFormatCtxId = readUInt32(MemInst, FormatCtxPtr); { @@ -48,11 +46,9 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avStream_index"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamIndex = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamIndex = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamIndex.run( @@ -64,11 +60,9 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_codecpar"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamCodecPar = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamCodecPar &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamCodecPar = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamCodecPar.run( @@ -82,19 +76,15 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_timebase"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamTimebase = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamTimebase &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamTimebase = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_set_timebase"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamSetTimebase = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamSetTimebase &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamSetTimebase = FuncInst->getHostFunc(); { int32_t Num = 3; @@ -118,83 +108,71 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_duration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamDuration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamDuration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamDuration = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamDuration.run( CallFrame, std::initializer_list{FormatCtxId, StreamIdx}, Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), INT64_C(30720)); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_start_time"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamStartTime = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamStartTime &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamStartTime = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamStartTime.run( CallFrame, std::initializer_list{FormatCtxId, StreamIdx}, Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), INT64_C(0)); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_nb_frames"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamNbFrames = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamNbFrames &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamNbFrames = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamNbFrames.run( CallFrame, std::initializer_list{FormatCtxId, StreamIdx}, Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), INT64_C(120)); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_disposition"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamDisposition = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamDisposition &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamDisposition = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamDisposition.run( CallFrame, std::initializer_list{FormatCtxId, StreamIdx}, Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), 1); // AV_DISPOSITION_DEFAULT } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_set_r_frame_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamSetRFrameRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamSetRFrameRate &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamSetRFrameRate = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_r_frame_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamRFrameRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamRFrameRate &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamRFrameRate = FuncInst->getHostFunc(); { int32_t Num = 3; @@ -218,19 +196,15 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_set_avg_frame_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamSetAvgFrameRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamSetAvgFrameRate &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamSetAvgFrameRate = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_avg_frame_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamAvgFrameRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamAvgFrameRate &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamAvgFrameRate = FuncInst->getHostFunc(); { int32_t Num = 3; @@ -255,19 +229,15 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_metadata"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamMetadata = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamMetadata &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamMetadata = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_set_metadata"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamSetMetadata = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamSetMetadata &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamSetMetadata = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamMetadata.run( CallFrame, @@ -287,11 +257,9 @@ TEST_F(FFmpegTest, AVStreamStruct) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avStream_discard"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVStreamDiscard = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamDiscard = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVStreamDiscard.run( CallFrame, diff --git a/test/plugins/wasmedge_ffmpeg/avformat/avformatContext.cpp b/test/plugins/wasmedge_ffmpeg/avformat/avformatContext.cpp index 3d23d403..23c6fcf0 100644 --- a/test/plugins/wasmedge_ffmpeg/avformat/avformatContext.cpp +++ b/test/plugins/wasmedge_ffmpeg/avformat/avformatContext.cpp @@ -26,11 +26,9 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { auto *FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_iformat"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxIFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxIFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxIFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxIFormat.run( @@ -44,11 +42,9 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_oformat"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxOFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxOFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxOFormat = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxOFormat.run( @@ -62,11 +58,9 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_probescope"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxProbeScore = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxProbeScore &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxProbeScore = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxProbeScore.run( @@ -77,11 +71,9 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_nb_streams"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxNbStreams = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxNbStreams &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxNbStreams = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxNbStreams.run( @@ -92,26 +84,22 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_duration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxDuration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxDuration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxDuration = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxDuration.run( CallFrame, std::initializer_list{FormatCtxId}, Result)); - EXPECT_TRUE(Result[0].get() >= 0 || Result[0].get() < 0); + EXPECT_EQ(Result[0].get(), AV_NOPTS_VALUE); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_bit_rate"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxBitRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxBitRate &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxBitRate = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxBitRate.run( @@ -122,19 +110,15 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_set_nb_chapters"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxSetNbChapters = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxSetNbChapters &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxSetNbChapters = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_nb_chapters"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxNbChapters = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxNbChapters &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxNbChapters = FuncInst->getHostFunc(); { uint32_t NbChapters = 200; EXPECT_TRUE(HostFuncAVFormatCtxSetNbChapters.run( @@ -151,19 +135,15 @@ TEST_F(FFmpegTest, AVFormatContextStruct) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_metadata"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxMetadata = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxMetadata &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxMetadata = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformatContext_set_metadata"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCtxSetMetadata = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCtxSetMetadata &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCtxSetMetadata = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncAVFormatCtxMetadata.run( diff --git a/test/plugins/wasmedge_ffmpeg/avformat/avformat_func.cpp b/test/plugins/wasmedge_ffmpeg/avformat/avformat_func.cpp index 809a25d9..dc9ad3a7 100644 --- a/test/plugins/wasmedge_ffmpeg/avformat/avformat_func.cpp +++ b/test/plugins/wasmedge_ffmpeg/avformat/avformat_func.cpp @@ -31,11 +31,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { auto *FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_open_input"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatOpenInput = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatOpenInput &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatOpenInput = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatOpenInput"sv); { @@ -62,11 +60,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_find_stream_info"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatFindStreamInfo = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatFindStreamInfo &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatFindStreamInfo = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatFindStreamInfo"sv); { @@ -79,11 +75,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_av_dump_format"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatAVDumpFormat = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatAVDumpFormat = FuncInst->getHostFunc(); spdlog::info("Testing AVDumpFormat"sv); { @@ -97,11 +91,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_av_find_best_stream"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFindBestStream = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFindBestStream &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFindBestStream = FuncInst->getHostFunc(); spdlog::info("Testing AVFindBestStream"sv); { @@ -115,11 +107,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_av_read_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVReadFrame = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVReadFrame = FuncInst->getHostFunc(); spdlog::info("Testing AVReadFrame"sv); { @@ -135,11 +125,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_network_init"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatNetworkInit = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatNetworkInit &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatNetworkInit = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatNetworkInit"sv); { @@ -151,11 +139,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_seek_file"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatSeekFile = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatSeekFile &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatSeekFile = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatSeekFile"sv); { @@ -176,11 +162,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_av_read_play"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatAVReadPlay = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatAVReadPlay = FuncInst->getHostFunc(); spdlog::info("Testing AVReadPlay"sv); { @@ -193,11 +177,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_av_read_pause"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatAVReadPause = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatAVReadPause = FuncInst->getHostFunc(); spdlog::info("Testing AVReadPause"sv); { @@ -210,11 +192,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_network_deinit"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatNetworkDeInit = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatNetworkDeInit &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatNetworkDeInit = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatNetworkDeInit"sv); { @@ -226,11 +206,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_close_input"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatCloseInput = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatCloseInput &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatCloseInput = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatCloseInput"sv); { @@ -242,11 +220,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_free_context"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFreeContext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatFreeContext &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFreeContext = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatFreeContext"sv); { @@ -258,27 +234,23 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avformat_version"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatVersion = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatVersion = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatVersion"sv); { EXPECT_TRUE(HostFuncAVFormatVersion.run( CallFrame, std::initializer_list{}, Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_TRUE((Result[0].get() >> 16) > 0); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_configuration_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatConfigurationLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatConfigurationLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatConfigurationLength = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatConfigurationLength"sv); int32_t Length = 0; @@ -291,11 +263,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_configuration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatConfiguration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatConfiguration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatConfiguration = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatConfiguration"sv); { @@ -304,15 +274,17 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { Result)); EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_NE(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_license_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatLicenseLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatLicenseLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatLicenseLength = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatLicenseLength"sv); { @@ -325,11 +297,9 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avformat_license"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatLicense = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatLicense = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatLicense"sv); { @@ -338,6 +308,10 @@ TEST_F(FFmpegTest, AVInputFormatFunc) { Result)); EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } } @@ -366,11 +340,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { auto *FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_alloc_output_context2"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatAllocOutputContext2 = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatAllocOutputContext2 &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatAllocOutputContext2 = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatAllocOutputContext2"sv); { @@ -398,11 +370,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { } FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avio_open"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOOpen = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOOpen = FuncInst->getHostFunc(); spdlog::info("Testing AVIOOpen"sv); { @@ -417,11 +387,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avio_open2"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOOpen2 = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOOpen2 = FuncInst->getHostFunc(); spdlog::info("Testing AVIOOpen2"sv); { @@ -455,11 +423,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_write_header"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatWriteHeader = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatWriteHeader &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatWriteHeader = FuncInst->getHostFunc(); spdlog::info("Testing AVFormatWriteHeader"sv); { @@ -494,11 +460,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avchapter_mallocz"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVIOClose = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVChapterMallocz &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVIOClose = FuncInst->getHostFunc(); spdlog::info("Testing AVChapterMallocz"sv); { @@ -532,11 +496,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_avformat_avfreep"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVFormatAVFreep = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatAVFreep = FuncInst->getHostFunc(); spdlog::info("Testing AVFreeP"sv); { @@ -549,11 +511,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_av_write_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVWriteFrame = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVWriteFrame = FuncInst->getHostFunc(); spdlog::info("Testing AVWriteFrame"sv); // Passing Empty Frame, Hence giving Invalid Argument Error. @@ -568,11 +528,9 @@ TEST_F(FFmpegTest, AVOutputFormatFunc) { FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_av_interleaved_write_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVInterleavedWriteFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVInterleavedWriteFrame &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVInterleavedWriteFrame = FuncInst->getHostFunc(); spdlog::info("Testing AVInterleavedWriteFrame"sv); // Passing Empty Frame, Hence giving Invalid Argument Error. diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avDictionary.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avDictionary.cpp index 779fb236..823e5a9b 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avDictionary.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avDictionary.cpp @@ -28,11 +28,9 @@ TEST_F(FFmpegTest, AVDictionary) { auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_dict_set"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVDictSet = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDictSet = FuncInst->getHostFunc(); // Fill 0 in WasmMemory. fillMemContent(MemInst, KeyStart, KeyLen + ValueLen); @@ -52,11 +50,9 @@ TEST_F(FFmpegTest, AVDictionary) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_dict_copy"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVDictCopy = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDictCopy = FuncInst->getHostFunc(); { uint32_t DestDictPtr = UINT32_C(80); @@ -70,11 +66,9 @@ TEST_F(FFmpegTest, AVDictionary) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_dict_get"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVDictGet = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDictGet = FuncInst->getHostFunc(); { // Store the string lengths of Key and value in the pointers below. @@ -104,11 +98,9 @@ TEST_F(FFmpegTest, AVDictionary) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_dict_get_key_value"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVDictGetKeyValue = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDictGetKeyValue = FuncInst->getHostFunc(); { // Store the strings of Key and value in the buffer pointers below. @@ -122,7 +114,12 @@ TEST_F(FFmpegTest, AVDictionary) { UINT32_C(3), PrevDictEntryIdx, Flags}, Result)); EXPECT_EQ(Result[0].get(), 1); - // Verify String. Read String from MemInst + EXPECT_EQ(std::string_view(MemInst->getPointer(KeyBufPtr), + static_cast(KeyLen)), + "KEY"sv); + EXPECT_EQ(std::string_view(MemInst->getPointer(ValueBufPtr), + static_cast(ValueLen)), + "VALUE"sv); // Pass a Null Dict and testing. EXPECT_TRUE(HostFuncAVDictGetKeyValue.run( @@ -136,11 +133,9 @@ TEST_F(FFmpegTest, AVDictionary) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_dict_free"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVDictFree = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDictFree = FuncInst->getHostFunc(); { uint32_t DictId = readUInt32(MemInst, DictPtr); diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avError.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avError.cpp index 8584c97b..d191a323 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avError.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avError.cpp @@ -24,21 +24,22 @@ TEST_F(FFmpegTest, AVError) { auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_strerror"); - auto &HostFuncAVUtilAVStrError = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilAVStrError = FuncInst->getHostFunc(); { - HostFuncAVUtilAVStrError.run( - CallFrame, std::initializer_list{}, Result); - - EXPECT_EQ(Result[0].get(), 0); + EXPECT_TRUE(HostFuncAVUtilAVStrError.run( + CallFrame, + std::initializer_list{ErrNum, ErrStartPtr, + ErrSize}, + Result)); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_AVERROR"); - auto &HostFuncAVUtilAVError = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilAVError = FuncInst->getHostFunc(); { HostFuncAVUtilAVError.run( @@ -49,9 +50,9 @@ TEST_F(FFmpegTest, AVError) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_AVUNERROR"); - auto &HostFuncAVUtilAVUNError = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilAVUNError = FuncInst->getHostFunc(); { HostFuncAVUtilAVUNError.run( diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avFrame.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avFrame.cpp index dd20f625..eb7ed6cb 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avFrame.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avFrame.cpp @@ -32,25 +32,26 @@ TEST_F(FFmpegTest, AVFrame) { auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_alloc"); - auto &HostFuncAVFrameAlloc = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameAlloc = FuncInst->getHostFunc(); - uint32_t EmptyFramePtr = UINT32_C(64); + uint32_t EmptyFramePtr = UINT32_C(88); { - HostFuncAVFrameAlloc.run( + writeUInt32(MemInst, UINT32_C(0), EmptyFramePtr); + EXPECT_TRUE(HostFuncAVFrameAlloc.run( CallFrame, std::initializer_list{EmptyFramePtr}, - Result); + Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); EXPECT_TRUE(readUInt32(MemInst, EmptyFramePtr) > 0); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_free"); - auto &HostFuncAVFrameFree = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameFree = FuncInst->getHostFunc(); { uint32_t EmptyFrameId = readUInt32(MemInst, EmptyFramePtr); @@ -63,9 +64,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_width"); - auto &HostFuncAVFrameWidth = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameWidth = FuncInst->getHostFunc(); { HostFuncAVFrameWidth.run( @@ -77,9 +78,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_height"); - auto &HostFuncAVFrameHeight = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameHeight = FuncInst->getHostFunc(); { HostFuncAVFrameHeight.run( @@ -91,9 +92,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_video_format"); - auto &HostFuncAVFrameVideoFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameVideoFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameVideoFormat = FuncInst->getHostFunc(); { HostFuncAVFrameVideoFormat.run( @@ -105,9 +106,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_isnull"); - auto &HostFuncAVFrameIsNull = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameIsNull = FuncInst->getHostFunc(); { HostFuncAVFrameIsNull.run( @@ -119,9 +120,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_linesize"); - auto &HostFuncAVFrameLinesize = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameLinesize = FuncInst->getHostFunc(); int32_t Stride = 0; uint32_t Idx = 0; @@ -136,9 +137,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_get_buffer"); - auto &HostFuncAVFrameGetBuffer = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameGetBuffer = FuncInst->getHostFunc(); { // For video, it is 32. int32_t Align = 32; @@ -151,9 +152,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_best_effort_timestamp"); - auto &HostFuncAVFrameBestEffortTimestamp = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameBestEffortTimestamp &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameBestEffortTimestamp = FuncInst->getHostFunc(); { HostFuncAVFrameBestEffortTimestamp.run( @@ -164,9 +165,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_pict_type"); - auto &HostFuncAVFramePictType = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFramePictType = FuncInst->getHostFunc(); { HostFuncAVFramePictType.run( @@ -177,9 +178,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_interlaced_frame"); - auto &HostFuncAVFrameInterlacedFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameInterlacedFrame &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameInterlacedFrame = FuncInst->getHostFunc(); { HostFuncAVFrameInterlacedFrame.run( @@ -190,9 +191,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_top_field_first"); - auto &HostFuncAVFrameTopFieldFirst = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameTopFieldFirst &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameTopFieldFirst = FuncInst->getHostFunc(); { HostFuncAVFrameTopFieldFirst.run( @@ -203,9 +204,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_palette_has_changed"); - auto &HostFuncAVFramePaletteHasChanged = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFramePaletteHasChanged &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFramePaletteHasChanged = FuncInst->getHostFunc(); { HostFuncAVFramePaletteHasChanged.run( @@ -216,9 +217,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_colorspace"); - auto &HostFuncAVFrameColorspace = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameColorspace = FuncInst->getHostFunc(); { HostFuncAVFrameColorspace.run( @@ -229,9 +230,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_color_range"); - auto &HostFuncAVFrameColorRange = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameColorRange = FuncInst->getHostFunc(); { HostFuncAVFrameColorRange.run( @@ -242,9 +243,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_color_trc"); - auto &HostAVFrameColorTransferCharacteristic = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameColorTransferCharacteristic - &>(FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameColorTransferCharacteristic = FuncInst->getHostFunc(); { HostAVFrameColorTransferCharacteristic.run( @@ -255,9 +256,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_chroma_location"); - auto &HostAVFrameChromaLocation = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameChromaLocation &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameChromaLocation = FuncInst->getHostFunc(); { HostAVFrameChromaLocation.run( @@ -268,9 +269,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_repeat_pict"); - auto &HostAVFrameRepeatPict = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameRepeatPict = FuncInst->getHostFunc(); { HostAVFrameRepeatPict.run( @@ -281,9 +282,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_flags"); - auto &HostAVFrameFlags = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameFlags = FuncInst->getHostFunc(); { HostAVFrameFlags.run(CallFrame, @@ -294,9 +295,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_quality"); - auto &HostAVFrameQuality = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameQuality = FuncInst->getHostFunc(); { HostAVFrameQuality.run( @@ -307,9 +308,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_metadata"); - auto &HostAVFrameMetadata = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameMetadata = FuncInst->getHostFunc(); { HostAVFrameMetadata.run( @@ -323,9 +324,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_metadata"); - auto &HostAVFrameSetMetadata = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetMetadata &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameSetMetadata = FuncInst->getHostFunc(); { HostAVFrameSetMetadata.run( @@ -336,9 +337,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_key_frame"); - auto &HostAVFrameKeyFrame = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameKeyFrame = FuncInst->getHostFunc(); { HostAVFrameKeyFrame.run( @@ -348,9 +349,9 @@ TEST_F(FFmpegTest, AVFrame) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_pts"); - auto &HostAVFramePts = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFramePts = FuncInst->getHostFunc(); { HostAVFramePts.run(CallFrame, @@ -360,9 +361,9 @@ TEST_F(FFmpegTest, AVFrame) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_copy"); - auto &HostAVFrameCopy = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameCopy = FuncInst->getHostFunc(); { HostAVFrameCopy.run( @@ -374,9 +375,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_copy_props"); - auto &HostAVFrameCopyProps = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostAVFrameCopyProps = FuncInst->getHostFunc(); { HostAVFrameCopyProps.run( @@ -388,9 +389,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_set_width"); - auto &HostFuncAVFrameSetWidth = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetWidth = FuncInst->getHostFunc(); { int32_t Width = 100; @@ -407,9 +408,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_set_height"); - auto &HostFuncAVFrameSetHeight = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetHeight = FuncInst->getHostFunc(); int32_t Height = 100; { @@ -425,9 +426,9 @@ TEST_F(FFmpegTest, AVFrame) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_data"); - auto &HostFuncAVFrameData = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameData = FuncInst->getHostFunc(); { int32_t Size = 1; // Just reading One byte data for test. @@ -441,9 +442,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_video_format"); - auto &HostFuncAVFrameSetVideoFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetVideoFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetVideoFormat = FuncInst->getHostFunc(); { uint32_t PixFormatId = 10; // GRAY8 @@ -461,9 +462,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_pict_type"); - auto &HostFuncAVFrameSetPictType = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetPictType &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetPictType = FuncInst->getHostFunc(); { int32_t PictureId = 4; // AV_PICTURE_TYPE_S @@ -481,9 +482,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_colorspace"); - auto &HostFuncAVFrameSetColorSpace = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetColorSpace &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetColorSpace = FuncInst->getHostFunc(); { int32_t ColorSpaceId = 4; // FCC @@ -501,9 +502,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_color_range"); - auto &HostFuncAVFrameSetColorRange = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetColorRange &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetColorRange = FuncInst->getHostFunc(); { int32_t ColorRangeId = 1; // MPEG @@ -521,10 +522,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_color_trc"); - auto &HostFuncAVFrameSetColorTransferCharacteristic = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetColorTransferCharacteristic = FuncInst->getHostFunc(); { int32_t ColorTrcId = 5; // GAMMA28 @@ -542,9 +542,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_set_pts"); - auto &HostFuncAVFrameSetPts = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetPts = FuncInst->getHostFunc(); { int64_t Pts = 10; @@ -561,9 +561,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_sample_aspect_ratio"); - auto &HostFuncAVFrameSampleAspectRatio = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSampleAspectRatio &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSampleAspectRatio = FuncInst->getHostFunc(); { HostFuncAVFrameSampleAspectRatio.run( @@ -576,9 +576,9 @@ TEST_F(FFmpegTest, AVFrame) { int32_t ColorPrimariesId = 1; // BT709 FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_color_primaries"); - auto &HostFuncAVFrameSetColorPrimaries = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetColorPrimaries &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetColorPrimaries = FuncInst->getHostFunc(); { HostFuncAVFrameSetColorPrimaries.run( @@ -591,9 +591,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_color_primaries"); - auto &HostFuncAVFrameColorPrimaries = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameColorPrimaries &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameColorPrimaries = FuncInst->getHostFunc(); { HostFuncAVFrameColorPrimaries.run( @@ -610,9 +610,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_audio_format"); - auto &HostFuncAVFrameSetAudioFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetAudioFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetAudioFormat = FuncInst->getHostFunc(); uint32_t SampleFormatId = 4; { @@ -625,9 +625,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_audio_format"); - auto &HostFuncAVFrameAudioFormat = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameAudioFormat &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameAudioFormat = FuncInst->getHostFunc(); { HostFuncAVFrameAudioFormat.run( @@ -638,9 +638,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_nb_samples"); - auto &HostFuncAVFrameSetNbSamples = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetNbSamples &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetNbSamples = FuncInst->getHostFunc(); int32_t NbSamples = 32; { @@ -653,9 +653,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_nb_samples"); - auto &HostFuncAVFrameNbSamples = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameNbSamples = FuncInst->getHostFunc(); { HostFuncAVFrameNbSamples.run( @@ -666,9 +666,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_sample_rate"); - auto &HostFuncAVFrameSetSampleRate = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetSampleRate &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetSampleRate = FuncInst->getHostFunc(); int32_t SampleRate = 10; { @@ -681,9 +681,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_sample_rate"); - auto &HostFuncAVFrameSampleRate = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSampleRate = FuncInst->getHostFunc(); { HostFuncAVFrameSampleRate.run( @@ -694,9 +694,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_channels"); - auto &HostFuncAVFrameSetChannels = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetChannels &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetChannels = FuncInst->getHostFunc(); int32_t Channels = 3; { @@ -709,9 +709,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_channels"); - auto &HostFuncAVFrameChannels = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameChannels = FuncInst->getHostFunc(); { HostFuncAVFrameChannels.run( @@ -722,9 +722,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_set_channel_layout"); - auto &HostFuncAVFrameSetChannelLayout = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameSetChannelLayout &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameSetChannelLayout = FuncInst->getHostFunc(); uint64_t ChannelLayout = 1UL << 10; { @@ -737,9 +737,9 @@ TEST_F(FFmpegTest, AVFrame) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_frame_channel_layout"); - auto &HostFuncAVFrameChannelLayout = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVFrameChannelLayout &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameChannelLayout = FuncInst->getHostFunc(); { HostFuncAVFrameChannelLayout.run( diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avPixfmt.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avPixfmt.cpp index 625acd10..2d29295c 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avPixfmt.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avPixfmt.cpp @@ -13,13 +13,14 @@ namespace Host { namespace WasmEdgeFFmpeg { TEST_F(FFmpegTest, AVPixFmt) { + using namespace std::literals::string_view_literals; uint32_t NamePtr = UINT32_C(4); auto *FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_avpixfmtdescriptor_nb_components"); - auto &HostFuncAVPixFmtDescriptorNbComponents = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AvPixFmtDescriptorNbComponents &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPixFmtDescriptorNbComponents = FuncInst->getHostFunc(); uint32_t PixFmtId = 3; // RGB24 @@ -33,38 +34,41 @@ TEST_F(FFmpegTest, AVPixFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_avpixfmtdescriptor_log2_chromaw"); - auto &HostFuncAvPixFmtDescriptorLog2ChromaW = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AvPixFmtDescriptorLog2ChromaW &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAvPixFmtDescriptorLog2ChromaW = FuncInst->getHostFunc(); + + uint32_t Yuv422PId = 5; // YUV422P: chroma subsampled on width only { - HostFuncAvPixFmtDescriptorLog2ChromaW.run( - CallFrame, std::initializer_list{1}, Result); + EXPECT_TRUE(HostFuncAvPixFmtDescriptorLog2ChromaW.run( + CallFrame, std::initializer_list{Yuv422PId}, + Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), 1); } FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_avpixfmtdescriptor_log2_chromah"); - auto &HostFuncAvPixFmtDescriptorLog2ChromaH = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AvPixFmtDescriptorLog2ChromaH &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAvPixFmtDescriptorLog2ChromaH = FuncInst->getHostFunc(); { - HostFuncAvPixFmtDescriptorLog2ChromaH.run( - CallFrame, std::initializer_list{PixFmtId}, - Result); + EXPECT_TRUE(HostFuncAvPixFmtDescriptorLog2ChromaH.run( + CallFrame, std::initializer_list{Yuv422PId}, + Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), 0); } int32_t Length = 0; int32_t TransferCharacteristicId = 6; // (SMPTE170M) FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_color_transfer_name_length"); - auto &HostFuncAVColorTransferNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVColorTransferNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorTransferNameLength = FuncInst->getHostFunc(); { HostFuncAVColorTransferNameLength.run( @@ -79,9 +83,9 @@ TEST_F(FFmpegTest, AVPixFmt) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_color_transfer_name"); - auto &HostFuncAVColorTransferName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVColorTransferName &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorTransferName = FuncInst->getHostFunc(); { HostFuncAVColorTransferName.run( @@ -91,14 +95,17 @@ TEST_F(FFmpegTest, AVPixFmt) { Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)), + "smpte170m"sv); } int32_t ColorRangeId = 2; //; JPEG FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_color_range_name_length"); - auto &HostFuncAVColorRangeNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVColorRangeNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorRangeNameLength = FuncInst->getHostFunc(); { HostFuncAVColorRangeNameLength.run( @@ -113,9 +120,9 @@ TEST_F(FFmpegTest, AVPixFmt) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_color_range_name"); - auto &HostFuncAVColorRangeName = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorRangeName = FuncInst->getHostFunc(); { HostFuncAVColorRangeName.run(CallFrame, @@ -124,14 +131,17 @@ TEST_F(FFmpegTest, AVPixFmt) { Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)), + std::string_view("pc"sv)); } int32_t ColorSpaceId = 1; // BT709 FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_color_space_name_length"); - auto &HostFuncAVColorSpaceNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVColorSpaceNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorSpaceNameLength = FuncInst->getHostFunc(); { HostFuncAVColorSpaceNameLength.run( @@ -146,9 +156,9 @@ TEST_F(FFmpegTest, AVPixFmt) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_color_space_name"); - auto &HostFuncAVColorSpaceName = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorSpaceName = FuncInst->getHostFunc(); { HostFuncAVColorSpaceName.run(CallFrame, @@ -157,14 +167,17 @@ TEST_F(FFmpegTest, AVPixFmt) { Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)), + "bt709"sv); } int32_t ColorPrimariesId = 1; // BT709 FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_color_primaries_name_length"); - auto &HostFuncAVColorPrimariesNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVColorPrimariesNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorPrimariesNameLength = FuncInst->getHostFunc(); { HostFuncAVColorPrimariesNameLength.run( @@ -179,9 +192,9 @@ TEST_F(FFmpegTest, AVPixFmt) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_color_primaries_name"); - auto &HostFuncAVColorPrimariesName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVColorPrimariesName &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVColorPrimariesName = FuncInst->getHostFunc(); { HostFuncAVColorPrimariesName.run( @@ -191,14 +204,17 @@ TEST_F(FFmpegTest, AVPixFmt) { Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)), + "bt709"sv); } PixFmtId = 1; // YUV420P FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_pix_format_name_length"); - auto &HostFuncAVPixFormatNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVPixelFormatNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPixFormatNameLength = FuncInst->getHostFunc(); { HostFuncAVPixFormatNameLength.run( @@ -213,9 +229,9 @@ TEST_F(FFmpegTest, AVPixFmt) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_pix_format_name"); - auto &HostFuncAVPixFormatName = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPixFormatName = FuncInst->getHostFunc(); { HostFuncAVPixFormatName.run( @@ -224,13 +240,16 @@ TEST_F(FFmpegTest, AVPixFmt) { Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)), + "yuv420p"sv); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_pix_format_mask"); - auto &HostFuncAVPixFormatMask = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPixFormatMask = FuncInst->getHostFunc(); { uint32_t PixId = 3; // AV_PIX_FMT_RGB24: diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avRational.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avRational.cpp index 85223ad9..d8cdffeb 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avRational.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avRational.cpp @@ -21,11 +21,9 @@ TEST_F(FFmpegTest, AVRational) { // Addition Function auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_add_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVAddQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVAddQ = FuncInst->getHostFunc(); { int32_t ANum = 3; @@ -44,11 +42,9 @@ TEST_F(FFmpegTest, AVRational) { // Subtraction Function FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_sub_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVSubQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVSubQ = FuncInst->getHostFunc(); { int32_t ANum = -843; @@ -69,11 +65,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_mul_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVMulQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVMulQ = FuncInst->getHostFunc(); { int32_t ANum = -6; @@ -94,11 +88,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_div_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVDivQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDivQ = FuncInst->getHostFunc(); { int32_t ANum = -6; @@ -121,11 +113,9 @@ TEST_F(FFmpegTest, AVRational) { // How to Pass a Double functions. FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_d2q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVD2Q = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVD2Q = FuncInst->getHostFunc(); { double D = 5; @@ -145,11 +135,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_q2d"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVQ2d = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVQ2d = FuncInst->getHostFunc(); { // Convert Rational Number to Double. @@ -165,11 +153,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_inv_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInvQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInvQ = FuncInst->getHostFunc(); { // Inverse a Rational Number. @@ -189,11 +175,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_q2intfloat"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVQ2IntFloat = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVQ2IntFloat = FuncInst->getHostFunc(); { int32_t ANum = 1; @@ -206,11 +190,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_nearer_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVNearerQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVNearerQ = FuncInst->getHostFunc(); { int32_t ANum = 1; @@ -251,11 +233,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_cmp_q"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVCmpQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCmpQ = FuncInst->getHostFunc(); { int32_t ANum = 1; @@ -293,11 +273,9 @@ TEST_F(FFmpegTest, AVRational) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_reduce"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVReduce = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVReduce = FuncInst->getHostFunc(); { int64_t ANum = 1; diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avSampleFmt.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avSampleFmt.cpp index d12cd16d..57d7ebc6 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avSampleFmt.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avSampleFmt.cpp @@ -20,12 +20,12 @@ TEST_F(FFmpegTest, AVSampleFmt) { uint32_t NamePtr = UINT32_C(80); uint32_t LinesizePtr = UINT32_C(20); - uint32_t SampleFmtId = 1; // AV_SAMPLE_FMT_S32 + uint32_t SampleFmtId = 1; // AV_SAMPLE_FMT_U8 auto *FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_packed_sample_fmt"); - auto &HostFuncAVGetPackedSampleFmt = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetPackedSampleFmt &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetPackedSampleFmt = FuncInst->getHostFunc(); { HostFuncAVGetPackedSampleFmt.run( @@ -37,9 +37,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_planar_sample_fmt"); - auto &HostFuncAVGetPlanarSampleFmt = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetPlanarSampleFmt &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetPlanarSampleFmt = FuncInst->getHostFunc(); { HostFuncAVGetPlanarSampleFmt.run( @@ -51,9 +51,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_sample_fmt_is_planar"); - auto &HostFuncAVSampleFmtIsPlanar = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVSampleFmtIsPlanar &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVSampleFmtIsPlanar = FuncInst->getHostFunc(); { HostFuncAVSampleFmtIsPlanar.run( @@ -65,23 +65,23 @@ TEST_F(FFmpegTest, AVSampleFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_bytes_per_sample"); - auto &HostFuncAVGetBytesPerSample = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetBytesPerSample &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetBytesPerSample = FuncInst->getHostFunc(); { - HostFuncAVGetBytesPerSample.run( + EXPECT_TRUE(HostFuncAVGetBytesPerSample.run( CallFrame, std::initializer_list{SampleFmtId}, - Result); + Result)); - EXPECT_TRUE(Result[0].get() >= 0); + EXPECT_EQ(Result[0].get(), 1); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_get_sample_fmt"); - auto &HostFuncAVGetSampleFmt = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetSampleFmt = FuncInst->getHostFunc(); uint32_t SampleFmtStart = 100; uint32_t SampleFmtSize = 2; @@ -99,9 +99,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_samples_get_buffer_size"); - auto &HostFuncAVSamplesGetBufferSize = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVSamplesGetBufferSize &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVSamplesGetBufferSize = FuncInst->getHostFunc(); int32_t NbChannels = 1; int32_t NbSamples = 5; @@ -120,9 +120,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_samples_alloc_array_and_samples"); - auto &HostFuncAVSamplesAllocArrayAndSamples = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVSamplesAllocArrayAndSamples &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVSamplesAllocArrayAndSamples = FuncInst->getHostFunc(); { HostFuncAVSamplesAllocArrayAndSamples.run( @@ -140,9 +140,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { int32_t Length = 0; FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_sample_fmt_name_length"); - auto &HostFuncAVGetSampleFmtNameLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetSampleFmtNameLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetSampleFmtNameLength = FuncInst->getHostFunc(); { HostFuncAVGetSampleFmtNameLength.run( @@ -155,9 +155,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_sample_fmt_name"); - auto &HostFuncAVGetSampleFmtName = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetSampleFmtName &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetSampleFmtName = FuncInst->getHostFunc(); // Fill Memory with 0. fillMemContent(MemInst, NamePtr, Length); @@ -168,13 +168,16 @@ TEST_F(FFmpegTest, AVSampleFmt) { Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)), + "u8"sv); } FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_sample_fmt_mask"); - auto &HostFuncAVGetSampleFmtMask = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetSampleFmtMask &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetSampleFmtMask = FuncInst->getHostFunc(); { uint32_t SampleId = 2; // AV_SAMPLE_FMT_S16; @@ -186,9 +189,9 @@ TEST_F(FFmpegTest, AVSampleFmt) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_freep"); - auto &HostFuncAVFreep = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFreep = FuncInst->getHostFunc(); { uint32_t BufferId = readUInt32(MemInst, BufferPtr); diff --git a/test/plugins/wasmedge_ffmpeg/avutil/avutil_func.cpp b/test/plugins/wasmedge_ffmpeg/avutil/avutil_func.cpp index 2406cea1..700c4efe 100644 --- a/test/plugins/wasmedge_ffmpeg/avutil/avutil_func.cpp +++ b/test/plugins/wasmedge_ffmpeg/avutil/avutil_func.cpp @@ -20,57 +20,57 @@ TEST_F(FFmpegTest, AVUtilFunc) { auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_log_set_level"); - auto &HostFuncAVLogSetLevel = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVLogSetLevel = FuncInst->getHostFunc(); - int32_t LogLvlId = 32; + int32_t LogLvlId = 16; // AV_LOG_ERROR, distinct from the default AV_LOG_INFO { - HostFuncAVLogSetLevel.run( - CallFrame, std::initializer_list{LogLvlId}, - Result); + EXPECT_TRUE(HostFuncAVLogSetLevel.run( + CallFrame, std::initializer_list{LogLvlId}, {})); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_log_get_level"); - auto &HostFuncAVLogGetLevel = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVLogGetLevel = FuncInst->getHostFunc(); { - HostFuncAVLogGetLevel.run( - CallFrame, std::initializer_list{}, Result); + EXPECT_TRUE(HostFuncAVLogGetLevel.run( + CallFrame, std::initializer_list{}, Result)); EXPECT_EQ(Result[0].get(), LogLvlId); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_log_set_flags"); - auto &HostFuncAVLogSetFlags = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVLogSetFlags = FuncInst->getHostFunc(); + int32_t FlagId = 1; { - HostFuncAVLogSetFlags.run( - CallFrame, std::initializer_list{1}, Result); + EXPECT_TRUE(HostFuncAVLogSetFlags.run( + CallFrame, std::initializer_list{FlagId}, {})); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_log_get_flags"); - auto &HostFuncAVLogGetFlags = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVLogGetFlags = FuncInst->getHostFunc(); { - HostFuncAVLogGetFlags.run( - CallFrame, std::initializer_list{1}, Result); + EXPECT_TRUE(HostFuncAVLogGetFlags.run( + CallFrame, std::initializer_list{}, Result)); - EXPECT_EQ(Result[0].get(), 32); + EXPECT_EQ(Result[0].get(), FlagId); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_rescale_q"); - auto &HostFuncAVRescaleQ = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVRescaleQ = FuncInst->getHostFunc(); int64_t A = 20; int32_t BNum = 5; @@ -89,9 +89,9 @@ TEST_F(FFmpegTest, AVUtilFunc) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_rescale_q_rnd"); - auto &HostFuncAVRescaleQRnd = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVRescaleQRnd = FuncInst->getHostFunc(); { int32_t RoundingId = 2; @@ -105,50 +105,51 @@ TEST_F(FFmpegTest, AVUtilFunc) { FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_avutil_version"); - auto &HostFuncAVUtilVersion = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilVersion = FuncInst->getHostFunc(); { - HostFuncAVUtilVersion.run( - CallFrame, std::initializer_list{}, Result); + EXPECT_TRUE(HostFuncAVUtilVersion.run( + CallFrame, std::initializer_list{}, Result)); - EXPECT_TRUE(Result[0].get() > 0); + EXPECT_TRUE((Result[0].get() >> 16) > 0); } uint64_t ChannelId = 1; // FRONT_LEFT FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_channel_layout_nb_channels"); - auto &HostFuncAVGetChannelLayoutNbChannels = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetChannelLayoutNbChannels &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetChannelLayoutNbChannels = FuncInst->getHostFunc(); { - HostFuncAVGetChannelLayoutNbChannels.run( + EXPECT_TRUE(HostFuncAVGetChannelLayoutNbChannels.run( CallFrame, std::initializer_list{ChannelId}, - Result); - EXPECT_TRUE(Result[0].get() > 0); + Result)); + EXPECT_EQ(Result[0].get(), 1); } FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_get_default_channel_layout"); - auto &HostFuncAVGetDefaultChannelLayout = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetDefaultChannelLayout &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetDefaultChannelLayout = FuncInst->getHostFunc(); { - HostFuncAVGetDefaultChannelLayout.run( + EXPECT_TRUE(HostFuncAVGetDefaultChannelLayout.run( CallFrame, std::initializer_list{ChannelId}, - Result); - EXPECT_TRUE(Result[0].get() > 0); + Result)); + EXPECT_EQ(Result[0].get(), + UINT64_C(67108868)); // guest-encoded AV_CH_LAYOUT_MONO } uint32_t Length = 0; FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_avutil_configuration_length"); - auto &HostFuncAVUtilConfigurationLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVUtilConfigurationLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilConfigurationLength = FuncInst->getHostFunc(); { HostFuncAVUtilConfigurationLength.run( @@ -162,22 +163,26 @@ TEST_F(FFmpegTest, AVUtilFunc) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_avutil_configuration"); - auto &HostFuncAVUtilConfiguration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVUtilConfiguration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilConfiguration = FuncInst->getHostFunc(); { HostFuncAVUtilConfiguration.run( CallFrame, std::initializer_list{NamePtr, Length}, Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_NE(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_avutil_license_length"); - auto &HostFuncAVUtilLicenseLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVUtilLicenseLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilLicenseLength = FuncInst->getHostFunc(); { HostFuncAVUtilLicenseLength.run( @@ -191,15 +196,19 @@ TEST_F(FFmpegTest, AVUtilFunc) { fillMemContent(MemInst, NamePtr, Length); FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_avutil_license"); - auto &HostFuncAVUtilLicense = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUtilLicense = FuncInst->getHostFunc(); { HostFuncAVUtilLicense.run( CallFrame, std::initializer_list{NamePtr, Length}, Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } } @@ -209,35 +218,41 @@ TEST_F(FFmpegTest, AVTime) { auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_gettime"); - auto &HostFuncAVGetTime = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetTime = FuncInst->getHostFunc(); + int64_t AbsTime = 0; { - HostFuncAVGetTime.run( - CallFrame, std::initializer_list{}, Result); + EXPECT_TRUE(HostFuncAVGetTime.run( + CallFrame, std::initializer_list{}, Result)); - EXPECT_TRUE(Result[0].get() > 0); + AbsTime = Result[0].get(); + // Wall-clock epoch microseconds: well past 2020-01-01. + EXPECT_GT(AbsTime, INT64_C(1577836800000000)); } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_gettime_relative"); - auto &HostFuncAVGetTimeRelative = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetTimeRelative = FuncInst->getHostFunc(); { - HostFuncAVGetTimeRelative.run( - CallFrame, std::initializer_list{}, Result); + EXPECT_TRUE(HostFuncAVGetTimeRelative.run( + CallFrame, std::initializer_list{}, Result)); - EXPECT_TRUE(Result[0].get() > 0); + int64_t RelTime = Result[0].get(); + EXPECT_GT(RelTime, 0); + // Relative monotonic clock is not epoch time; it stays smaller. + EXPECT_LT(RelTime, AbsTime); } FuncInst = AVUtilMod->findFuncExports( "wasmedge_ffmpeg_avutil_av_gettime_relative_is_monotonic"); - auto &HostFuncAVGetTimeRelativeIsMonotonic = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVUtil::AVGetTimeRelativeIsMonotonic &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVGetTimeRelativeIsMonotonic = FuncInst->getHostFunc(); { HostFuncAVGetTimeRelativeIsMonotonic.run( @@ -247,9 +262,9 @@ TEST_F(FFmpegTest, AVTime) { } FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_usleep"); - auto &HostFuncAVUSleep = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVUSleep = FuncInst->getHostFunc(); { HostFuncAVUSleep.run( diff --git a/test/plugins/wasmedge_ffmpeg/swresample/swresample_func.cpp b/test/plugins/wasmedge_ffmpeg/swresample/swresample_func.cpp index 6f84db6f..832f8e72 100644 --- a/test/plugins/wasmedge_ffmpeg/swresample/swresample_func.cpp +++ b/test/plugins/wasmedge_ffmpeg/swresample/swresample_func.cpp @@ -37,24 +37,20 @@ TEST_F(FFmpegTest, SWResampleFunc) { auto *FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swresample_version"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSWResampleVersion = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWResampleVersion &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSWResampleVersion = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSWResampleVersion.run(CallFrame, {}, Result)); - ASSERT_TRUE(Result[0].get() > 0); + ASSERT_TRUE((Result[0].get() >> 16) > 0); } FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swr_alloc_set_opts"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrAllocSetOpts = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWRAllocSetOpts &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrAllocSetOpts = FuncInst->getHostFunc(); // Testing with Null Old SwrCtx. Hence 2nd argument is 0. { @@ -100,11 +96,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports("wasmedge_ffmpeg_swresample_swr_free"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrFree = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrFree = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSwrFree.run( @@ -114,11 +108,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports("wasmedge_ffmpeg_swresample_swr_init"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrInit = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrInit = FuncInst->getHostFunc(); { SwrId = readUInt32(MemInst, SWResamplePtr); @@ -129,11 +121,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_av_opt_set_dict"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncAVOptSetDict = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVOptSetDict = FuncInst->getHostFunc(); { uint32_t EmptyDictId = 0; @@ -155,11 +145,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swr_convert_frame"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrConvertFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWRConvertFrame &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrConvertFrame = FuncInst->getHostFunc(); { SwrId = readUInt32(MemInst, SWResamplePtr); @@ -172,11 +160,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swr_get_delay"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrGetDelay = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrGetDelay = FuncInst->getHostFunc(); { SwrId = readUInt32(MemInst, SWResamplePtr); @@ -188,11 +174,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swresample_configuration_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrConfigLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWResampleConfigurationLength - &>(FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrConfigLength = FuncInst->getHostFunc(); int32_t Length = 0; { @@ -205,11 +189,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swresample_configuration"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrConfig = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWResampleConfiguration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrConfig = FuncInst->getHostFunc(); { SwrId = readUInt32(MemInst, SWResamplePtr); @@ -217,15 +199,17 @@ TEST_F(FFmpegTest, SWResampleFunc) { CallFrame, std::initializer_list{StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_NE(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swresample_license_length"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrLicenseLen = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWResampleLicenseLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrLicenseLen = FuncInst->getHostFunc(); { SwrId = readUInt32(MemInst, SWResamplePtr); @@ -238,11 +222,9 @@ TEST_F(FFmpegTest, SWResampleFunc) { FuncInst = SWResampleMod->findFuncExports( "wasmedge_ffmpeg_swresample_swresample_license"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwrLicense = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWResample::SWResampleLicense &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwrLicense = FuncInst->getHostFunc(); { SwrId = readUInt32(MemInst, SWResamplePtr); @@ -250,6 +232,10 @@ TEST_F(FFmpegTest, SWResampleFunc) { CallFrame, std::initializer_list{StrPtr, Length}, Result)); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(StrPtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } } diff --git a/test/plugins/wasmedge_ffmpeg/swscale/swscale_func.cpp b/test/plugins/wasmedge_ffmpeg/swscale/swscale_func.cpp index 805b2224..de140425 100644 --- a/test/plugins/wasmedge_ffmpeg/swscale/swscale_func.cpp +++ b/test/plugins/wasmedge_ffmpeg/swscale/swscale_func.cpp @@ -21,11 +21,9 @@ TEST_F(FFmpegTest, SwsContext) { auto *FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getContext"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetContext = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetContext = FuncInst->getHostFunc(); uint32_t SWScalePtr = UINT32_C(4); uint32_t SWCachedScalePtr = UINT32_C(8); @@ -44,6 +42,7 @@ TEST_F(FFmpegTest, SwsContext) { uint32_t YUV420PId = 1; // YUV420P AVPixFormatId (From Bindings.h) uint32_t RGB24Id = 3; // RGB24 AVPixFormatId (From Bindings.h) uint32_t XVMCId = 174; // XVMC AVPixFormatId (From Bindings.h) + uint32_t PAL8Id = 13; // PAL8 AVPixFormatId (From Bindings.h) uint32_t SrcWidth = 100; uint32_t SrcHeight = 100; @@ -71,11 +70,9 @@ TEST_F(FFmpegTest, SwsContext) { // Checking correctness of function. Returns Invalid Argument Error. FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_scale"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsScale = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsScale = FuncInst->getHostFunc(); { EXPECT_TRUE( @@ -88,11 +85,9 @@ TEST_F(FFmpegTest, SwsContext) { FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_sws_getCachedContext"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetCachedContext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwsGetCachedContext &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetCachedContext = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSwsGetCachedContext.run( @@ -107,11 +102,9 @@ TEST_F(FFmpegTest, SwsContext) { FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_sws_isSupportedInput"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsIsSupportedInput = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwsIsSupportedInput &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsIsSupportedInput = FuncInst->getHostFunc(); { // AV_PIX_FMT_RGB24 is a supported pixel format. @@ -125,15 +118,19 @@ TEST_F(FFmpegTest, SwsContext) { CallFrame, std::initializer_list{XVMCId}, Result)); ASSERT_TRUE(Result[0].get() == 0); + + // AV_PIX_FMT_PAL8 is supported as input but not as output. + EXPECT_TRUE(HostFuncSwsIsSupportedInput.run( + CallFrame, std::initializer_list{PAL8Id}, + Result)); + ASSERT_TRUE(Result[0].get() > 0); } FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_sws_isSupportedOutput"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsIsSupportedOutput = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwsIsSupportedOutput &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsIsSupportedOutput = FuncInst->getHostFunc(); { // AV_PIX_FMT_RGB24 is a supported pixel format. @@ -147,16 +144,19 @@ TEST_F(FFmpegTest, SwsContext) { CallFrame, std::initializer_list{XVMCId}, Result)); ASSERT_TRUE(Result[0].get() == 0); + + // AV_PIX_FMT_PAL8 is supported as input but not as output. + EXPECT_TRUE(HostFuncSwsIsSupportedOutput.run( + CallFrame, std::initializer_list{PAL8Id}, + Result)); + ASSERT_TRUE(Result[0].get() == 0); } FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_sws_isSupportedEndiannessConversion"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsIsSupportedEndiannessConversion = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsIsSupportedEndiannessConversion = FuncInst->getHostFunc(); { // AV_PIX_FMT_XVMC is not a supported pixel format for @@ -168,11 +168,9 @@ TEST_F(FFmpegTest, SwsContext) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_freeContext"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsFreeContext = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsFreeContext = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSwsFreeContext.run( @@ -205,11 +203,9 @@ TEST_F(FFmpegTest, SwsFilter) { ASSERT_TRUE(SWScaleMod != nullptr); auto *FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_sws_getDefaultFilter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetDefaultFilter = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwsGetDefaultFilter &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetDefaultFilter = FuncInst->getHostFunc(); uint32_t SwsFilterPtr = UINT32_C(40); { @@ -234,11 +230,9 @@ TEST_F(FFmpegTest, SwsFilter) { uint32_t FilterId = readUInt32(MemInst, SwsFilterPtr); FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getLumaH"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetLumaH = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetLumaH = FuncInst->getHostFunc(); uint32_t SwsVectorPtr = UINT32_C(20); { @@ -252,11 +246,9 @@ TEST_F(FFmpegTest, SwsFilter) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getLumaV"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetLumaV = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetLumaV = FuncInst->getHostFunc(); { writeUInt32(MemInst, UINT32_C(0), SwsVectorPtr); @@ -270,11 +262,9 @@ TEST_F(FFmpegTest, SwsFilter) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getChromaH"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetChromaH = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetChromaH = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSwsGetChromaH.run( @@ -287,11 +277,9 @@ TEST_F(FFmpegTest, SwsFilter) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getChromaV"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetChromaV = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetChromaV = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSwsGetChromaV.run( @@ -304,11 +292,9 @@ TEST_F(FFmpegTest, SwsFilter) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_freeFilter"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsFreeFilter = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsFreeFilter = FuncInst->getHostFunc(); { EXPECT_TRUE(HostFuncSwsFreeFilter.run( @@ -329,11 +315,9 @@ TEST_F(FFmpegTest, SwsVector) { auto *FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_allocVec"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsAllocVec = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsAllocVec = FuncInst->getHostFunc(); { writeUInt32(MemInst, UINT32_C(0), SwsVectorPtr); @@ -348,11 +332,9 @@ TEST_F(FFmpegTest, SwsVector) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getGaussianVec"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetGaussianVec = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwsGetGaussianVec &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetGaussianVec = FuncInst->getHostFunc(); { writeUInt32(MemInst, UINT32_C(0), SwsVectorPtr); @@ -369,11 +351,9 @@ TEST_F(FFmpegTest, SwsVector) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_scaleVec"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsScaleVec = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsScaleVec = FuncInst->getHostFunc(); { uint32_t SwsVecId = readUInt32(MemInst, SwsVectorPtr); @@ -386,11 +366,9 @@ TEST_F(FFmpegTest, SwsVector) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_normalizeVec"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsNormalizeVec = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsNormalizeVec = FuncInst->getHostFunc(); { uint32_t SwsVecId = readUInt32(MemInst, SwsVectorPtr); @@ -403,11 +381,9 @@ TEST_F(FFmpegTest, SwsVector) { FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_sws_getCoeffVecLength"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetCoeffVecLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwsGetCoeffVecLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetCoeffVecLength = FuncInst->getHostFunc(); int Length = 0; { @@ -421,11 +397,9 @@ TEST_F(FFmpegTest, SwsVector) { FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_getCoeff"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsGetCoeff = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsGetCoeff = FuncInst->getHostFunc(); fillMemContent(MemInst, CoeffPtr, Length); { @@ -438,11 +412,9 @@ TEST_F(FFmpegTest, SwsVector) { } FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_sws_freeVec"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncSwsFreeVec = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwsFreeVec = FuncInst->getHostFunc(); { uint32_t SwsVecId = readUInt32(MemInst, SwsVectorPtr); @@ -465,22 +437,22 @@ TEST_F(FFmpegTest, SWScaleVersion) { auto *FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_swscale_version"); - auto &HostFuncSwscaleVersion = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwscaleVersion = FuncInst->getHostFunc(); { - HostFuncSwscaleVersion.run( - CallFrame, std::initializer_list{}, Result); + EXPECT_TRUE(HostFuncSwscaleVersion.run( + CallFrame, std::initializer_list{}, Result)); - EXPECT_TRUE(Result[0].get() > 0); + EXPECT_TRUE((Result[0].get() >> 16) > 0); } FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_swscale_configuration_length"); - auto &HostFuncSwscaleConfigurationLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwscaleConfigurationLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwscaleConfigurationLength = FuncInst->getHostFunc(); { HostFuncSwscaleConfigurationLength.run( @@ -495,22 +467,26 @@ TEST_F(FFmpegTest, SWScaleVersion) { fillMemContent(MemInst, NamePtr, Length); FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_swscale_configuration"); - auto &HostFuncSwscaleConfiguration = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwscaleConfiguration &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwscaleConfiguration = FuncInst->getHostFunc(); { HostFuncSwscaleConfiguration.run( CallFrame, std::initializer_list{NamePtr, Length}, Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_NE(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } FuncInst = SWScaleMod->findFuncExports( "wasmedge_ffmpeg_swscale_swscale_license_length"); - auto &HostFuncSwscaleLicenseLength = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::SWScale::SwscaleLicenseLength &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwscaleLicenseLength = FuncInst->getHostFunc(); { HostFuncSwscaleLicenseLength.run( @@ -524,15 +500,19 @@ TEST_F(FFmpegTest, SWScaleVersion) { fillMemContent(MemInst, NamePtr, Length); FuncInst = SWScaleMod->findFuncExports("wasmedge_ffmpeg_swscale_swscale_license"); - auto &HostFuncSwscaleLicense = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncSwscaleLicense = FuncInst->getHostFunc(); { HostFuncSwscaleLicense.run( CallFrame, std::initializer_list{NamePtr, Length}, Result); EXPECT_EQ(Result[0].get(), static_cast(ErrNo::Success)); + EXPECT_EQ(std::string_view(MemInst->getPointer(NamePtr), + static_cast(Length)) + .find("--"), + std::string_view::npos); } } diff --git a/test/plugins/wasmedge_ffmpeg/utils.cpp b/test/plugins/wasmedge_ffmpeg/utils.cpp index 2656cbb3..ce2101df 100644 --- a/test/plugins/wasmedge_ffmpeg/utils.cpp +++ b/test/plugins/wasmedge_ffmpeg/utils.cpp @@ -18,11 +18,11 @@ namespace WasmEdgeFFmpeg { void FFmpegTest::initEmptyFrame(uint32_t FramePtr) { auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_frame_alloc"); - auto &HostFuncAVFrameAlloc = - dynamic_cast( - FuncInst->getHostFunc()); - HostFuncAVFrameAlloc.run( - CallFrame, std::initializer_list{FramePtr}, Result); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFrameAlloc = FuncInst->getHostFunc(); + ASSERT_TRUE(HostFuncAVFrameAlloc.run( + CallFrame, std::initializer_list{FramePtr}, Result)); } void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, @@ -36,9 +36,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, auto *FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_av_find_best_stream"); - auto &HostFuncAVFindBestStream = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFindBestStream &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFindBestStream = FuncInst->getHostFunc(); uint32_t MediaTypeId = 0; // Video uint32_t WantedStream = -1; uint32_t RelatedStream = -1; @@ -54,10 +54,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avStream_codecpar"); - - auto &HostFuncAVStreamCodecpar = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVStreamCodecPar &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVStreamCodecpar = FuncInst->getHostFunc(); HostFuncAVStreamCodecpar.run(CallFrame, std::initializer_list{ @@ -68,9 +67,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_alloc_context3"); - auto &HostFuncAVCodecAllocContext3 = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecAllocContext3 &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecAllocContext3 = FuncInst->getHostFunc(); HostFuncAVCodecAllocContext3.run( CallFrame, std::initializer_list{0, AVCodecCtxPtr}, @@ -80,9 +79,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_parameters_to_context"); - auto &HostFuncAVCodecParametersToContext = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecParametersToContext &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecParametersToContext = FuncInst->getHostFunc(); HostFuncAVCodecParametersToContext.run( CallFrame, @@ -92,9 +91,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodeccontext_codec_id"); - auto &HostFuncAVCodecContextCodecId = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecCtxCodecID &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecContextCodecId = FuncInst->getHostFunc(); HostFuncAVCodecContextCodecId.run( CallFrame, std::initializer_list{AVCodecCtxId}, @@ -104,9 +103,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_find_decoder"); - auto &HostFuncAVCodecFindDecoder = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecFindDecoder &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecFindDecoder = FuncInst->getHostFunc(); HostFuncAVCodecFindDecoder.run( CallFrame, @@ -116,9 +115,9 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_avcodec_open2"); - auto &HostFuncAVCodecOpen2 = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecOpen2 = FuncInst->getHostFunc(); HostFuncAVCodecOpen2.run( CallFrame, @@ -130,27 +129,27 @@ void FFmpegTest::initFFmpegStructs(uint32_t AVCodecPtr, uint32_t AVFormatCtxPtr, FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_receive_frame"); - auto &HostFuncAVCodecReceiveFrame = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecReceiveFrame &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecReceiveFrame = FuncInst->getHostFunc(); FuncInst = AVFormatMod->findFuncExports("wasmedge_ffmpeg_avformat_av_read_frame"); - auto &HostFuncAVReadFrame = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVReadFrame = FuncInst->getHostFunc(); FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_avcodec_send_packet"); - auto &HostFuncAVCodecSendPacket = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVCodecSendPacket &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVCodecSendPacket = FuncInst->getHostFunc(); FuncInst = AVCodecMod->findFuncExports( "wasmedge_ffmpeg_avcodec_av_packet_stream_index"); - auto &HostFuncAVPacketStreamIndex = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVcodec::AVPacketStreamIndex &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketStreamIndex = FuncInst->getHostFunc(); while (true) { HostFuncAVCodecReceiveFrame.run( @@ -210,9 +209,9 @@ void FFmpegTest::initFormatCtx(uint32_t AVFormatCtxPtr, uint32_t FilePtr, auto *FuncInst = AVFormatMod->findFuncExports( "wasmedge_ffmpeg_avformat_avformat_open_input"); - auto &HostFuncAVFormatOpenInput = dynamic_cast< - WasmEdge::Host::WasmEdgeFFmpeg::AVFormat::AVFormatOpenInput &>( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVFormatOpenInput = FuncInst->getHostFunc(); HostFuncAVFormatOpenInput.run( CallFrame, std::initializer_list{ @@ -230,9 +229,9 @@ void FFmpegTest::initDict(uint32_t DictPtr, uint32_t KeyPtr, std::string Key, auto *FuncInst = AVUtilMod->findFuncExports("wasmedge_ffmpeg_avutil_av_dict_set"); - auto &HostFuncAVDictSet = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVDictSet = FuncInst->getHostFunc(); HostFuncAVDictSet.run(CallFrame, std::initializer_list{ @@ -243,9 +242,9 @@ void FFmpegTest::initDict(uint32_t DictPtr, uint32_t KeyPtr, std::string Key, void FFmpegTest::allocPacket(uint32_t PacketPtr) { auto *FuncInst = AVCodecMod->findFuncExports("wasmedge_ffmpeg_avcodec_av_packet_alloc"); - auto &HostFuncAVPacketAlloc = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncAVPacketAlloc = FuncInst->getHostFunc(); HostFuncAVPacketAlloc.run( CallFrame, std::initializer_list{PacketPtr}, diff --git a/test/plugins/wasmedge_llmc/CMakeLists.txt b/test/plugins/wasmedge_llmc/CMakeLists.txt index 7fce5e8a..6798cef7 100644 --- a/test/plugins/wasmedge_llmc/CMakeLists.txt +++ b/test/plugins/wasmedge_llmc/CMakeLists.txt @@ -1,78 +1,4 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: 2019-2024 Second State INC -wasmedge_add_executable(wasmedgeLLMCTests - wasmedge_llmc.cpp -) - -add_dependencies(wasmedgeLLMCTests - wasmedgePluginWasmEdgeLLMC -) - -target_include_directories(wasmedgeLLMCTests - PUBLIC - $ - $ -) - -target_link_libraries(wasmedgeLLMCTests - PRIVATE - ${GTEST_BOTH_LIBRARIES} -) - -# Link to the WasmEdge library -if(WASMEDGE_LINK_PLUGINS_STATIC) - target_link_libraries(wasmedgeLLMCTests - PRIVATE - wasmedgeCAPI - ) -else() - target_link_libraries(wasmedgeLLMCTests - PRIVATE - wasmedge_shared - ) -endif() - -function(download URL OUTPUT HASH) - file(DOWNLOAD - ${URL} - ${OUTPUT} - SHOW_PROGRESS - EXPECTED_HASH ${HASH} - ) -endfunction() - -message(STATUS "Downloading GPT2 model check point to ${CMAKE_CURRENT_BINARY_DIR}/gpt2_124M.bin") -if (WASMEDGE_PLUGIN_LLMC_CUDA) - download( - https://huggingface.co/datasets/karpathy/llmc-starter-pack/resolve/main/gpt2_124M_bf16.bin - ${CMAKE_CURRENT_BINARY_DIR}/wasmedge_llmc/gpt2_124M.bin - SHA256=6661f45628102b4c6e86835d9057b5ba2c024dbf9b81445175e258b7878a1a6f - ) -else() - download( - https://huggingface.co/datasets/karpathy/llmc-starter-pack/resolve/main/gpt2_124M.bin - ${CMAKE_CURRENT_BINARY_DIR}/wasmedge_llmc/gpt2_124M.bin - SHA256=3da8b207584030bcdcd207cf7a99952e3421dce92da218b351071857511bf162 - ) -endif() -message(STATUS "Downloading training dataset to ${CMAKE_CURRENT_BINARY_DIR}/tiny_shakespeare_train.bin") -download( - https://huggingface.co/datasets/karpathy/llmc-starter-pack/resolve/main/tiny_shakespeare_train.bin - ${CMAKE_CURRENT_BINARY_DIR}/wasmedge_llmc/tiny_shakespeare_train.bin - SHA256=8a70606be574040c26d225694f5f9759973b419852d22f7fe5c118e1b359dcc8 -) -message(STATUS "Downloading validation dataset to ${CMAKE_CURRENT_BINARY_DIR}/tiny_shakespeare_val.bin") -download( - https://huggingface.co/datasets/karpathy/llmc-starter-pack/resolve/main/tiny_shakespeare_val.bin - ${CMAKE_CURRENT_BINARY_DIR}/wasmedge_llmc/tiny_shakespeare_val.bin - SHA256=fe99db720dc7c83e694806d4e047a952909411da1daccde4ccc2e55f40882a62 -) -message(STATUS "Downloading tokenizer data to ${CMAKE_CURRENT_BINARY_DIR}/gpt2_tokenizer.bin") -download( - https://huggingface.co/datasets/karpathy/llmc-starter-pack/resolve/main/gpt2_tokenizer.bin - ${CMAKE_CURRENT_BINARY_DIR}/wasmedge_llmc/gpt2_tokenizer.bin - SHA256=6f3abc21e444e4e8300e225f4e03da48ea121cf17e30f67009b8dad7a66c2f13 -) - -add_test(wasmedgeLLMCTests wasmedgeLLMCTests) +message(FATAL_ERROR "WasmEdge LLMC plugin is removed due to the upstream end-of-life. Reference: https://github.com/WasmEdge/llm.c") diff --git a/test/plugins/wasmedge_llmc/wasmedge_llmc.cpp b/test/plugins/wasmedge_llmc/wasmedge_llmc.cpp deleted file mode 100644 index 4fcbff20..00000000 --- a/test/plugins/wasmedge_llmc/wasmedge_llmc.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2019-2024 Second State INC - -#include "llmc_func.h" -#include "llmc_module.h" - -#include "common/defines.h" -#include "common/types.h" -#include "plugin/plugin.h" -#include "runtime/callingframe.h" -#include "runtime/instance/module.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -using WasmEdge::Host::WasmEdgeLLMC::ErrNo; - -namespace { - -template -inline std::unique_ptr dynamicPointerCast(std::unique_ptr &&R) noexcept { - static_assert(std::has_virtual_destructor_v); - T *P = dynamic_cast(R.get()); - if (P) { - R.release(); - } - return std::unique_ptr(P); -} - -std::unique_ptr createModule() { - using namespace std::literals::string_view_literals; - WasmEdge::Plugin::Plugin::load(std::filesystem::u8path( - "../../../plugins/wasmedge_llmc/" WASMEDGE_LIB_PREFIX - "wasmedgePluginWasmEdgeLLMC" WASMEDGE_LIB_EXTENSION)); - if (const auto *Plugin = WasmEdge::Plugin::Plugin::find("wasmedge_llmc"sv)) { - if (const auto *Module = Plugin->findModule("wasmedge_llmc"sv)) { - return dynamicPointerCast( - Module->create()); - } - } - return {}; -} -} // namespace - -template -void writeBinaries(WasmEdge::Runtime::Instance::MemoryInstance &MemInst, - WasmEdge::Span Binaries, uint32_t Ptr) noexcept { - std::copy(Binaries.begin(), Binaries.end(), MemInst.getPointer(Ptr)); -} - -void writeUInt32(WasmEdge::Runtime::Instance::MemoryInstance &MemInst, - uint32_t Value, uint32_t &Ptr) { - uint32_t *BufPtr = MemInst.getPointer(Ptr); - *BufPtr = Value; - Ptr += 4; -} - -TEST(WasmEdgeLLMTest, TrainGPT2) { - // Create wasmedge_llmc module instance. - auto LLMCMod = createModule(); - ASSERT_TRUE(LLMCMod); - EXPECT_EQ(LLMCMod->getFuncExportNum(), 4U); - - // Create the calling frame with memory instance. - WasmEdge::Runtime::Instance::ModuleInstance Mod(""); - Mod.addHostMemory( - "memory", std::make_unique( - WasmEdge::AST::MemoryType(60000))); - auto *MemInstPtr = Mod.findMemoryExports("memory"); - EXPECT_NE(MemInstPtr, nullptr); - auto &MemInst = *MemInstPtr; - WasmEdge::Runtime::CallingFrame CallFrame(nullptr, &Mod); - - auto *ModelCreate = LLMCMod->findFuncExports("model_create"); - EXPECT_NE(ModelCreate, nullptr); - EXPECT_TRUE(ModelCreate->isHostFunction()); - auto &HostFuncModelCreate = - dynamic_cast( - ModelCreate->getHostFunc()); - - auto *DataLoaderCreate = LLMCMod->findFuncExports("dataloader_create"); - EXPECT_NE(DataLoaderCreate, nullptr); - EXPECT_TRUE(DataLoaderCreate->isHostFunction()); - auto &HostFuncDataLoadereCreate = - dynamic_cast( - DataLoaderCreate->getHostFunc()); - - auto *TokenizerCreate = LLMCMod->findFuncExports("tokenizer_create"); - EXPECT_NE(TokenizerCreate, nullptr); - EXPECT_TRUE(TokenizerCreate->isHostFunction()); - auto &HostFuncTokenizerCreate = - dynamic_cast( - TokenizerCreate->getHostFunc()); - - auto *ModelTrain = LLMCMod->findFuncExports("model_train"); - EXPECT_NE(ModelTrain, nullptr); - EXPECT_TRUE(ModelTrain->isHostFunction()); - auto &HostFuncModelTrain = - dynamic_cast( - ModelTrain->getHostFunc()); - - std::array Errno = {UINT32_C(0)}; - - std::string CheckPointString = "./wasmedge_llmc/gpt2_124M.bin"; - std::vector CheckPointPath(CheckPointString.begin(), - CheckPointString.end()); - uint32_t CheckPointPathPtr = UINT32_C(0); - writeBinaries(MemInst, CheckPointPath, CheckPointPathPtr); - - std::string TrainDataString = "./wasmedge_llmc/tiny_shakespeare_train.bin"; - std::vector TrainDataPath(TrainDataString.begin(), - TrainDataString.end()); - uint32_t TrainDataPathPtr = CheckPointPathPtr + CheckPointPath.size(); - writeBinaries(MemInst, TrainDataPath, TrainDataPathPtr); - - std::string ValDataString = "./wasmedge_llmc/tiny_shakespeare_val.bin"; - std::vector ValDataPath(ValDataString.begin(), ValDataString.end()); - uint32_t ValDataPathPtr = TrainDataPathPtr + TrainDataPath.size(); - writeBinaries(MemInst, ValDataPath, ValDataPathPtr); - - std::string TokenizerBin = "./wasmedge_llmc/gpt2_tokenizer.bin"; - std::vector TokenizerBinPath(TokenizerBin.begin(), TokenizerBin.end()); - uint32_t TokenizerBinPtr = ValDataPathPtr + ValDataPath.size(); - writeBinaries(MemInst, TokenizerBinPath, TokenizerBinPtr); - - uint32_t ModelIdPtr = UINT32_C(0); - uint32_t ModelId = UINT32_C(0); - uint32_t TrainDataLoaderIdPtr = UINT32_C(0); - uint32_t TrainDataLoaderId = UINT32_C(0); - uint32_t ValDataLoaderIdPtr = UINT32_C(0); - uint32_t ValDataLoaderId = UINT32_C(0); - uint32_t TokenizerIdPtr = UINT32_C(0); - uint32_t TokenizerId = UINT32_C(0); - - { - EXPECT_TRUE(HostFuncModelCreate.run( - CallFrame, - std::initializer_list{ - CheckPointPathPtr, static_cast(CheckPointPath.size()), - ModelIdPtr}, - Errno)); - EXPECT_EQ(Errno[0].get(), static_cast(ErrNo::Success)); - ModelId = *MemInst.getPointer(ModelIdPtr); - EXPECT_EQ(ModelId, 0); - } - - { - EXPECT_TRUE(HostFuncDataLoadereCreate.run( - CallFrame, - std::initializer_list{ - TrainDataPathPtr, static_cast(TrainDataPath.size()), - /*B*/ 4, - /*T*/ 64, - /*ProcessRank*/ 0, - /*NumProcesses*/ 1, - /*ShouldShuffle*/ 1, TrainDataLoaderIdPtr}, - Errno)); - EXPECT_EQ(Errno[0].get(), static_cast(ErrNo::Success)); - TrainDataLoaderId = *MemInst.getPointer(TrainDataLoaderIdPtr); - EXPECT_EQ(TrainDataLoaderId, 0); - } - - { - EXPECT_TRUE(HostFuncDataLoadereCreate.run( - CallFrame, - std::initializer_list{ - ValDataPathPtr, static_cast(ValDataPath.size()), - /*B*/ 4, - /*T*/ 64, - /*ProcessRank*/ 0, - /*NumProcesses*/ 1, - /*ShouldShuffle*/ 0, ValDataLoaderIdPtr}, - Errno)); - EXPECT_EQ(Errno[0].get(), static_cast(ErrNo::Success)); - ValDataLoaderId = *MemInst.getPointer(ValDataLoaderIdPtr); - EXPECT_EQ(ValDataLoaderId, 1); - } - - { - EXPECT_TRUE(HostFuncTokenizerCreate.run( - CallFrame, - std::initializer_list{ - TokenizerBinPtr, static_cast(TokenizerBinPath.size()), - TokenizerIdPtr}, - Errno)); - EXPECT_EQ(Errno[0].get(), static_cast(ErrNo::Success)); - TokenizerId = *MemInst.getPointer(TokenizerIdPtr); - EXPECT_EQ(TokenizerId, 0); - } - - { - - EXPECT_TRUE(HostFuncModelTrain.run( - CallFrame, - std::initializer_list{ - ModelId, TrainDataLoaderId, ValDataLoaderId, TokenizerId, - /*B*/ 4, - /*T*/ 64, - /*Lr*/ 1e-4f, - /*Epoch*/ 20}, - Errno)); - } -} - -GTEST_API_ int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/plugins/wasmedge_opencvmini/CMakeLists.txt b/test/plugins/wasmedge_opencvmini/CMakeLists.txt index 9f0946f2..006ccbab 100644 --- a/test/plugins/wasmedge_opencvmini/CMakeLists.txt +++ b/test/plugins/wasmedge_opencvmini/CMakeLists.txt @@ -5,6 +5,10 @@ wasmedge_add_executable(wasmedgeOpencvminiTests wasmedge_opencvmini.cpp ) +# OpenCV headers come in through the plugin's include directories as regular +# includes and trip the shadow warnings; they are not ours to fix. +wasmedge_suppress_shadow_warnings(wasmedgeOpencvminiTests) + add_dependencies(wasmedgeOpencvminiTests wasmedgePluginWasmEdgeOpenCVMini ) diff --git a/test/plugins/wasmedge_process/wasmedge_process.cpp b/test/plugins/wasmedge_process/wasmedge_process.cpp index ea80f906..dfec2a9d 100644 --- a/test/plugins/wasmedge_process/wasmedge_process.cpp +++ b/test/plugins/wasmedge_process/wasmedge_process.cpp @@ -82,11 +82,9 @@ TEST(WasmEdgeProcessTest, SetProgName) { // Get the function "wasmedge_process_set_prog_name". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_set_prog_name"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Test: Run function successfully. EXPECT_TRUE(HostFuncInst.run( @@ -128,10 +126,9 @@ TEST(WasmEdgeProcessTest, AddArg) { // Get the function "wasmedge_process_add_arg". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_add_arg"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Test: Run function successfully to add "arg1". EXPECT_TRUE(HostFuncInst.run( @@ -192,10 +189,9 @@ TEST(WasmEdgeProcessTest, AddEnv) { // Get the function "wasmedge_process_add_env". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_add_env"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Test: Run function successfully to add "ENV1", "VALUE1". EXPECT_TRUE( @@ -247,10 +243,9 @@ TEST(WasmEdgeProcessTest, AddStdIn) { // Get the function "wasmedge_process_add_stdin". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_add_stdin"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Test: Run function successfully to add "\01\02\03\04". EXPECT_TRUE(HostFuncInst.run( @@ -286,11 +281,9 @@ TEST(WasmEdgeProcessTest, SetTimeOut) { // Get the function "wasmedge_process_set_timeout". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_set_timeout"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Test: Run function successfully to set timeout 100. EXPECT_TRUE(HostFuncInst.run( @@ -323,10 +316,9 @@ TEST(WasmEdgeProcessTest, Run) { // Get the function "wasmedge_process_run". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_run"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Return value. std::array RetVal; @@ -385,10 +377,9 @@ TEST(WasmEdgeProcessTest, TimeoutPrecision) { // Get the function "wasmedge_process_run". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_run"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncRun = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncRun = FuncInst->getHostFunc(); // Return value. std::array RetVal; @@ -428,16 +419,15 @@ TEST(WasmEdgeProcessTest, GetExitCode) { // Get the function "wasmedge_process_get_exit_code". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_get_exit_code"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncInst = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncInst = FuncInst->getHostFunc(); // Test: Run function successfully to get exit code. + ProcMod->getEnv().ExitCode = 42; std::array RetVal; EXPECT_TRUE(HostFuncInst.run(DummyCallFrame, {}, RetVal)); - EXPECT_EQ(RetVal[0].get(), 0); + EXPECT_EQ(RetVal[0].get(), 42); } TEST(WasmEdgeProcessTest, GetStdOut) { @@ -460,24 +450,19 @@ TEST(WasmEdgeProcessTest, GetStdOut) { // Get the function "wasmedge_process_run". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_run"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncRun = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncRun = FuncInst->getHostFunc(); // Get the function "wasmedge_process_run". FuncInst = ProcMod->findFuncExports("wasmedge_process_get_stdout_len"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetStdOutLen = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncGetStdOutLen = FuncInst->getHostFunc(); // Get the function "wasmedge_process_run". FuncInst = ProcMod->findFuncExports("wasmedge_process_get_stdout"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetStdOut = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncGetStdOut = FuncInst->getHostFunc(); // Return value. std::array RetVal; @@ -527,24 +512,19 @@ TEST(WasmEdgeProcessTest, GetStdErr) { // Get the function "wasmedge_process_run". auto *FuncInst = ProcMod->findFuncExports("wasmedge_process_run"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncRun = dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncRun = FuncInst->getHostFunc(); // Get the function "wasmedge_process_run". FuncInst = ProcMod->findFuncExports("wasmedge_process_get_stderr_len"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetStdErrLen = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncGetStdErrLen = FuncInst->getHostFunc(); // Get the function "wasmedge_process_run". FuncInst = ProcMod->findFuncExports("wasmedge_process_get_stderr"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncGetStdErr = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncGetStdErr = FuncInst->getHostFunc(); // Return value. std::array RetVal; @@ -568,8 +548,8 @@ TEST(WasmEdgeProcessTest, GetStdErr) { // Test: Run wasmedge_process_get_stdout successfully. EXPECT_TRUE(HostFuncGetStdErr.run( CallFrame, std::initializer_list{UINT32_C(0)}, {})); - EXPECT_TRUE(std::equal(ProcMod->getEnv().StdOut.begin(), - ProcMod->getEnv().StdOut.end(), + EXPECT_TRUE(std::equal(ProcMod->getEnv().StdErr.begin(), + ProcMod->getEnv().StdErr.end(), MemInst.getPointer(0))); } diff --git a/test/plugins/wasmedge_stablediffusion/wasmedge_stablediffusion.cpp b/test/plugins/wasmedge_stablediffusion/wasmedge_stablediffusion.cpp index e6817916..018b666f 100644 --- a/test/plugins/wasmedge_stablediffusion/wasmedge_stablediffusion.cpp +++ b/test/plugins/wasmedge_stablediffusion/wasmedge_stablediffusion.cpp @@ -87,32 +87,24 @@ TEST(WasmEdgeStableDiffusionTest, ModuleFunctions) { // Get the function "convert". auto *FuncInst = SBMod->findFuncExports("convert"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncConvert = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncConvert = FuncInst->getHostFunc(); // Get the function "create_context". FuncInst = SBMod->findFuncExports("create_context"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncCreateContext = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncCreateContext = FuncInst->getHostFunc(); // Get the function "text_to_image". FuncInst = SBMod->findFuncExports("text_to_image"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncTextToImage = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncTextToImage = FuncInst->getHostFunc(); // Get the function "image_to_image". FuncInst = SBMod->findFuncExports("image_to_image"); - EXPECT_NE(FuncInst, nullptr); - EXPECT_TRUE(FuncInst->isHostFunction()); - auto &HostFuncImageToImage = - dynamic_cast( - FuncInst->getHostFunc()); + ASSERT_NE(FuncInst, nullptr); + ASSERT_TRUE(FuncInst->isHostFunction()); + auto &HostFuncImageToImage = FuncInst->getHostFunc(); std::string Prompt = "a lovely cat"; std::string Prompt2 = "with blue eyes";