mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
committed by
Tate, Hongliang Tian
parent
985813c7f9
commit
c5009e38f1
43
test/apps/pipe/short_rw.c
Normal file
43
test/apps/pipe/short_rw.c
Normal file
@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../network/test.h"
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
static void *page;
|
||||
static int rfd, wfd;
|
||||
|
||||
FN_SETUP(short_read_and_write)
|
||||
{
|
||||
int fildes[2];
|
||||
|
||||
page = mmap((void *)0x20000000, PAGE_SIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
|
||||
CHECK(page == NULL ? -1 : 0);
|
||||
|
||||
CHECK(pipe(fildes));
|
||||
rfd = fildes[0];
|
||||
wfd = fildes[1];
|
||||
|
||||
CHECK_WITH(write(wfd, "ab", 2), _ret == 2);
|
||||
}
|
||||
END_SETUP()
|
||||
|
||||
FN_TEST(short_read_and_write)
|
||||
{
|
||||
char *buf = page + PAGE_SIZE - 1;
|
||||
buf[0] = 'x';
|
||||
|
||||
TEST_ERRNO(read(rfd, buf, 2), EFAULT);
|
||||
|
||||
TEST_RES(read(rfd, buf, 1), _ret == 1 && buf[0] == 'a');
|
||||
|
||||
TEST_ERRNO(write(wfd, buf, 2), EFAULT);
|
||||
|
||||
TEST_RES(write(wfd, buf, 1), _ret == 1);
|
||||
}
|
||||
END_TEST()
|
@ -62,4 +62,5 @@ test_fdatasync
|
||||
echo "All fdatasync test passed."
|
||||
|
||||
pipe/pipe_err
|
||||
pipe/short_rw
|
||||
epoll/epoll_err
|
||||
|
Reference in New Issue
Block a user