From 5b695c95393472e61c663a9acd78ab9be8150963 Mon Sep 17 00:00:00 2001 From: "Hui, Chunyang" Date: Wed, 27 May 2020 07:02:34 +0000 Subject: [PATCH] Format c/c++ files in src, tools and test --- src/pal/include/errno2str.h | 2 +- src/pal/include/occlum_pal_api.h | 16 ++-- src/pal/src/errno2str.c | 46 ++++++---- src/pal/src/ocalls/attestation.c | 20 ++--- src/pal/src/ocalls/log.c | 8 +- src/pal/src/ocalls/mem.c | 8 +- src/pal/src/ocalls/net.c | 18 ++-- src/pal/src/ocalls/sched.c | 5 +- src/pal/src/ocalls/spawn.c | 11 +-- src/pal/src/ocalls/time.c | 12 +-- src/pal/src/pal_api.c | 26 +++--- src/pal/src/pal_enclave.c | 34 ++++---- src/pal/src/pal_error.c | 6 +- src/run/main.c | 13 ++- test/access/main.c | 5 +- test/chmod/main.c | 11 ++- test/chown/main.c | 11 ++- test/client/main.c | 29 ++++--- test/cout/main.cc | 6 +- test/cpuid/main.c | 25 +++--- test/data_sink/main.c | 2 +- test/device/main.c | 4 +- test/empty/main.c | 2 +- test/emulate_syscall/main.c | 26 +++--- test/env/main.c | 24 +++--- test/eventfd/main.c | 22 ++--- test/exit_group/main.c | 4 +- test/fcntl/main.c | 11 ++- test/file/main.c | 19 ++-- test/fs_perms/main.c | 35 ++++---- test/getpid/main.c | 2 +- test/hello_world/main.c | 7 +- test/hostfs/main.c | 11 ++- test/include/test.h | 6 +- test/ioctl/main.c | 33 ++++--- test/link/main.c | 22 ++--- test/malloc/main.c | 4 +- test/mkdir/main.c | 20 ++--- test/mmap/main.c | 96 ++++++++++----------- test/open/main.c | 8 +- test/pipe/main.c | 18 ++-- test/pipe_throughput/main.c | 6 +- test/pthread/main.c | 26 +++--- test/readdir/main.c | 2 +- test/rlimit/main.c | 2 +- test/sched/main.c | 10 +-- test/server/main.c | 76 +++++++++------- test/server_epoll/main.c | 11 +-- test/signal/main.c | 42 ++++----- test/sleep/main.c | 21 +++-- test/spawn/main.c | 2 +- test/spawn_and_exit_latency/main.c | 6 +- test/stat/main.c | 11 ++- test/symlink/main.c | 13 +-- test/tls/main.c | 4 +- test/truncate/main.c | 6 +- test/uname/main.c | 12 +-- test/unix_socket/main.c | 19 ++-- test/unix_socket_throughput/main.c | 8 +- tools/protect-integrity/App/App.cpp | 82 +++++++++--------- tools/protect-integrity/Enclave/Enclave.cpp | 28 +++--- 61 files changed, 567 insertions(+), 508 deletions(-) diff --git a/src/pal/include/errno2str.h b/src/pal/include/errno2str.h index 4861e525..29f07998 100644 --- a/src/pal/include/errno2str.h +++ b/src/pal/include/errno2str.h @@ -5,7 +5,7 @@ extern "C" { #endif -const char* errno2str(int errno_); +const char *errno2str(int errno_); #ifdef __cplusplus } diff --git a/src/pal/include/occlum_pal_api.h b/src/pal/include/occlum_pal_api.h index f23d299f..6395b687 100644 --- a/src/pal/include/occlum_pal_api.h +++ b/src/pal/include/occlum_pal_api.h @@ -30,14 +30,14 @@ typedef struct occlum_pal_attr { // ".occlum"; it can be renamed to an arbitrary name. // // Mandatory field. Must not be NULL. - const char* instance_dir; + const char *instance_dir; // Log level. // // Specifies the log level of Occlum LibOS. Valid values: "off", "error", // "warn", "info", and "trace". Case insensitive. // // Optional field. If NULL, the LibOS will treat it as "off". - const char* log_level; + const char *log_level; } occlum_pal_attr_t; #define OCCLUM_PAL_ATTR_INITVAL { \ @@ -61,7 +61,7 @@ typedef struct occlum_stdio_fds { * * @retval If 0, then success; otherwise, check errno for the exact error type. */ -int occlum_pal_init(const struct occlum_pal_attr* attr); +int occlum_pal_init(const struct occlum_pal_attr *attr); /* * @brief Execute a command inside the Occlum enclave @@ -82,11 +82,11 @@ int occlum_pal_init(const struct occlum_pal_attr* attr); * * @retval If 0, then success; otherwise, check errno for the exact error type. */ -int occlum_pal_exec(const char* cmd_path, - const char** cmd_args, - const char** cmd_env, - const struct occlum_stdio_fds* io_fds, - int* exit_status); +int occlum_pal_exec(const char *cmd_path, + const char **cmd_args, + const char **cmd_env, + const struct occlum_stdio_fds *io_fds, + int *exit_status); /* * @brief Send a signal to one or multiple LibOS processes diff --git a/src/pal/src/errno2str.c b/src/pal/src/errno2str.c index 5865e7dd..39acc7af 100644 --- a/src/pal/src/errno2str.c +++ b/src/pal/src/errno2str.c @@ -1,21 +1,35 @@ #include #include "errno2str.h" -const char* errno2str(int errno_) { - switch(errno_) { - case EPERM: return "EPERM"; - case ENOENT: return "ENOENT"; - case ESRCH: return "ESRCH"; - case ENOEXEC: return "ENOEXEC"; - case EBADF: return "EBADF"; - case ECHILD: return "ECHILD"; - case EAGAIN: return "EAGAIN"; - case ENOMEM: return "ENOMEM"; - case EACCES: return "EACCES"; - case EFAULT: return "EFAULT"; - case EBUSY: return "EBUSY"; - case EINVAL: return "EINVAL"; - case ENOSYS: return "ENOSYS"; - default: return "unknown"; +const char *errno2str(int errno_) { + switch (errno_) { + case EPERM: + return "EPERM"; + case ENOENT: + return "ENOENT"; + case ESRCH: + return "ESRCH"; + case ENOEXEC: + return "ENOEXEC"; + case EBADF: + return "EBADF"; + case ECHILD: + return "ECHILD"; + case EAGAIN: + return "EAGAIN"; + case ENOMEM: + return "ENOMEM"; + case EACCES: + return "EACCES"; + case EFAULT: + return "EFAULT"; + case EBUSY: + return "EBUSY"; + case EINVAL: + return "EINVAL"; + case ENOSYS: + return "ENOSYS"; + default: + return "unknown"; } } diff --git a/src/pal/src/ocalls/attestation.c b/src/pal/src/ocalls/attestation.c index 31fdb226..73c5de54 100644 --- a/src/pal/src/ocalls/attestation.c +++ b/src/pal/src/ocalls/attestation.c @@ -2,9 +2,8 @@ #include "ocalls.h" sgx_status_t occlum_ocall_sgx_init_quote( - sgx_target_info_t* target_info, - sgx_epid_group_id_t* epid_group_id) -{ + sgx_target_info_t *target_info, + sgx_epid_group_id_t *epid_group_id) { // Intel's manual: // It's suggested that the caller should wait (typically several seconds // to ten of seconds) and retry this API if SGX_ERROR_BUSY is returned. @@ -12,16 +11,15 @@ sgx_status_t occlum_ocall_sgx_init_quote( } sgx_status_t occlum_ocall_sgx_get_quote( - uint8_t* sigrl, + uint8_t *sigrl, uint32_t sigrl_len, - sgx_report_t* report, + sgx_report_t *report, sgx_quote_sign_type_t quote_type, - sgx_spid_t* spid, - sgx_quote_nonce_t* nonce, - sgx_report_t* qe_report, - sgx_quote_t* quote_buf, - uint32_t quote_buf_len) -{ + sgx_spid_t *spid, + sgx_quote_nonce_t *nonce, + sgx_report_t *qe_report, + sgx_quote_t *quote_buf, + uint32_t quote_buf_len) { sgx_status_t ret = SGX_SUCCESS; uint32_t real_quote_len; diff --git a/src/pal/src/ocalls/log.c b/src/pal/src/ocalls/log.c index 18694f4e..7d164587 100644 --- a/src/pal/src/ocalls/log.c +++ b/src/pal/src/ocalls/log.c @@ -16,18 +16,18 @@ typedef enum { #define COLOR_GREEN "\x1B[32m" static level_t new_level(unsigned int level) { - if (level >= 5) level = 5; + if (level >= 5) { level = 5; } return (level_t) level; } -void occlum_ocall_print_log(unsigned int _level, const char* msg) { +void occlum_ocall_print_log(unsigned int _level, const char *msg) { level_t level = new_level(_level); if (level == LEVEL_OFF) { return; } - const char* color; - switch(level) { + const char *color; + switch (level) { case LEVEL_ERROR: color = COLOR_RED; break; diff --git a/src/pal/src/ocalls/mem.c b/src/pal/src/ocalls/mem.c index bfeebaa8..2f7d3cde 100644 --- a/src/pal/src/ocalls/mem.c +++ b/src/pal/src/ocalls/mem.c @@ -1,15 +1,15 @@ #include #include "ocalls.h" -void* occlum_ocall_posix_memalign(size_t alignment, size_t size) { - void* ptr = NULL; +void *occlum_ocall_posix_memalign(size_t alignment, size_t size) { + void *ptr = NULL; int ret = posix_memalign(&ptr, alignment, size); if (ret == 0) { return ptr; } // Handle errors - switch(ret) { + switch (ret) { case ENOMEM: PAL_ERROR("Out of memory on the untrusted side"); break; @@ -22,6 +22,6 @@ void* occlum_ocall_posix_memalign(size_t alignment, size_t size) { return NULL; } -void occlum_ocall_free(void* ptr) { +void occlum_ocall_free(void *ptr) { free(ptr); } diff --git a/src/pal/src/ocalls/net.c b/src/pal/src/ocalls/net.c index bc699061..badfed87 100644 --- a/src/pal/src/ocalls/net.c +++ b/src/pal/src/ocalls/net.c @@ -11,14 +11,13 @@ ssize_t occlum_ocall_sendmsg(int sockfd, size_t msg_iovlen, const void *msg_control, size_t msg_controllen, - int flags) -{ + int flags) { struct msghdr msg = { - (void*) msg_name, + (void *) msg_name, msg_namelen, (struct iovec *) msg_iov, msg_iovlen, - (void*) msg_control, + (void *) msg_control, msg_controllen, 0, }; @@ -28,15 +27,14 @@ ssize_t occlum_ocall_sendmsg(int sockfd, ssize_t occlum_ocall_recvmsg(int sockfd, void *msg_name, socklen_t msg_namelen, - socklen_t* msg_namelen_recv, + socklen_t *msg_namelen_recv, struct iovec *msg_iov, size_t msg_iovlen, void *msg_control, size_t msg_controllen, - size_t* msg_controllen_recv, - int* msg_flags_recv, - int flags) -{ + size_t *msg_controllen_recv, + int *msg_flags_recv, + int flags) { struct msghdr msg = { msg_name, msg_namelen, @@ -47,7 +45,7 @@ ssize_t occlum_ocall_recvmsg(int sockfd, 0, }; ssize_t ret = recvmsg(sockfd, &msg, flags); - if (ret < 0) return ret; + if (ret < 0) { return ret; } *msg_namelen_recv = msg.msg_namelen; *msg_controllen_recv = msg.msg_controllen; diff --git a/src/pal/src/ocalls/sched.c b/src/pal/src/ocalls/sched.c index 8b94f56e..c7213835 100644 --- a/src/pal/src/ocalls/sched.c +++ b/src/pal/src/ocalls/sched.c @@ -3,7 +3,7 @@ #include #include "ocalls.h" -int occlum_ocall_sched_getaffinity(size_t cpusize, unsigned char* buf) { +int occlum_ocall_sched_getaffinity(size_t cpusize, unsigned char *buf) { int ret; cpu_set_t mask; CPU_ZERO(&mask); @@ -13,7 +13,8 @@ int occlum_ocall_sched_getaffinity(size_t cpusize, unsigned char* buf) { return ret; } -int occlum_ocall_sched_setaffinity(int host_tid, size_t cpusize, const unsigned char* buf) { +int occlum_ocall_sched_setaffinity(int host_tid, size_t cpusize, + const unsigned char *buf) { return syscall(__NR_sched_setaffinity, host_tid, cpusize, buf); } diff --git a/src/pal/src/ocalls/spawn.c b/src/pal/src/ocalls/spawn.c index bae97801..b4656537 100644 --- a/src/pal/src/ocalls/spawn.c +++ b/src/pal/src/ocalls/spawn.c @@ -7,15 +7,16 @@ typedef struct { int libos_tid; } thread_data_t; -void* exec_libos_thread(void* _thread_data) { - thread_data_t* thread_data = _thread_data; +void *exec_libos_thread(void *_thread_data) { + thread_data_t *thread_data = _thread_data; sgx_enclave_id_t eid = thread_data->enclave_id; int host_tid = gettid(); int libos_tid = thread_data->libos_tid; int libos_exit_status = -1; - sgx_status_t status = occlum_ecall_exec_thread(eid, &libos_exit_status, libos_tid, host_tid); + sgx_status_t status = occlum_ecall_exec_thread(eid, &libos_exit_status, libos_tid, + host_tid); if (status != SGX_SUCCESS) { - const char* sgx_err = pal_get_sgx_error_msg(status); + const char *sgx_err = pal_get_sgx_error_msg(status); PAL_ERROR("Failed to enter the enclave to execute a LibOS thread: %s", sgx_err); exit(EXIT_FAILURE); } @@ -29,7 +30,7 @@ int occlum_ocall_exec_thread_async(int libos_tid) { int ret = 0; pthread_t thread; - thread_data_t* thread_data = malloc(sizeof *thread_data); + thread_data_t *thread_data = malloc(sizeof * thread_data); thread_data->enclave_id = pal_get_enclave_id(); thread_data->libos_tid = libos_tid; diff --git a/src/pal/src/ocalls/time.c b/src/pal/src/ocalls/time.c index ca990e7e..af670dd6 100644 --- a/src/pal/src/ocalls/time.c +++ b/src/pal/src/ocalls/time.c @@ -2,7 +2,7 @@ #include #include "ocalls.h" -void occlum_ocall_gettimeofday(struct timeval* tv) { +void occlum_ocall_gettimeofday(struct timeval *tv) { gettimeofday(tv, NULL); } @@ -10,22 +10,22 @@ void occlum_ocall_clock_gettime(int clockid, struct timespec *tp) { clock_gettime(clockid, tp); } -void occlum_ocall_nanosleep(const struct timespec* req) { +void occlum_ocall_nanosleep(const struct timespec *req) { nanosleep(req, NULL); } int occlum_ocall_thread_getcpuclock(struct timespec *tp) { clockid_t thread_clock_id; int ret = pthread_getcpuclockid(pthread_self(), &thread_clock_id); - if(ret != 0) { - PAL_ERROR("failed to get clock id"); - return -1; + if (ret != 0) { + PAL_ERROR("failed to get clock id"); + return -1; } return clock_gettime(thread_clock_id, tp); } -void occlum_ocall_rdtsc(uint32_t* low, uint32_t* high) { +void occlum_ocall_rdtsc(uint32_t *low, uint32_t *high) { uint64_t rax, rdx; asm volatile("rdtsc" : "=a"(rax), "=d"(rdx)); *low = (uint32_t)rax; diff --git a/src/pal/src/pal_api.c b/src/pal/src/pal_api.c index 72b16e44..39a27ced 100644 --- a/src/pal/src/pal_api.c +++ b/src/pal/src/pal_api.c @@ -10,7 +10,7 @@ int occlum_pal_get_version(void) { return OCCLUM_PAL_VERSION; } -int occlum_pal_init(const struct occlum_pal_attr* attr) { +int occlum_pal_init(const struct occlum_pal_attr *attr) { errno = 0; if (attr == NULL) { @@ -35,9 +35,10 @@ int occlum_pal_init(const struct occlum_pal_attr* attr) { eid = pal_get_enclave_id(); int ecall_ret = 0; - sgx_status_t ecall_status = occlum_ecall_init(eid, &ecall_ret, attr->log_level, attr->instance_dir); + sgx_status_t ecall_status = occlum_ecall_init(eid, &ecall_ret, attr->log_level, + attr->instance_dir); if (ecall_status != SGX_SUCCESS) { - const char* sgx_err = pal_get_sgx_error_msg(ecall_status); + const char *sgx_err = pal_get_sgx_error_msg(ecall_status); PAL_ERROR("Failed to do ECall: %s", sgx_err); return -1; } @@ -49,11 +50,11 @@ int occlum_pal_init(const struct occlum_pal_attr* attr) { return 0; } -int occlum_pal_exec(const char* cmd_path, - const char** cmd_args, - const char** cmd_env, - const struct occlum_stdio_fds* io_fds, - int* exit_status) { +int occlum_pal_exec(const char *cmd_path, + const char **cmd_args, + const char **cmd_env, + const struct occlum_stdio_fds *io_fds, + int *exit_status) { errno = 0; if (cmd_path == NULL || cmd_args == NULL || exit_status == NULL) { @@ -69,9 +70,10 @@ int occlum_pal_exec(const char* cmd_path, } int ecall_ret = 0; // libos_tid - sgx_status_t ecall_status = occlum_ecall_new_process(eid, &ecall_ret, cmd_path, cmd_args, cmd_env, io_fds); + sgx_status_t ecall_status = occlum_ecall_new_process(eid, &ecall_ret, cmd_path, cmd_args, + cmd_env, io_fds); if (ecall_status != SGX_SUCCESS) { - const char* sgx_err = pal_get_sgx_error_msg(ecall_status); + const char *sgx_err = pal_get_sgx_error_msg(ecall_status); PAL_ERROR("Failed to do ECall: %s", sgx_err); return -1; } @@ -85,7 +87,7 @@ int occlum_pal_exec(const char* cmd_path, int host_tid = gettid(); ecall_status = occlum_ecall_exec_thread(eid, &ecall_ret, libos_tid, host_tid); if (ecall_status != SGX_SUCCESS) { - const char* sgx_err = pal_get_sgx_error_msg(ecall_status); + const char *sgx_err = pal_get_sgx_error_msg(ecall_status); PAL_ERROR("Failed to do ECall: %s", sgx_err); return -1; } @@ -112,7 +114,7 @@ int occlum_pal_kill(int pid, int sig) { int ecall_ret = 0; sgx_status_t ecall_status = occlum_ecall_kill(eid, &ecall_ret, pid, sig); if (ecall_status != SGX_SUCCESS) { - const char* sgx_err = pal_get_sgx_error_msg(ecall_status); + const char *sgx_err = pal_get_sgx_error_msg(ecall_status); PAL_ERROR("Failed to do ECall: %s", sgx_err); return -1; } diff --git a/src/pal/src/pal_enclave.c b/src/pal/src/pal_enclave.c index 3ccb191a..48e08ffc 100644 --- a/src/pal/src/pal_enclave.c +++ b/src/pal/src/pal_enclave.c @@ -31,24 +31,24 @@ static sgx_enclave_id_t global_eid = SGX_INVALID_ENCLAVE_ID; /* Get enclave debug flag according to env "OCCLUM_RELEASE_ENCLAVE" */ static int get_enclave_debug_flag() { - const char* release_enclave_val = getenv("OCCLUM_RELEASE_ENCLAVE"); + const char *release_enclave_val = getenv("OCCLUM_RELEASE_ENCLAVE"); if (release_enclave_val) { if (!strcmp(release_enclave_val, "1") || - !strcasecmp(release_enclave_val, "y") || - !strcasecmp(release_enclave_val, "yes") || - !strcasecmp(release_enclave_val, "true")) { + !strcasecmp(release_enclave_val, "y") || + !strcasecmp(release_enclave_val, "yes") || + !strcasecmp(release_enclave_val, "true")) { return 0; } } return 1; } -static const char* get_enclave_absolute_path(const char* instance_dir) { +static const char *get_enclave_absolute_path(const char *instance_dir) { static char enclave_path[MAX_PATH + 1] = {0}; strncat(enclave_path, instance_dir, MAX_PATH); strncat(enclave_path, "/build/lib/", MAX_PATH); strncat(enclave_path, ENCLAVE_FILENAME, MAX_PATH); - return (const char*)enclave_path; + return (const char *)enclave_path; } /* Initialize the enclave: @@ -56,7 +56,7 @@ static const char* get_enclave_absolute_path(const char* instance_dir) { * Step 2: call sgx_create_enclave to initialize an enclave instance * Step 3: save the launch token if it is updated */ -int pal_init_enclave(const char* instance_dir) { +int pal_init_enclave(const char *instance_dir) { char token_path[MAX_PATH] = {'\0'}; sgx_launch_token_t token = {0}; sgx_status_t ret = SGX_ERROR_UNEXPECTED; @@ -69,11 +69,11 @@ int pal_init_enclave(const char* instance_dir) { const char *home_dir = getpwuid(getuid())->pw_dir; if (home_dir != NULL && - (strlen(home_dir)+strlen("/")+sizeof(TOKEN_FILENAME)+1) <= MAX_PATH) { + (strlen(home_dir) + strlen("/") + sizeof(TOKEN_FILENAME) + 1) <= MAX_PATH) { /* compose the token path */ strncpy(token_path, home_dir, strlen(home_dir)); strncat(token_path, "/", strlen("/")); - strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)+1); + strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME) + 1); } else { /* if token path is too long or $HOME is NULL */ strncpy(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)); @@ -96,29 +96,31 @@ int pal_init_enclave(const char* instance_dir) { /* Step 2: call sgx_create_enclave to initialize an enclave instance */ /* Debug Support: set 2nd parameter to 1 */ - const char* enclave_path = get_enclave_absolute_path(instance_dir); + const char *enclave_path = get_enclave_absolute_path(instance_dir); int sgx_debug_flag = get_enclave_debug_flag(); - ret = sgx_create_enclave(enclave_path, sgx_debug_flag, &token, &updated, &global_eid, NULL); + ret = sgx_create_enclave(enclave_path, sgx_debug_flag, &token, &updated, &global_eid, + NULL); if (ret != SGX_SUCCESS) { - const char* sgx_err_msg = pal_get_sgx_error_msg(ret); + const char *sgx_err_msg = pal_get_sgx_error_msg(ret); PAL_ERROR("Failed to create enclave: %s", sgx_err_msg); - if (fp != NULL) fclose(fp); + if (fp != NULL) { fclose(fp); } return -1; } /* Step 3: save the launch token if it is updated */ if (updated == 0 || fp == NULL) { /* if the token is not updated, or file handler is invalid, do not perform saving */ - if (fp != NULL) fclose(fp); + if (fp != NULL) { fclose(fp); } return 0; } /* reopen the file with write capablity */ fp = freopen(token_path, "wb", fp); - if (fp == NULL) return 0; + if (fp == NULL) { return 0; } size_t write_num = fwrite(token, 1, sizeof(sgx_launch_token_t), fp); - if (write_num != sizeof(sgx_launch_token_t)) + if (write_num != sizeof(sgx_launch_token_t)) { PAL_WARN("Warning: Failed to save launch token to \"%s\".\n", token_path); + } fclose(fp); return 0; } diff --git a/src/pal/src/pal_error.c b/src/pal/src/pal_error.c index b023b129..dd458ac0 100644 --- a/src/pal/src/pal_error.c +++ b/src/pal/src/pal_error.c @@ -79,10 +79,10 @@ static sgx_err_msg_t err_msg_table[] = { }, }; -const char* pal_get_sgx_error_msg(sgx_status_t error) { - int err_max = sizeof err_msg_table/sizeof err_msg_table[0]; +const char *pal_get_sgx_error_msg(sgx_status_t error) { + int err_max = sizeof err_msg_table / sizeof err_msg_table[0]; for (int err_i = 0; err_i < err_max; err_i++) { - if(error == err_msg_table[err_i].err) { + if (error == err_msg_table[err_i].err) { return err_msg_table[err_i].msg; } } diff --git a/src/run/main.c b/src/run/main.c index 11622425..937ce0cd 100644 --- a/src/run/main.c +++ b/src/run/main.c @@ -6,25 +6,24 @@ #include #include -static const char* get_instance_dir(void) { - const char* instance_dir_from_env = (const char*) getenv("OCCLUM_INSTANCE_DIR"); +static const char *get_instance_dir(void) { + const char *instance_dir_from_env = (const char *) getenv("OCCLUM_INSTANCE_DIR"); if (instance_dir_from_env != NULL) { return instance_dir_from_env; - } - else { + } else { return "./.occlum"; } } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { // Parse arguments if (argc < 2) { fprintf(stderr, "[ERROR] occlum-run: at least one argument must be provided\n\n"); fprintf(stderr, "Usage: occlum-run []\n"); return EXIT_FAILURE; } - const char* cmd_path = (const char*) argv[1]; - const char** cmd_args = (const char**) &argv[2]; + const char *cmd_path = (const char *) argv[1]; + const char **cmd_args = (const char **) &argv[2]; extern const char **environ; // Check Occlum PAL version diff --git a/test/access/main.c b/test/access/main.c index 35e1d529..c9a94b7e 100644 --- a/test/access/main.c +++ b/test/access/main.c @@ -11,7 +11,7 @@ // ============================================================================ static int create_file(const char *file_path, mode_t mode) { - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int fd; fd = open(file_path, flags, mode); @@ -116,8 +116,9 @@ static int test_access_framework(test_access_func_t fn) { if (create_file(file_path, mode) < 0) { return -1; } - if (fn(file_path) < 0) + if (fn(file_path) < 0) { return -1; + } return 0; } diff --git a/test/chmod/main.c b/test/chmod/main.c index 7c1063da..b7b672ee 100644 --- a/test/chmod/main.c +++ b/test/chmod/main.c @@ -11,7 +11,7 @@ static int create_file(const char *file_path) { int fd; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00444; fd = open(file_path, flags, mode); @@ -85,12 +85,15 @@ typedef int(*test_chmod_func_t)(const char *); static int test_chmod_framework(test_chmod_func_t fn) { const char *file_path = "/root/test_filesystem_chmod.txt"; - if (create_file(file_path) < 0) + if (create_file(file_path) < 0) { return -1; - if (fn(file_path) < 0) + } + if (fn(file_path) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/chown/main.c b/test/chown/main.c index 5546881c..0f4bba24 100644 --- a/test/chown/main.c +++ b/test/chown/main.c @@ -11,7 +11,7 @@ static int create_file(const char *file_path) { int fd; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00444; fd = open(file_path, flags, mode); @@ -107,12 +107,15 @@ typedef int(*test_chown_func_t)(const char *); static int test_chown_framework(test_chown_func_t fn) { const char *file_path = "/root/test_filesystem_chown.txt"; - if (create_file(file_path) < 0) + if (create_file(file_path) < 0) { return -1; - if (fn(file_path) < 0) + } + if (fn(file_path) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/client/main.c b/test/client/main.c index 01dbf35c..283573c0 100644 --- a/test/client/main.c +++ b/test/client/main.c @@ -16,13 +16,15 @@ int connect_with_server(const char *addr_string, const char *port_string) { //"NULL" addr means connectionless, no need to connect to server - if (strcmp(addr_string, "NULL") == 0) + if (strcmp(addr_string, "NULL") == 0) { return 0; + } int ret = 0; int sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) + if (sockfd < 0) { THROW_ERROR("create socket error"); + } struct sockaddr_in servaddr; memset(&servaddr, 0, sizeof(servaddr)); @@ -44,8 +46,9 @@ int connect_with_server(const char *addr_string, const char *port_string) { } int neogotiate_msg(int server_fd, char *buf, int buf_size) { - if (read(server_fd, buf, buf_size) < 0) + if (read(server_fd, buf, buf_size) < 0) { THROW_ERROR("read failed"); + } if (write(server_fd, RESPONSE, sizeof(RESPONSE)) < 0) { THROW_ERROR("write failed"); @@ -54,8 +57,9 @@ int neogotiate_msg(int server_fd, char *buf, int buf_size) { } int client_send(int server_fd, char *buf) { - if (send(server_fd, buf, strlen(buf), 0) < 0) + if (send(server_fd, buf, strlen(buf), 0) < 0) { THROW_ERROR("send msg error"); + } return 0; } @@ -74,15 +78,17 @@ int client_sendmsg(int server_fd, char *buf) { msg.msg_flags = 0; ret = sendmsg(server_fd, &msg, 0); - if (ret <= 0) + if (ret <= 0) { THROW_ERROR("sendmsg failed"); + } msg.msg_iov = NULL; msg.msg_iovlen = 0; ret = sendmsg(server_fd, &msg, 0); - if (ret != 0) + if (ret != 0) { THROW_ERROR("empty sendmsg failed"); + } return ret; } @@ -95,7 +101,7 @@ int client_connectionless_sendmsg(char *buf) { servaddr.sin_family = AF_INET; servaddr.sin_port = htons(9900); - servaddr.sin_addr.s_addr= htonl(INADDR_ANY); + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); msg.msg_name = &servaddr; msg.msg_namelen = sizeof(servaddr); @@ -108,12 +114,14 @@ int client_connectionless_sendmsg(char *buf) { msg.msg_flags = 0; int server_fd = socket(AF_INET, SOCK_DGRAM, 0); - if (server_fd < 0) + if (server_fd < 0) { THROW_ERROR("create socket error"); + } ret = sendmsg(server_fd, &msg, 0); - if (ret <= 0) + if (ret <= 0) { THROW_ERROR("sendmsg failed"); + } return ret; } @@ -128,8 +136,7 @@ int main(int argc, const char *argv[]) { int port = strtol(argv[2], NULL, 10); int server_fd = connect_with_server(argv[1], argv[2]); - switch (port) - { + switch (port) { case 8800: neogotiate_msg(server_fd, buf, buf_size); break; diff --git a/test/cout/main.cc b/test/cout/main.cc index cb6ad8a5..c2c87b4c 100644 --- a/test/cout/main.cc +++ b/test/cout/main.cc @@ -1,5 +1,5 @@ #include -int main(){ - std::cout<< "hello world" <eax), - "=b" (p->ebx), - "=c" (p->ecx), - "=d" (p->edx) - : "a" (leaf), "c" (subleaf)); + : "=a" (p->eax), + "=b" (p->ebx), + "=c" (p->ecx), + "=d" (p->edx) + : "a" (leaf), "c" (subleaf)); } static bool is_cpuidinfo_equal(int leaf, t_cpuid_t *cpu, t_cpuid_t *cpu_sgx) { @@ -184,7 +183,7 @@ static int test_cpuid_with_invalid_leaf() { int leaf[] = {0x8, 0xC, 0xE, 0x11}; int subleaf = 0; - for (int i = 0; i < sizeof(leaf)/sizeof(leaf[0]); i++) { + for (int i = 0; i < sizeof(leaf) / sizeof(leaf[0]); i++) { if (leaf[i] > g_max_basic_leaf) { printf("Warning: test leaf 0x%x is greater than CPU max basic leaf. Skipped.\n", leaf[i]); continue; @@ -210,7 +209,7 @@ static int test_cpuid_with_oversized_leaf() { native_cpuid(leaf, subleaf, &cpu_max); if ((cpu.eax != cpu_max.eax) || (cpu.ebx != cpu_max.ebx) || - (cpu.ecx != cpu_max.ecx) || (cpu.edx != cpu_max.edx)) { + (cpu.ecx != cpu_max.ecx) || (cpu.edx != cpu_max.edx)) { THROW_ERROR("failed to call cpuid with oversize leaf"); } return 0; @@ -235,7 +234,7 @@ static int test_cpuid_with_random_leaf() { #define BUFF_SIZE (1024) static int test_cpuid_with_host_cpuidinfo() { char buff[BUFF_SIZE] = {0}; - FILE * fp = fopen("./test_cpuid.txt","r"); + FILE *fp = fopen("./test_cpuid.txt", "r"); if (fp == NULL) { THROW_ERROR("failed to open host cpuid.txt"); } @@ -244,7 +243,7 @@ static int test_cpuid_with_host_cpuidinfo() { uint32_t subleaf = 0; t_cpuid_t cpu = {0}; int num = sscanf(buff, " %x %x: eax=%x ebx=%x ecx=%x edx=%x", &leaf, &subleaf, - &cpu.eax, &cpu.ebx, &cpu.ecx, &cpu.edx); + &cpu.eax, &cpu.ebx, &cpu.ecx, &cpu.edx); if (num != 6) { continue; } @@ -253,9 +252,9 @@ static int test_cpuid_with_host_cpuidinfo() { if (!is_cpuidinfo_equal(leaf, &cpu, &cpu_sgx)) { printf("leaf:0x%x subleaf:0x%x\n", leaf, subleaf); printf("ori_eax:0x%x ori_ebx:0x%x ori_ecx:0x%x ori_edx:0x%x\n", - cpu.eax, cpu.ebx, cpu.ecx, cpu.edx); + cpu.eax, cpu.ebx, cpu.ecx, cpu.edx); printf("sgx_eax:0x%x sgx_ebx:0x%x sgx_ecx:0x%x sgx_edx:0x%x\n", - cpu_sgx.eax, cpu_sgx.ebx, cpu_sgx.ecx, cpu_sgx.edx); + cpu_sgx.eax, cpu_sgx.ebx, cpu_sgx.ecx, cpu_sgx.edx); THROW_ERROR("failed to check cpuid info"); } } diff --git a/test/data_sink/main.c b/test/data_sink/main.c index 0152c01c..d05b2cb7 100644 --- a/test/data_sink/main.c +++ b/test/data_sink/main.c @@ -6,7 +6,7 @@ #define MIN(x, y) ((x) <= (y) ? (x) : (y)) // This program consumes a specific amount of data from stdin -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { // Get the total number of bytes to read size_t remain_bytes = 0; while (read(0, &remain_bytes, sizeof(remain_bytes)) != sizeof(remain_bytes)); diff --git a/test/device/main.c b/test/device/main.c index f3933a1c..0bfaf162 100644 --- a/test/device/main.c +++ b/test/device/main.c @@ -10,7 +10,7 @@ // Test utilities // ============================================================================ -static int check_file_readable(const char* filename) { +static int check_file_readable(const char *filename) { int fd; char buf[512] = {0}; int len; @@ -24,7 +24,7 @@ static int check_file_readable(const char* filename) { return 0; } -static int check_file_writable(const char* filename) { +static int check_file_writable(const char *filename) { int fd; char buf[512] = {0}; int len; diff --git a/test/empty/main.c b/test/empty/main.c index 11a3d8fc..857bcc02 100644 --- a/test/empty/main.c +++ b/test/empty/main.c @@ -1,3 +1,3 @@ -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return 0; } diff --git a/test/emulate_syscall/main.c b/test/emulate_syscall/main.c index 41e3b45a..94e2221c 100644 --- a/test/emulate_syscall/main.c +++ b/test/emulate_syscall/main.c @@ -29,8 +29,8 @@ static inline uint64_t native_syscall(syscall_args_t *p) { register unsigned long arg5 asm ("r9") = p->arg5; asm volatile("syscall" - : "=a" (ret) - : "r" (num), "r" (arg0), "r" (arg1), "r" (arg2), "r" (arg3), "r" (arg4), "r" (arg5)); + : "=a" (ret) + : "r" (num), "r" (arg0), "r" (arg1), "r" (arg2), "r" (arg3), "r" (arg4), "r" (arg5)); return ret; } @@ -47,13 +47,13 @@ static inline uint64_t native_syscall(syscall_args_t *p) { int test_mmap_and_munmap_via_syscall_instruction() { int len = PAGE_SIZE; syscall_args_t mmap_arg = { - .num= __NR_mmap, - .arg0 = (unsigned long) NULL, - .arg1 = len, - .arg2 = PROT_READ | PROT_WRITE, - .arg3 = MAP_PRIVATE | MAP_ANONYMOUS, - .arg4 = -1, - .arg5 = 0, + .num = __NR_mmap, + .arg0 = (unsigned long) NULL, + .arg1 = len, + .arg2 = PROT_READ | PROT_WRITE, + .arg3 = MAP_PRIVATE | MAP_ANONYMOUS, + .arg4 = -1, + .arg5 = 0, }; char *buf = (char *) native_syscall(&mmap_arg); if (buf == MAP_FAILED) { @@ -66,9 +66,9 @@ int test_mmap_and_munmap_via_syscall_instruction() { } syscall_args_t munmap_arg = { - .num= __NR_munmap, - .arg0 = (unsigned long) buf, - .arg1 = len, + .num = __NR_munmap, + .arg0 = (unsigned long) buf, + .arg1 = len, }; int ret = native_syscall(&munmap_arg); if (ret < 0) { @@ -84,6 +84,6 @@ static test_case_t test_cases[] = { TEST_CASE(test_mmap_and_munmap_via_syscall_instruction), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return test_suite_run(test_cases, ARRAY_SIZE(test_cases)); } diff --git a/test/env/main.c b/test/env/main.c index 5a9638ce..4efc7c81 100644 --- a/test/env/main.c +++ b/test/env/main.c @@ -13,12 +13,12 @@ // Helper structs & variables & functions // ============================================================================ -const char** g_argv; +const char **g_argv; int g_argc; // Expected arguments are given by Makefile throught macro ARGC, ARG1, ARG2 and // ARG3 -const char* expect_argv[EXPECT_ARGC] = { +const char *expect_argv[EXPECT_ARGC] = { "env", EXPECT_ARG1, EXPECT_ARG2, @@ -27,40 +27,40 @@ const char* expect_argv[EXPECT_ARGC] = { // Expected child arguments const int child_argc = 2; -const char* child_argv[3] = { +const char *child_argv[3] = { "env", "child", NULL }; // Expected child environment variables -const char* child_envp[] = { +const char *child_envp[] = { "ENV_CHILD=ok", NULL }; -static int test_argv_val(const char** expect_argv) { +static int test_argv_val(const char **expect_argv) { for (int arg_i = 0; arg_i < g_argc; arg_i++) { - const char* actual_arg = *(g_argv + arg_i); - const char* expect_arg = *(expect_argv + arg_i); + const char *actual_arg = *(g_argv + arg_i); + const char *expect_arg = *(expect_argv + arg_i); if (strcmp(actual_arg, expect_arg) != 0) { printf("ERROR: expect argument %d is %s, but given %s\n", - arg_i, expect_arg, actual_arg); + arg_i, expect_arg, actual_arg); return -1; } } return 0; } -static int test_env_val(const char* expect_env_key, const char* expect_env_val) { - const char* actual_env_val = getenv(expect_env_key); +static int test_env_val(const char *expect_env_key, const char *expect_env_val) { + const char *actual_env_val = getenv(expect_env_key); if (actual_env_val == NULL) { printf("ERROR: cannot find %s\n", expect_env_key); return -1; } if (strcmp(actual_env_val, expect_env_val) != 0) { printf("ERROR: environment variable %s=%s expected, but given %s\n", - expect_env_key, expect_env_val, actual_env_val); + expect_env_key, expect_env_val, actual_env_val); return -1; } return 0; @@ -204,7 +204,7 @@ static test_case_t child_test_cases[] = { TEST_CASE(test_env_child_getenv), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { // Save argument for test cases g_argc = argc; g_argv = argv; diff --git a/test/eventfd/main.c b/test/eventfd/main.c index 9af406b5..5c2078c5 100644 --- a/test/eventfd/main.c +++ b/test/eventfd/main.c @@ -131,7 +131,7 @@ int test_read_write() { THROW_ERROR("received length is not as expected"); } data_recv += cur_data; - } while (data_recv != TEST_DATA*CHILD_NUM); + } while (data_recv != TEST_DATA * CHILD_NUM); close(event_fd); @@ -162,14 +162,14 @@ int test_select_with_socket() { FD_SET(sock, &wfds); FD_SET(event_fd, &rfds); FD_SET(event_fd, &wfds); - ret = select(sock > event_fd? sock + 1: event_fd + 1, &rfds, &wfds, NULL, &tv); + ret = select(sock > event_fd ? sock + 1 : event_fd + 1, &rfds, &wfds, NULL, &tv); if (ret != 3) { close_files(2, sock, event_fd); THROW_ERROR("select failed"); } if (FD_ISSET(event_fd, &rfds) == 1 || FD_ISSET(event_fd, &wfds) == 0 || - FD_ISSET(sock, &rfds) == 0 || FD_ISSET(sock, &wfds) == 0) { + FD_ISSET(sock, &rfds) == 0 || FD_ISSET(sock, &wfds) == 0) { close_files(2, sock, event_fd); THROW_ERROR("bad select return"); } @@ -211,15 +211,15 @@ int test_epoll_with_socket() { struct epoll_event ctl_events[2] = {0}; // Add eventfd to the interest list - ctl_events[0].data.fd = event_fd; - ctl_events[0].events = EPOLLIN | EPOLLET; + ctl_events[0].data.fd = event_fd; + ctl_events[0].events = EPOLLIN | EPOLLET; // Add socket to the interest list - ctl_events[1].data.fd = sock; - ctl_events[1].events = EPOLLIN | EPOLLET; - if (epoll_ctl(epfd, EPOLL_CTL_ADD, event_fd, &ctl_events[0]) == -1 || + ctl_events[1].data.fd = sock; + ctl_events[1].events = EPOLLIN | EPOLLET; + if (epoll_ctl(epfd, EPOLL_CTL_ADD, event_fd, &ctl_events[0]) == -1 || epoll_ctl(epfd, EPOLL_CTL_ADD, sock, &ctl_events[1]) == -1) { close_files(3, event_fd, sock, epfd); - THROW_ERROR("epoll_ctl"); + THROW_ERROR("epoll_ctl"); } struct thread_arg child_arg = { .tid = 0, .fd = event_fd, .data = TEST_DATA }; @@ -229,7 +229,7 @@ int test_epoll_with_socket() { } struct epoll_event events[MAXEVENTS] = {0}; - if (epoll_pwait(epfd, events, MAXEVENTS, -1, NULL) <= 0){ + if (epoll_pwait(epfd, events, MAXEVENTS, -1, NULL) <= 0) { close_files(3, event_fd, sock, epfd); THROW_ERROR("epoll failed"); } @@ -256,6 +256,6 @@ static test_case_t test_cases[] = { TEST_CASE(test_select_with_socket), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return test_suite_run(test_cases, ARRAY_SIZE(test_cases)); } diff --git a/test/exit_group/main.c b/test/exit_group/main.c index e1872975..fb541685 100644 --- a/test/exit_group/main.c +++ b/test/exit_group/main.c @@ -16,7 +16,7 @@ // // Type 1: a busy loop thread -static void* busyloop_thread_func(void* _) { +static void *busyloop_thread_func(void *_) { while (1) { // By calling getpid, we give the LibOS a chance to force the thread // to terminate if exit_group is called by any thread in a thread group @@ -49,7 +49,7 @@ int test_exit_group_to_force_threads_terminate(void) { return -1; } - // Disable below two test cases, needs interrupt support + // Disable below two test cases, needs interrupt support // pthread_t sleeping_thread; // if (pthread_create(&sleeping_thread, NULL, sleeping_thread_func, NULL) < 0) { // printf("ERROR: pthread_create failed\n"); diff --git a/test/fcntl/main.c b/test/fcntl/main.c index 221d3502..7dc149a9 100644 --- a/test/fcntl/main.c +++ b/test/fcntl/main.c @@ -57,10 +57,11 @@ static int __fcntl_getlk_and_setlk(int fd, int open_flags) { } // setlk - if ((open_flags & O_WRONLY) || (open_flags & O_RDWR)) + if ((open_flags & O_WRONLY) || (open_flags & O_RDWR)) { fl.l_type = F_WRLCK; - else + } else { fl.l_type = F_RDLCK; + } ret = fcntl(fd, F_SETLK, &fl); if (ret < 0) { THROW_ERROR("failed to call setlk"); @@ -70,8 +71,9 @@ static int __fcntl_getlk_and_setlk(int fd, int open_flags) { } static int __fcntl_dupfd(int fd, int open_flags) { - if (fcntl(fd, F_DUPFD, 0) < 0) + if (fcntl(fd, F_DUPFD, 0) < 0) { THROW_ERROR("failed to duplicate the fd"); + } return 0; } @@ -87,8 +89,9 @@ static int test_fcntl_framework(test_fcntl_func_t fn) { if (fd < 0) { THROW_ERROR("failed to open & create file"); } - if (fn(fd, open_flags) < 0) + if (fn(fd, open_flags) < 0) { return -1; + } close(fd); ret = unlink(file_path); if (ret < 0) { diff --git a/test/file/main.c b/test/file/main.c index 00a8f3c6..d372d4eb 100644 --- a/test/file/main.c +++ b/test/file/main.c @@ -13,7 +13,7 @@ static int create_file(const char *file_path) { int fd; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00666; fd = open(file_path, flags, mode); if (fd < 0) { @@ -99,7 +99,7 @@ static int __test_pwrite_pread(const char *file_path) { } static int __test_writev_readv(const char *file_path) { - const char* iov_msg[2] = {"hello_", "world!"}; + const char *iov_msg[2] = {"hello_", "world!"}; char read_buf[128] = { 0 }; struct iovec iov[2]; int fd, len = 0; @@ -108,8 +108,8 @@ static int __test_writev_readv(const char *file_path) { if (fd < 0) { THROW_ERROR("failed to open a file to writev"); } - for(int i = 0; i < 2; ++i) { - iov[i].iov_base = (void*)iov_msg[i]; + for (int i = 0; i < 2; ++i) { + iov[i].iov_base = (void *)iov_msg[i]; iov[i].iov_len = strlen(iov_msg[i]); len += iov[i].iov_len; } @@ -130,7 +130,7 @@ static int __test_writev_readv(const char *file_path) { THROW_ERROR("failed to read vectors from the file"); } if (memcmp(read_buf, iov_msg[0], strlen(iov_msg[0])) != 0 || - memcmp(read_buf + strlen(iov_msg[0]), iov_msg[1], strlen(iov_msg[1])) != 0) { + memcmp(read_buf + strlen(iov_msg[0]), iov_msg[1], strlen(iov_msg[1])) != 0) { THROW_ERROR("the message read from the file is not as it was written"); } close(fd); @@ -177,12 +177,15 @@ typedef int(*test_file_func_t)(const char *); static int test_file_framework(test_file_func_t fn) { const char *file_path = "/root/test_filesystem_file_read_write.txt"; - if (create_file(file_path) < 0) + if (create_file(file_path) < 0) { return -1; - if (fn(file_path) < 0) + } + if (fn(file_path) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/fs_perms/main.c b/test/fs_perms/main.c index 3be86f3e..ca83af30 100644 --- a/test/fs_perms/main.c +++ b/test/fs_perms/main.c @@ -30,11 +30,11 @@ static int open_file(const char *filename, int flags, int mode) { return fd; } -static const char* write_msg = "Hello SEFS 1234567890\n"; +static const char *write_msg = "Hello SEFS 1234567890\n"; static int write_file(int fd) { int len = strlen(write_msg); - if ((len = write(fd, write_msg, len)<= 0)) { + if ((len = write(fd, write_msg, len) <= 0)) { PRINT_DBG("ERROR: failed to write to the file\n"); return -1; } @@ -43,7 +43,7 @@ static int write_file(int fd) { return 0; } -static int read_file(int fd){ +static int read_file(int fd) { int len; char read_buf[128] = {0}; if ((len = read(fd, read_buf, sizeof(read_buf) - 1)) <= 0) { @@ -65,14 +65,13 @@ static int read_file(int fd){ // do read or write according to do_write // check the result of the read/write with the given expected_result static int do_perm_tests( - const char** files, + const char **files, size_t num_files, int flags, int do_write, - int* expected_results) -{ + int *expected_results) { flags |= O_CREAT | O_TRUNC; - for(size_t i = 0; i < num_files; i++) { - const char* filename = files[i]; + for (size_t i = 0; i < num_files; i++) { + const char *filename = files[i]; int expected_result = expected_results[i]; int fd = open_file(filename, flags, 0666); @@ -89,7 +88,7 @@ static int do_perm_tests( // ============================================================================ // Test files -static const char* test_files[NUM_TEST_FILES] = { +static const char *test_files[NUM_TEST_FILES] = { "/test_fs_perms.txt", "/bin/test_fs_perms.txt", "/lib/test_fs_perms.txt", @@ -98,7 +97,7 @@ static const char* test_files[NUM_TEST_FILES] = { }; // Test cases X Test files -> Test Results -static int test_expected_results[NUM_TEST_CASES][NUM_TEST_FILES]= { +static int test_expected_results[NUM_TEST_CASES][NUM_TEST_FILES] = { // test_open_ro_then_write() {NG, NG, NG, NG, NG}, // test_open_wo_then_write() @@ -115,32 +114,32 @@ static int test_expected_results[NUM_TEST_CASES][NUM_TEST_FILES]= { int test_open_ro_then_write() { return do_perm_tests(test_files, NUM_TEST_FILES, - O_RDONLY, 1, test_expected_results[0]); + O_RDONLY, 1, test_expected_results[0]); } int test_open_wo_then_write() { return do_perm_tests(test_files, NUM_TEST_FILES, - O_WRONLY, 1, test_expected_results[1]); + O_WRONLY, 1, test_expected_results[1]); } int test_open_rw_then_write() { return do_perm_tests(test_files, NUM_TEST_FILES, - O_RDWR, 1, test_expected_results[2]); + O_RDWR, 1, test_expected_results[2]); } int test_open_ro_then_read() { return do_perm_tests(test_files, NUM_TEST_FILES, - O_RDONLY, 0, test_expected_results[3]); + O_RDONLY, 0, test_expected_results[3]); } -int test_open_wo_then_read(){ +int test_open_wo_then_read() { return do_perm_tests(test_files, NUM_TEST_FILES, - O_WRONLY, 0, test_expected_results[4]); + O_WRONLY, 0, test_expected_results[4]); } int test_open_rw_then_read() { return do_perm_tests(test_files, NUM_TEST_FILES, - O_RDWR, 0, test_expected_results[5]); + O_RDWR, 0, test_expected_results[5]); } // ============================================================================ @@ -156,6 +155,6 @@ test_case_t test_cases[NUM_TEST_CASES] = { TEST_CASE(test_open_rw_then_read) }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return test_suite_run(test_cases, NUM_TEST_CASES); } diff --git a/test/getpid/main.c b/test/getpid/main.c index 4479952f..7643df8c 100644 --- a/test/getpid/main.c +++ b/test/getpid/main.c @@ -2,7 +2,7 @@ #include #include -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { printf("Run a new process with pid = %d and ppid = %d\n", getpid(), getppid()); return 0; } diff --git a/test/hello_world/main.c b/test/hello_world/main.c index 82872cff..bd2b72a0 100644 --- a/test/hello_world/main.c +++ b/test/hello_world/main.c @@ -2,12 +2,11 @@ #include #include -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { if (argc <= 1) { printf("Hello World!\n"); - } - else { - const char* echo_msg = argv[1]; + } else { + const char *echo_msg = argv[1]; printf("%s\n", echo_msg); } return 0; diff --git a/test/hostfs/main.c b/test/hostfs/main.c index 5c6352cf..1f2abc26 100644 --- a/test/hostfs/main.c +++ b/test/hostfs/main.c @@ -12,7 +12,7 @@ static int create_file(const char *file_path) { int fd; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00666; fd = open(file_path, flags, mode); if (fd < 0) { @@ -90,12 +90,15 @@ typedef int(*test_hostfs_func_t)(const char *); static int test_hostfs_framework(test_hostfs_func_t fn) { const char *file_path = "/host/hostfs_test.txt"; - if (create_file(file_path) < 0) + if (create_file(file_path) < 0) { return -1; - if (fn(file_path) < 0) + } + if (fn(file_path) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/include/test.h b/test/include/test.h index 52bc5b91..9af38aa7 100644 --- a/test/include/test.h +++ b/test/include/test.h @@ -14,7 +14,7 @@ typedef int(*test_case_func_t)(void); typedef struct { - const char* name; + const char *name; test_case_func_t func; } test_case_t; @@ -26,9 +26,9 @@ typedef struct { return -1; \ } while (0) -int test_suite_run(test_case_t* test_cases, int num_test_cases) { +int test_suite_run(test_case_t *test_cases, int num_test_cases) { for (int ti = 0; ti < num_test_cases; ti++) { - test_case_t* tc = &test_cases[ti]; + test_case_t *tc = &test_cases[ti]; if (tc->func() < 0) { printf(" func %s - [ERR]\n", tc->name); return -1; diff --git a/test/ioctl/main.c b/test/ioctl/main.c index 16beb834..6c41b3b6 100644 --- a/test/ioctl/main.c +++ b/test/ioctl/main.c @@ -38,19 +38,19 @@ typedef struct { sgx_quote_sign_type_t quote_type; // input sgx_spid_t spid; // input sgx_quote_nonce_t nonce; // input - const uint8_t* sigrl_ptr; // input (optional) + const uint8_t *sigrl_ptr; // input (optional) uint32_t sigrl_len; // input (optional) uint32_t quote_buf_len; // input union { - uint8_t* as_buf; - sgx_quote_t* as_quote; + uint8_t *as_buf; + sgx_quote_t *as_quote; } quote; // output } sgxioc_gen_quote_arg_t; typedef struct { - const sgx_target_info_t* target_info; // input (optinal) - const sgx_report_data_t* report_data; // input (optional) - sgx_report_t* report; // output + const sgx_target_info_t *target_info; // input (optinal) + const sgx_report_data_t *report_data; // input (optional) + sgx_report_t *report; // output } sgxioc_create_report_arg_t; #define SGXIOC_IS_EDMM_SUPPORTED _IOR('s', 0, int) @@ -83,8 +83,7 @@ static int do_SGXIOC_GET_EPID_GROUP_ID(int sgx_fd) { int ret = ioctl(sgx_fd, SGXIOC_GET_EPID_GROUP_ID, &epid_group_id); if (ret == 0) { break; - } - else if (errno != EBUSY) { + } else if (errno != EBUSY) { THROW_ERROR("failed to ioctl /dev/sgx"); } @@ -108,15 +107,14 @@ static int do_SGXIOC_GEN_QUOTE(int sgx_fd) { .sigrl_ptr = NULL, // input (optional) .sigrl_len = 0, // input (optional) .quote_buf_len = sizeof(quote_buf), // input - .quote = { .as_buf = (uint8_t*) quote_buf } // output + .quote = { .as_buf = (uint8_t *) quote_buf } // output }; int nretries = 0; while (nretries < IOCTL_MAX_RETRIES) { int ret = ioctl(sgx_fd, SGXIOC_GEN_QUOTE, &gen_quote_arg); if (ret == 0) { break; - } - else if (errno != EBUSY) { + } else if (errno != EBUSY) { THROW_ERROR("failed to ioctl /dev/sgx"); } @@ -128,14 +126,15 @@ static int do_SGXIOC_GEN_QUOTE(int sgx_fd) { THROW_ERROR("failed to ioctl /dev/sgx due to timeout"); } - sgx_quote_t* quote = (sgx_quote_t*)quote_buf; + sgx_quote_t *quote = (sgx_quote_t *)quote_buf; if (quote->sign_type != SGX_LINKABLE_SIGNATURE) { THROW_ERROR("invalid quote: wrong sign type"); } if (quote->signature_len == 0) { THROW_ERROR("invalid quote: zero-length signature"); } - if (memcmp(&gen_quote_arg.report_data, "e->report_body.report_data, sizeof(sgx_report_data_t)) != 0) { + if (memcmp(&gen_quote_arg.report_data, "e->report_body.report_data, + sizeof(sgx_report_data_t)) != 0) { THROW_ERROR("invalid quote: wrong report data"); } return 0; @@ -174,19 +173,19 @@ static int do_SGXIOC_CREATE_AND_VERIFY_REPORT(int sgx_fd) { sgxioc_create_report_arg_t args[] = { { - .target_info = (const sgx_target_info_t*) &target_info, + .target_info = (const sgx_target_info_t *) &target_info, .report_data = NULL, .report = &report }, { - .target_info = (const sgx_target_info_t*) &target_info, - .report_data = (const sgx_report_data_t*) &report_data, + .target_info = (const sgx_target_info_t *) &target_info, + .report_data = (const sgx_report_data_t *) &report_data, .report = &report } }; for (int arg_i = 0; arg_i < ARRAY_SIZE(args); arg_i++) { memset(&report, 0, sizeof(report)); - sgxioc_create_report_arg_t* arg = &args[arg_i]; + sgxioc_create_report_arg_t *arg = &args[arg_i]; if (ioctl(sgx_fd, SGXIOC_CREATE_REPORT, arg) < 0) { THROW_ERROR("failed to create report"); } diff --git a/test/link/main.c b/test/link/main.c index fbc12129..6317404e 100644 --- a/test/link/main.c +++ b/test/link/main.c @@ -6,15 +6,15 @@ #include #include -int main(int argc, const char* argv[]) { - const char* file_name = "/root/test_filesystem_link.txt"; - const char* link_name = "/root/link.txt"; - const char* write_msg = "Hello World\n"; +int main(int argc, const char *argv[]) { + const char *file_name = "/root/test_filesystem_link.txt"; + const char *link_name = "/root/link.txt"; + const char *write_msg = "Hello World\n"; char read_buf[128] = {0}; int ret; // create a file and write message - int flags = O_WRONLY | O_CREAT| O_TRUNC; + int flags = O_WRONLY | O_CREAT | O_TRUNC; int mode = 00666; int fd = open(file_name, flags, mode); if (fd < 0) { @@ -30,7 +30,7 @@ int main(int argc, const char* argv[]) { // link ret = link(file_name, link_name); - if(ret < 0) { + if (ret < 0) { printf("ERROR: failed to link the file\n"); return -1; } @@ -54,7 +54,7 @@ int main(int argc, const char* argv[]) { // unlink ret = unlink(link_name); - if(ret < 0) { + if (ret < 0) { printf("ERROR: failed to link the file\n"); return -1; } @@ -62,26 +62,26 @@ int main(int argc, const char* argv[]) { // stat struct stat stat_buf; ret = stat(link_name, &stat_buf); - if(!(ret < 0 && errno == ENOENT)) { + if (!(ret < 0 && errno == ENOENT)) { printf("ERROR: stat on \"%s\" should return ENOENT", link_name); return -1; } // rename ret = rename(file_name, link_name); - if(ret < 0) { + if (ret < 0) { printf("ERROR: failed to rename the file"); return -1; } // stat ret = stat(file_name, &stat_buf); - if(!(ret < 0 && errno == ENOENT)) { + if (!(ret < 0 && errno == ENOENT)) { printf("ERROR: stat on \"%s\" should return ENOENT", file_name); return -1; } ret = stat(link_name, &stat_buf); - if(ret < 0) { + if (ret < 0) { printf("ERROR: failed to stat the file"); return -1; } diff --git a/test/malloc/main.c b/test/malloc/main.c index a3ec42c1..4cb2484b 100644 --- a/test/malloc/main.c +++ b/test/malloc/main.c @@ -4,11 +4,11 @@ #define MAX_SIZE (1*1024*1024) #define MIN_SIZE 8 -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { printf("Testing malloc and free...\n"); for (size_t buf_size = MIN_SIZE; buf_size <= MAX_SIZE; buf_size *= 4) { printf("buf_size = %lu\n", buf_size); - void* buf = malloc(buf_size); + void *buf = malloc(buf_size); if (buf == NULL) { printf("ERROR: failed to malloc for a buffer of %lu size\n", buf_size); return -1; diff --git a/test/mkdir/main.c b/test/mkdir/main.c index 90c08ab3..04486f78 100644 --- a/test/mkdir/main.c +++ b/test/mkdir/main.c @@ -5,20 +5,20 @@ #include #include -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { const int BUF_SIZE = 20; char buf[10]; int ret; - char* cwd = getcwd(buf, BUF_SIZE); - if(cwd != buf) { + char *cwd = getcwd(buf, BUF_SIZE); + if (cwd != buf) { printf("failed to getcwd\n"); return -1; } const char expect_cwd[] = "/"; - if(strcmp(buf, expect_cwd)) { + if (strcmp(buf, expect_cwd)) { printf("incorrect cwd \"%s\". expect \"%s\".\n", buf, expect_cwd); return -1; } @@ -29,37 +29,37 @@ int main(int argc, const char* argv[]) { const char DIR_PATH[] = "/root/test_dir"; const int DIR_MODE = 0664; ret = mkdir(DIR_NAME, DIR_MODE); - if(ret < 0) { + if (ret < 0) { printf("failed to mkdir \"%s\"", DIR_NAME); return ret; } ret = chdir(DIR_NAME); - if(ret < 0) { + if (ret < 0) { printf("failed to chdir to \"%s\"", DIR_NAME); return ret; } cwd = getcwd(buf, BUF_SIZE); - if(cwd != buf) { + if (cwd != buf) { printf("failed to getcwd\n"); return -1; } - if(strcmp(buf, DIR_PATH)) { + if (strcmp(buf, DIR_PATH)) { printf("incorrect cwd \"%s\". expect \"%s\".\n", buf, DIR_PATH); return -1; } ret = rmdir(DIR_PATH); - if(ret < 0) { + if (ret < 0) { printf("failed to rmdir \"%s\"", DIR_PATH); return ret; } struct stat stat_buf; ret = stat(DIR_PATH, &stat_buf); - if(!(ret < 0 && errno == ENOENT)) { + if (!(ret < 0 && errno == ENOENT)) { printf("stat on \"%s\" should return ENOENT", DIR_PATH); return ret; } diff --git a/test/mmap/main.c b/test/mmap/main.c index 82dc3456..80682508 100644 --- a/test/mmap/main.c +++ b/test/mmap/main.c @@ -43,20 +43,20 @@ static int fill_file_with_repeated_bytes(int fd, size_t len, int byte_val) { return 0; } -static int check_bytes_in_buf(char* buf, size_t len, int expected_byte_val) { +static int check_bytes_in_buf(char *buf, size_t len, int expected_byte_val) { for (size_t bi = 0; bi < len; bi++) { if (buf[bi] != (char)expected_byte_val) { printf("check_bytes_in_buf: expect %02X, but found %02X, at offset %lu\n", - (unsigned char)expected_byte_val, (unsigned char)buf[bi], bi); + (unsigned char)expected_byte_val, (unsigned char)buf[bi], bi); return -1; } } return 0; } -static void* get_a_stack_ptr() { +static void *get_a_stack_ptr() { volatile int a = 0; - return (void*) &a; + return (void *) &a; } // ============================================================================ @@ -68,7 +68,7 @@ static int get_a_valid_range_of_hints(size_t *hint_begin, size_t *hint_end) { size_t big_buf_len = MAX_MMAP_USED_MEMORY; int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; - void* big_buf = mmap(NULL, big_buf_len, prot, flags, -1, 0); + void *big_buf = mmap(NULL, big_buf_len, prot, flags, -1, 0); if (big_buf == MAP_FAILED) { THROW_ERROR("mmap failed"); } @@ -99,7 +99,7 @@ int test_anonymous_mmap() { int flags = MAP_PRIVATE | MAP_ANONYMOUS; for (size_t len = PAGE_SIZE; len <= MAX_MMAP_USED_MEMORY; len *= 2) { - void* buf = mmap(NULL, len, prot, flags, -1, 0); + void *buf = mmap(NULL, len, prot, flags, -1, 0); if (buf == MAP_FAILED) { THROW_ERROR("mmap failed"); } @@ -120,7 +120,7 @@ int test_anonymous_mmap_randomly() { int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; - void* bufs[16] = {NULL}; + void *bufs[16] = {NULL}; size_t lens[16]; size_t num_bufs = 0; size_t used_memory = 0; @@ -128,15 +128,14 @@ int test_anonymous_mmap_randomly() { for (int i = 0; i < 5; i++) { // Phrase 1: do mmap with random sizes until no more buffers or memory for (num_bufs = 0; - num_bufs < ARRAY_SIZE(bufs) && used_memory < MAX_MMAP_USED_MEMORY; - num_bufs++) - { + num_bufs < ARRAY_SIZE(bufs) && used_memory < MAX_MMAP_USED_MEMORY; + num_bufs++) { // Choose the mmap size randomly size_t len = rand() % (MAX_MMAP_USED_MEMORY - used_memory) + 1; len = ALIGN_UP(len, PAGE_SIZE); // Do mmap - void* buf = mmap(NULL, len, prot, flags, -1, 0); + void *buf = mmap(NULL, len, prot, flags, -1, 0); if (buf == MAP_FAILED) { THROW_ERROR("mmap failed"); } @@ -149,7 +148,7 @@ int test_anonymous_mmap_randomly() { // Phrase 2: do munmap to free all memory mapped memory for (int bi = 0; bi < num_bufs; bi++) { - void* buf = bufs[bi]; + void *buf = bufs[bi]; size_t len = lens[bi]; int ret = munmap(buf, len); if (ret < 0) { @@ -175,10 +174,10 @@ int test_anonymous_mmap_randomly_with_good_hints() { hint = ALIGN_DOWN(hint, PAGE_SIZE); size_t len = rand() % (HINT_END - (size_t)hint); - len = ALIGN_UP(len+1, PAGE_SIZE); + len = ALIGN_UP(len + 1, PAGE_SIZE); - void* addr = mmap((void*)hint, len, prot, flags, -1, 0); - if (addr != (void*)hint) { + void *addr = mmap((void *)hint, len, prot, flags, -1, 0); + if (addr != (void *)hint) { THROW_ERROR("mmap with hint failed"); } @@ -201,8 +200,8 @@ int test_anonymous_mmap_with_bad_hints() { int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; for (int hi = 0; hi < ARRAY_SIZE(bad_hints); hi++) { - void* bad_hint = (void*)bad_hints[hi]; - void* addr = mmap(bad_hint, len, prot, flags, -1, 0); + void *bad_hint = (void *)bad_hints[hi]; + void *addr = mmap(bad_hint, len, prot, flags, -1, 0); if (addr == MAP_FAILED) { THROW_ERROR("mmap should have tolerated a bad hint"); } @@ -221,7 +220,7 @@ int test_anonymous_mmap_with_zero_len() { int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; int len = 0; // invalid! - void* buf = mmap(NULL, len, prot, flags, -1, 0); + void *buf = mmap(NULL, len, prot, flags, -1, 0); if (buf != MAP_FAILED) { THROW_ERROR("mmap with zero len should have been failed"); } @@ -232,7 +231,7 @@ int test_anonymous_mmap_with_non_page_aligned_len() { int len = PAGE_SIZE + 17; // length need not to be page aligned! int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; - void* buf = mmap(NULL, len, prot, flags, -1, 0); + void *buf = mmap(NULL, len, prot, flags, -1, 0); if (buf == MAP_FAILED) { THROW_ERROR("mmap with non-page aligned len should have worked"); } @@ -254,7 +253,7 @@ int test_anonymous_mmap_with_non_page_aligned_len() { // ============================================================================ int test_file_mmap() { - const char* file_path = "/root/mmap_file.data"; + const char *file_path = "/root/mmap_file.data"; int fd = open(file_path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd < 0) { THROW_ERROR("file creation failed"); @@ -272,7 +271,7 @@ int test_file_mmap() { } off_t offset = 0; for (size_t len = PAGE_SIZE; len <= file_len; len *= 2) { - char* buf = mmap(NULL, len, prot, flags, fd, offset); + char *buf = mmap(NULL, len, prot, flags, fd, offset); if (buf == MAP_FAILED) { THROW_ERROR("mmap failed"); } @@ -292,7 +291,7 @@ int test_file_mmap() { } int test_file_mmap_with_offset() { - const char* file_path = "/root/mmap_file.data"; + const char *file_path = "/root/mmap_file.data"; int fd = open(file_path, O_CREAT | O_TRUNC | O_RDWR, 0644); if (fd < 0) { THROW_ERROR("file creation failed"); @@ -310,12 +309,12 @@ int test_file_mmap_with_offset() { int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE; assert(offset <= first_len); - char* buf = mmap(NULL, len, prot, flags, fd, offset); + char *buf = mmap(NULL, len, prot, flags, fd, offset); if (buf == MAP_FAILED) { THROW_ERROR("mmap failed"); } - char* buf_cursor = buf; + char *buf_cursor = buf; if (check_bytes_in_buf(buf_cursor, first_len - offset, first_val) < 0) { THROW_ERROR("the buffer is not initialized according to the file"); } @@ -324,7 +323,8 @@ int test_file_mmap_with_offset() { THROW_ERROR("the buffer is not initialized according to the file"); } buf_cursor += second_len; - if (check_bytes_in_buf(buf_cursor, ALIGN_UP(len, PAGE_SIZE) - (buf_cursor - buf), 0) < 0) { + if (check_bytes_in_buf(buf_cursor, ALIGN_UP(len, PAGE_SIZE) - (buf_cursor - buf), + 0) < 0) { THROW_ERROR("the remaining of the last page occupied by the buffer is not initialized to zeros"); } @@ -344,7 +344,7 @@ int test_file_mmap_with_invalid_fd() { int flags = MAP_PRIVATE; int fd = 1234; // invalid! off_t offset = 0; - void* buf = mmap(NULL, len, prot, flags, fd, offset); + void *buf = mmap(NULL, len, prot, flags, fd, offset); if (buf != MAP_FAILED) { THROW_ERROR("file mmap with an invalid fd should have been failed"); } @@ -352,7 +352,7 @@ int test_file_mmap_with_invalid_fd() { } int test_file_mmap_with_non_page_aligned_offset() { - const char* file_path = "/root/mmap_file.data"; + const char *file_path = "/root/mmap_file.data"; int fd = open(file_path, O_CREAT | O_TRUNC | O_RDWR, 0644); if (fd < 0) { THROW_ERROR("file creation failed"); @@ -365,7 +365,7 @@ int test_file_mmap_with_non_page_aligned_offset() { int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; off_t offset = PAGE_SIZE + 127; // Invalid! - void* buf = mmap(NULL, len, prot, flags, fd, offset); + void *buf = mmap(NULL, len, prot, flags, fd, offset); if (buf != MAP_FAILED) { THROW_ERROR("mmap with non-page aligned len should have been failed"); } @@ -388,8 +388,8 @@ int test_fixed_mmap_that_does_not_override_any_mmaping() { len = ALIGN_UP(len, PAGE_SIZE); int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; - void* addr = mmap((void*)hint, len, prot, flags, -1, 0); - if (addr != (void*)hint) { + void *addr = mmap((void *)hint, len, prot, flags, -1, 0); + if (addr != (void *)hint) { THROW_ERROR("mmap with fixed address failed"); } @@ -412,7 +412,7 @@ int test_fixed_mmap_that_overrides_existing_mmaping() { // Allocate parent_buf int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; - void* parent_buf = mmap(NULL, parent_len, prot, flags, -1, 0); + void *parent_buf = mmap(NULL, parent_len, prot, flags, -1, 0); if (parent_buf == MAP_FAILED) { THROW_ERROR("mmap for parent failed"); } @@ -420,7 +420,7 @@ int test_fixed_mmap_that_overrides_existing_mmaping() { memset(parent_buf, parent_val, parent_len); // Allocate child_buf - void* child_buf = (char*)parent_buf + pre_child_len; + void *child_buf = (char *)parent_buf + pre_child_len; if (mmap(child_buf, child_len, prot, flags | MAP_FIXED, -1, 0) != child_buf) { THROW_ERROR("mmap with fixed address failed"); } @@ -430,10 +430,10 @@ int test_fixed_mmap_that_overrides_existing_mmaping() { THROW_ERROR("the content of child mmap memory is not initialized"); } // Check that the rest of parent_buf are kept intact - if (check_bytes_in_buf((char*)child_buf - pre_child_len, - pre_child_len, parent_val) < 0 || - check_bytes_in_buf((char*)child_buf + child_len, - post_child_len, parent_val) < 0) { + if (check_bytes_in_buf((char *)child_buf - pre_child_len, + pre_child_len, parent_val) < 0 || + check_bytes_in_buf((char *)child_buf + child_len, + post_child_len, parent_val) < 0) { THROW_ERROR("the content of parent mmap memory is broken"); } @@ -451,7 +451,7 @@ int test_fixed_mmap_with_non_page_aligned_addr() { size_t len = 1 * PAGE_SIZE; int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; - void* addr = mmap((void*)hint, len, prot, flags, -1, 0); + void *addr = mmap((void *)hint, len, prot, flags, -1, 0); if (addr != MAP_FAILED) { THROW_ERROR("fixed mmap with non-page aligned hint should have failed"); } @@ -462,15 +462,15 @@ int test_fixed_mmap_with_non_page_aligned_addr() { // Test cases for munmap // ============================================================================ -static int check_buf_is_munmapped(void* target_addr, size_t len) { +static int check_buf_is_munmapped(void *target_addr, size_t len) { // The trivial case of zero-len meory region is considered as unmapped - if (len == 0) return 0; + if (len == 0) { return 0; } // If the target_addr is not already mmaped, it should succeed to use it as // a hint for mmap. int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS; - void* real_addr = mmap(target_addr, len, prot, flags, -1, 0); + void *real_addr = mmap(target_addr, len, prot, flags, -1, 0); if (real_addr != target_addr) { THROW_ERROR("address is already mmaped"); } @@ -482,12 +482,12 @@ static int mmap_then_munmap(size_t mmap_len, ssize_t munmap_offset, size_t munma int prot = PROT_READ | PROT_WRITE; int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; // Make sure that we are manipulating memory between [HINT_BEGIN, HINT_END) - void* mmap_addr = (void*)(munmap_offset >= 0 ? HINT_BEGIN : HINT_BEGIN - munmap_offset); + void *mmap_addr = (void *)(munmap_offset >= 0 ? HINT_BEGIN : HINT_BEGIN - munmap_offset); if (mmap(mmap_addr, mmap_len, prot, flags, -1, 0) != mmap_addr) { THROW_ERROR("mmap failed"); } - void* munmap_addr = (char*)mmap_addr + munmap_offset; + void *munmap_addr = (char *)mmap_addr + munmap_offset; if (munmap(munmap_addr, munmap_len) < 0) { THROW_ERROR("munmap failed"); } @@ -497,7 +497,7 @@ static int mmap_then_munmap(size_t mmap_len, ssize_t munmap_offset, size_t munma // Make sure that when this function returns, there are no memory mappings // within [HINT_BEGIN, HINT_END) - if (munmap((void*)HINT_BEGIN, HINT_END - HINT_BEGIN) < 0) { + if (munmap((void *)HINT_BEGIN, HINT_END - HINT_BEGIN) < 0) { THROW_ERROR("munmap failed"); } return 0; @@ -548,13 +548,13 @@ int test_munmap_whose_range_intersects_with_multiple_mmap_regions() { int flags = MAP_PRIVATE | MAP_ANONYMOUS; size_t mmap_len1 = 100 * PAGE_SIZE; - void* mmap_addr1 = mmap(NULL, mmap_len1, prot, flags, -1, 0); + void *mmap_addr1 = mmap(NULL, mmap_len1, prot, flags, -1, 0); if (mmap_addr1 == MAP_FAILED) { THROW_ERROR("mmap failed"); } size_t mmap_len2 = 12 * PAGE_SIZE; - void* mmap_addr2 = mmap(NULL, mmap_len2, prot, flags, -1, 0); + void *mmap_addr2 = mmap(NULL, mmap_len2, prot, flags, -1, 0); if (mmap_addr2 == MAP_FAILED) { THROW_ERROR("mmap failed"); } @@ -563,7 +563,7 @@ int test_munmap_whose_range_intersects_with_multiple_mmap_regions() { size_t mmap_max = MAX((size_t)mmap_addr1 + mmap_len1, (size_t)mmap_addr2 + mmap_len2); - void* munmap_addr = (void*)mmap_min; + void *munmap_addr = (void *)mmap_min; size_t munmap_len = mmap_max - mmap_min; if (munmap(munmap_addr, munmap_len) < 0) { THROW_ERROR("munmap failed"); @@ -581,7 +581,7 @@ int test_munmap_with_null_addr() { // The man page of munmap states that "it is not an error if the indicated // range does not contain any mapped pages". This is not considered as // an error! - void* munmap_addr = NULL; + void *munmap_addr = NULL; size_t munmap_len = PAGE_SIZE; if (munmap(munmap_addr, munmap_len) < 0) { THROW_ERROR("munmap failed"); @@ -590,7 +590,7 @@ int test_munmap_with_null_addr() { } int test_munmap_with_zero_len() { - void* munmap_addr = (void*)HINT_BEGIN; + void *munmap_addr = (void *)HINT_BEGIN; // Set the length for munmap to 0! This is invalid! size_t munmap_len = 0; if (munmap(munmap_addr, munmap_len) == 0) { diff --git a/test/open/main.c b/test/open/main.c index 48f92567..de7e7449 100644 --- a/test/open/main.c +++ b/test/open/main.c @@ -74,13 +74,15 @@ typedef int(*test_open_func_t)(const char *, int, int); static int test_open_framework(test_open_func_t fn) { const char *file_path = "/root/test_filesystem_open.txt"; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00666; - if (fn(file_path, flags, mode) < 0) + if (fn(file_path, flags, mode) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/pipe/main.c b/test/pipe/main.c index 1ecc41c3..da372042 100644 --- a/test/pipe/main.c +++ b/test/pipe/main.c @@ -27,7 +27,7 @@ int test_fcntl_get_flags() { } if ((fcntl(pipe_fds[0], F_GETFL, 0) != O_RDONLY) || - (fcntl(pipe_fds[1], F_GETFL, 0) != O_WRONLY)) { + (fcntl(pipe_fds[1], F_GETFL, 0) != O_WRONLY)) { free_pipe(pipe_fds); THROW_ERROR("fcntl get flags failed"); } @@ -44,7 +44,7 @@ int test_fcntl_set_flags() { fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK); if ((fcntl(pipe_fds[0], F_GETFL, 0) != (O_NONBLOCK | O_RDONLY)) || - (fcntl(pipe_fds[1], F_GETFL, 0) != O_WRONLY)) { + (fcntl(pipe_fds[1], F_GETFL, 0) != O_WRONLY)) { free_pipe(pipe_fds); THROW_ERROR("fcntl set flags failed"); } @@ -60,7 +60,7 @@ int test_create_with_flags() { } if ((fcntl(pipe_fds[0], F_GETFL, 0) != (O_NONBLOCK | O_RDONLY)) || - (fcntl(pipe_fds[1], F_GETFL, 0) != (O_NONBLOCK | O_WRONLY))) { + (fcntl(pipe_fds[1], F_GETFL, 0) != (O_NONBLOCK | O_WRONLY))) { free_pipe(pipe_fds); THROW_ERROR("create flags failed\n"); } @@ -83,17 +83,17 @@ int test_read_write() { posix_spawn_file_actions_adddup2(&file_actions, pipe_wr_fd, STDOUT_FILENO); posix_spawn_file_actions_addclose(&file_actions, pipe_rd_fd); - const char* msg = "Echo!\n"; - const char* child_prog = "/bin/hello_world"; - const char* child_argv[3] = { child_prog, msg, NULL }; + const char *msg = "Echo!\n"; + const char *child_prog = "/bin/hello_world"; + const char *child_argv[3] = { child_prog, msg, NULL }; int child_pid; if (posix_spawn(&child_pid, child_prog, &file_actions, - NULL, (char*const *)child_argv, NULL) < 0) { + NULL, (char *const *)child_argv, NULL) < 0) { THROW_ERROR("failed to spawn a child process"); } close(pipe_wr_fd); - const char* expected_str = msg; + const char *expected_str = msg; size_t expected_len = strlen(expected_str); char actual_str[32] = {0}; ssize_t actual_len; @@ -123,6 +123,6 @@ static test_case_t test_cases[] = { TEST_CASE(test_read_write), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return test_suite_run(test_cases, ARRAY_SIZE(test_cases)); } diff --git a/test/pipe_throughput/main.c b/test/pipe_throughput/main.c index 11e2f339..834d3f61 100644 --- a/test/pipe_throughput/main.c +++ b/test/pipe_throughput/main.c @@ -16,7 +16,7 @@ #define MIN(x, y) ((x) <= (y) ? (x) : (y)) -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { // Create pipe int pipe_fds[2]; if (pipe(pipe_fds) < 0) { @@ -34,7 +34,7 @@ int main(int argc, const char* argv[]) { int child_pid; if (posix_spawn(&child_pid, "/bin/data_sink", &file_actions, - NULL, NULL, NULL) < 0) { + NULL, NULL, NULL) < 0) { printf("ERROR: failed to spawn a child process\n"); return -1; } @@ -81,7 +81,7 @@ int main(int argc, const char* argv[]) { // Calculate the throughput double total_s = (tv_end.tv_sec - tv_start.tv_sec) - + (double)(tv_end.tv_usec - tv_start.tv_usec) / 1000000; + + (double)(tv_end.tv_usec - tv_start.tv_usec) / 1000000; if (total_s < 1.0) { printf("WARNING: run long enough to get meaningful results\n"); if (total_s == 0) { return 0; } diff --git a/test/pthread/main.c b/test/pthread/main.c index f3274661..1b3937f3 100644 --- a/test/pthread/main.c +++ b/test/pthread/main.c @@ -21,12 +21,12 @@ struct thread_arg { int ti; long local_count; - volatile unsigned long* global_count; - pthread_mutex_t* mutex; + volatile unsigned long *global_count; + pthread_mutex_t *mutex; }; -static void* thread_func(void* _arg) { - struct thread_arg* arg = _arg; +static void *thread_func(void *_arg) { + struct thread_arg *arg = _arg; for (long i = 0; i < arg->local_count; i++) { pthread_mutex_lock(arg->mutex); (*arg->global_count)++; @@ -51,7 +51,7 @@ static int test_mutex_with_concurrent_counter(void) { * Start the threads */ for (int ti = 0; ti < NTHREADS; ti++) { - struct thread_arg* thread_arg = &thread_args[ti]; + struct thread_arg *thread_arg = &thread_args[ti]; thread_arg->ti = ti; thread_arg->local_count = LOCAL_COUNT; thread_arg->global_count = &global_count; @@ -76,7 +76,7 @@ static int test_mutex_with_concurrent_counter(void) { */ if (global_count != EXPECTED_GLOBAL_COUNT) { printf("ERROR: incorrect global_count (actual = %ld, expected = %ld)\n", - global_count, EXPECTED_GLOBAL_COUNT); + global_count, EXPECTED_GLOBAL_COUNT); return -1; } @@ -92,14 +92,14 @@ static int test_mutex_with_concurrent_counter(void) { struct thread_cond_arg { int ti; - volatile unsigned int* val; - volatile int* exit_thread_count; - pthread_cond_t* cond_val; - pthread_mutex_t* mutex; + volatile unsigned int *val; + volatile int *exit_thread_count; + pthread_cond_t *cond_val; + pthread_mutex_t *mutex; }; -static void* thread_cond_wait(void* _arg) { - struct thread_cond_arg* arg = _arg; +static void *thread_cond_wait(void *_arg) { + struct thread_cond_arg *arg = _arg; printf("Thread #%d: start to wait on condition variable.\n", arg->ti); for (unsigned int i = 0; i < WAIT_ROUND; ++i) { pthread_mutex_lock(arg->mutex); @@ -124,7 +124,7 @@ static int test_mutex_with_cond_wait(void) { * Start the threads waiting on the condition variable */ for (int ti = 0; ti < NTHREADS; ti++) { - struct thread_cond_arg* thread_arg = &thread_args[ti]; + struct thread_cond_arg *thread_arg = &thread_args[ti]; thread_arg->ti = ti; thread_arg->val = &val; thread_arg->exit_thread_count = &exit_thread_count; diff --git a/test/readdir/main.c b/test/readdir/main.c index ee06d3bd..5f62e054 100644 --- a/test/readdir/main.c +++ b/test/readdir/main.c @@ -14,7 +14,7 @@ static int test_readdir() { struct dirent *dp; - DIR* dirp; + DIR *dirp; dirp = opendir("/"); if (dirp == NULL) { diff --git a/test/rlimit/main.c b/test/rlimit/main.c index 5e1943e5..78761f71 100644 --- a/test/rlimit/main.c +++ b/test/rlimit/main.c @@ -1,7 +1,7 @@ #include #include -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { struct rlimit rlim; if (getrlimit(RLIMIT_AS, &rlim) < 0) { printf("ERROR: getrlimit failed\n"); diff --git a/test/sched/main.c b/test/sched/main.c index fe5dce12..66fbb97e 100644 --- a/test/sched/main.c +++ b/test/sched/main.c @@ -17,14 +17,14 @@ #define MAX_CPU_NUM 1024 -static int* g_online_cpu_idxs; +static int *g_online_cpu_idxs; int get_online_cpu() { int online_num = sysconf(_SC_NPROCESSORS_ONLN); cpu_set_t mask; int index = 0; - g_online_cpu_idxs = (int*)calloc(online_num, sizeof(int)); + g_online_cpu_idxs = (int *)calloc(online_num, sizeof(int)); CPU_ZERO(&mask); if (sched_getaffinity(0, sizeof(cpu_set_t), &mask) < 0) { THROW_ERROR("failed to call sched_getaffinity"); @@ -94,7 +94,7 @@ static int test_sched_xetaffinity_with_child_pid() { } cpu_set_t mask; CPU_ZERO(&mask); - CPU_SET(g_online_cpu_idxs[num - 1] , &mask); + CPU_SET(g_online_cpu_idxs[num - 1], &mask); int ret = posix_spawn(&child_pid, "/bin/getpid", NULL, NULL, NULL, NULL); if (ret < 0 ) { THROW_ERROR("spawn process error"); @@ -177,7 +177,7 @@ static int test_sched_setaffinity_with_zero_cpusetsize() { static int test_sched_getaffinity_with_null_buffer() { unsigned char *buf = NULL; - if (sched_getaffinity(0, sizeof(cpu_set_t), (cpu_set_t*)buf) != -1) { + if (sched_getaffinity(0, sizeof(cpu_set_t), (cpu_set_t *)buf) != -1) { THROW_ERROR("check invalid buffer pointer(NULL) fail"); } return 0; @@ -185,7 +185,7 @@ static int test_sched_getaffinity_with_null_buffer() { static int test_sched_setaffinity_with_null_buffer() { unsigned char *buf = NULL; - if (sched_setaffinity(0, sizeof(cpu_set_t), (cpu_set_t*)buf) != -1) { + if (sched_setaffinity(0, sizeof(cpu_set_t), (cpu_set_t *)buf) != -1) { THROW_ERROR("check invalid buffer pointer(NULL) fail"); } return 0; diff --git a/test/server/main.c b/test/server/main.c index be252c13..c1fb58c1 100644 --- a/test/server/main.c +++ b/test/server/main.c @@ -21,11 +21,13 @@ int connect_with_child(int port, int *child_pid) { int ret = 0; int listen_fd = socket(AF_INET, SOCK_STREAM, 0); - if (listen_fd < 0) + if (listen_fd < 0) { THROW_ERROR("create socket error"); + } int reuse = 1; - if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) + if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { THROW_ERROR("setsockopt port to reuse failed"); + } struct sockaddr_in servaddr; memset(&servaddr, 0, sizeof(servaddr)); @@ -46,7 +48,7 @@ int connect_with_child(int port, int *child_pid) { char port_string[8]; sprintf(port_string, "%d", port); - char* client_argv[] = {"client", "127.0.0.1", port_string, NULL}; + char *client_argv[] = {"client", "127.0.0.1", port_string, NULL}; ret = posix_spawn(child_pid, "/bin/client", NULL, NULL, client_argv, NULL); if (ret < 0) { close(listen_fd); @@ -65,11 +67,13 @@ int connect_with_child(int port, int *child_pid) { int neogotiate_msg(int client_fd) { char buf[16]; - if (write(client_fd, ECHO_MSG, strlen(ECHO_MSG)) < 0) + if (write(client_fd, ECHO_MSG, strlen(ECHO_MSG)) < 0) { THROW_ERROR("write failed"); + } - if (read(client_fd, buf, sizeof(RESPONSE)) < 0) + if (read(client_fd, buf, sizeof(RESPONSE)) < 0) { THROW_ERROR("read failed"); + } if (strncmp(buf, RESPONSE, sizeof(RESPONSE)) != 0) { THROW_ERROR("msg recv mismatch"); @@ -81,8 +85,9 @@ int server_recv(int client_fd) { const int buf_size = 32; char buf[buf_size]; - if (recv(client_fd, buf, buf_size, 0) <= 0) + if (recv(client_fd, buf, buf_size, 0) <= 0) { THROW_ERROR("msg recv failed"); + } if (strncmp(buf, ECHO_MSG, strlen(ECHO_MSG)) != 0) { THROW_ERROR("msg recv mismatch"); @@ -125,8 +130,9 @@ int server_recvmsg(int client_fd) { msg.msg_iov = NULL; msg.msg_iovlen = 0; ret = recvmsg(client_fd, &msg, 0); - if (ret != 0) + if (ret != 0) { THROW_ERROR("recvmsg empty failed"); + } return ret; } @@ -143,8 +149,9 @@ int server_connectionless_recvmsg() { memset(&clientaddr, 0, sizeof(clientaddr)); int sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) + if (sock < 0) { THROW_ERROR("create socket error"); + } servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); @@ -174,8 +181,8 @@ int server_connectionless_recvmsg() { THROW_ERROR("msg recvmsg mismatch"); } else { inet_ntop(AF_INET, &clientaddr.sin_addr, - buf, sizeof(buf)); - if(strcmp(buf, "127.0.0.1") !=0) { + buf, sizeof(buf)); + if (strcmp(buf, "127.0.0.1") != 0) { printf("from port %d and address %s\n", ntohs(clientaddr.sin_port), buf); THROW_ERROR("client addr mismatch"); } @@ -196,10 +203,11 @@ int test_read_write() { int ret = 0; int child_pid = 0; int client_fd = connect_with_child(8800, &child_pid); - if (client_fd < 0) + if (client_fd < 0) { THROW_ERROR("connect failed"); - else + } else { ret = neogotiate_msg(client_fd); + } //wait for the child to exit for next spawn int status = 0; @@ -214,14 +222,16 @@ int test_send_recv() { int ret = 0; int child_pid = 0; int client_fd = connect_with_child(8801, &child_pid); - if (client_fd < 0) + if (client_fd < 0) { THROW_ERROR("connect failed"); + } - if (neogotiate_msg(client_fd) < 0) + if (neogotiate_msg(client_fd) < 0) { THROW_ERROR("neogotiate failed"); + } ret = server_recv(client_fd); - if (ret < 0) return -1; + if (ret < 0) { return -1; } ret = wait_for_child_exit(child_pid); @@ -232,14 +242,16 @@ int test_sendmsg_recvmsg() { int ret = 0; int child_pid = 0; int client_fd = connect_with_child(8802, &child_pid); - if (client_fd < 0) + if (client_fd < 0) { THROW_ERROR("connect failed"); + } - if (neogotiate_msg(client_fd) < 0) + if (neogotiate_msg(client_fd) < 0) { THROW_ERROR("neogotiate failed"); + } ret = server_recvmsg(client_fd); - if (ret < 0) return -1; + if (ret < 0) { return -1; } ret = wait_for_child_exit(child_pid); @@ -250,14 +262,14 @@ int test_sendmsg_recvmsg_connectionless() { int ret = 0; int child_pid = 0; - char* client_argv[] = {"client", "NULL", "8803", NULL}; + char *client_argv[] = {"client", "NULL", "8803", NULL}; ret = posix_spawn(&child_pid, "/bin/client", NULL, NULL, client_argv, NULL); if (ret < 0) { THROW_ERROR("spawn client process error"); } ret = server_connectionless_recvmsg(); - if (ret < 0) return -1; + if (ret < 0) { return -1; } ret = wait_for_child_exit(child_pid); @@ -271,19 +283,23 @@ int test_fcntl_setfl_and_getfl() { int original_flags, actual_flags; client_fd = connect_with_child(8804, &child_pid); - if (client_fd < 0) + if (client_fd < 0) { THROW_ERROR("connect failed"); + } original_flags = fcntl(client_fd, F_GETFL, 0); - if (original_flags < 0) + if (original_flags < 0) { THROW_ERROR("fcntl getfl failed"); + } ret = fcntl(client_fd, F_SETFL, original_flags | O_NONBLOCK); - if (ret < 0) + if (ret < 0) { THROW_ERROR("fcntl setfl failed"); + } actual_flags = fcntl(client_fd, F_GETFL, 0); - if (actual_flags != (original_flags | O_NONBLOCK)) + if (actual_flags != (original_flags | O_NONBLOCK)) { THROW_ERROR("check the getfl value after setfl failed"); + } ret = wait_for_child_exit(child_pid); @@ -300,14 +316,16 @@ int test_poll_sockets() { }; ret = poll(pollfds, 2, 0); - if (ret < 0) + if (ret < 0) { THROW_ERROR("poll error"); + } if (pollfds[0].fd != socks[0] || - pollfds[0].events != POLLIN || - pollfds[1].fd != socks[1] || - pollfds[1].events != POLLIN) + pollfds[0].events != POLLIN || + pollfds[1].fd != socks[1] || + pollfds[1].events != POLLIN) { THROW_ERROR("fd and events of pollfd should remain unchanged"); + } return 0; } @@ -320,6 +338,6 @@ static test_case_t test_cases[] = { TEST_CASE(test_poll_sockets), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return test_suite_run(test_cases, ARRAY_SIZE(test_cases)); } diff --git a/test/server_epoll/main.c b/test/server_epoll/main.c index 8ce6ce13..8ec75138 100644 --- a/test/server_epoll/main.c +++ b/test/server_epoll/main.c @@ -30,8 +30,9 @@ static int create_and_bind() { servaddr.sin_port = htons(6667); int reuse = 1; - if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) + if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { THROW_ERROR("setsockopt port to reuse failed"); + } int ret = bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); if (ret < 0) { @@ -67,8 +68,8 @@ int test_ip_socket() { int client_pid; int proc_num = DEFAULT_PROC_NUM; - char* client_argv[] = {"client", "127.0.0.1", "6667", NULL}; - for(int i=0; isi_signo == SIGFPE); - ucontext_t* ucontext = _context; - mcontext_t* mcontext = &ucontext->uc_mcontext; + ucontext_t *ucontext = _context; + mcontext_t *mcontext = &ucontext->uc_mcontext; // The faulty instruction should be `idiv %esi` (f7 fe) mcontext->gregs[REG_RIP] += 2; @@ -230,7 +231,7 @@ int div_maybe_zero(int x, int y) { int test_catch_fault() { #ifdef SGX_MODE_SIM printf("WARNING: Skip this test case as we do not support " - "capturing hardware exception in SGX simulation mode\n"); + "capturing hardware exception in SGX simulation mode\n"); return 0; #else // Set up a signal handler that handles divide-by-zero exception @@ -268,10 +269,10 @@ int test_catch_fault() { stack_t g_old_ss; -static void handle_sigpipe(int num, siginfo_t* info, void* context) { +static void handle_sigpipe(int num, siginfo_t *info, void *context) { static volatile int recursion_level = 0; printf("Hello from SIGPIPE signal handler on the alternate signal stack (recursion_level = %d)\n", - recursion_level); + recursion_level); // save old_ss to check if we are on stack stack_t old_ss; @@ -279,8 +280,9 @@ static void handle_sigpipe(int num, siginfo_t* info, void* context) { g_old_ss = old_ss; recursion_level++; - if (recursion_level <= MAX_ALTSTACK_RECURSION_LEVEL) + if (recursion_level <= MAX_ALTSTACK_RECURSION_LEVEL) { raise(SIGPIPE); + } recursion_level--; } @@ -299,8 +301,8 @@ int test_sigaltstack() { THROW_ERROR("failed to call sigaltstack"); } if (actual_ss.ss_size != expected_ss.ss_size - || actual_ss.ss_sp != expected_ss.ss_sp - || actual_ss.ss_flags != expected_ss.ss_flags) { + || actual_ss.ss_sp != expected_ss.ss_sp + || actual_ss.ss_flags != expected_ss.ss_flags) { THROW_ERROR("failed to check the signal stack after set"); } @@ -341,14 +343,14 @@ int test_sigchld() { printf("Run a parent process has pid = %d and ppid = %d\n", getpid(), getppid()); ret = posix_spawn(&child_pid, "/bin/getpid", NULL, NULL, NULL, NULL); - if (ret < 0){ + if (ret < 0) { printf("ERROR: failed to spawn a child process\n"); return -1; } printf("Spawn a new proces successfully (pid = %d)\n", child_pid); wait(NULL); - if (sigchld == 0) THROW_ERROR("Did not receive SIGCHLD"); + if (sigchld == 0) { THROW_ERROR("Did not receive SIGCHLD"); } return 0; } @@ -367,16 +369,14 @@ static test_case_t test_cases[] = { TEST_CASE(test_sigchld), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { if (argc > 1) { - const char* cmd = argv[1]; + const char *cmd = argv[1]; if (strcmp(cmd, "aborted_child") == 0) { return aborted_child(); - } - else if (strcmp(cmd, "killed_child") == 0) { + } else if (strcmp(cmd, "killed_child") == 0) { return killed_child(); - } - else { + } else { fprintf(stderr, "ERROR: unknown command: %s\n", cmd); return EXIT_FAILURE; } diff --git a/test/sleep/main.c b/test/sleep/main.c index 7de13d82..6925be2f 100644 --- a/test/sleep/main.c +++ b/test/sleep/main.c @@ -17,14 +17,13 @@ // Helper functions // ============================================================================ -static inline void validate_timespec(const struct timespec* tv) { +static inline void validate_timespec(const struct timespec *tv) { assert(tv->tv_sec >= 0 && tv->tv_nsec >= 0 && tv->tv_nsec < S); } // retval = (a < b) ? -1 : ((a > b) ? 1 : 0) -static int timespec_cmp(const struct timespec *a, const struct timespec *b) -{ +static int timespec_cmp(const struct timespec *a, const struct timespec *b) { validate_timespec(a); validate_timespec(b); @@ -34,22 +33,23 @@ static int timespec_cmp(const struct timespec *a, const struct timespec *b) return 1; } else { return a->tv_nsec < b->tv_nsec ? -1 : - (a->tv_nsec > b->tv_nsec ? 1 : 0); + (a->tv_nsec > b->tv_nsec ? 1 : 0); } } // diff = | a - b | static void timespec_diff(const struct timespec *a, const struct timespec *b, - struct timespec *diff) -{ + struct timespec *diff) { validate_timespec(a); validate_timespec(b); const struct timespec *begin, *end; if (timespec_cmp(a, b) <= 0) { - begin = a; end = b; + begin = a; + end = b; } else { - begin = b; end = a; + begin = b; + end = a; } diff->tv_nsec = end->tv_nsec - begin->tv_nsec; @@ -64,15 +64,14 @@ static void timespec_diff(const struct timespec *a, const struct timespec *b, // retval = | a - b | <= precision static int timespec_equal(const struct timespec *a, const struct timespec *b, - const struct timespec *precision) -{ + const struct timespec *precision) { struct timespec diff; timespec_diff(a, b, &diff); return timespec_cmp(&diff, precision) <= 0; } -static int check_nanosleep(struct timespec* expected_sleep_period) { +static int check_nanosleep(struct timespec *expected_sleep_period) { // The time obtained from Occlum is not very precise. // Here we take 1 millisecond as the time precision of Occlum. static struct timespec OS_TIME_PRECISION = { diff --git a/test/spawn/main.c b/test/spawn/main.c index 876dee5a..8bfd9682 100644 --- a/test/spawn/main.c +++ b/test/spawn/main.c @@ -4,7 +4,7 @@ #include #include -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { int ret, child_pid, status; printf("Run a parent process has pid = %d and ppid = %d\n", getpid(), getppid()); diff --git a/test/spawn_and_exit_latency/main.c b/test/spawn_and_exit_latency/main.c index 36a5244c..072bd2f9 100644 --- a/test/spawn_and_exit_latency/main.c +++ b/test/spawn_and_exit_latency/main.c @@ -7,13 +7,13 @@ #define NREPEATS 5000 -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { struct timeval tv_start, tv_end; gettimeofday(&tv_start, NULL); for (unsigned long i = 0; i < NREPEATS; i++) { int child_pid, status; - if (posix_spawn(&child_pid, "/bin/empty", NULL, NULL, NULL, NULL) <0) { + if (posix_spawn(&child_pid, "/bin/empty", NULL, NULL, NULL, NULL) < 0) { printf("ERROR: failed to spawn (# of repeats = %lu)\n", i); return -1; } @@ -29,7 +29,7 @@ int main(int argc, const char* argv[]) { gettimeofday(&tv_end, NULL); suseconds_t total_us = (tv_end.tv_sec - tv_start.tv_sec) * 1000000UL + - + (tv_end.tv_usec - tv_start.tv_usec); + + (tv_end.tv_usec - tv_start.tv_usec); suseconds_t latency = total_us / NREPEATS; printf("Latency of spawn/exit = %lu us\n", latency); return 0; diff --git a/test/stat/main.c b/test/stat/main.c index fda24512..d7145a00 100644 --- a/test/stat/main.c +++ b/test/stat/main.c @@ -12,7 +12,7 @@ static int create_file(const char *file_path) { int fd; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00666; fd = open(file_path, flags, mode); @@ -145,12 +145,15 @@ typedef int(*test_stat_func_t)(const char *); static int test_stat_framework(test_stat_func_t fn) { const char *file_path = "/root/test_filesystem_stat.txt"; - if (create_file(file_path) < 0) + if (create_file(file_path) < 0) { return -1; - if (fn(file_path) < 0) + } + if (fn(file_path) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/symlink/main.c b/test/symlink/main.c index 5ad5ed96..6a819cd7 100644 --- a/test/symlink/main.c +++ b/test/symlink/main.c @@ -28,7 +28,7 @@ static ssize_t get_path_by_fd(int fd, char *buf, ssize_t buf_len) { static int create_file(const char *file_path) { int fd; - int flags = O_RDONLY | O_CREAT| O_TRUNC; + int flags = O_RDONLY | O_CREAT | O_TRUNC; int mode = 00666; fd = open(file_path, flags, mode); @@ -87,7 +87,7 @@ static int __test_realpath(const char *file_path) { int ret; if (snprintf(dirc, sizeof(dirc), "%s", file_path) < 0 || - snprintf(basec, sizeof(dirc), "%s", file_path) < 0) { + snprintf(basec, sizeof(dirc), "%s", file_path) < 0) { THROW_ERROR("failed to copy file path"); } dir_name = dirname(dirc); @@ -115,12 +115,15 @@ typedef int(*test_readlink_func_t)(const char *); static int test_readlink_framework(test_readlink_func_t fn) { const char *file_path = "/root/test_filesystem_symlink.txt"; - if (create_file(file_path) < 0) + if (create_file(file_path) < 0) { return -1; - if (fn(file_path) < 0) + } + if (fn(file_path) < 0) { return -1; - if (remove_file(file_path) < 0) + } + if (remove_file(file_path) < 0) { return -1; + } return 0; } diff --git a/test/tls/main.c b/test/tls/main.c index a128aa99..bbe5d729 100644 --- a/test/tls/main.c +++ b/test/tls/main.c @@ -1,11 +1,11 @@ volatile int g_int = 0; -static void use_int(int* a) { +static void use_int(int *a) { g_int += *a; } __thread int tls_g_int = 0; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { use_int(&tls_g_int); return g_int; } diff --git a/test/truncate/main.c b/test/truncate/main.c index 12334971..b6b727ee 100644 --- a/test/truncate/main.c +++ b/test/truncate/main.c @@ -5,15 +5,15 @@ #include #include -int main(int argc, const char* argv[]) { - const char* FILE_NAME = "root/test_filesystem_truncate.txt"; +int main(int argc, const char *argv[]) { + const char *FILE_NAME = "root/test_filesystem_truncate.txt"; const int TRUNC_LEN = 256; const int TRUNC_LEN1 = 128; const int MODE_MASK = 0777; int ret; - int flags = O_WRONLY | O_CREAT| O_TRUNC; + int flags = O_WRONLY | O_CREAT | O_TRUNC; int mode = 00666; int fd = open(FILE_NAME, flags, mode); if (fd < 0) { diff --git a/test/uname/main.c b/test/uname/main.c index 18d64e31..f487ca8c 100644 --- a/test/uname/main.c +++ b/test/uname/main.c @@ -4,11 +4,11 @@ int main(void) { struct utsname name; uname(&name); - printf("sysname = %s\n", (const char*)&name.sysname); - printf("nodename = %s\n", (const char*)&name.nodename); - printf("release = %s\n", (const char*)&name.release); - printf("version = %s\n", (const char*)&name.version); - printf("machine = %s\n", (const char*)&name.machine); - printf("domainname = %s\n", (const char*)&name.__domainname); + printf("sysname = %s\n", (const char *)&name.sysname); + printf("nodename = %s\n", (const char *)&name.nodename); + printf("release = %s\n", (const char *)&name.release); + printf("version = %s\n", (const char *)&name.version); + printf("machine = %s\n", (const char *)&name.machine); + printf("domainname = %s\n", (const char *)&name.__domainname); return 0; } diff --git a/test/unix_socket/main.c b/test/unix_socket/main.c index b41d0c71..a98d93ba 100644 --- a/test/unix_socket/main.c +++ b/test/unix_socket/main.c @@ -64,8 +64,8 @@ int create_connceted_sockets_default(int *sockets) { } int verify_child_echo(int *connected_sockets) { - const char* child_prog = "/bin/hello_world"; - const char* child_argv[3] = { child_prog, ECHO_MSG, NULL }; + const char *child_prog = "/bin/hello_world"; + const char *child_argv[3] = { child_prog, ECHO_MSG, NULL }; int child_pid; posix_spawn_file_actions_t file_actions; @@ -74,7 +74,7 @@ int verify_child_echo(int *connected_sockets) { posix_spawn_file_actions_addclose(&file_actions, connected_sockets[1]); if (posix_spawn(&child_pid, child_prog, &file_actions, - NULL, (char*const*)child_argv, NULL) < 0) { + NULL, (char *const *)child_argv, NULL) < 0) { THROW_ERROR("failed to spawn a child process"); } @@ -124,24 +124,24 @@ int test_multiple_socketpairs() { int i; int ret = 0; - for(i = 0; i < PAIR_NUM; i++) { + for (i = 0; i < PAIR_NUM; i++) { if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets[i]) < 0) { THROW_ERROR("opening stream socket pair"); } - if(verify_connection(sockets[i][0], sockets[i][1]) < 0) { + if (verify_connection(sockets[i][0], sockets[i][1]) < 0) { ret = -1; goto cleanup; } - if(verify_connection(sockets[i][1], sockets[i][0]) < 0) { + if (verify_connection(sockets[i][1], sockets[i][0]) < 0) { ret = -1; goto cleanup; } } i--; cleanup: - for(; i >= 0; i--){ + for (; i >= 0; i--) { close(sockets[i][0]); close(sockets[i][1]); } @@ -156,8 +156,9 @@ typedef int(*create_connection_func_t)(int *); int test_connected_sockets_inter_process(create_connection_func_t fn) { int ret = 0; int sockets[2]; - if (fn(sockets) < 0) + if (fn(sockets) < 0) { return -1; + } ret = verify_child_echo(sockets); @@ -180,6 +181,6 @@ static test_case_t test_cases[] = { TEST_CASE(test_multiple_socketpairs), }; -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { return test_suite_run(test_cases, ARRAY_SIZE(test_cases)); } diff --git a/test/unix_socket_throughput/main.c b/test/unix_socket_throughput/main.c index 64bc2ff7..9817cd41 100644 --- a/test/unix_socket_throughput/main.c +++ b/test/unix_socket_throughput/main.c @@ -64,7 +64,7 @@ int create_client_socket() { return fd; } -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { size_t buf_size, total_bytes; if (argc >= 2) { buf_size = atol(argv[1]); @@ -75,7 +75,7 @@ int main(int argc, const char* argv[]) { total_bytes = atol(argv[2]); } else { // BUG: throughput fall down when buf_size > 65536 - total_bytes = buf_size > 65536? buf_size << 15: buf_size << 21; + total_bytes = buf_size > 65536 ? buf_size << 15 : buf_size << 21; } printf("buf_size = 0x%zx\n", buf_size); printf("total_bytes = 0x%zx\n", total_bytes); @@ -109,8 +109,8 @@ int main(int argc, const char* argv[]) { posix_spawn_file_actions_addclose(&file_actions, socket_wr_fd); int child_pid; - extern char ** environ; - char* new_argv[] = {"/bin/data_sink", NULL}; + extern char **environ; + char *new_argv[] = {"/bin/data_sink", NULL}; if (posix_spawn(&child_pid, "/bin/data_sink", &file_actions, NULL, new_argv, environ) < 0) { printf("ERROR: failed to spawn a child process\n"); diff --git a/tools/protect-integrity/App/App.cpp b/tools/protect-integrity/App/App.cpp index e7d0322c..c92c665b 100644 --- a/tools/protect-integrity/App/App.cpp +++ b/tools/protect-integrity/App/App.cpp @@ -113,25 +113,26 @@ static sgx_errlist_t sgx_errlist[] = { }; /* Check error conditions for loading enclave */ -static void print_error_message(sgx_status_t ret) -{ +static void print_error_message(sgx_status_t ret) { size_t idx = 0; - size_t ttl = sizeof sgx_errlist/sizeof sgx_errlist[0]; + size_t ttl = sizeof sgx_errlist / sizeof sgx_errlist[0]; for (idx = 0; idx < ttl; idx++) { - if(ret == sgx_errlist[idx].err) { - if(NULL != sgx_errlist[idx].sug) + if (ret == sgx_errlist[idx].err) { + if (NULL != sgx_errlist[idx].sug) { printf("Info: %s\n", sgx_errlist[idx].sug); + } printf("Error: %s\n", sgx_errlist[idx].msg); break; } } - if (idx == ttl) + if (idx == ttl) { printf("Error: Unexpected error occurred.\n"); + } } -static const char* get_enclave_absolute_path() { +static const char *get_enclave_absolute_path() { static char enclave_path[MAX_PATH] = {0}; // Get the absolute path of the executable readlink("/proc/self/exe", enclave_path, sizeof(enclave_path)); @@ -140,7 +141,7 @@ static const char* get_enclave_absolute_path() { // Get the absolute path of the enclave strncat(enclave_path, "/../lib/", sizeof(enclave_path)); strncat(enclave_path, ENCLAVE_FILENAME, sizeof(enclave_path)); - return (const char*)enclave_path; + return (const char *)enclave_path; } /* Initialize the enclave: @@ -148,8 +149,7 @@ static const char* get_enclave_absolute_path() { * Step 2: call sgx_create_enclave to initialize an enclave instance * Step 3: save the launch token if it is updated */ -static int initialize_enclave(void) -{ +static int initialize_enclave(void) { char token_path[MAX_PATH] = {'\0'}; sgx_launch_token_t token = {0}; sgx_status_t ret = SGX_ERROR_UNEXPECTED; @@ -162,11 +162,11 @@ static int initialize_enclave(void) const char *home_dir = getpwuid(getuid())->pw_dir; if (home_dir != NULL && - (strlen(home_dir)+strlen("/")+sizeof(TOKEN_FILENAME)+1) <= MAX_PATH) { + (strlen(home_dir) + strlen("/") + sizeof(TOKEN_FILENAME) + 1) <= MAX_PATH) { /* compose the token path */ strncpy(token_path, home_dir, strlen(home_dir)); strncat(token_path, "/", strlen("/")); - strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)+1); + strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME) + 1); } else { /* if token path is too long or $HOME is NULL */ strncpy(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)); @@ -189,27 +189,29 @@ static int initialize_enclave(void) /* Step 2: call sgx_create_enclave to initialize an enclave instance */ /* Debug Support: set 2nd parameter to 1 */ - const char* enclave_path = get_enclave_absolute_path(); - ret = sgx_create_enclave(enclave_path, SGX_DEBUG_FLAG, &token, &updated, &global_eid, NULL); + const char *enclave_path = get_enclave_absolute_path(); + ret = sgx_create_enclave(enclave_path, SGX_DEBUG_FLAG, &token, &updated, &global_eid, + NULL); if (ret != SGX_SUCCESS) { print_error_message(ret); - if (fp != NULL) fclose(fp); + if (fp != NULL) { fclose(fp); } return -1; } /* Step 3: save the launch token if it is updated */ if (updated == 0 || fp == NULL) { /* if the token is not updated, or file handler is invalid, do not perform saving */ - if (fp != NULL) fclose(fp); + if (fp != NULL) { fclose(fp); } return 0; } /* reopen the file with write capablity */ fp = freopen(token_path, "wb", fp); - if (fp == NULL) return 0; + if (fp == NULL) { return 0; } size_t write_num = fwrite(token, 1, sizeof(sgx_launch_token_t), fp); - if (write_num != sizeof(sgx_launch_token_t)) + if (write_num != sizeof(sgx_launch_token_t)) { printf("Warning: Failed to save launch token to \"%s\".\n", token_path); + } fclose(fp); return 0; } @@ -226,15 +228,15 @@ void ocall_eprint(const char *str) { fprintf(stderr, "%s", str); } -int ocall_open(const char* path) { +int ocall_open(const char *path) { return open(path, O_RDONLY); } -ssize_t ocall_read(int fd, void* buf, size_t size) { +ssize_t ocall_read(int fd, void *buf, size_t size) { return read(fd, buf, size); } -ssize_t ocall_write(int fd, const void* buf, size_t size) { +ssize_t ocall_write(int fd, const void *buf, size_t size) { return write(fd, buf, size); } @@ -262,25 +264,21 @@ static void print_help(void) { #define CMD_SHOW_MAC 2 static int parse_args( - /* inputs */ - int argc, - char* argv[], - /* outputs */ - int* arg_command, - char** arg_file_path) -{ - if (argc != 3) return -1; + /* inputs */ + int argc, + char *argv[], + /* outputs */ + int *arg_command, + char **arg_file_path) { + if (argc != 3) { return -1; } if (strcmp(argv[1], "protect") == 0) { *arg_command = CMD_PROTECT; - } - else if (strcmp(argv[1], "show") == 0) { + } else if (strcmp(argv[1], "show") == 0) { *arg_command = CMD_SHOW; - } - else if (strcmp(argv[1], "show-mac") == 0) { + } else if (strcmp(argv[1], "show-mac") == 0) { *arg_command = CMD_SHOW_MAC; - } - else { + } else { return -1; } @@ -295,7 +293,7 @@ static int parse_args( int SGX_CDECL main(int argc, char *argv[]) { /* Parse arguments */ int arg_command = CMD_ERROR; - char* arg_file_path = NULL; + char *arg_file_path = NULL; if (parse_args(argc, argv, &arg_command, &arg_file_path) < 0) { print_help(); return -1; @@ -309,14 +307,14 @@ int SGX_CDECL main(int argc, char *argv[]) { /* Do the command */ int ret = 0; - switch(arg_command){ + switch (arg_command) { case CMD_PROTECT: { - const char* input_path = arg_file_path; + const char *input_path = arg_file_path; - const char* output_ext = ".protected"; + const char *output_ext = ".protected"; size_t output_path_len = strlen(input_path) + strlen(output_ext) + 1; - char* output_path = (char*) malloc(output_path_len); + char *output_path = (char *) malloc(output_path_len); strncpy(output_path, input_path, output_path_len); strncat(output_path, output_ext, output_path_len); @@ -327,7 +325,7 @@ int SGX_CDECL main(int argc, char *argv[]) { break; } case CMD_SHOW: { - const char* input_path = arg_file_path; + const char *input_path = arg_file_path; if (ecall_show(global_eid, &ret, input_path)) { fprintf(stderr, "Error: ecall failed\n"); ret = -1; @@ -335,7 +333,7 @@ int SGX_CDECL main(int argc, char *argv[]) { break; } case CMD_SHOW_MAC: { - const char* input_path = arg_file_path; + const char *input_path = arg_file_path; if (ecall_show_mac(global_eid, &ret, input_path)) { fprintf(stderr, "Error: ecall failed\n"); ret = -1; diff --git a/tools/protect-integrity/Enclave/Enclave.cpp b/tools/protect-integrity/Enclave/Enclave.cpp index 1bfc667a..6bd3e2c0 100644 --- a/tools/protect-integrity/Enclave/Enclave.cpp +++ b/tools/protect-integrity/Enclave/Enclave.cpp @@ -10,7 +10,7 @@ #define PRINTF_BUFSIZE 512 -static int printf(const char* fmt, ...) { +static int printf(const char *fmt, ...) { char buf[PRINTF_BUFSIZE] = {0}; va_list args; va_start(args, fmt); @@ -20,7 +20,7 @@ static int printf(const char* fmt, ...) { return 0; } -static int eprintf(const char* fmt, ...) { +static int eprintf(const char *fmt, ...) { char buf[PRINTF_BUFSIZE] = {0}; va_list args; va_start(args, fmt); @@ -30,29 +30,29 @@ static int eprintf(const char* fmt, ...) { return 0; } -static void print_mac(sgx_aes_gcm_128bit_tag_t* mac) { - unsigned char* bytes = (unsigned char*) mac; +static void print_mac(sgx_aes_gcm_128bit_tag_t *mac) { + unsigned char *bytes = (unsigned char *) mac; for (size_t bi = 0; bi < sizeof(*mac); bi++) { - if (bi != 0) printf("-"); + if (bi != 0) { printf("-"); } printf("%02x", bytes[bi] & 0xFF); } printf("\n"); } -static int open(const char* path) { +static int open(const char *path) { int fd = 0; ocall_open(&fd, path); return fd; } -static ssize_t read(int fd, void* buf, size_t size) { +static ssize_t read(int fd, void *buf, size_t size) { ssize_t ret = 0; ocall_read(&ret, fd, buf, size); return ret; } -static ssize_t write(int fd, const void* buf, size_t size) { +static ssize_t write(int fd, const void *buf, size_t size) { ssize_t ret = 0; ocall_write(&ret, fd, buf, size); return ret; @@ -68,9 +68,9 @@ static int close(int fd) { // ECalls // ========================================================================== -int ecall_protect(const char* input_path, const char* output_path) { +int ecall_protect(const char *input_path, const char *output_path) { int input_file = -1; - SGX_FILE* output_file = NULL; + SGX_FILE *output_file = NULL; size_t len; char buf[4 * 1024]; @@ -107,8 +107,8 @@ on_error: return -1; } -int ecall_show(const char* protected_file_path) { - SGX_FILE* protected_file = NULL; +int ecall_show(const char *protected_file_path) { + SGX_FILE *protected_file = NULL; ssize_t len; char buf[4 * 1024]; @@ -136,8 +136,8 @@ on_error: return -1; } -int ecall_show_mac(const char* protected_file_path) { - SGX_FILE* protected_file = NULL; +int ecall_show_mac(const char *protected_file_path) { + SGX_FILE *protected_file = NULL; sgx_aes_gcm_128bit_tag_t mac = { 0 }; protected_file = sgx_fopen_integrity_only(protected_file_path, "r");