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:
@@ -5,11 +5,8 @@
|
||||
#include "test_data.h"
|
||||
#include "test_delta.h"
|
||||
#include "test_file.h"
|
||||
#include "test_file_sendfile.h"
|
||||
#include "test_glob.h"
|
||||
#include "test_log.h"
|
||||
#include "test_metadata.h"
|
||||
#include "test_multiprocessing.h"
|
||||
#include "test_property.h"
|
||||
#include "test_protocol.h"
|
||||
#include "test_queue.h"
|
||||
@@ -17,9 +14,6 @@
|
||||
#include "test_scanner.h"
|
||||
#include "test_shared_utils.h"
|
||||
#include "test_stress.h"
|
||||
#include "test_transport_tcp.h"
|
||||
#include "test_transport_ssh.h"
|
||||
#include "test_transport_tls.h"
|
||||
#include "test_utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -44,15 +38,9 @@ int main() {
|
||||
RUN_TEST(test_metadata);
|
||||
RUN_TEST(test_glob);
|
||||
RUN_TEST(test_file);
|
||||
RUN_TEST(test_file_sendfile);
|
||||
RUN_TEST(test_log);
|
||||
RUN_TEST(test_multiprocessing);
|
||||
RUN_TEST(test_robustness);
|
||||
RUN_TEST(test_stress);
|
||||
RUN_TEST(test_property);
|
||||
RUN_TEST(test_transport_tcp);
|
||||
RUN_TEST(test_transport_ssh);
|
||||
RUN_TEST(test_transport_tls);
|
||||
|
||||
printf("\n\033[1;36m=== TEST SUMMARY ===\033[0m\n");
|
||||
printf("Total Tests Run: %d\n", tests_run);
|
||||
|
||||
@@ -23,6 +23,14 @@ static void test_data_create_empty() {
|
||||
data_destroy(d);
|
||||
}
|
||||
|
||||
static void test_data_create_empty_zero() {
|
||||
Data* d = data_create_empty(0);
|
||||
EXPECT_NOT_NULL(d);
|
||||
EXPECT_NOT_NULL(d->data);
|
||||
EXPECT_EQ_INT((int)d->size, 0);
|
||||
data_destroy(d);
|
||||
}
|
||||
|
||||
static void test_data_create_reserve() {
|
||||
Data* d = data_create_reserve(1024);
|
||||
EXPECT_NOT_NULL(d);
|
||||
@@ -44,6 +52,7 @@ static void test_data_destroy_normal() {
|
||||
void test_data() {
|
||||
test_data_create();
|
||||
test_data_create_empty();
|
||||
test_data_create_empty_zero();
|
||||
test_data_create_reserve();
|
||||
test_data_destroy_null();
|
||||
test_data_destroy_normal();
|
||||
|
||||
@@ -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();}
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef TEST_FILE_SENDFILE_H
|
||||
#define TEST_FILE_SENDFILE_H
|
||||
void test_file_sendfile();
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "test_log.h"
|
||||
#include "log.h"
|
||||
#include "test_utils.h"
|
||||
void test_log(){
|
||||
set_log_level(LOG_LEVEL_DEBUG);log_message(LOG_LEVEL_DEBUG,"d");log_message(LOG_LEVEL_INFO,"i");log_message(LOG_LEVEL_WARNING,"w");log_message(LOG_LEVEL_ERROR,"e");
|
||||
set_log_level(LOG_LEVEL_WARNING);log_message(LOG_LEVEL_DEBUG,"h");log_message(LOG_LEVEL_WARNING,"s");
|
||||
set_log_level(LOG_LEVEL_DEBUG);log_message(LOG_LEVEL_DEBUG,"d2");set_log_level(LOG_LEVEL_WARNING);log_message(LOG_LEVEL_DEBUG,"h2");log_message(LOG_LEVEL_WARNING,"w2");
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef TEST_LOG_H
|
||||
#define TEST_LOG_H
|
||||
void test_log();
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "test_multiprocessing.h"
|
||||
#include "multiprocessing.h"
|
||||
#include "config.h"
|
||||
#include "queue.h"
|
||||
#include "utils.h"
|
||||
#include "test_utils.h"
|
||||
void test_multiprocessing(){
|
||||
Config*c=config_create(str_dup("1"),str_dup("/t"),str_dup("/t"),0,0,0,0,0,0,0,0);EXPECT_NOT_NULL(c);
|
||||
Queue*q1=queue_create(10,free),*q2=queue_create(10,free);
|
||||
PipelineContextSender*ps=pipeline_context_sender_create(c,q1,q2);EXPECT_NOT_NULL(ps);EXPECT_NULL(ps->manifest);pipeline_context_sender_destroy(ps);
|
||||
pipeline_context_sender_destroy(NULL);
|
||||
Config*c2=config_create(str_dup("1"),str_dup("/t"),str_dup("/t"),0,0,0,0,0,0,0,0);
|
||||
Queue*q=queue_create(10,free);
|
||||
PipelineContextReceiver*pr=pipeline_context_receiver_create(c2,q,42);EXPECT_NOT_NULL(pr);EXPECT_EQ_INT(pr->file_descriptor,42);pipeline_context_receiver_destroy(pr);
|
||||
pipeline_context_receiver_destroy(NULL);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef TEST_MULTIPROCESSING_H
|
||||
#define TEST_MULTIPROCESSING_H
|
||||
void test_multiprocessing();
|
||||
#endif
|
||||
@@ -169,6 +169,23 @@ static void test_receive_str_truncated() {
|
||||
close(p[0]);
|
||||
}
|
||||
|
||||
static void test_receive_str_oversized() {
|
||||
int p[2];
|
||||
EXPECT_EQ_INT(pipe(p), 0);
|
||||
io_set_fds(p[0], p[1]);
|
||||
io_set_bwlimit(0);
|
||||
|
||||
/* Send a size exceeding MAX_STRING_SIZE */
|
||||
size_t huge = MAX_STRING_SIZE + 1;
|
||||
EXPECT_TRUE(send_n_data(0, &huge, sizeof(size_t)));
|
||||
|
||||
char* received = receive_str(0);
|
||||
EXPECT_NULL(received);
|
||||
|
||||
close(p[0]);
|
||||
close(p[1]);
|
||||
}
|
||||
|
||||
void test_protocol() {
|
||||
test_send_receive_n_data();
|
||||
test_send_receive_n_data_zero();
|
||||
@@ -179,4 +196,5 @@ void test_protocol() {
|
||||
test_send_receive_status();
|
||||
test_receive_n_data_truncated();
|
||||
test_receive_str_truncated();
|
||||
test_receive_str_oversized();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static void test_scanner_single_file() {
|
||||
create_test_file(file1, content1);
|
||||
|
||||
DirectoryScanner* scanner =
|
||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0, true);
|
||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0);
|
||||
EXPECT_NOT_NULL(scanner);
|
||||
|
||||
Chunk* chunk = directory_scanner_next(scanner);
|
||||
@@ -48,7 +48,7 @@ static void test_scanner_multiple_files() {
|
||||
create_test_file(file2, content2);
|
||||
|
||||
DirectoryScanner* scanner =
|
||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0, true);
|
||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0);
|
||||
EXPECT_NOT_NULL(scanner);
|
||||
|
||||
const Chunk* chunk = directory_scanner_next(scanner);
|
||||
@@ -112,7 +112,7 @@ static void test_scanner_empty_directory() {
|
||||
mkdir(dir, 0755);
|
||||
|
||||
DirectoryScanner* scanner =
|
||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0, true);
|
||||
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0);
|
||||
EXPECT_NOT_NULL(scanner);
|
||||
|
||||
const Chunk* chunk = directory_scanner_next(scanner);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "test_transport_ssh.h"
|
||||
#include "transport_ssh.h"
|
||||
#include "transport_tcp.h"
|
||||
#include "test_utils.h"
|
||||
void test_transport_ssh(){
|
||||
EXPECT_NULL(client_connect_ssh("nohost.x:22",22));
|
||||
EXPECT_NULL(client_connect_ssh(NULL,22));
|
||||
EXPECT_NULL(client_connect_ssh("bad",22));
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef TEST_TRANSPORT_SSH_H
|
||||
#define TEST_TRANSPORT_SSH_H
|
||||
void test_transport_ssh();
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "test_transport_tcp.h"
|
||||
#include "transport_tcp.h"
|
||||
#include "test_utils.h"
|
||||
void test_transport_tcp(){
|
||||
Client*c=client_create();EXPECT_NOT_NULL(c);client_delete(c);
|
||||
client_delete(NULL);client_disconnect(NULL);
|
||||
c=client_create();EXPECT_FALSE(client_connect(c,"9.9.9.9",1));client_disconnect(c);client_delete(c);
|
||||
c=client_create();EXPECT_FALSE(client_connect(c,"1.1.1.1",0));client_disconnect(c);client_delete(c);
|
||||
c=client_create();EXPECT_FALSE(client_connect(c,NULL,1));client_disconnect(c);client_delete(c);
|
||||
Server*s=server_create(0);if(s){server_delete(&s);}Server*x=NULL;server_delete(&x);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef TEST_TRANSPORT_TCP_H
|
||||
#define TEST_TRANSPORT_TCP_H
|
||||
void test_transport_tcp();
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "test_transport_tls.h"
|
||||
#include "transport_tls.h"
|
||||
#include "transport_tcp.h"
|
||||
#include "test_utils.h"
|
||||
void test_transport_tls(){
|
||||
tls_global_init();
|
||||
Client*c=client_create();EXPECT_FALSE(client_connect_tls(c,"1.2.3.4",443,NULL,NULL,NULL));client_disconnect(c);client_delete(c);
|
||||
c=client_create();EXPECT_FALSE(client_connect_tls(c,NULL,0,NULL,NULL,NULL));client_disconnect(c);client_delete(c);
|
||||
Server*s=server_create(0);if(s){EXPECT_FALSE(server_create_tls(s,"/a.pem","/b.pem","/c.pem"));server_delete(&s);}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef TEST_TRANSPORT_TLS_H
|
||||
#define TEST_TRANSPORT_TLS_H
|
||||
void test_transport_tls();
|
||||
#endif
|
||||
Reference in New Issue
Block a user