Format code manually for regression tests

This commit is contained in:
Ruihan Li 2024-03-16 00:28:37 +08:00 committed by Tate, Hongliang Tian
parent 82de200d03
commit 42881bcdaa
13 changed files with 37 additions and 36 deletions

View File

@ -15,4 +15,4 @@ int main()
printf("Should not print\n");
fflush(stdout);
return 0;
}
}

View File

@ -16,4 +16,4 @@ int main(int argc, char *argv[], char *envp[])
printf("%s\n", envp[i]);
}
return 0;
}
}

View File

@ -14,4 +14,4 @@ int main()
}
fflush(stdout);
return 0;
}
}

View File

@ -6,4 +6,4 @@ int main()
{
printf("hello world from hello_c!\n");
return 0;
}
}

View File

@ -6,4 +6,4 @@ int main()
{
printf("hello world from hello_pie!\n");
return 0;
}
}

View File

@ -38,4 +38,4 @@ int main()
close(sockets[0]);
}
return 0;
}
}

View File

@ -76,4 +76,4 @@ int main()
close(sockfd);
return 0;
}
}

View File

@ -59,4 +59,4 @@ int main()
// close socket
close(sock_fd);
return 0;
}
}

View File

@ -63,8 +63,8 @@ int main()
exit(EXIT_FAILURE);
}
// 关闭socket
// Close socket
close(sock_fd);
return 0;
}
}

View File

@ -65,4 +65,4 @@ int main()
close(client_fd);
return 0;
}
}

View File

@ -17,14 +17,14 @@ int main()
struct sockaddr_un server_addr, client_addr;
char buf[BUFFER_SIZE];
// 创建Server Socket
// Create the server socket
server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (server_fd == -1) {
perror("socket");
exit(EXIT_FAILURE);
}
// 绑定Socket地址
// Bind the socket address
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sun_family = AF_UNIX;
strncpy(server_addr.sun_path, SOCKET_NAME,
@ -36,7 +36,7 @@ int main()
exit(EXIT_FAILURE);
}
// 监听连接请求
// Listen for an incoming connection
if (listen(server_fd, 5) == -1) {
perror("listen");
exit(EXIT_FAILURE);
@ -44,7 +44,7 @@ int main()
printf("Server is listening...\n");
// 接收连接请求
// Accept the incoming connection
len = sizeof(client_addr);
accepted_fd = accept(server_fd, (struct sockaddr *)&client_addr, &len);
if (accepted_fd == -1) {
@ -64,7 +64,8 @@ int main()
printf("Server is connected to client\n");
char *mesg = "Hello from unix socket server";
write(accepted_fd, mesg, strlen(mesg));
// 读取客户端发送的数据并打印
// Read data from the client
memset(buf, 0, BUFFER_SIZE);
if (read(accepted_fd, buf, BUFFER_SIZE) == -1) {
perror("read");
@ -72,10 +73,10 @@ int main()
}
printf("Server Received: %s\n", buf);
// 关闭Socket
// Close the socket
close(accepted_fd);
close(server_fd);
unlink(SOCKET_NAME);
return 0;
}
}

View File

@ -64,19 +64,19 @@ static void *thread_func(void *_arg)
static int test_mutex_with_concurrent_counter(void)
{
/*
* Multiple threads are to increase a global counter concurrently
*/
* Multiple threads are to increase a global counter concurrently
*/
volatile unsigned long global_count = 0;
pthread_t threads[NTHREADS];
struct thread_arg thread_args[NTHREADS];
/*
* Protect the counter with a mutex
*/
* Protect the counter with a mutex
*/
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, NULL);
/*
* Start the threads
*/
* Start the threads
*/
for (int ti = 0; ti < NTHREADS; ti++) {
struct thread_arg *thread_arg = &thread_args[ti];
thread_arg->ti = ti;
@ -91,8 +91,8 @@ static int test_mutex_with_concurrent_counter(void)
}
}
/*
* Wait for the threads to finish
*/
* Wait for the threads to finish
*/
for (int ti = 0; ti < NTHREADS; ti++) {
if (pthread_join(threads[ti], NULL) < 0) {
printf("ERROR: pthread_join failed (ti = %d)\n", ti);
@ -100,8 +100,8 @@ static int test_mutex_with_concurrent_counter(void)
}
}
/*
* Check the correctness of the concurrent counter
*/
* Check the correctness of the concurrent counter
*/
if (global_count != EXPECTED_GLOBAL_COUNT) {
printf("ERROR: incorrect global_count (actual = %ld, expected = %ld)\n",
global_count, EXPECTED_GLOBAL_COUNT);
@ -247,8 +247,8 @@ static int test_mutex_with_cond_wait(void)
pthread_cond_t cond_val = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
/*
* Start the threads waiting on the condition variable
*/
* Start the threads waiting on the condition variable
*/
for (int ti = 0; ti < NTHREADS; ti++) {
struct thread_cond_arg *thread_arg = &thread_args[ti];
thread_arg->ti = ti;
@ -264,8 +264,8 @@ static int test_mutex_with_cond_wait(void)
}
}
/*
* Unblock all threads currently waiting on the condition variable
*/
* Unblock all threads currently waiting on the condition variable
*/
while (exit_thread_count < NTHREADS) {
pthread_mutex_lock(&mutex);
val = 1;
@ -277,8 +277,8 @@ static int test_mutex_with_cond_wait(void)
pthread_mutex_unlock(&mutex);
}
/*
* Wait for the threads to finish
*/
* Wait for the threads to finish
*/
for (int ti = 0; ti < NTHREADS; ti++) {
if (pthread_join(threads[ti], NULL) < 0) {
printf("ERROR: pthread_join failed (ti = %d)\n", ti);
@ -294,4 +294,4 @@ int main()
test_robust_mutex_with_concurrent_counter();
// test_mutex_with_cond_wait();
return 0;
}
}

View File

@ -372,4 +372,4 @@ int main()
test_sigchld();
test_sigaltstack();
return 0;
}
}