Skip to content

Commit

Permalink
coomit
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Oct 10, 2023
1 parent 772f7aa commit 3e8c31b
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 54 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ jobs:
sudo wget https://asplos.dev/wasi-sdk-20.0-linux.tar.gz
sudo tar -xzf wasi-sdk-*.tar.gz
- name: Make WASM LD no check features
run: |
sudo mv /opt/wasi-sdk/bin/wasm-ld /opt/wasi-sdk/bin/wasm-ld.bak
echo '#!/bin/bash
/opt/wasi-sdk/bin/wasm-ld.bak --no-check-features "$@"' | sudo tee /opt/wasi-sdk/bin/wasm-ld
sudo chmod +x /opt/wasi-sdk/bin/wasm-ld
# - name: Make WASM LD no check features
# run: |
# sudo mv /opt/wasi-sdk/bin/wasm-ld /opt/wasi-sdk/bin/wasm-ld.bak
# echo '#!/bin/bash
# /opt/wasi-sdk/bin/wasm-ld.bak --no-check-features "$@"' | sudo tee /opt/wasi-sdk/bin/wasm-ld
# sudo chmod +x /opt/wasi-sdk/bin/wasm-ld

- name: Make WASI Socket Ext
run: |
Expand Down
52 changes: 26 additions & 26 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ include(ExternalProject)

# add_subdirectory(gapbs)
# add_subdirectory(clickhouse)
ExternalProject_Add(gapbs
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gapbs
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
-GUnix\ Makefiles
-DWASI_SDK_DIR=${WASI_SDK_DIR}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
${CMAKE_CURRENT_SOURCE_DIR}/gapbs
BUILD_COMMAND ${CMAKE_COMMAND} --build .
)
# ExternalProject_Add(gapbs
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gapbs
# UPDATE_COMMAND ""
# PATCH_COMMAND ""
# CONFIGURE_COMMAND ${CMAKE_COMMAND}
# -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
# -GNinja
# -DWASI_SDK_DIR=${WASI_SDK_DIR}
# -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
# -DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
# ${CMAKE_CURRENT_SOURCE_DIR}/gapbs
# BUILD_COMMAND ${CMAKE_COMMAND} --build .
# )

