mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-10 13:56:48 +00:00
Format code manually for regression tests
This commit is contained in:
parent
82de200d03
commit
42881bcdaa
@ -15,4 +15,4 @@ int main()
|
||||
printf("Should not print\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ int main(int argc, char *argv[], char *envp[])
|
||||
printf("%s\n", envp[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,4 @@ int main()
|
||||
}
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,4 @@ int main()
|
||||
{
|
||||
printf("hello world from hello_c!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,4 @@ int main()
|
||||
{
|
||||
printf("hello world from hello_pie!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -38,4 +38,4 @@ int main()
|
||||
close(sockets[0]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,4 @@ int main()
|
||||
close(sockfd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -59,4 +59,4 @@ int main()
|
||||
// close socket
|
||||
close(sock_fd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ int main()
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// 关闭socket
|
||||
// Close socket
|
||||
close(sock_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -65,4 +65,4 @@ int main()
|
||||
close(client_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -372,4 +372,4 @@ int main()
|
||||
test_sigchld();
|
||||
test_sigaltstack();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user