Skip to content

Commit

Permalink
Merge pull request #90 from thenetrunna/master
Browse files Browse the repository at this point in the history
fix sonic tests
  • Loading branch information
thenetrunna authored Apr 14, 2024
2 parents 1755004 + 5c235e9 commit 8b68596
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 60 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
run: make dev
- name: run tests
run: make test
- name: test libs
run: make test-libs

build-macos:
runs-on: macos-latest
Expand All @@ -28,5 +30,6 @@ jobs:
run: make dev
- name: run tests
run: make test
- name: test libs
run: make test-libs


54 changes: 29 additions & 25 deletions camel/src/camel.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../include/tuwi.h"

#include <netlibc/fs.h>
#include <netlibc/log.h>

#include <fcntl.h>
#include <pthread.h>
Expand All @@ -25,39 +26,42 @@
#include <unistd.h>

bool __files_equal(char *first_file, char *second_file) {
char command1[1024]; // Buffer for the first checksum command
char command2[1024]; // Buffer for the second checksum command
FILE *file1 = fopen(first_file, "rb");
FILE *file2 = fopen(second_file, "rb");

// Create the shell command to calculate the checksum of file1
snprintf(command1, sizeof(command1), "md5sum \"%s\" 2>/dev/null", first_file);
if (file1 == NULL || file2 == NULL) {
perror("Error opening file");
PANIC("could not open files");
}

int byte1;
int byte2;
bool equal = true;

// Create the shell command to calculate the checksum of file2
snprintf(command2, sizeof(command2), "md5sum \"%s\" 2>/dev/null",
second_file);
while (1) {
byte1 = fgetc(file1);
byte2 = fgetc(file2);

// Execute the shell commands using popen and capture their output
FILE *fp1 = popen(command1, "r");
FILE *fp2 = popen(command2, "r");
if (byte1 == EOF || byte2 == EOF) {
break;
}

if (fp1 == NULL || fp2 == NULL) {
perror("popen");
exit(EXIT_FAILURE);
if (byte1 != byte2) {
equal = false;
break;
}
}

char checksum1[32], checksum2[32]; // Buffer to store checksums
fgets(checksum1, sizeof(checksum1), fp1);
fgets(checksum2, sizeof(checksum2), fp2);
// Check if both files have reached EOF at the same time
if (byte1 != EOF || byte2 != EOF) {
LOG(INFO, "THIS!");
equal = false;
}

// Close the file pointers
pclose(fp1);
pclose(fp2);
fclose(file1);
fclose(file2);

// Compare the checksums
if (strcmp(checksum1, checksum2) == 0) {
return true; // Checksums match
} else {
return false; // Checksums do not match
}
return equal;
}

char *__read_file(char *path) {
Expand Down
2 changes: 1 addition & 1 deletion makefiles/test.mk

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 28 additions & 24 deletions sonic/tests/client/makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions sonic/tests/server/makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b68596

Please sign in to comment.