From 89d59e312a56da50775a46becdad3b1a334dd29b Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 24 Mar 2026 09:24:12 +0100 Subject: [PATCH] feat(testing): cat Signed-off-by: Marco Casaroli --- CMakeLists.txt | 6 +++++ testing/cat/CMakeLists.txt | 7 ++++++ testing/cat/main.c | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 testing/cat/CMakeLists.txt create mode 100644 testing/cat/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 06a70fa..b0bdb78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,3 +147,9 @@ ExternalProject_Add(sleep5_return0 CMAKE_ARGS "-DCMAKE_VERBOSE_MAKEFILE:BOOL=${CMAKE_VERBOSE_MAKEFILE}" "-DWAMR_ROOT:STRING=${WAMR_ROOT}" INSTALL_COMMAND cp sleep5_return0.wasm ${CMAKE_CURRENT_BINARY_DIR}/dist ) + +ExternalProject_Add(cat + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/testing/cat + CMAKE_ARGS "-DCMAKE_VERBOSE_MAKEFILE:BOOL=${CMAKE_VERBOSE_MAKEFILE}" "-DWAMR_ROOT:STRING=${WAMR_ROOT}" + INSTALL_COMMAND cp cat.wasm ${CMAKE_CURRENT_BINARY_DIR}/dist +) diff --git a/testing/cat/CMakeLists.txt b/testing/cat/CMakeLists.txt new file mode 100644 index 0000000..b9b90be --- /dev/null +++ b/testing/cat/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.20.0) + +include(${CMAKE_CURRENT_LIST_DIR}/../../ocre.cmake) + +project(cat) + +add_executable(cat.wasm main.c) diff --git a/testing/cat/main.c b/testing/cat/main.c new file mode 100644 index 0000000..f6ac304 --- /dev/null +++ b/testing/cat/main.c @@ -0,0 +1,47 @@ +/* + * @copyright Copyright © contributors to Project Ocre, + * which has been established as Project Ocre a Series of LF Projects, LLC + + * SPDX-License-Identifier: Apache-2.0 + + */ + +#include +#include +#include +#include + +#define BUF_SIZE 4096 + +int main(int argc, char *argv[]) +{ + int use_stderr = 0; + int out_fd = STDOUT_FILENO; + + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "-e") == 0) { + use_stderr = 1; + out_fd = STDERR_FILENO; + } + } + + char buf[BUF_SIZE]; + ssize_t n; + + while ((n = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { + ssize_t written = 0; + while (written < n) { + ssize_t w = write(out_fd, buf + written, n - written); + if (w < 0) { + return 1; + } + written += w; + } + } + + if (n < 0) { + return 1; + } + + return 0; +}