fix: add unit test coverage for sendfile, log, multiprocessing, transport, scanner edge cases (#71, #63, #62, #56, #55)
CI / lint (pull_request) Failing after 2s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
CI / lint (pull_request) Failing after 2s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#include "test_file_sendfile.h"
|
||||
#include "file.h"
|
||||
#include "data.h"
|
||||
#include "protocol.h"
|
||||
#include "utils.h"
|
||||
#include "test_utils.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
static void t1() {
|
||||
const char*c="Hi";size_t l=2;
|
||||
EXPECT_TRUE(to_disk("tsf1",c,l));
|
||||
File*f=file_create("tsf1");EXPECT_NOT_NULL(f);
|
||||
f->data->size=l;f->data->data=malloc(l);memcpy(f->data->data,c,l);
|
||||
int p[2];EXPECT_EQ_INT(pipe(p),0);io_set_fds(p[0],p[1]);io_set_bwlimit(0);
|
||||
pid_t pid=fork();
|
||||
if(pid==0){close(p[1]);bool ok=1;unsigned long long rs;
|
||||
ok=ok&&receive_n_data(p[0],&rs,sizeof(rs));ok=ok&&((int)rs==(int)l);
|
||||
if(ok&&l>0){char*b=malloc(rs+1);if(b){ok=ok&&receive_n_data(p[0],b,rs);free(b);}}
|
||||
close(p[0]);_exit(ok?0:1);
|
||||
}else{close(p[0]);bool s=file_send_sendfile(f,p[1],0,0,0);close(p[1]);int st;waitpid(pid,&st,0);
|
||||
file_destroy(f);unlink("tsf1");EXPECT_TRUE(s);EXPECT_TRUE(WIFEXITED(st)&&WEXITSTATUS(st)==0);}
|
||||
}
|
||||
static void t2() {
|
||||
EXPECT_TRUE(to_disk("tsf2","",0));
|
||||
File*f=file_create("tsf2");f->data->size=0;
|
||||
int p[2];EXPECT_EQ_INT(pipe(p),0);io_set_fds(p[0],p[1]);io_set_bwlimit(0);
|
||||
pid_t pid=fork();
|
||||
if(pid==0){close(p[1]);bool ok=1;unsigned long long rs;ok=ok&&receive_n_data(p[0],&rs,sizeof(rs));ok=ok&&((int)rs==0);close(p[0]);_exit(ok?0:1);}
|
||||
else{close(p[0]);bool s=file_send_sendfile(f,p[1],0,0,0);close(p[1]);int st;waitpid(pid,&st,0);file_destroy(f);unlink("tsf2");EXPECT_TRUE(s);EXPECT_TRUE(WIFEXITED(st)&&WEXITSTATUS(st)==0);}
|
||||
}
|
||||
static void t3() {
|
||||
File*f=file_create("tsf3");f->data->size=100;f->data->data=malloc(100);
|
||||
int p[2];EXPECT_EQ_INT(pipe(p),0);io_set_fds(p[0],p[1]);io_set_bwlimit(0);close(p[0]);
|
||||
bool s=file_send_sendfile(f,p[1],0,0,0);close(p[1]);file_destroy(f);EXPECT_FALSE(s);
|
||||
}
|
||||
void test_file_sendfile(){t1();t2();t3();}
|
||||
Reference in New Issue
Block a user