Add standalone cases (#3536)
This commit is contained in:
59
tests/standalone/test-wasi1/main.c
Normal file
59
tests/standalone/test-wasi1/main.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int n, m;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage: %s <from> <to>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("##open %s\n", argv[1]);
|
||||
int in = open(argv[1], O_RDONLY);
|
||||
if (in < 0) {
|
||||
fprintf(stderr, "error opening input %s: %s\n", argv[1],
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("##open %s\n", argv[2]);
|
||||
int out = open(argv[2], O_WRONLY | O_CREAT, 0660);
|
||||
if (out < 0) {
|
||||
fprintf(stderr, "error opening output %s: %s\n", argv[2],
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("##read content of %s, and write it to %s\n", argv[1], argv[2]);
|
||||
while ((n = read(in, buf, BUFSIZ)) > 0) {
|
||||
while (n > 0) {
|
||||
m = write(out, buf, n);
|
||||
if (m < 0) {
|
||||
fprintf(stderr, "write error: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
n -= m;
|
||||
}
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
fprintf(stderr, "read error: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("##success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
30
tests/standalone/test-wasi1/run.sh
Executable file
30
tests/standalone/test-wasi1/run.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
if [[ $2 == "--sgx" ]];then
|
||||
readonly IWASM_CMD="../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm"
|
||||
else
|
||||
readonly IWASM_CMD="../../../product-mini/platforms/linux/build/iwasm"
|
||||
fi
|
||||
readonly WAMRC_CMD="../../../wamr-compiler/build/wamrc"
|
||||
|
||||
echo "============> compile test-wasi1 to wasm"
|
||||
/opt/wasi-sdk/bin/clang -O3 -z stack-size=16384 -Wl,--initial-memory=131072 \
|
||||
-Wl,--export=main -Wl,--export=__heap_base,--export=__data_end \
|
||||
-Wl,--allow-undefined \
|
||||
-o test-wasi1.wasm main.c
|
||||
|
||||
if [[ $1 != "--aot" ]]; then
|
||||
echo "============> run test-wasi1.wasm"
|
||||
${IWASM_CMD} --dir=. --dir=/tmp test-wasi1.wasm test.txt /tmp/somewhere.txt
|
||||
else
|
||||
echo "============> compile test-wasi1.wasm to aot"
|
||||
[[ $2 == "--sgx" ]] && ${WAMRC_CMD} -sgx -o test-wasi1.aot test-wasi1.wasm \
|
||||
|| ${WAMRC_CMD} -o test-wasi1.aot test-wasi1.wasm
|
||||
echo "============> run test-wasi1.aot"
|
||||
${IWASM_CMD} --dir=. --dir=/tmp test-wasi1.aot test.txt /tmp/somewhere.txt
|
||||
fi
|
||||
|
||||
2
tests/standalone/test-wasi1/test.txt
Normal file
2
tests/standalone/test-wasi1/test.txt
Normal file
@ -0,0 +1,2 @@
|
||||
hello world!
|
||||
1234
|
||||
Reference in New Issue
Block a user