Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
7 changes: 7 additions & 0 deletions testing/cat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 47 additions & 0 deletions testing/cat/main.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#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;
}
Loading