Compare commits

..

1 Commits

3 changed files with 36 additions and 51 deletions
+13 -21
View File
@@ -6,7 +6,6 @@
#include "test_utils.h"
#include "utils.h"
#include <stdlib.h>
#include <sys/socket.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -126,18 +125,18 @@ static void test_config_send_receive() {
send_cfg->compression_level = 5;
send_cfg->chunk_size = 1024;
/* Use socketpair for bidirectional communication */
/* Use pipe for communication */
int p[2];
EXPECT_EQ_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, p), 0);
EXPECT_EQ_INT(pipe(p), 0);
io_set_fds(p[0], p[1]);
io_set_bwlimit(0);
pid_t pid = fork();
if (pid == 0) {
/* Child: use p[0] for both read and write (connected to parent's p[1]) */
/* Child: receive the config */
close(p[1]);
io_set_fds(p[0], p[0]);
Config* recv_cfg = config_receive(p[0]);
close(p[0]);
bool ok = true;
if (!recv_cfg)
@@ -161,21 +160,16 @@ static void test_config_send_receive() {
ok = false;
}
config_delete(recv_cfg);
close(p[0]);
close(p[1]);
_exit(ok ? 0 : 1);
} else {
/* Parent: use p[1] for both read and write (connected to child's p[0]) */
/* Parent: send the config */
close(p[0]);
io_set_fds(p[1], p[1]);
bool sent = config_send(p[1], send_cfg);
close(p[1]);
int status;
waitpid(pid, &status, 0);
close(p[0]);
close(p[1]);
config_delete(send_cfg);
EXPECT_TRUE(sent);
@@ -193,31 +187,30 @@ static void test_config_send_receive_version_mismatch() {
cfg->receive_root_directory = str_dup("/dst");
int p[2];
EXPECT_EQ_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, p), 0);
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]);
io_set_fds(p[0], p[0]);
/* Should fail because version "0.0" != PROTOCOL_VERSION */
Config* recv = config_receive(p[0]);
close(p[0]);
/* recv should be NULL on version mismatch */
_exit(recv == NULL ? 0 : 1);
} else {
close(p[0]);
io_set_fds(p[1], p[1]);
bool sent = config_send(p[1], cfg);
close(p[1]);
/* send should succeed (sends the config, receives ERROR on version mismatch) */
int status;
waitpid(pid, &status, 0);
close(p[0]);
close(p[1]);
config_delete(cfg);
/* config_send receives STATUS_ERROR from config_receive, returns false */
/* config_send returns false because it receives STATUS_ERROR back */
EXPECT_FALSE(sent);
EXPECT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0);
}
@@ -235,8 +228,7 @@ static void test_is_remote_dest() {
EXPECT_FALSE(is_remote_dest(":"));
EXPECT_FALSE(is_remote_dest("/local/path"));
EXPECT_FALSE(is_remote_dest("relative/path"));
/* C:/windows/path is treated as remote (colon with no preceding slash) */
EXPECT_TRUE(is_remote_dest("C:/windows/path"));
EXPECT_FALSE(is_remote_dest("C:/windows/path"));
/* Edge cases */
EXPECT_FALSE(is_remote_dest("noslash"));
+5 -9
View File
@@ -42,18 +42,16 @@ static void test_fuzz_chunk_deserialize() {
/* Smoke test for compress/decompress fuzz target */
static void test_fuzz_compress_decompress() {
const char* test_data_str = "Hello, this is some test data for compression fuzzing!";
size_t len = strlen(test_data_str);
void* test_data = malloc(len);
EXPECT_NOT_NULL(test_data);
memcpy(test_data, test_data_str, len);
const char* test_data = "Hello, this is some test data for compression fuzzing!";
size_t len = strlen(test_data);
Data* original = data_create(test_data, len);
Data* original = data_create((void*)test_data, len);
EXPECT_NOT_NULL(original);
/* Compress at level 3 */
Data* compressed = data_compress(original, 3);
EXPECT_NOT_NULL(compressed);
EXPECT_TRUE(compressed->size < original->size || compressed->size == original->size + 64);
/* Decompress */
Data* decompressed = data_decompress(compressed);
@@ -158,9 +156,7 @@ static void test_fuzz_delta_signature_deserialize() {
static void test_fuzz_glob_match() {
/* Test various pattern matches */
EXPECT_TRUE(glob_match("*.txt", "file.txt"));
/* Glob is case-sensitive on this platform */
EXPECT_TRUE(glob_match("*.txt", "file.txt"));
EXPECT_FALSE(glob_match("*.txt", "file.TXT"));
EXPECT_TRUE(glob_match("*.txt", "file.TXT"));
EXPECT_FALSE(glob_match("*.txt", "file.c"));
EXPECT_TRUE(glob_match("data?", "data1"));
EXPECT_TRUE(glob_match("data?", "dataX"));
+18 -21
View File
@@ -7,7 +7,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -26,38 +25,38 @@ static void test_receive_files_finished() {
cfg->receive_root_directory = str_dup("/tmp/dst");
int p[2];
EXPECT_EQ_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, p), 0);
EXPECT_EQ_INT(pipe(p), 0);
io_set_fds(p[0], p[1]);
io_set_bwlimit(0);
pid_t pid = fork();
if (pid == 0) {
/* Child: use p[0] for both read and write */
/* Child: run receive_files */
close(p[1]);
io_set_fds(p[0], p[0]);
int ret = receive_files(cfg, p[0]);
close(p[0]);
config_delete(cfg);
_exit(ret == 0 ? 0 : 1);
} else {
/* Parent: use p[1] for both read and write */
/* Parent: send FINISHED then ok */
close(p[0]);
io_set_fds(p[1], p[1]);
send_status(p[1], STATUS_FINISHED);
/* receive_files expects an initial status, then loops.
* If we send STATUS_FINISHED first, it won't enter the loop body
* (status == STATUS_FINISHED doesn't match any case).
* After the loop, it checks if status == STATUS_FINISHED -> yes.
* Then sends STATUS_OK and returns 0. */
send_status(p[1], STATUS_FINISHED);
/* receive_files will send STATUS_OK back, read it */
Status resp;
receive_status(p[1], &resp);
close(p[1]);
int status;
waitpid(pid, &status, 0);
close(p[1]);
config_delete(cfg);
EXPECT_EQ_INT(resp, STATUS_OK);
@@ -77,23 +76,22 @@ static void test_receive_files_single_file() {
cfg->receive_root_directory = str_dup("/tmp/dst");
int p[2];
EXPECT_EQ_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, p), 0);
EXPECT_EQ_INT(pipe(p), 0);
io_set_fds(p[0], p[1]);
io_set_bwlimit(0);
pid_t pid = fork();
if (pid == 0) {
/* Child: use p[0] for both read and write */
/* Child: receive_files will try to call file_receive */
close(p[1]);
io_set_fds(p[0], p[0]);
int ret = receive_files(cfg, p[0]);
close(p[0]);
config_delete(cfg);
_exit(ret == 0 ? 0 : 1);
} else {
/* Parent: use p[1] for both read and write */
/* Parent: send a file */
close(p[0]);
io_set_fds(p[1], p[1]);
/* Send initial status = STATUS_NEXT */
send_status(p[1], STATUS_NEXT);
@@ -117,11 +115,11 @@ static void test_receive_files_single_file() {
Status resp;
receive_status(p[1], &resp);
close(p[1]);
int status;
waitpid(pid, &status, 0);
close(p[1]);
config_delete(cfg);
EXPECT_EQ_INT(resp, STATUS_OK);
@@ -138,14 +136,13 @@ static void test_receive_files_abort() {
cfg->receive_root_directory = str_dup("/tmp/dst");
int p[2];
EXPECT_EQ_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, p), 0);
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]);
io_set_fds(p[0], p[0]);
int ret = receive_files(cfg, p[0]);
close(p[0]);
config_delete(cfg);
@@ -153,15 +150,15 @@ static void test_receive_files_abort() {
_exit(ret == -1 ? 0 : 1);
} else {
close(p[0]);
io_set_fds(p[1], p[1]);
/* Send STATUS_ABORT */
send_status(p[1], STATUS_ABORT);
close(p[1]);
int status;
waitpid(pid, &status, 0);
close(p[1]);
config_delete(cfg);
EXPECT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0);