ExternalProject_Add(clickhouse
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
-GUnix\ Makefiles
-DWASI_SDK_DIR=${WASI_SDK_DIR}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
BUILD_COMMAND ${CMAKE_COMMAND} --build .
)
# ExternalProject_Add(clickhouse
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
# UPDATE_COMMAND ""
# PATCH_COMMAND ""
# CONFIGURE_COMMAND ${CMAKE_COMMAND}
# -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
# -GNinja
# -DWASI_SDK_DIR=${WASI_SDK_DIR}
# -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
# -DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
# ${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
# BUILD_COMMAND ${CMAKE_COMMAND} --build .
# )
4 changes: 2 additions & 2 deletions src/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
WAMRInstance *wamr = nullptr;
std::ostringstream re{};
auto writer = FwriteStream("test.bin");
std::vector<std::unique_ptr<WAMRExecEnv>> as;
std::mutex as_mtx;
constinit std::vector<std::unique_ptr<WAMRExecEnv>> as;
constinit std::mutex as_mtx;
/**fopen, fseek*/
void insert_fd(int fd, const char *path, int flags, int offset) {
printf("\n #insert_fd(fd,filename,flags, offset) %d %s %d %d \n\n",fd, path,flags, offset);
Expand Down
5 changes: 0 additions & 5 deletions src/wamr_wasi_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ void WAMRWASIContext::restore_impl(WASIContext *env) {
}
i++;
}
#endif
#ifdef __linux__
wamr->invoke_preopen(0, "/dev/stdin");
wamr->invoke_preopen(1, "/dev/stdout");
wamr->invoke_preopen(2, "/dev/stderr");
#endif
for (auto [fd, res] : this->fd_map) {
// differ from path from file
Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ enable_testing()
function(wamr_app input)
add_custom_target(${input}_wamr ALL COMMAND ${WASI_SDK_DIR}/bin/clang -Wno-implicit-function-declaration -Wno-int-conversion --target=wasm32-unknown-wasi -g -pthread -Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt --sysroot=${WASI_SDK_DIR}/share/wasi-sysroot ${CMAKE_CURRENT_SOURCE_DIR}/${input}.c -o ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
add_test(NAME ${input}_checkpoint COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../MVVM_checkpoint --target ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
# add_test(NAME ${input}_restore COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../MVVM_restore --target ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
add_test(NAME ${input}_restore COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../MVVM_restore --target ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
endfunction()

wamr_app(counter)
Expand All @@ -14,7 +14,7 @@ wamr_app(gups)
function(wamr_socket_app input)
add_custom_target(${input}_wamr ALL COMMAND ${WASI_SDK_DIR}/bin/clang --target=wasm32-unknown-wasi -g -pthread -Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt --sysroot=${WASI_SDK_DIR}/share/wasi-sysroot ${WAMR_DIR}/samples/socket-api/wasm-app-prefix/src/wasm-app-build/libsocket_wasi_ext.a -I${WAMR_DIR}/core/iwasm/libraries/lib-socket/inc/ ${CMAKE_CURRENT_SOURCE_DIR}/${input}.c -o ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
add_test(NAME ${input}_checkpoint COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../MVVM_checkpoint --target ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
# add_test(NAME ${input}_restore COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../MVVM_restore --target ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
add_test(NAME ${input}_restore COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../MVVM_restore --target ${CMAKE_CURRENT_BINARY_DIR}/${input}.wasm)
endfunction()

wamr_socket_app(server)
Expand Down
76 changes: 64 additions & 12 deletions test/read-file.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,77 @@

// #include <cstdio>
#include <stdio.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
// #include <cstdio>

FILE *fopen_test(const char *restrict filename, const char *restrict mode)
{
FILE *f;
int fd;
int flags;

/* Check for valid initial mode character */
if (!strchr("rwa", *mode)) {
return 0;
}

/* Compute the flags to pass to open() */
flags = __fmodeflags(mode);

#ifdef __wasilibc_unmodified_upstream // WASI has no sys_open
fd = sys_open(filename, flags, 0666);
#else
// WASI libc ignores the mode parameter anyway, so skip the varargs.
fd = __wasilibc_open_nomode(filename, flags);
printf("\n fopen_test(fd,filename,flags) %d %s %d \n\n",fd,filename,flags);
#endif
if (fd < 0) return 0;
#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
if (flags & O_CLOEXEC)
__syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC);
#else
/* Avoid __syscall, but also, FD_CLOEXEC is not supported in WASI. */
#endif

f = __fdopen(fd, mode);
if (f) return f;

#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
__syscall(SYS_close, fd);
#else
close(fd);
#endif
return 0;
}

int main() {
FILE *file = fopen("./text.txt", "w");
FILE *file = fopen_test("./text.txt", "w");

FILE *file1 = fopen("./text1.txt", "w");
FILE *file2 = fopen("./text2.txt", "w");
fseek(file,1,1);
int c = 0;
while (1){
FILE *file1 = fopen_test("./text1.txt", "w");
FILE *file2 = fopen_test("./text2.txt", "w");
// fseek(file,1,1);

/** Test fread*/
volatile int c = 0;
FILE *file3 = fopen_test("./test.txt", "a");
const char* line1 = "This is line 1\n";
const char* line2 = "This is line 2\n";
size_t len1 = strlen(line1);
size_t len2 = strlen(line2);

fwrite(line1, sizeof(char), len1, file3);

for( int i =0;i<10000;i++){
c++;
if (c==100000){
break;
}
}
fprintf(file, "Successfully wrote to the file.");
fwrite(line2, sizeof(char), len2, file3);

fclose(file);
fclose(file1);
fclose(file2);
}
fclose(file3);
}

0 comments on commit 3e8c31b

Please sign in to comment.