-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add preadv and readv to fix erlang file reading (#2179)
* add preadv and readv to fix erlang file reading * changelog * .. * cr * lint * Add readv test. * Handle null pointer being passed to us. * fix testS * CR --------- Co-authored-by: meowjesty <[email protected]>
- Loading branch information
Showing
6 changed files
with
190 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add preadv and readv to fix erlang file reading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <stdio.h> | ||
#include <fcntl.h> | ||
#include <sys/uio.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <signal.h> | ||
|
||
|
||
/// Opens a test file, then tries to read (part) of it with `readv`. | ||
int main(int argc, char *argv[]) { | ||
printf("test issue 2178: START"); | ||
|
||
char first[4], second[8]; | ||
|
||
struct iovec iov[2]; | ||
|
||
int fd = open("/app/test.txt", O_RDONLY); | ||
if (fd == -1) { | ||
printf("test issue 2178: FAILED"); | ||
perror("open"); | ||
return 1; | ||
} | ||
|
||
memset(second, 0, 8); | ||
|
||
iov[0].iov_base = first; | ||
iov[0].iov_len = sizeof(first); | ||
iov[1].iov_base = second; | ||
iov[1].iov_len = sizeof(second); | ||
|
||
ssize_t result = readv(fd, iov, 2); | ||
if (result == -1) { | ||
printf("test issue 2178: FAILED"); | ||
perror("readv"); | ||
return 1; | ||
} | ||
|
||
|
||
if (memcmp(first, "abcd", 4) != 0) { | ||
printf("test issue 2178: FAILED"); | ||
printf("first: %s", first); | ||
return 1; | ||
} | ||
|
||
if (memcmp(second, "efgh\x00\x00\x00\x00", 8) != 0) { | ||
printf("test issue 2178: FAILED"); | ||
printf("second: %s", second); | ||
return 1; | ||
} | ||
|
||
ssize_t null_result = readv(fd, NULL, 2); | ||
if (null_result == -1) { | ||
printf("test issue 2178: expected `readv: Bad address`"); | ||
} | ||
|
||
close(fd); | ||
|
||
printf("test issue 2178: SUCCESS"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#![feature(assert_matches)] | ||
use std::{path::PathBuf, time::Duration}; | ||
|
||
use rstest::rstest; | ||
|
||
mod common; | ||
pub use common::*; | ||
|
||
#[rstest] | ||
#[tokio::test] | ||
#[timeout(Duration::from_secs(60))] | ||
async fn test_issue2178( | ||
#[values(Application::CIssue2178)] application: Application, | ||
dylib_path: &PathBuf, | ||
) { | ||
let (mut test_process, mut intproxy) = application | ||
.start_process_with_layer(dylib_path, Default::default(), None) | ||
.await; | ||
|
||
println!("waiting for file request."); | ||
|
||
intproxy | ||
.expect_file_open_with_read_flag("/app/test.txt", 3) | ||
.await; | ||
assert_eq!(intproxy.expect_only_file_read(3).await, 12); | ||
let file_data = "abcdefgh".as_bytes().to_vec(); | ||
intproxy.answer_file_read(file_data).await; | ||
intproxy.expect_file_close(3).await; | ||
|
||
test_process.wait_assert_success().await; | ||
test_process | ||
.assert_stdout_contains("test issue 2178: START") | ||
.await; | ||
test_process | ||
.assert_stdout_contains("test issue 2178: SUCCESS") | ||
.await; | ||
} |